From 3ca6c44a944213e42f6f99f680c42f68cdbe3131 Mon Sep 17 00:00:00 2001 From: ework-agent Date: Wed, 21 Oct 2026 21:51:01 +0800 Subject: [PATCH 01/16] web: rotate pathologically wide compression trees instead of shrinking them to smears (#4173) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 大会话(如 dsh 主会话,180 个压缩块)的「压缩结构」树图实测平铺布局 21558px 宽 x 204px 高,fit-to-card 缩放系数 0.052 —— 每个 118x36 的方块 渲染为约 6px 的像素点,完全不可读。根因:blockGraphLayout 的宽度由叶子数 决定,而 buildGraphSvg 一律 fit = min(1, 1120/W)。 The tree now rotates when the flat width overflows the card AND the rotated long dimension is shorter: depth becomes the x-axis, sibling stacks pile along y at full box size inside the pane's existing 70vh scroll area. Same fixture: 414px wide x 8356px tall, all 180 nodes + 104 edges intact. Small/narrow trees render byte-identically to before (rotation is only considered once flat width exceeds GRAPH_FIT_W). New det.tree_graph_hint_lr names the left-to-right reading direction; the hint switches per orientation. --- src/web/client.ts | 96 ++++++++++++++++++++++++++++------- src/web/i18n.ts | 2 + tests/web-blocks-tree.test.ts | 41 +++++++++++++++ 3 files changed, 121 insertions(+), 18 deletions(-) diff --git a/src/web/client.ts b/src/web/client.ts index e536a0f5bc..a10dd9cd89 100644 --- a/src/web/client.ts +++ b/src/web/client.ts @@ -1823,11 +1823,14 @@ export const WEB_CLIENT = `(function () { }); return { children: children, roots: roots }; } - // #3917: at-a-glance view of the same folds. Layered top-down (roots on top, - // each fold one level below the block that absorbed it), edges drawn as - // beziers — a knowledge-graph-ish shape for reading structure, while the - // list view stays the place to read concrete messages. A wide tree is scaled - // to fit the card rather than hiding nodes behind a horizontal scroll. + // #3917: at-a-glance view of the same folds. Layered (roots first, each fold + // one level beyond the block that absorbed it), edges drawn as beziers — a + // knowledge-graph-ish shape for reading structure, while the list view stays + // the place to read concrete messages. Modest trees are scaled down to fit + // the card; pathologically WIDE ones used to be scaled the same way and + // became sub-pixel smears (a 161-leaf session fits ≈ 0.05 ⇒ 6px boxes), so + // those rotate: depth runs along x, sibling stacks pile along y at full node + // size (#4173). const GRAPH_NODE_W = 118; const GRAPH_NODE_H = 36; const GRAPH_GAP_X = 16; @@ -1865,23 +1868,78 @@ export const WEB_CLIENT = `(function () { if (!nodes.length) return { nodes: [], links: [], width: 0, height: 0 }; return { nodes: nodes, links: links, width: cursor - GRAPH_GAP_X, height: maxDepth * GRAPH_LEVEL_H + GRAPH_NODE_H }; } + // #4173: vertical mirror of blockGraphLayout — depth is the x-axis and the + // shared cursor packs sibling stacks along y. Chosen when a tree is far + // wider than it is tall: rotating puts the long dimension on the one axis + // the pane already scrolls (.tree-graph max-height:70vh overflow:auto) and + // keeps every box at its natural 118×36 size. + function blockGraphLayoutVertical(blocks) { + const shape = blockTreeShape(blocks); + const nodes = []; + const links = []; + let cursor = 0; + let maxDepth = 0; + const place = function (b, depth) { + if (depth > 40) return null; + const kids = shape.children[b.blockId] || []; + const childNodes = []; + kids.forEach(function (k) { + const kid = place(k, depth + 1); + if (kid) childNodes.push(kid); + }); + let y; + if (!childNodes.length) { + y = cursor; + cursor += GRAPH_NODE_H + GRAPH_GAP_X; + } else { + y = (childNodes[0].y + childNodes[childNodes.length - 1].y) / 2; + } + const node = { b: b, x: depth * (GRAPH_NODE_W + GRAPH_GAP_X), y: y }; + nodes.push(node); + if (depth > maxDepth) maxDepth = depth; + childNodes.forEach(function (c) { links.push([node, c]); }); + return node; + }; + const roots = shape.roots.length ? shape.roots : blocks; + roots.forEach(function (r) { place(r, 0); }); + if (!nodes.length) return { nodes: [], links: [], width: 0, height: 0 }; + return { nodes: nodes, links: links, width: maxDepth * (GRAPH_NODE_W + GRAPH_GAP_X) + GRAPH_NODE_W, height: cursor - GRAPH_GAP_X }; + } function buildGraphSvg(blocks) { - const layout = blockGraphLayout(blocks); - if (!layout.nodes.length) return ""; + const lh = blockGraphLayout(blocks); + if (!lh.nodes.length) return { html: "", vertical: false }; + // #4173: only consider rotating once the flat width actually overflows + // the card, and only when the rotated long dimension is shorter than the + // flat one — small trees stay byte-identical to the original rendering. + const lv = lh.width > GRAPH_FIT_W ? blockGraphLayoutVertical(blocks) : null; + const vertical = !!lv && lv.height < lh.width; + const layout = vertical ? lv : lh; const pad = 14; - const half = GRAPH_NODE_W / 2; + const halfW = GRAPH_NODE_W / 2; + const halfH = GRAPH_NODE_H / 2; const W = Math.ceil(layout.width + pad * 2); const H = Math.ceil(layout.height + pad * 2); const fit = W > GRAPH_FIT_W ? GRAPH_FIT_W / W : 1; const parts = []; - parts.push(''); + parts.push(''); layout.links.forEach(function (l) { - const x1 = l[0].x + pad + half; - const y1 = l[0].y + pad + GRAPH_NODE_H; - const x2 = l[1].x + pad + half; - const y2 = l[1].y + pad; - const my = (y1 + y2) / 2; - parts.push(''); + let d; + if (vertical) { + const x1 = l[0].x + pad + GRAPH_NODE_W; + const y1 = l[0].y + pad + halfH; + const x2 = l[1].x + pad; + const y2 = l[1].y + pad + halfH; + const mx = (x1 + x2) / 2; + d = "M" + x1 + " " + y1 + " C" + mx + " " + y1 + " " + mx + " " + y2 + " " + x2 + " " + y2; + } else { + const x1 = l[0].x + pad + halfW; + const y1 = l[0].y + pad + GRAPH_NODE_H; + const x2 = l[1].x + pad + halfW; + const y2 = l[1].y + pad; + const my = (y1 + y2) / 2; + d = "M" + x1 + " " + y1 + " C" + x1 + " " + my + " " + x2 + " " + my + " " + x2 + " " + y2; + } + parts.push(''); }); layout.nodes.forEach(function (n) { const b = n.b; @@ -1897,7 +1955,7 @@ export const WEB_CLIENT = `(function () { + ""); }); parts.push(""); - return parts.join(""); + return { html: parts.join(""), vertical: vertical }; } function refRangeOf(b) { if (!b.startRef) return ""; @@ -1984,8 +2042,10 @@ export const WEB_CLIENT = `(function () { parts.push(""); parts.push('
' + t("det.tree_hint") + "
"); parts.push(""); - parts.push('"); + const graph = buildGraphSvg(blocks); + const graphHint = graph.vertical ? t("det.tree_graph_hint_lr") : t("det.tree_graph_hint"); + parts.push('"); parts.push(""); return parts.join(""); } diff --git a/src/web/i18n.ts b/src/web/i18n.ts index 341db2c4a4..b518294a04 100644 --- a/src/web/i18n.ts +++ b/src/web/i18n.ts @@ -397,6 +397,7 @@ export const MESSAGES: Record> = { "det.tree_view_list": "列表", "det.tree_view_graph": "树图", "det.tree_graph_hint": "整体形状:每个方块是一个压缩块,从上到下是「谁压缩了谁」。点方块跳到列表里对应的一行。", + "det.tree_graph_hint_lr": "整体形状:每个方块是一个压缩块,从左到右是「谁压缩了谁」(此树很宽,已转为竖向排布,完整尺寸滚动查看)。点方块跳到列表里对应的一行。", "det.tree_graph_legend": "实线框=活跃,虚线框=已归档", "det.handoff": "会话交接文档", "det.handoff_hint": "与 bili export 相同的内容 —— 复制粘贴到新会话即可继续", @@ -934,6 +935,7 @@ export const MESSAGES: Record> = { "det.tree_view_list": "List", "det.tree_view_graph": "Tree map", "det.tree_graph_hint": "Overall shape: each box is one block, top-down is which block folded which. Click a box to jump to that row in the list.", + "det.tree_graph_hint_lr": "Overall shape: each box is one block, left-to-right is which block folded which (this tree is very wide, so it is laid out vertically at full box size — scroll to see all of it). Click a box to jump to that row in the list.", "det.tree_graph_legend": "solid border = active, dashed = archived", "det.handoff": "Handoff document", "det.handoff_hint": "Same content as bili export — paste into a new session to continue", diff --git a/tests/web-blocks-tree.test.ts b/tests/web-blocks-tree.test.ts index 5257669e45..23b0323065 100644 --- a/tests/web-blocks-tree.test.ts +++ b/tests/web-blocks-tree.test.ts @@ -189,6 +189,7 @@ test("#3917: the tree's strings exist in both locales with identical placeholder "det.tree_view_list", "det.tree_view_graph", "det.tree_graph_hint", + "det.tree_graph_hint_lr", "det.tree_graph_legend", ]; const placeholders = (s: string) => (s.match(/\{[a-z]+\}/g) ?? []).sort().join(","); @@ -208,8 +209,48 @@ test("#3917: the web client bundle stays parseable JS after the tree additions", // the graph reading of the same folds: layered boxes + list⇄graph switch assert.match(WEB_CLIENT, /function buildGraphSvg\(blocks\)/); assert.match(WEB_CLIENT, /function blockGraphLayout\(blocks\)/); + // #4173: pathologically wide trees rotate instead of shrinking to sub-pixel + assert.match(WEB_CLIENT, /function blockGraphLayoutVertical\(blocks\)/); + assert.match(WEB_CLIENT, /g-svg-v/); + assert.match(WEB_CLIENT, /det\.tree_graph_hint_lr/); assert.match(WEB_CLIENT, /"g-node tier-" \+/); assert.match(WEB_CLIENT, /data-mode="graph"/); assert.match(WEB_CLIENT, /id="tree-graph"/); assert.match(WEB_CLIENT, /\.block-node\[data-bid=/); }); + +// #4173: run the actual layout/graph code from the bundle against fixtures. +test("#4173: wide trees rotate to vertical full-size instead of shrinking to smears", () => { + const start = WEB_CLIENT.indexOf("function blockTreeShape("); + const end = WEB_CLIENT.indexOf("function refRangeOf("); + assert.ok(start > 0 && end > start, "graph section anchors present in the bundle"); + const stubs = "var escapeHtml=function(s){return String(s);};var fmtW=function(n){return String(n);};var blockTopic=function(b){return b.topic||'';};var t=function(k){return k;};"; + const ctx = vm.createContext({}); + vm.runInContext(stubs + WEB_CLIENT.slice(start, end) + "this.api={blockGraphLayout:blockGraphLayout,blockGraphLayoutVertical:blockGraphLayoutVertical,buildGraphSvg:buildGraphSvg};;this.api", ctx, { filename: "web-graph.js" }); + const api = ctx.api; + + // 30 independent T1 roots → flat row 4004px wide: the old code fit-scaled it + // to ≈ 33px boxes; now it must rotate. + const wide = []; + for (let i = 0; i < 30; i++) wide.push({ blockId: "b" + i, tier: 1, active: true, parentBlockId: undefined }); + const res = api.buildGraphSvg(wide); + assert.equal(res.vertical, true, "a 30-root flat tree rotates"); + assert.match(res.html, /class="g-svg g-svg-v"/); + assert.ok((res.html.match(/data-bid=/g) || []).length === 30, "rotation keeps every node"); + const m = res.html.match(/ width="(\d+)" height="(\d+)"/); + assert.ok(m, "svg carries explicit dimensions"); + // vertical extent ≈ 30 slots × 52 − gap (+padding), rendered UNscaled (width axis ~3 levels) + assert.ok(Number(m[1]) < 600, "long dimension moved off the width axis (got " + m[1] + "px)"); + assert.ok(Number(m[2]) >= 1400, "height holds the 30 stacked nodes near natural size (got " + m[2] + "px)"); + + // small deep chain: stays top-down, byte-level unchanged rendering path + const chain = [{ blockId: "c1", tier: 1, active: true, parentBlockId: undefined }, { blockId: "c2", tier: 2, active: true, parentBlockId: "c1" }, { blockId: "c3", tier: 3, active: true, parentBlockId: "c2" }]; + const small = api.buildGraphSvg(chain); + assert.equal(small.vertical, false, "a narrow chain does not rotate"); + assert.doesNotMatch(small.html, /g-svg-v/); + assert.ok(small.html.includes('viewBox="0 0'), "still an svg"); + + // empty tree keeps the old falsy contract via {html:""} + const none = api.buildGraphSvg([]); + assert.equal(none.html, ""); +}); From beaba8c424cefbeb2adb239bea5ca0b54d0f3431 Mon Sep 17 00:00:00 2001 From: ework-agent Date: Wed, 21 Oct 2026 22:46:10 +0800 Subject: [PATCH 02/16] web: live tree thumbnail in the session page head (#4173) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit A small always-visible minimap of the compression tree sits in the top-right corner of the session detail page and refreshes itself while the session is live — you can watch compressions land without opening the tab. - GET /__bili/sessions//tree: compact edge feed only (id/tier/active/ parent/fold edges, no summaries or refs) — a 180-block session ships ~6KB. Served by buildSessionTree() with the same first-parent-wins inversion the detail payload uses. - client.ts shares ONE orientation rule (graphLayouts) between the full graph and the new rect-only thumbnail, plus one bezier helper (graphEdgePath), so both drawings always agree and wide trees rotate in the chip as well. - the chip joins the existing 5s poller on the detail view only; it is a decorative lane: failures keep the last good frame and never touch the error strip or the #1937 backoff ladder. Clicking it jumps into the Compression-Structure tab, switches to Tree-Graph mode, and scrolls there. - tests: server-side feed pin (edges wired, summaries never leave the wire, unknown session -> null), thumbnail invariants (no text nodes, width cap, rotation shared), i18n key pair, bundle wiring regexes. --- src/server/admin.ts | 24 ++++++- src/web/client.ts | 129 +++++++++++++++++++++++++++------- src/web/i18n.ts | 2 + src/web/index.ts | 4 +- src/web/sessions-data.ts | 34 +++++++++ src/web/styles.ts | 7 ++ tests/web-blocks-tree.test.ts | 41 ++++++++++- 7 files changed, 209 insertions(+), 32 deletions(-) diff --git a/src/server/admin.ts b/src/server/admin.ts index c585c13a57..14bcf5a0db 100644 --- a/src/server/admin.ts +++ b/src/server/admin.ts @@ -30,7 +30,7 @@ import { formatUpstreamError, getUpstreamConnectionStatus, proxyDispatcher, reco import { detectStaleInstall, getLastInstall } from "../update.js"; import { getPlannedUpgrade, getUpdatePolicyState } from "../update-policy.js"; import { PACKAGE_NAME, VERSION, BUILD_COMMIT } from "../version.js"; -import { buildBlockContent, buildMessageContent, buildOverview, buildSessionDetail, buildSessionList, buildSessionPage, handleConfigGet, handleConfigPut, hiddenEmptyCount, renderUI, type BlockContentView } from "../web/index.js"; +import { buildBlockContent, buildMessageContent, buildOverview, buildSessionDetail, buildSessionList, buildSessionPage, buildSessionTree, handleConfigGet, handleConfigPut, hiddenEmptyCount, renderUI, type BlockContentView } from "../web/index.js"; import { buildSessionReportMd, buildSessionReportSvg } from "../web/report.js"; import { queryLogLines } from "../web/logs-query.js"; import { buildDiagnostics } from "../web/diagnostics.js"; @@ -215,6 +215,8 @@ export async function handleAdminRoute(req: http.IncomingMessage, res: http.Serv if (req.method === "GET" && req.url?.startsWith("/__bili/logs")) return sendWebLogs(res, req); if (req.method === "GET" && req.url?.startsWith("/__bili/diagnostics")) return sendDiagnostics(res, req.url); if (req.method === "GET" && req.url?.startsWith("/__bili/sessions/") && req.url.endsWith("/detail")) return sendWebSessionDetail(res, req.url); + // #4173: compact fold-edge feed for the live tree thumbnail (5s client poll). + if (req.method === "GET" && req.url?.startsWith("/__bili/sessions/") && req.url.endsWith("/tree")) return sendWebSessionTree(res, req.url); // #3917: one block's original text for the 压缩结构 tree — lazy per click, so // the detail payload never carries whole originals. if (req.method === "GET" && req.url !== undefined && isBlockContentPath(req.url)) return sendWebBlockContent(res, req.url); @@ -1219,6 +1221,26 @@ async function sendWebSessionDetail(res: http.ServerResponse, url: string): Prom res.end(JSON.stringify(detail, null, 2)); } +// #4173: minimal edge set for the tree thumbnail — see buildSessionTree. +async function sendWebSessionTree(res: http.ServerResponse, url: string): Promise { + const prefix = "/__bili/sessions/"; + const suffix = "/tree"; + let id = ""; + try { + id = decodeURIComponent(url.slice(prefix.length, -suffix.length)); + } catch { + // malformed percent-encoding → unknown session (404 below) + } + const tree = await buildSessionTree(id); + if (!tree) { + res.writeHead(404, { "content-type": "application/json" }); + res.end(JSON.stringify({ error: `unknown session: ${id}` })); + return; + } + res.writeHead(200, { "content-type": "application/json", "cache-control": "no-store" }); + res.end(JSON.stringify(tree)); +} + // #3917: `/__bili/sessions//block-content?blockId=bN&view=one|full`. const BLOCK_CONTENT_PATH = "/block-content"; diff --git a/src/web/client.ts b/src/web/client.ts index a10dd9cd89..27dfd662ed 100644 --- a/src/web/client.ts +++ b/src/web/client.ts @@ -1905,41 +1905,46 @@ export const WEB_CLIENT = `(function () { if (!nodes.length) return { nodes: [], links: [], width: 0, height: 0 }; return { nodes: nodes, links: links, width: maxDepth * (GRAPH_NODE_W + GRAPH_GAP_X) + GRAPH_NODE_W, height: cursor - GRAPH_GAP_X }; } - function buildGraphSvg(blocks) { + // #4173: orientation shared by the full graph and the page-head thumbnail — + // flat unless the tree overflows the card AND rotation shortens the long + // dimension; small trees stay byte-identical to the original rendering. + function graphLayouts(blocks) { const lh = blockGraphLayout(blocks); - if (!lh.nodes.length) return { html: "", vertical: false }; - // #4173: only consider rotating once the flat width actually overflows - // the card, and only when the rotated long dimension is shorter than the - // flat one — small trees stay byte-identical to the original rendering. const lv = lh.width > GRAPH_FIT_W ? blockGraphLayoutVertical(blocks) : null; const vertical = !!lv && lv.height < lh.width; - const layout = vertical ? lv : lh; + return { layout: vertical ? lv : lh, vertical: vertical }; + } + // Bezier for one parent→child edge in either orientation — shared with the + // #4173 thumbnail so both drawings always agree. + function graphEdgePath(l, pad, vertical) { + if (vertical) { + const x1 = l[0].x + pad + GRAPH_NODE_W; + const y1 = l[0].y + pad + GRAPH_NODE_H / 2; + const x2 = l[1].x + pad; + const y2 = l[1].y + pad + GRAPH_NODE_H / 2; + const mx = (x1 + x2) / 2; + return "M" + x1 + " " + y1 + " C" + mx + " " + y1 + " " + mx + " " + y2 + " " + x2 + " " + y2; + } + const x1 = l[0].x + pad + GRAPH_NODE_W / 2; + const y1 = l[0].y + pad + GRAPH_NODE_H; + const x2 = l[1].x + pad + GRAPH_NODE_W / 2; + const y2 = l[1].y + pad; + const my = (y1 + y2) / 2; + return "M" + x1 + " " + y1 + " C" + x1 + " " + my + " " + x2 + " " + my + " " + x2 + " " + y2; + } + function buildGraphSvg(blocks) { + const g = graphLayouts(blocks); + const layout = g.layout; + const vertical = g.vertical; + if (!layout.nodes.length) return { html: "", vertical: false }; const pad = 14; - const halfW = GRAPH_NODE_W / 2; - const halfH = GRAPH_NODE_H / 2; const W = Math.ceil(layout.width + pad * 2); const H = Math.ceil(layout.height + pad * 2); const fit = W > GRAPH_FIT_W ? GRAPH_FIT_W / W : 1; const parts = []; parts.push(''); layout.links.forEach(function (l) { - let d; - if (vertical) { - const x1 = l[0].x + pad + GRAPH_NODE_W; - const y1 = l[0].y + pad + halfH; - const x2 = l[1].x + pad; - const y2 = l[1].y + pad + halfH; - const mx = (x1 + x2) / 2; - d = "M" + x1 + " " + y1 + " C" + mx + " " + y1 + " " + mx + " " + y2 + " " + x2 + " " + y2; - } else { - const x1 = l[0].x + pad + halfW; - const y1 = l[0].y + pad + GRAPH_NODE_H; - const x2 = l[1].x + pad + halfW; - const y2 = l[1].y + pad; - const my = (y1 + y2) / 2; - d = "M" + x1 + " " + y1 + " C" + x1 + " " + my + " " + x2 + " " + my + " " + x2 + " " + y2; - } - parts.push(''); + parts.push(''); }); layout.nodes.forEach(function (n) { const b = n.b; @@ -1957,6 +1962,34 @@ export const WEB_CLIENT = `(function () { parts.push(""); return { html: parts.join(""), vertical: vertical }; } + // #4173: live minimap for the page header — the same orientation rule as the + // full graph, boxes only (no text: labels cannot survive sub-pixel scale). + // CSS caps it at ~170×56px; /sessions//tree feeds its 5s live refresh. + const THUMB_MAX_W = 168; + function buildGraphThumbSvg(blocks) { + const g = graphLayouts(blocks); + const layout = g.layout; + const vertical = g.vertical; + if (!layout.nodes.length) return ""; + const pad = 14; + const W = Math.ceil(layout.width + pad * 2); + const H = Math.ceil(layout.height + pad * 2); + const parts = []; + parts.push('"); + return parts.join(""); + } function refRangeOf(b) { if (!b.startRef) return ""; return b.endRef && b.endRef !== b.startRef ? b.startRef + "–" + b.endRef : String(b.startRef); @@ -2051,13 +2084,16 @@ export const WEB_CLIENT = `(function () { } function buildDetailHtml(d) { const parts = []; + // #4173: hoisted above the page head so the live tree thumbnail can reuse + // the same array (previously declared further down, after the head). + const blocks = d.blockDetails || []; parts.push('' + t("common.back") + ""); - parts.push('

' + escapeHtml(d.title || d.label || d.id.slice(0, 16)) + '

' + escapeHtml(d.id) + "
" + detailBadges(d) + "
"); + parts.push('

' + escapeHtml(d.title || d.label || d.id.slice(0, 16)) + '

' + escapeHtml(d.id) + "
" + detailBadges(d) + "
" + + '
' + (blocks.length ? '
' + buildGraphThumbSvg(blocks) + "
" : "") + "
"); parts.push('
' + t("det.report_note") + '
'); // #3917: the detail page splits into panes — overview (identity, usage, // cache economics), the compression tree, and the handoff document. The // blocks card moved out of the overview into its own tier-tree pane. - const blocks = d.blockDetails || []; parts.push('
' + '" + '" @@ -2407,6 +2443,7 @@ if (d.keepalive) kv(parts, t("det.keepalive"), d.keepalive.tierLabel + " · " + bindBlockContentActions(d); bindTreeModeActions(); bindDetTabs(); + bindTreeThumb(); bindCacheReportActions(d); bindSessionReportActions(d); bindTrajectoryBrush(d); @@ -2709,6 +2746,20 @@ if (d.keepalive) kv(parts, t("det.keepalive"), d.keepalive.tierLabel + " · " + }); }); } + // #4173: clicking the page-head minimap jumps straight into the 压缩结构 tab's + // 树图 mode and scrolls it into view. + function bindTreeThumb() { + const th = $("tree-thumb"); + if (!th) return; + th.addEventListener("click", function () { + const tabBtn = document.querySelector('.det-tab[data-pane="blocks"]'); + if (tabBtn) tabBtn.click(); + const gb = document.querySelector('.tree-mode[data-mode="graph"]'); + if (gb) gb.click(); + const pane = document.querySelector('#session-detail-view .det-pane[data-pane="blocks"]'); + if (pane) pane.scrollIntoView({ block: "start", behavior: "smooth" }); + }); + } function bindCacheReportActions(d) { const copyB = $("cacherpt-copy"); const dlB = $("cacherpt-dl"); @@ -3712,6 +3763,28 @@ if (d.keepalive) kv(parts, t("det.keepalive"), d.keepalive.tierLabel + " · " + }); } + // #4173: keep the page-head tree minimap live while a session detail is open. + // Decorative lane: failures keep the last good frame and never touch the + // error strip or the #1937 backoff ladder (always resolves true). + let thumbBusy = false; + async function refreshTreeThumb() { + if (thumbBusy) return true; + const th = $("tree-thumb"); + if (!th) return true; + const m = location.hash.match(new RegExp("^#/session/(.+)$")); + if (!m) return true; + thumbBusy = true; + try { + const r = await json(API_ROOT + "/sessions/" + encodeURIComponent(m[1]) + "/tree"); + if (r && Array.isArray(r.blocks)) th.innerHTML = buildGraphThumbSvg(r.blocks); + } catch (e) { + /* decorative lane — keep the stale minimap */ + } finally { + thumbBusy = false; + } + return true; + } + hydrate(); initStaticHandlers(); route(); @@ -3730,6 +3803,8 @@ if (d.keepalive) kv(parts, t("det.keepalive"), d.keepalive.tierLabel + " · " + // A paged-down or searched list must not be clobbered by the background refresh. if (current === "sessions" && $("session-detail-view").hidden && sesPage === 1 && !hasActiveFilters()) ok = (await refreshSessions(false, 1)) && ok; else if (current === "logs") ok = (await loadLogs()) && ok; + // #4173: session DETAIL view → keep the page-head tree minimap live. + else if (current === "sessions") ok = (await refreshTreeThumb()) && ok; if (ok) { pollFailures = 0; nextPollAt = 0; hideDataError(); } else { pollFailures += 1; diff --git a/src/web/i18n.ts b/src/web/i18n.ts index b518294a04..6504f59688 100644 --- a/src/web/i18n.ts +++ b/src/web/i18n.ts @@ -398,6 +398,7 @@ export const MESSAGES: Record> = { "det.tree_view_graph": "树图", "det.tree_graph_hint": "整体形状:每个方块是一个压缩块,从上到下是「谁压缩了谁」。点方块跳到列表里对应的一行。", "det.tree_graph_hint_lr": "整体形状:每个方块是一个压缩块,从左到右是「谁压缩了谁」(此树很宽,已转为竖向排布,完整尺寸滚动查看)。点方块跳到列表里对应的一行。", + "det.tree_graph_thumb": "压缩树缩略图 · 每 5 秒实时刷新 · 点按打开树图", "det.tree_graph_legend": "实线框=活跃,虚线框=已归档", "det.handoff": "会话交接文档", "det.handoff_hint": "与 bili export 相同的内容 —— 复制粘贴到新会话即可继续", @@ -936,6 +937,7 @@ export const MESSAGES: Record> = { "det.tree_view_graph": "Tree map", "det.tree_graph_hint": "Overall shape: each box is one block, top-down is which block folded which. Click a box to jump to that row in the list.", "det.tree_graph_hint_lr": "Overall shape: each box is one block, left-to-right is which block folded which (this tree is very wide, so it is laid out vertically at full box size — scroll to see all of it). Click a box to jump to that row in the list.", + "det.tree_graph_thumb": "Live compression-tree thumbnail · refreshes every 5s · click to open the graph", "det.tree_graph_legend": "solid border = active, dashed = archived", "det.handoff": "Handoff document", "det.handoff_hint": "Same content as bili export — paste into a new session to continue", diff --git a/src/web/index.ts b/src/web/index.ts index 0878a71528..7a4fb71a56 100644 --- a/src/web/index.ts +++ b/src/web/index.ts @@ -9,8 +9,8 @@ export { readUpstreamSettings, } from "./api.js"; -export { buildOverview, buildSessionList, buildSessionPage, buildSessionDetail, buildBlockContent, buildMessageContent, hiddenEmptyCount } from "./sessions-data.js"; -export type { BlockContentLookup, BlockContentView, MessageContentLookup } from "./sessions-data.js"; +export { buildOverview, buildSessionList, buildSessionPage, buildSessionDetail, buildSessionTree, buildBlockContent, buildMessageContent, hiddenEmptyCount } from "./sessions-data.js"; +export type { BlockContentLookup, BlockContentView, MessageContentLookup, WebSessionTreeNode } from "./sessions-data.js"; export function renderUI(origin: string, opts?: { embed?: boolean; theme?: "light" | "dark" }): string { // #1426 fix: reuse the bundle-safe VERSION from src/version.ts — resolving diff --git a/src/web/sessions-data.ts b/src/web/sessions-data.ts index 14537b46b7..1ea97b01bb 100644 --- a/src/web/sessions-data.ts +++ b/src/web/sessions-data.ts @@ -1022,6 +1022,40 @@ export function buildSessionDetail(id: string): Promise return done; } +// #4173 (live tree thumbnail): the compact edge feed behind GET /sessions//tree. +// Block id, tier, activity and fold edges ONLY — no summaries, tokens or refs: +// a 180-block session ships ~6KB so the web UI can re-poll every 5s while a live +// compression run redraws the page-head minimap. +export interface WebSessionTreeNode { + blockId: string; + tier: number; + active: boolean; + parentBlockId?: string; + directBlockIds: string[]; +} + +const TREE_MAX_BLOCKS = 5000; + +export async function buildSessionTree(id: string): Promise<{ blocks: WebSessionTreeNode[] } | null> { + const found = await loadSessionById(id); + if (!found) return null; + // Same first-parent-wins inversion as renderDetail's parentBlockIdOf. + const parentOf = new Map(); + for (const b of found.session.state.blocks) { + for (const childId of b.directBlockIds || []) { + if (!parentOf.has(childId)) parentOf.set(childId, b.blockId); + } + } + const blocks: WebSessionTreeNode[] = found.session.state.blocks.slice(0, TREE_MAX_BLOCKS).map((b) => ({ + blockId: b.blockId, + tier: b.tier, + active: b.active !== false, + ...(parentOf.get(b.blockId) !== undefined ? { parentBlockId: parentOf.get(b.blockId)! } : {}), + directBlockIds: (b.directBlockIds || []).slice(), + })); + return { blocks }; +} + function renderDetail(session: Session, live: boolean): WebSessionDetail { // renderHandoff reads lastMessages (a bounded snapshot) — safe for disk // sessions; the v2 fallback path renders header + block summaries. diff --git a/src/web/styles.ts b/src/web/styles.ts index 27f6942135..0a9aa0e550 100644 --- a/src/web/styles.ts +++ b/src/web/styles.ts @@ -266,6 +266,13 @@ td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; font-fam .tree-mode.active { color: var(--accent); border-color: var(--accent); background: var(--bg-muted); } .tree-graph { max-height: 70vh; overflow: auto; border-top: 1px solid var(--border-soft); padding: 12px 8px 8px; background: var(--bg-muted); border-radius: 0 0 10px 10px; } .g-svg { display: block; max-width: 100%; height: auto; } +/* #4173: page-head live tree minimap — capped chip, click through to the graph. */ +.page-thumb { display: flex; align-items: center; } +.g-thumb { cursor: pointer; border: 1px solid var(--border-soft); border-radius: 9px; background: var(--bg-muted); padding: 3px 5px; line-height: 0; } +.g-thumb:hover { border-color: var(--accent); } +.g-thumb svg { display: block; width: auto; max-width: 170px; height: auto; max-height: 56px; } +.g-thumb .g-node { pointer-events: none; cursor: default; } +.g-thumb .g-edge { opacity: .3; } .g-edge { stroke: var(--accent); stroke-width: 1.6; opacity: .5; } .g-node { cursor: pointer; } .g-node rect { fill: #fff; stroke: var(--border-soft); stroke-width: 1.4; } diff --git a/tests/web-blocks-tree.test.ts b/tests/web-blocks-tree.test.ts index 23b0323065..07fac9eec9 100644 --- a/tests/web-blocks-tree.test.ts +++ b/tests/web-blocks-tree.test.ts @@ -8,7 +8,7 @@ import { createInitialState, defaultCountTokens } from "acp-kernel"; import type { CompressionBlock } from "acp-kernel"; import { LazyBlockContents, _resetSessionsForTest, getSession } from "../src/session.ts"; import { SessionStore, _setStoreForTest } from "../src/persist.ts"; -import { _resetDiskCacheForTest, buildBlockContent, buildMessageContent, buildSessionDetail } from "../src/web/sessions-data.ts"; +import { _resetDiskCacheForTest, buildBlockContent, buildMessageContent, buildSessionDetail, buildSessionTree } from "../src/web/sessions-data.ts"; import { MESSAGES } from "../src/web/i18n.ts"; import { WEB_CLIENT } from "../src/web/client.ts"; @@ -168,6 +168,21 @@ test("#3917: a folded message the host pruned reports a miss instead of a guess" assert.deepEqual(await buildMessageContent("tree-pruned", "m00001"), { ok: false, reason: "unknown-message" }); }); +test("#4173: the live tree endpoint ships only ids/tiers/edges — no summaries", async () => { + const t1 = mkBlock("b1", 1, "## T1 summary\n- point one", ["rm1"], ["rm1"], []); + const t2 = mkBlock("b2", 2, "T2 summary", ["rm3"], ["rm1", "rm3"], ["b1"]); + seedSession("tree-live", [t1, t2]); + const tree = await buildSessionTree("tree-live"); + assert.ok(tree); + assert.equal(tree.blocks.length, 2); + const byId = new Map(tree.blocks.map((b) => [b.blockId, b])); + assert.deepEqual(byId.get("b1"), { blockId: "b1", tier: 1, active: true, parentBlockId: "b2", directBlockIds: [] }, "the child names its fold parent"); + assert.deepEqual(byId.get("b2"), { blockId: "b2", tier: 2, active: true, directBlockIds: ["b1"] }, "the root has no parent field at all"); + // The whole point of the compact feed: no summary bytes on the wire. + assert.ok(!JSON.stringify(tree).includes("point one"), "summaries never leave the server"); + assert.equal(await buildSessionTree("no-such-session"), null, "unknown session resolves to a 404 payload"); +}); + test("#3917: the tree's strings exist in both locales with identical placeholders", () => { const keys = [ "det.tab_overview", @@ -190,6 +205,7 @@ test("#3917: the tree's strings exist in both locales with identical placeholder "det.tree_view_graph", "det.tree_graph_hint", "det.tree_graph_hint_lr", + "det.tree_graph_thumb", "det.tree_graph_legend", ]; const placeholders = (s: string) => (s.match(/\{[a-z]+\}/g) ?? []).sort().join(","); @@ -213,6 +229,14 @@ test("#3917: the web client bundle stays parseable JS after the tree additions", assert.match(WEB_CLIENT, /function blockGraphLayoutVertical\(blocks\)/); assert.match(WEB_CLIENT, /g-svg-v/); assert.match(WEB_CLIENT, /det\.tree_graph_hint_lr/); + // #4173: page-head live minimap — shared orientation helper + rect-only svg + // fed by GET /sessions//tree on the 5s poller. + assert.match(WEB_CLIENT, /function graphLayouts\(blocks\)/); + assert.match(WEB_CLIENT, /function buildGraphThumbSvg\(blocks\)/); + assert.match(WEB_CLIENT, /g-thumb-svg/); + assert.match(WEB_CLIENT, /id="tree-thumb"/); + assert.match(WEB_CLIENT, /function refreshTreeThumb\(\)/); + assert.ok(WEB_CLIENT.includes('"/sessions/" + encodeURIComponent(m[1]) + "/tree"'), "#4173 tree URL wiring present in the bundle"); assert.match(WEB_CLIENT, /"g-node tier-" \+/); assert.match(WEB_CLIENT, /data-mode="graph"/); assert.match(WEB_CLIENT, /id="tree-graph"/); @@ -226,7 +250,7 @@ test("#4173: wide trees rotate to vertical full-size instead of shrinking to sme assert.ok(start > 0 && end > start, "graph section anchors present in the bundle"); const stubs = "var escapeHtml=function(s){return String(s);};var fmtW=function(n){return String(n);};var blockTopic=function(b){return b.topic||'';};var t=function(k){return k;};"; const ctx = vm.createContext({}); - vm.runInContext(stubs + WEB_CLIENT.slice(start, end) + "this.api={blockGraphLayout:blockGraphLayout,blockGraphLayoutVertical:blockGraphLayoutVertical,buildGraphSvg:buildGraphSvg};;this.api", ctx, { filename: "web-graph.js" }); + vm.runInContext(stubs + WEB_CLIENT.slice(start, end) + "this.api={blockGraphLayout:blockGraphLayout,blockGraphLayoutVertical:blockGraphLayoutVertical,buildGraphSvg:buildGraphSvg,graphLayouts:graphLayouts,buildGraphThumbSvg:buildGraphThumbSvg};;this.api", ctx, { filename: "web-graph.js" }); const api = ctx.api; // 30 independent T1 roots → flat row 4004px wide: the old code fit-scaled it @@ -253,4 +277,17 @@ test("#4173: wide trees rotate to vertical full-size instead of shrinking to sme // empty tree keeps the old falsy contract via {html:""} const none = api.buildGraphSvg([]); assert.equal(none.html, ""); + + // #4173: the page-head minimap shares the orientation rule but draws boxes + // ONLY — labels cannot survive sub-pixel scale, so no may appear, + // and the explicit width must stay within the ~170px chip budget. + const thumbWide = api.buildGraphThumbSvg(wide); + assert.ok(thumbWide.startsWith(' 0 && thumbChain.includes('viewBox="0 0'), "a narrow chain renders a non-empty thumb with viewBox geometry"); + assert.equal(api.buildGraphThumbSvg([]), "", "empty tree renders nothing"); }); From 3a254c2743ec1ac63ca9372bb160f8156242ab37 Mon Sep 17 00:00:00 2001 From: ework-agent Date: Wed, 21 Oct 2026 23:03:01 +0800 Subject: [PATCH 03/16] web: stop heuristic browser caching from pinning a stale UI build (#4173) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The shell document inlines the entire client bundle and carried no cache directive, so browsers applied HEURISTIC caching: after a proxy upgrade the page kept serving an old client build until someone happened to hard-refresh (witnessed live — the tree thumbnail deploy stayed invisible this way). Cache-Control: no-cache forces revalidation; the document is stateless HTML so always-refetch costs nothing but a few hundred KB of loopback traffic. --- src/server/admin.ts | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/server/admin.ts b/src/server/admin.ts index 14bcf5a0db..c051442696 100644 --- a/src/server/admin.ts +++ b/src/server/admin.ts @@ -266,7 +266,16 @@ export async function handleAdminRoute(req: http.IncomingMessage, res: http.Serv // framed document's prefers-color-scheme. const rawTheme = u.searchParams.get("theme"); const theme = rawTheme === "light" || rawTheme === "dark" ? rawTheme : undefined; - const headers: Record = { "content-type": "text/html; charset=utf-8" }; + const headers: Record = { + "content-type": "text/html; charset=utf-8", + // The entire client bundle ships INLINE in this one document, so + // without a cache directive the browser's HEURISTIC caching can pin + // a stale build across a proxy upgrade — the user keeps loading the + // old UI long after the server moved on (seen live: a fresh deploy + // of new web features stayed invisible until a hard refresh). + // Revalidating every load is fine: the shell is stateless HTML. + "cache-control": "no-cache", + }; // #3xxx: the dsh settings pane's #3100 pre-flight fetches this route // CROSS-ORIGIN (dsh web serves the page on its own port, the proxy on // another — both loopback names, so isTrustedAdminOrigin above accepts From 39d47382eaa18355d5d1d89ed886888a8032e5fe Mon Sep 17 00:00:00 2001 From: ework-agent Date: Thu, 22 Oct 2026 00:20:27 +0800 Subject: [PATCH 04/16] web: replace the page-head tree chip with an in-pane live panorama (#4173) The fixed-size corner chip rendered as a blank sliver for pathological trees (this session: rotated 386x8356 -> ~3px of content in a 170px box). The compression tree now opens its own pane section: full labeled drawing at natural node size inside a bounded viewport, wheel zoom to cursor, drag pan, fit button, click a block to jump to its list row. Same 5s /tree poller; re-renders only on population change and restores the viewer transform. --- src/web/client.ts | 173 +++++++++++++++++++++------------- src/web/i18n.ts | 8 +- src/web/styles.ts | 15 +-- tests/web-blocks-tree.test.ts | 51 +++++----- 4 files changed, 151 insertions(+), 96 deletions(-) diff --git a/src/web/client.ts b/src/web/client.ts index 27dfd662ed..5363009d05 100644 --- a/src/web/client.ts +++ b/src/web/client.ts @@ -1905,7 +1905,7 @@ export const WEB_CLIENT = `(function () { if (!nodes.length) return { nodes: [], links: [], width: 0, height: 0 }; return { nodes: nodes, links: links, width: maxDepth * (GRAPH_NODE_W + GRAPH_GAP_X) + GRAPH_NODE_W, height: cursor - GRAPH_GAP_X }; } - // #4173: orientation shared by the full graph and the page-head thumbnail — + // #4173: orientation shared by the full graph and the in-pane tree map — // flat unless the tree overflows the card AND rotation shortens the long // dimension; small trees stay byte-identical to the original rendering. function graphLayouts(blocks) { @@ -1914,8 +1914,8 @@ export const WEB_CLIENT = `(function () { const vertical = !!lv && lv.height < lh.width; return { layout: vertical ? lv : lh, vertical: vertical }; } - // Bezier for one parent→child edge in either orientation — shared with the - // #4173 thumbnail so both drawings always agree. + // Bezier for one parent→child edge in either orientation — shared by every + // #4173 drawing (static graph and live in-pane map) so they always agree. function graphEdgePath(l, pad, vertical) { if (vertical) { const x1 = l[0].x + pad + GRAPH_NODE_W; @@ -1932,7 +1932,10 @@ export const WEB_CLIENT = `(function () { const my = (y1 + y2) / 2; return "M" + x1 + " " + y1 + " C" + x1 + " " + my + " " + x2 + " " + my + " " + x2 + " " + y2; } - function buildGraphSvg(blocks) { + // #4173: "wrapped" switches this same labeled drawing into in-pane map mode: + // no fixed size attributes (CSS owns the viewport via .tm-svg) and the + // content wraps in , which is the pan/zoom transform target. + function buildGraphSvg(blocks, wrapped) { const g = graphLayouts(blocks); const layout = g.layout; const vertical = g.vertical; @@ -1942,7 +1945,8 @@ export const WEB_CLIENT = `(function () { const H = Math.ceil(layout.height + pad * 2); const fit = W > GRAPH_FIT_W ? GRAPH_FIT_W / W : 1; const parts = []; - parts.push(''); + parts.push(''); + if (wrapped) parts.push(''); layout.links.forEach(function (l) { parts.push(''); }); @@ -1951,45 +1955,18 @@ export const WEB_CLIENT = `(function () { const tierNum = Number(b.tier) || 1; const cls = "g-node tier-" + (tierNum > 3 ? "n" : String(tierNum)) + (b.active ? "" : " inactive"); const ratio = b.compressedTokens > 0 && b.summaryTokens > 0 ? (100 * b.summaryTokens / b.compressedTokens).toFixed(1) + "%" : ""; - const meta = fmtW(b.compressedTokens) + " → " + fmtW(b.summaryTokens) + (ratio ? " " + ratio : ""); + const meta = fmtW(b.compressedTokens) + " \u2192 " + fmtW(b.summaryTokens) + (ratio ? " " + ratio : ""); parts.push('' - + "" + escapeHtml(b.blockId + " · T" + tierNum + " · " + blockTopic(b)) + "" + + "" + escapeHtml(b.blockId + " \u00b7 T" + tierNum + " \u00b7 " + blockTopic(b)) + "" + '' - + '' + escapeHtml(b.blockId + " · T" + tierNum) + "" + + '' + escapeHtml(b.blockId + " \u00b7 T" + tierNum) + "" + '' + escapeHtml(meta) + "" + ""); }); + if (wrapped) parts.push(""); parts.push(""); return { html: parts.join(""), vertical: vertical }; } - // #4173: live minimap for the page header — the same orientation rule as the - // full graph, boxes only (no text: labels cannot survive sub-pixel scale). - // CSS caps it at ~170×56px; /sessions//tree feeds its 5s live refresh. - const THUMB_MAX_W = 168; - function buildGraphThumbSvg(blocks) { - const g = graphLayouts(blocks); - const layout = g.layout; - const vertical = g.vertical; - if (!layout.nodes.length) return ""; - const pad = 14; - const W = Math.ceil(layout.width + pad * 2); - const H = Math.ceil(layout.height + pad * 2); - const parts = []; - parts.push('"); - return parts.join(""); - } function refRangeOf(b) { if (!b.startRef) return ""; return b.endRef && b.endRef !== b.startRef ? b.startRef + "–" + b.endRef : String(b.startRef); @@ -2057,6 +2034,9 @@ export const WEB_CLIENT = `(function () { } const stats = blockTreeStats(blocks); const tierBits = Object.keys(stats.tiers).sort(function (a, b) { return Number(a) - Number(b); }).map(function (k) { return "T" + k + " ×" + stats.tiers[k]; }); + // #4173: live tree panorama — full labeled drawing at natural node size, + // wheel-zoom/drag-pan inside a fixed viewport, click through to the list. + parts.push('
' + t("det.tree_map_title") + '' + t("det.tree_map_hint") + '
' + buildGraphSvg(blocks, true).html + '
'); parts.push('
' + "" + escapeHtml(t("det.tree_total", { n: blocks.length })) + "" + "" + escapeHtml(t("det.tree_active", { n: stats.active })) + "" @@ -2084,12 +2064,11 @@ export const WEB_CLIENT = `(function () { } function buildDetailHtml(d) { const parts = []; - // #4173: hoisted above the page head so the live tree thumbnail can reuse - // the same array (previously declared further down, after the head). + // Hoisted above the page head so the tab count badge can share the same + // array (originally declared further down, inside the tree pane). const blocks = d.blockDetails || []; parts.push('' + t("common.back") + ""); - parts.push('

' + escapeHtml(d.title || d.label || d.id.slice(0, 16)) + '

' + escapeHtml(d.id) + "
" + detailBadges(d) + "
" - + '
' + (blocks.length ? '
' + buildGraphThumbSvg(blocks) + "
" : "") + "
"); + parts.push('

' + escapeHtml(d.title || d.label || d.id.slice(0, 16)) + '

' + escapeHtml(d.id) + "
" + detailBadges(d) + "
"); parts.push('
' + t("det.report_note") + '
'); // #3917: the detail page splits into panes — overview (identity, usage, // cache economics), the compression tree, and the handoff document. The @@ -2443,7 +2422,7 @@ if (d.keepalive) kv(parts, t("det.keepalive"), d.keepalive.tierLabel + " · " + bindBlockContentActions(d); bindTreeModeActions(); bindDetTabs(); - bindTreeThumb(); + bindTreeMap(); bindCacheReportActions(d); bindSessionReportActions(d); bindTrajectoryBrush(d); @@ -2746,19 +2725,68 @@ if (d.keepalive) kv(parts, t("det.keepalive"), d.keepalive.tierLabel + " · " + }); }); } - // #4173: clicking the page-head minimap jumps straight into the 压缩结构 tab's - // 树图 mode and scrolls it into view. - function bindTreeThumb() { - const th = $("tree-thumb"); - if (!th) return; - th.addEventListener("click", function () { - const tabBtn = document.querySelector('.det-tab[data-pane="blocks"]'); - if (tabBtn) tabBtn.click(); - const gb = document.querySelector('.tree-mode[data-mode="graph"]'); - if (gb) gb.click(); - const pane = document.querySelector('#session-detail-view .det-pane[data-pane="blocks"]'); - if (pane) pane.scrollIntoView({ block: "start", behavior: "smooth" }); + // #4173: the in-pane live tree panorama. All interaction binds on the stable + // #tree-map container (event delegation) because the 5s poller swaps its + // innerHTML; zoom/pan state survives re-renders via view.__vm. With no + // transform set, the browser meet-scales the whole viewBox to the viewport + // (the overview); wheel zooms to the cursor, drag pans, and a plain click + // on a node jumps to that block's row in the list below. + function bindTreeMap() { + const view = $("tree-map"); + if (!view) return; + const applyVm = function () { + const g = view.querySelector(".tm-g"); + if (!g || !view.__vm) return; + g.setAttribute("transform", "translate(" + view.__vm.x + " " + view.__vm.y + ") scale(" + view.__vm.k + ")"); + }; + const fb = $("tm-fit"); + if (fb) fb.addEventListener("click", function () { view.__vm = null; applyVm(); }); + view.addEventListener("wheel", function (e) { + e.preventDefault(); + const vm = view.__vm || (view.__vm = { k: 1, x: 0, y: 0 }); + const rect = view.getBoundingClientRect(); + const px = e.clientX - rect.left; + const py = e.clientY - rect.top; + const k2 = Math.max(0.02, Math.min(8, vm.k * Math.exp(-e.deltaY * 0.0015))); + vm.x = px - (px - vm.x) * (k2 / vm.k); + vm.y = py - (py - vm.y) * (k2 / vm.k); + vm.k = k2; + applyVm(); + }, { passive: false }); + let drag = null; + view.addEventListener("pointerdown", function (e) { + if (e.button !== 0) return; + const vm = view.__vm || { k: 1, x: 0, y: 0 }; + drag = { sx: e.clientX, sy: e.clientY, ox: vm.x, oy: vm.y, moved: false }; + try { view.setPointerCapture(e.pointerId); } catch (err) {} + }); + view.addEventListener("pointermove", function (e) { + if (!drag) return; + const dx = e.clientX - drag.sx; + const dy = e.clientY - drag.sy; + if (!drag.moved && Math.abs(dx) <= 3 && Math.abs(dy) <= 3) return; + drag.moved = true; + view.__vm = { k: view.__vm ? view.__vm.k : 1, x: drag.ox + dx, y: drag.oy + dy }; + applyVm(); + }); + view.addEventListener("pointerup", function (e) { + if (!drag) return; + const moved = drag.moved; + drag = null; + if (moved) return; + const n = e.target && e.target.closest ? e.target.closest("[data-bid]") : null; + if (!n) return; + const bid = n.getAttribute("data-bid"); + const lb = document.querySelector('.tree-mode[data-mode="list"]'); + if (lb) lb.click(); + const row = document.querySelector('.block-node[data-bid="' + bid + '"]'); + if (!row) return; + row.open = true; + row.classList.add("flash"); + row.scrollIntoView({ block: "center", behavior: "smooth" }); + setTimeout(function () { row.classList.remove("flash"); }, 1600); }); + view.addEventListener("pointercancel", function () { drag = null; }); } function bindCacheReportActions(d) { const copyB = $("cacherpt-copy"); @@ -3763,24 +3791,37 @@ if (d.keepalive) kv(parts, t("det.keepalive"), d.keepalive.tierLabel + " · " + }); } - // #4173: keep the page-head tree minimap live while a session detail is open. + // #4173: keep the in-pane tree panorama live while a session detail is open. // Decorative lane: failures keep the last good frame and never touch the - // error strip or the #1937 backoff ladder (always resolves true). - let thumbBusy = false; - async function refreshTreeThumb() { - if (thumbBusy) return true; - const th = $("tree-thumb"); - if (!th) return true; + // error strip or the #1937 backoff ladder (always resolves true). Re-renders + // only when the block population actually changed; the viewer's zoom/pan + // (view.__vm) is restored on top of each rebuild. + let mapBusy = false; + let lastMapSig = ""; + async function refreshTreeMap() { + if (mapBusy) return true; + const view = $("tree-map"); + if (!view) return true; const m = location.hash.match(new RegExp("^#/session/(.+)$")); if (!m) return true; - thumbBusy = true; + mapBusy = true; try { const r = await json(API_ROOT + "/sessions/" + encodeURIComponent(m[1]) + "/tree"); - if (r && Array.isArray(r.blocks)) th.innerHTML = buildGraphThumbSvg(r.blocks); + if (r && Array.isArray(r.blocks)) { + const sig = r.blocks.map(function (b) { return b.blockId + String(b.tier) + (b.active ? "a" : ""); }).join("|"); + if (sig !== lastMapSig) { + lastMapSig = sig; + view.innerHTML = buildGraphSvg(r.blocks, true).html; + if (view.__vm) { + const g = view.querySelector(".tm-g"); + if (g) g.setAttribute("transform", "translate(" + view.__vm.x + " " + view.__vm.y + ") scale(" + view.__vm.k + ")"); + } + } + } } catch (e) { - /* decorative lane — keep the stale minimap */ + /* decorative lane — keep the stale frame */ } finally { - thumbBusy = false; + mapBusy = false; } return true; } @@ -3803,8 +3844,8 @@ if (d.keepalive) kv(parts, t("det.keepalive"), d.keepalive.tierLabel + " · " + // A paged-down or searched list must not be clobbered by the background refresh. if (current === "sessions" && $("session-detail-view").hidden && sesPage === 1 && !hasActiveFilters()) ok = (await refreshSessions(false, 1)) && ok; else if (current === "logs") ok = (await loadLogs()) && ok; - // #4173: session DETAIL view → keep the page-head tree minimap live. - else if (current === "sessions") ok = (await refreshTreeThumb()) && ok; + // #4173: session DETAIL view → keep the in-pane tree panorama live. + else if (current === "sessions") ok = (await refreshTreeMap()) && ok; if (ok) { pollFailures = 0; nextPollAt = 0; hideDataError(); } else { pollFailures += 1; diff --git a/src/web/i18n.ts b/src/web/i18n.ts index 6504f59688..2edf400533 100644 --- a/src/web/i18n.ts +++ b/src/web/i18n.ts @@ -398,7 +398,9 @@ export const MESSAGES: Record> = { "det.tree_view_graph": "树图", "det.tree_graph_hint": "整体形状:每个方块是一个压缩块,从上到下是「谁压缩了谁」。点方块跳到列表里对应的一行。", "det.tree_graph_hint_lr": "整体形状:每个方块是一个压缩块,从左到右是「谁压缩了谁」(此树很宽,已转为竖向排布,完整尺寸滚动查看)。点方块跳到列表里对应的一行。", - "det.tree_graph_thumb": "压缩树缩略图 · 每 5 秒实时刷新 · 点按打开树图", + "det.tree_map_title": "压缩树 · 实时全景", + "det.tree_map_hint": "滚轮缩放 · 拖拽平移 · 点按块跳到列表对应行 · 每 5 秒自动刷新", + "det.tree_map_fit": "适配", "det.tree_graph_legend": "实线框=活跃,虚线框=已归档", "det.handoff": "会话交接文档", "det.handoff_hint": "与 bili export 相同的内容 —— 复制粘贴到新会话即可继续", @@ -937,7 +939,9 @@ export const MESSAGES: Record> = { "det.tree_view_graph": "Tree map", "det.tree_graph_hint": "Overall shape: each box is one block, top-down is which block folded which. Click a box to jump to that row in the list.", "det.tree_graph_hint_lr": "Overall shape: each box is one block, left-to-right is which block folded which (this tree is very wide, so it is laid out vertically at full box size — scroll to see all of it). Click a box to jump to that row in the list.", - "det.tree_graph_thumb": "Live compression-tree thumbnail · refreshes every 5s · click to open the graph", + "det.tree_map_title": "Compression tree · live overview", + "det.tree_map_hint": "scroll to zoom · drag to pan · click a block to jump to its list row · auto-refresh every 5 s", + "det.tree_map_fit": "Fit", "det.tree_graph_legend": "solid border = active, dashed = archived", "det.handoff": "Handoff document", "det.handoff_hint": "Same content as bili export — paste into a new session to continue", diff --git a/src/web/styles.ts b/src/web/styles.ts index 0a9aa0e550..5f861c73c7 100644 --- a/src/web/styles.ts +++ b/src/web/styles.ts @@ -266,13 +266,14 @@ td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; font-fam .tree-mode.active { color: var(--accent); border-color: var(--accent); background: var(--bg-muted); } .tree-graph { max-height: 70vh; overflow: auto; border-top: 1px solid var(--border-soft); padding: 12px 8px 8px; background: var(--bg-muted); border-radius: 0 0 10px 10px; } .g-svg { display: block; max-width: 100%; height: auto; } -/* #4173: page-head live tree minimap — capped chip, click through to the graph. */ -.page-thumb { display: flex; align-items: center; } -.g-thumb { cursor: pointer; border: 1px solid var(--border-soft); border-radius: 9px; background: var(--bg-muted); padding: 3px 5px; line-height: 0; } -.g-thumb:hover { border-color: var(--accent); } -.g-thumb svg { display: block; width: auto; max-width: 170px; height: auto; max-height: 56px; } -.g-thumb .g-node { pointer-events: none; cursor: default; } -.g-thumb .g-edge { opacity: .3; } +.tm-view { position: relative; height: min(44vh, 440px); min-height: 220px; overflow: hidden; cursor: grab; touch-action: none; } +.tm-view:active { cursor: grabbing; } +.tm-svg { display: block; width: 100%; height: 100%; } +/* #4173: in-pane live tree panorama — full labeled drawing at natural node + size inside a fixed viewport; wheel zooms, drag pans (client-side transform). */ +.tm-wrap { border: 1px solid var(--border-soft); border-radius: 10px; background: var(--bg-muted); margin-bottom: 12px; overflow: hidden; } +.tm-head { display: flex; align-items: center; gap: 8px; padding: 7px 10px; border-bottom: 1px solid var(--border-soft); font-size: 12px; color: var(--text-muted); } +.tm-head .hint { flex: 1; font-size: 11px; } .g-edge { stroke: var(--accent); stroke-width: 1.6; opacity: .5; } .g-node { cursor: pointer; } .g-node rect { fill: #fff; stroke: var(--border-soft); stroke-width: 1.4; } diff --git a/tests/web-blocks-tree.test.ts b/tests/web-blocks-tree.test.ts index 07fac9eec9..826dd07b55 100644 --- a/tests/web-blocks-tree.test.ts +++ b/tests/web-blocks-tree.test.ts @@ -205,7 +205,9 @@ test("#3917: the tree's strings exist in both locales with identical placeholder "det.tree_view_graph", "det.tree_graph_hint", "det.tree_graph_hint_lr", - "det.tree_graph_thumb", + "det.tree_map_title", + "det.tree_map_hint", + "det.tree_map_fit", "det.tree_graph_legend", ]; const placeholders = (s: string) => (s.match(/\{[a-z]+\}/g) ?? []).sort().join(","); @@ -223,19 +225,24 @@ test("#3917: the web client bundle stays parseable JS after the tree additions", assert.match(WEB_CLIENT, /function buildTreePane\(blocks\)/); assert.match(WEB_CLIENT, /\/block-content\?blockId=/); // the graph reading of the same folds: layered boxes + list⇄graph switch - assert.match(WEB_CLIENT, /function buildGraphSvg\(blocks\)/); + assert.match(WEB_CLIENT, /function buildGraphSvg\(blocks/); assert.match(WEB_CLIENT, /function blockGraphLayout\(blocks\)/); // #4173: pathologically wide trees rotate instead of shrinking to sub-pixel assert.match(WEB_CLIENT, /function blockGraphLayoutVertical\(blocks\)/); assert.match(WEB_CLIENT, /g-svg-v/); assert.match(WEB_CLIENT, /det\.tree_graph_hint_lr/); - // #4173: page-head live minimap — shared orientation helper + rect-only svg - // fed by GET /sessions//tree on the 5s poller. + // #4173: in-pane live tree map — the full labeled drawing in wrapped mode + // (tm-g transform group, CSS-owned viewport), fed by GET /sessions//tree + // on the 5s poller; wheel/drag/click bind on the stable #tree-map container. assert.match(WEB_CLIENT, /function graphLayouts\(blocks\)/); - assert.match(WEB_CLIENT, /function buildGraphThumbSvg\(blocks\)/); - assert.match(WEB_CLIENT, /g-thumb-svg/); - assert.match(WEB_CLIENT, /id="tree-thumb"/); - assert.match(WEB_CLIENT, /function refreshTreeThumb\(\)/); + assert.match(WEB_CLIENT, /function buildGraphSvg\(blocks, wrapped\)/); + assert.match(WEB_CLIENT, /class="tm-g"/); + assert.match(WEB_CLIENT, /id="tree-map"/); + assert.match(WEB_CLIENT, /function bindTreeMap\(\)/); + assert.match(WEB_CLIENT, /function refreshTreeMap\(\)/); + assert.match(WEB_CLIENT, /addEventListener\("wheel"/); + assert.match(WEB_CLIENT, /pointerdown/); + assert.match(WEB_CLIENT, /tm-fit/); assert.ok(WEB_CLIENT.includes('"/sessions/" + encodeURIComponent(m[1]) + "/tree"'), "#4173 tree URL wiring present in the bundle"); assert.match(WEB_CLIENT, /"g-node tier-" \+/); assert.match(WEB_CLIENT, /data-mode="graph"/); @@ -250,7 +257,7 @@ test("#4173: wide trees rotate to vertical full-size instead of shrinking to sme assert.ok(start > 0 && end > start, "graph section anchors present in the bundle"); const stubs = "var escapeHtml=function(s){return String(s);};var fmtW=function(n){return String(n);};var blockTopic=function(b){return b.topic||'';};var t=function(k){return k;};"; const ctx = vm.createContext({}); - vm.runInContext(stubs + WEB_CLIENT.slice(start, end) + "this.api={blockGraphLayout:blockGraphLayout,blockGraphLayoutVertical:blockGraphLayoutVertical,buildGraphSvg:buildGraphSvg,graphLayouts:graphLayouts,buildGraphThumbSvg:buildGraphThumbSvg};;this.api", ctx, { filename: "web-graph.js" }); + vm.runInContext(stubs + WEB_CLIENT.slice(start, end) + "this.api={blockGraphLayout:blockGraphLayout,blockGraphLayoutVertical:blockGraphLayoutVertical,buildGraphSvg:buildGraphSvg,graphLayouts:graphLayouts};;this.api", ctx, { filename: "web-graph.js" }); const api = ctx.api; // 30 independent T1 roots → flat row 4004px wide: the old code fit-scaled it @@ -278,16 +285,18 @@ test("#4173: wide trees rotate to vertical full-size instead of shrinking to sme const none = api.buildGraphSvg([]); assert.equal(none.html, ""); - // #4173: the page-head minimap shares the orientation rule but draws boxes - // ONLY — labels cannot survive sub-pixel scale, so no may appear, - // and the explicit width must stay within the ~170px chip budget. - const thumbWide = api.buildGraphThumbSvg(wide); - assert.ok(thumbWide.startsWith(' 0 && thumbChain.includes('viewBox="0 0'), "a narrow chain renders a non-empty thumb with viewBox geometry"); - assert.equal(api.buildGraphThumbSvg([]), "", "empty tree renders nothing"); + // #4173: the in-pane live map reuses the full labeled drawing — every node + // keeps its box AND its text — but switches into wrapped mode: content sits + // in the pan/zoom group and the svg tag carries NO fixed + // size attributes (CSS owns the viewport). The plain path is untouched. + const mapWide = api.buildGraphSvg(wide, true).html; + assert.ok(mapWide.startsWith(''), "map wraps its drawing in the transform group"); + assert.ok(mapWide.includes("]*>/)[0].includes("width="), "wrapped svg has no fixed size attrs"); + assert.ok(api.buildGraphSvg(wide).html.match(/]*>/)[0].includes("width="), "plain svg keeps fit size attrs"); + const mapChain = api.buildGraphSvg(chain, true).html; + assert.ok(mapChain.length > 0 && mapChain.includes('viewBox="0 0'), "a narrow chain renders a non-empty map with viewBox geometry"); + assert.equal(api.buildGraphSvg([], true).html, "", "empty tree renders nothing"); }); From b3ec26290f3b4d6e4783484f1f536938876eb9d5 Mon Sep 17 00:00:00 2001 From: ework-agent Date: Thu, 22 Oct 2026 00:37:24 +0800 Subject: [PATCH 05/16] =?UTF-8?q?web:=20keep=20the=20tree=20panorama=20at?= =?UTF-8?q?=20natural=20size=20=E2=80=94=20scroll=20instead=20of=20meet-sh?= =?UTF-8?q?rink=20(#4173)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The default meet-scaled viewBox still smears pathological aspect ratios inside the fixed viewport (this session: a 386x8356 rotated tree met into a ~20px sliver). The pane now renders the drawing at natural pixels (block boxes stay 118x36, labels readable) in a natively scrollable box; wheel zooms around the cursor by resizing the inner frame so scroll ranges stay honest, drag pans via the native scroll position, Fit shrinks to the whole-tree overview, double-click restores natural size. Click-through to the list row and the 5s /tree refresh are unchanged. --- src/web/client.ts | 104 ++++++++++++++++++++++------------ src/web/i18n.ts | 4 +- src/web/styles.ts | 7 ++- tests/web-blocks-tree.test.ts | 19 +++++-- 4 files changed, 89 insertions(+), 45 deletions(-) diff --git a/src/web/client.ts b/src/web/client.ts index 5363009d05..98f70532b5 100644 --- a/src/web/client.ts +++ b/src/web/client.ts @@ -1933,19 +1933,21 @@ export const WEB_CLIENT = `(function () { return "M" + x1 + " " + y1 + " C" + x1 + " " + my + " " + x2 + " " + my + " " + x2 + " " + y2; } // #4173: "wrapped" switches this same labeled drawing into in-pane map mode: - // no fixed size attributes (CSS owns the viewport via .tm-svg) and the - // content wraps in , which is the pan/zoom transform target. + // it carries its NATURAL pixel size (width/height attrs) so the pane can + // show it 1:1 inside a scrollable viewport; zoom resizes the wrapping + // .tm-inner box (the svg fills it via CSS), which keeps scroll ranges + // honest while the browser scales the drawing uniformly. function buildGraphSvg(blocks, wrapped) { const g = graphLayouts(blocks); const layout = g.layout; const vertical = g.vertical; - if (!layout.nodes.length) return { html: "", vertical: false }; + if (!layout.nodes.length) return { html: "", vertical: false, width: 0, height: 0 }; const pad = 14; const W = Math.ceil(layout.width + pad * 2); const H = Math.ceil(layout.height + pad * 2); const fit = W > GRAPH_FIT_W ? GRAPH_FIT_W / W : 1; const parts = []; - parts.push(''); + parts.push(''); if (wrapped) parts.push(''); layout.links.forEach(function (l) { parts.push(''); @@ -1965,7 +1967,33 @@ export const WEB_CLIENT = `(function () { }); if (wrapped) parts.push(""); parts.push(""); - return { html: parts.join(""), vertical: vertical }; + return { html: parts.join(""), vertical: vertical, width: W, height: H }; + } + // #4173: the scrollable inner frame of the in-pane tree map — sized at the + // drawing's natural pixels; treeMapApply() resizes it when zooming. + function treeMapInnerHtml(graph) { + if (!graph.html) return ""; + return '
' + graph.html + "
"; + } + function treeMapApply(view) { + const inner = view.querySelector(".tm-inner"); + if (!inner) return; + const k = view.__vm ? view.__vm.k : 1; + const nw = parseFloat(inner.getAttribute("data-nw")) || 0; + const nh = parseFloat(inner.getAttribute("data-nh")) || 0; + inner.style.width = (nw * k) + "px"; + inner.style.height = (nh * k) + "px"; + } + function treeMapFit(view) { + const inner = view.querySelector(".tm-inner"); + if (!inner) return; + const nw = parseFloat(inner.getAttribute("data-nw")) || 0; + const nh = parseFloat(inner.getAttribute("data-nh")) || 0; + if (!nw || !nh) return; + view.__vm = { k: Math.min(view.clientWidth / nw, view.clientHeight / nh) * 0.98 }; + treeMapApply(view); + view.scrollLeft = Math.max(0, (nw * view.__vm.k - view.clientWidth) / 2); + view.scrollTop = Math.max(0, (nh * view.__vm.k - view.clientHeight) / 2); } function refRangeOf(b) { if (!b.startRef) return ""; @@ -2035,8 +2063,9 @@ export const WEB_CLIENT = `(function () { const stats = blockTreeStats(blocks); const tierBits = Object.keys(stats.tiers).sort(function (a, b) { return Number(a) - Number(b); }).map(function (k) { return "T" + k + " ×" + stats.tiers[k]; }); // #4173: live tree panorama — full labeled drawing at natural node size, - // wheel-zoom/drag-pan inside a fixed viewport, click through to the list. - parts.push('
' + t("det.tree_map_title") + '' + t("det.tree_map_hint") + '
' + buildGraphSvg(blocks, true).html + '
'); + // scrolling natively in both directions; wheel zoom, Fit for overview. + const mapGraph = buildGraphSvg(blocks, true); + parts.push('
' + t("det.tree_map_title") + '' + t("det.tree_map_hint") + '
' + treeMapInnerHtml(mapGraph) + '
'); parts.push('
' + "" + escapeHtml(t("det.tree_total", { n: blocks.length })) + "" + "" + escapeHtml(t("det.tree_active", { n: stats.active })) + "" @@ -2725,39 +2754,42 @@ if (d.keepalive) kv(parts, t("det.keepalive"), d.keepalive.tierLabel + " · " + }); }); } - // #4173: the in-pane live tree panorama. All interaction binds on the stable - // #tree-map container (event delegation) because the 5s poller swaps its - // innerHTML; zoom/pan state survives re-renders via view.__vm. With no - // transform set, the browser meet-scales the whole viewBox to the viewport - // (the overview); wheel zooms to the cursor, drag pans, and a plain click - // on a node jumps to that block's row in the list below. + // #4173: the in-pane live tree panorama. The drawing renders at NATURAL + // size (a block box is always 118x36 px, labels readable) inside a + // natively scrollable viewport — pathological trees (very wide OR very + // tall) stay legible instead of meeting into smears. All interaction + // binds on the stable #tree-map container (event delegation) because the + // 5s poller swaps its innerHTML: wheel zooms around the cursor (the + // .tm-inner box resizes, so scroll ranges stay honest), drag pans via the + // native scroll position, #tm-fit shrinks to the whole-tree overview, + // double-click restores natural size, and a plain click on a node jumps + // to that block's row in the list below. Zoom state (view.__vm) survives + // re-renders. function bindTreeMap() { const view = $("tree-map"); if (!view) return; - const applyVm = function () { - const g = view.querySelector(".tm-g"); - if (!g || !view.__vm) return; - g.setAttribute("transform", "translate(" + view.__vm.x + " " + view.__vm.y + ") scale(" + view.__vm.k + ")"); - }; const fb = $("tm-fit"); - if (fb) fb.addEventListener("click", function () { view.__vm = null; applyVm(); }); + if (fb) fb.addEventListener("click", function () { treeMapFit(view); }); + view.addEventListener("dblclick", function () { view.__vm = null; treeMapApply(view); }); view.addEventListener("wheel", function (e) { e.preventDefault(); - const vm = view.__vm || (view.__vm = { k: 1, x: 0, y: 0 }); + const old = view.__vm ? view.__vm.k : 1; + const k2 = Math.max(0.02, Math.min(8, old * Math.exp(-e.deltaY * 0.0015))); + if (k2 === old) return; const rect = view.getBoundingClientRect(); - const px = e.clientX - rect.left; - const py = e.clientY - rect.top; - const k2 = Math.max(0.02, Math.min(8, vm.k * Math.exp(-e.deltaY * 0.0015))); - vm.x = px - (px - vm.x) * (k2 / vm.k); - vm.y = py - (py - vm.y) * (k2 / vm.k); - vm.k = k2; - applyVm(); + const cx = e.clientX - rect.left; + const cy = e.clientY - rect.top; + const wx = (cx + view.scrollLeft) / old; + const wy = (cy + view.scrollTop) / old; + view.__vm = { k: k2 }; + treeMapApply(view); + view.scrollLeft = wx * k2 - cx; + view.scrollTop = wy * k2 - cy; }, { passive: false }); let drag = null; view.addEventListener("pointerdown", function (e) { if (e.button !== 0) return; - const vm = view.__vm || { k: 1, x: 0, y: 0 }; - drag = { sx: e.clientX, sy: e.clientY, ox: vm.x, oy: vm.y, moved: false }; + drag = { sx: e.clientX, sy: e.clientY, sl: view.scrollLeft, st: view.scrollTop, moved: false }; try { view.setPointerCapture(e.pointerId); } catch (err) {} }); view.addEventListener("pointermove", function (e) { @@ -2766,8 +2798,8 @@ if (d.keepalive) kv(parts, t("det.keepalive"), d.keepalive.tierLabel + " · " + const dy = e.clientY - drag.sy; if (!drag.moved && Math.abs(dx) <= 3 && Math.abs(dy) <= 3) return; drag.moved = true; - view.__vm = { k: view.__vm ? view.__vm.k : 1, x: drag.ox + dx, y: drag.oy + dy }; - applyVm(); + view.scrollLeft = drag.sl - dx; + view.scrollTop = drag.st - dy; }); view.addEventListener("pointerup", function (e) { if (!drag) return; @@ -3811,11 +3843,11 @@ if (d.keepalive) kv(parts, t("det.keepalive"), d.keepalive.tierLabel + " · " + const sig = r.blocks.map(function (b) { return b.blockId + String(b.tier) + (b.active ? "a" : ""); }).join("|"); if (sig !== lastMapSig) { lastMapSig = sig; - view.innerHTML = buildGraphSvg(r.blocks, true).html; - if (view.__vm) { - const g = view.querySelector(".tm-g"); - if (g) g.setAttribute("transform", "translate(" + view.__vm.x + " " + view.__vm.y + ") scale(" + view.__vm.k + ")"); - } + const keepSl = view.scrollLeft, keepSt = view.scrollTop; + view.innerHTML = treeMapInnerHtml(buildGraphSvg(r.blocks, true)); + treeMapApply(view); + view.scrollLeft = keepSl; + view.scrollTop = keepSt; } } } catch (e) { diff --git a/src/web/i18n.ts b/src/web/i18n.ts index 2edf400533..4d62e89e63 100644 --- a/src/web/i18n.ts +++ b/src/web/i18n.ts @@ -399,7 +399,7 @@ export const MESSAGES: Record> = { "det.tree_graph_hint": "整体形状:每个方块是一个压缩块,从上到下是「谁压缩了谁」。点方块跳到列表里对应的一行。", "det.tree_graph_hint_lr": "整体形状:每个方块是一个压缩块,从左到右是「谁压缩了谁」(此树很宽,已转为竖向排布,完整尺寸滚动查看)。点方块跳到列表里对应的一行。", "det.tree_map_title": "压缩树 · 实时全景", - "det.tree_map_hint": "滚轮缩放 · 拖拽平移 · 点按块跳到列表对应行 · 每 5 秒自动刷新", + "det.tree_map_hint": "内容原始大小 · 滚轮缩放 · 拖拽/滚动条平移 · 点按块跳到列表对应行 · 「适配」看全树 · 双击还原 · 每 5 秒自动刷新", "det.tree_map_fit": "适配", "det.tree_graph_legend": "实线框=活跃,虚线框=已归档", "det.handoff": "会话交接文档", @@ -940,7 +940,7 @@ export const MESSAGES: Record> = { "det.tree_graph_hint": "Overall shape: each box is one block, top-down is which block folded which. Click a box to jump to that row in the list.", "det.tree_graph_hint_lr": "Overall shape: each box is one block, left-to-right is which block folded which (this tree is very wide, so it is laid out vertically at full box size — scroll to see all of it). Click a box to jump to that row in the list.", "det.tree_map_title": "Compression tree · live overview", - "det.tree_map_hint": "scroll to zoom · drag to pan · click a block to jump to its list row · auto-refresh every 5 s", + "det.tree_map_hint": "natural-size content · wheel to zoom · drag or scrollbars to pan · click a block to jump to its list row · Fit for the whole tree · double-click resets · auto-refresh every 5 s", "det.tree_map_fit": "Fit", "det.tree_graph_legend": "solid border = active, dashed = archived", "det.handoff": "Handoff document", diff --git a/src/web/styles.ts b/src/web/styles.ts index 5f861c73c7..94fc611b7b 100644 --- a/src/web/styles.ts +++ b/src/web/styles.ts @@ -266,11 +266,12 @@ td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; font-fam .tree-mode.active { color: var(--accent); border-color: var(--accent); background: var(--bg-muted); } .tree-graph { max-height: 70vh; overflow: auto; border-top: 1px solid var(--border-soft); padding: 12px 8px 8px; background: var(--bg-muted); border-radius: 0 0 10px 10px; } .g-svg { display: block; max-width: 100%; height: auto; } -.tm-view { position: relative; height: min(44vh, 440px); min-height: 220px; overflow: hidden; cursor: grab; touch-action: none; } +.tm-view { position: relative; height: min(44vh, 440px); min-height: 220px; overflow: auto; cursor: grab; touch-action: none; } .tm-view:active { cursor: grabbing; } .tm-svg { display: block; width: 100%; height: 100%; } -/* #4173: in-pane live tree panorama — full labeled drawing at natural node - size inside a fixed viewport; wheel zooms, drag pans (client-side transform). */ +/* #4173: in-pane live tree panorama — natural-size drawing inside a natively + scrollable viewport; zoom resizes .tm-inner so scroll ranges stay honest. */ +.tm-inner { position: relative; margin: 0 auto; } .tm-wrap { border: 1px solid var(--border-soft); border-radius: 10px; background: var(--bg-muted); margin-bottom: 12px; overflow: hidden; } .tm-head { display: flex; align-items: center; gap: 8px; padding: 7px 10px; border-bottom: 1px solid var(--border-soft); font-size: 12px; color: var(--text-muted); } .tm-head .hint { flex: 1; font-size: 11px; } diff --git a/tests/web-blocks-tree.test.ts b/tests/web-blocks-tree.test.ts index 826dd07b55..ba4a6ab25d 100644 --- a/tests/web-blocks-tree.test.ts +++ b/tests/web-blocks-tree.test.ts @@ -232,12 +232,17 @@ test("#3917: the web client bundle stays parseable JS after the tree additions", assert.match(WEB_CLIENT, /g-svg-v/); assert.match(WEB_CLIENT, /det\.tree_graph_hint_lr/); // #4173: in-pane live tree map — the full labeled drawing in wrapped mode - // (tm-g transform group, CSS-owned viewport), fed by GET /sessions//tree - // on the 5s poller; wheel/drag/click bind on the stable #tree-map container. + // (natural pixel size inside a scrollable .tm-view/.tm-inner box), fed by + // GET /sessions//tree on the 5s poller; wheel/pan/click bind on the + // stable #tree-map container and zoom resizes .tm-inner via treeMapApply. assert.match(WEB_CLIENT, /function graphLayouts\(blocks\)/); assert.match(WEB_CLIENT, /function buildGraphSvg\(blocks, wrapped\)/); assert.match(WEB_CLIENT, /class="tm-g"/); + assert.match(WEB_CLIENT, /class="tm-inner" data-nw=/); assert.match(WEB_CLIENT, /id="tree-map"/); + assert.match(WEB_CLIENT, /function treeMapInnerHtml\(graph\)/); + assert.match(WEB_CLIENT, /function treeMapApply\(view\)/); + assert.match(WEB_CLIENT, /function treeMapFit\(view\)/); assert.match(WEB_CLIENT, /function bindTreeMap\(\)/); assert.match(WEB_CLIENT, /function refreshTreeMap\(\)/); assert.match(WEB_CLIENT, /addEventListener\("wheel"/); @@ -289,12 +294,18 @@ test("#4173: wide trees rotate to vertical full-size instead of shrinking to sme // keeps its box AND its text — but switches into wrapped mode: content sits // in the pan/zoom group and the svg tag carries NO fixed // size attributes (CSS owns the viewport). The plain path is untouched. - const mapWide = api.buildGraphSvg(wide, true).html; + const mapRes = api.buildGraphSvg(wide, true); + const mapWide = mapRes.html; assert.ok(mapWide.startsWith(''), "map wraps its drawing in the transform group"); assert.ok(mapWide.includes("]*>/)[0].includes("width="), "wrapped svg has no fixed size attrs"); + const mvb = mapWide.match(/viewBox="0 0 (\d+) (\d+)"/); + const mwd = mapWide.match(/ width="(\d+)" height="(\d+)"/); + assert.ok(mvb && mwd, "wrapped svg carries viewBox plus natural size attrs"); + assert.equal(Number(mvb[1]), Number(mwd[1]), "wrapped width is the natural width (no fit shrink)"); + assert.equal(Number(mvb[2]), Number(mwd[2]), "wrapped height is the natural height (no fit shrink)"); + assert.equal(mapRes.width, Number(mwd[1]), "returned width matches the drawing"); assert.ok(api.buildGraphSvg(wide).html.match(/]*>/)[0].includes("width="), "plain svg keeps fit size attrs"); const mapChain = api.buildGraphSvg(chain, true).html; assert.ok(mapChain.length > 0 && mapChain.includes('viewBox="0 0'), "a narrow chain renders a non-empty map with viewBox geometry"); From 4b8e6b433caa544cc4a5b12b8469857c75dd5f89 Mon Sep 17 00:00:00 2001 From: awork Date: Thu, 22 Oct 2026 01:42:56 +0800 Subject: [PATCH 06/16] fix: count fold edges in the tree-map refresh signature (#4173 review) The /tree poller's change signature covered blockId/tier/active, so an absorption that only adds a fold edge (the child keeps its id, tier and active flag) left the in-pane panorama stale until the next unrelated population change. Edges are part of the drawing, so they belong in the signature. --- src/web/client.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/web/client.ts b/src/web/client.ts index 98f70532b5..19fe8b9ad3 100644 --- a/src/web/client.ts +++ b/src/web/client.ts @@ -3840,7 +3840,7 @@ if (d.keepalive) kv(parts, t("det.keepalive"), d.keepalive.tierLabel + " · " + try { const r = await json(API_ROOT + "/sessions/" + encodeURIComponent(m[1]) + "/tree"); if (r && Array.isArray(r.blocks)) { - const sig = r.blocks.map(function (b) { return b.blockId + String(b.tier) + (b.active ? "a" : ""); }).join("|"); + const sig = r.blocks.map(function (b) { return b.blockId + String(b.tier) + (b.active ? "a" : "") + ":" + (b.directBlockIds || []).join(","); }).join("|"); if (sig !== lastMapSig) { lastMapSig = sig; const keepSl = view.scrollLeft, keepSt = view.scrollTop; From 78a123f09a5b2aa0cfad31ad0212c1173d61af55 Mon Sep 17 00:00:00 2001 From: ework-agent Date: Thu, 22 Oct 2026 10:04:54 +0800 Subject: [PATCH 07/16] =?UTF-8?q?web:=20merge=20the=20live=20tree=20panora?= =?UTF-8?q?ma=20into=20the=20=E6=A0=91=E5=9B=BE=20view=20=E2=80=94=20one?= =?UTF-8?q?=20tree,=20with=20zoom=20(#4173)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit User reported two trees on the compression pane (standalone panorama card above plus the 列表/树图 switch below) and asked for ONE: drop the real-time card, give 树图 itself the natural-size live drawing with zoom. - #tree-graph now renders the wrapped natural-size svg (treeMapInnerHtml): boxes stay 118x36 px, native two-axis scroll, wheel zoom at cursor, drag pan, 适配(Fit) overview, double-click resets, click a box jumps to its list row. The 5s /tree poller repaints this same container (sig-guarded, including awork's fold-edge signature fix). - The hint line and Fit button move into the 列表/树图 row; Fit only shows while 树图 is active. Per-node click listeners dropped (delegated pointerup in bindTreeMap covers click-vs-drag). - Removed: tm-wrap/tm-head card markup+CSS, det.tree_map_title (zh/en). Re-applied on top of the rebuilt branch history (previous attempt was lost when the branch was rebased onto master); gates green (tsc, web-blocks-tree 10/10, battery, gen-config-docs, unused-exports, build). --- src/web/client.ts | 36 ++++++++++------------------------- src/web/i18n.ts | 6 ------ src/web/styles.ts | 8 +++----- tests/web-blocks-tree.test.ts | 5 ----- 4 files changed, 13 insertions(+), 42 deletions(-) diff --git a/src/web/client.ts b/src/web/client.ts index 19fe8b9ad3..d5f70c517d 100644 --- a/src/web/client.ts +++ b/src/web/client.ts @@ -2062,11 +2062,7 @@ export const WEB_CLIENT = `(function () { } const stats = blockTreeStats(blocks); const tierBits = Object.keys(stats.tiers).sort(function (a, b) { return Number(a) - Number(b); }).map(function (k) { return "T" + k + " ×" + stats.tiers[k]; }); - // #4173: live tree panorama — full labeled drawing at natural node size, - // scrolling natively in both directions; wheel zoom, Fit for overview. - const mapGraph = buildGraphSvg(blocks, true); - parts.push('
' + t("det.tree_map_title") + '' + t("det.tree_map_hint") + '
' + treeMapInnerHtml(mapGraph) + '
'); - parts.push('
' + parts.push('
' + "" + escapeHtml(t("det.tree_total", { n: blocks.length })) + "" + "" + escapeHtml(t("det.tree_active", { n: stats.active })) + "" + "" + escapeHtml(t("det.tree_split", { x: fmtW(stats.coverTokens), y: fmtW(stats.summaryTokens), p: stats.coverTokens > 0 ? (100 * stats.summaryTokens / stats.coverTokens).toFixed(1) + "%" : t("common.none") })) + "" @@ -2076,7 +2072,7 @@ export const WEB_CLIENT = `(function () { const shape = blockTreeShape(blocks); const idxOf = {}; blocks.forEach(function (b, i) { if (idxOf[b.blockId] === undefined) idxOf[b.blockId] = i; }); - parts.push('
"); + parts.push('
' + t("det.tree_map_hint") + '
"); parts.push('
'); parts.push('
'); const rootBlocks = shape.roots.length ? shape.roots : blocks; @@ -2084,10 +2080,11 @@ export const WEB_CLIENT = `(function () { parts.push("
"); parts.push('
' + t("det.tree_hint") + "
"); parts.push("
"); - const graph = buildGraphSvg(blocks); - const graphHint = graph.vertical ? t("det.tree_graph_hint_lr") : t("det.tree_graph_hint"); - parts.push('"); + const mapGraph = buildGraphSvg(blocks, true); + // #4173: one tree, natural-size nodes inside the scrollable pane: + // wheel zoom at cursor, drag/scroll pan, tm-fit overview, 5s live refresh. + parts.push(''); parts.push("
"); return parts.join(""); } @@ -2740,25 +2737,12 @@ if (d.keepalive) kv(parts, t("det.keepalive"), d.keepalive.tierLabel + " · " + setMode(b.getAttribute("data-mode") === "graph" ? "graph" : "list"); }); }); - graph.querySelectorAll(".g-node").forEach(function (n) { - n.addEventListener("click", function () { - const bid = n.getAttribute("data-bid"); - if (!bid) return; - setMode("list"); - const row = document.querySelector('.block-node[data-bid="' + bid + '"]'); - if (!row) return; - row.open = true; - row.classList.add("flash"); - row.scrollIntoView({ block: "center", behavior: "smooth" }); - setTimeout(function () { row.classList.remove("flash"); }, 1600); - }); - }); } // #4173: the in-pane live tree panorama. The drawing renders at NATURAL // size (a block box is always 118x36 px, labels readable) inside a // natively scrollable viewport — pathological trees (very wide OR very // tall) stay legible instead of meeting into smears. All interaction - // binds on the stable #tree-map container (event delegation) because the + // binds on the stable #tree-graph container (event delegation) because the // 5s poller swaps its innerHTML: wheel zooms around the cursor (the // .tm-inner box resizes, so scroll ranges stay honest), drag pans via the // native scroll position, #tm-fit shrinks to the whole-tree overview, @@ -2766,7 +2750,7 @@ if (d.keepalive) kv(parts, t("det.keepalive"), d.keepalive.tierLabel + " · " + // to that block's row in the list below. Zoom state (view.__vm) survives // re-renders. function bindTreeMap() { - const view = $("tree-map"); + const view = $("tree-graph"); if (!view) return; const fb = $("tm-fit"); if (fb) fb.addEventListener("click", function () { treeMapFit(view); }); @@ -3832,7 +3816,7 @@ if (d.keepalive) kv(parts, t("det.keepalive"), d.keepalive.tierLabel + " · " + let lastMapSig = ""; async function refreshTreeMap() { if (mapBusy) return true; - const view = $("tree-map"); + const view = $("tree-graph"); if (!view) return true; const m = location.hash.match(new RegExp("^#/session/(.+)$")); if (!m) return true; diff --git a/src/web/i18n.ts b/src/web/i18n.ts index 4d62e89e63..eba358faa8 100644 --- a/src/web/i18n.ts +++ b/src/web/i18n.ts @@ -396,9 +396,6 @@ export const MESSAGES: Record> = { "det.tree_hint": "按压缩的父子关系嵌套:T1 收原始消息,T2 收 T1 的块,以此类推。点「原文」按需加载内容。", "det.tree_view_list": "列表", "det.tree_view_graph": "树图", - "det.tree_graph_hint": "整体形状:每个方块是一个压缩块,从上到下是「谁压缩了谁」。点方块跳到列表里对应的一行。", - "det.tree_graph_hint_lr": "整体形状:每个方块是一个压缩块,从左到右是「谁压缩了谁」(此树很宽,已转为竖向排布,完整尺寸滚动查看)。点方块跳到列表里对应的一行。", - "det.tree_map_title": "压缩树 · 实时全景", "det.tree_map_hint": "内容原始大小 · 滚轮缩放 · 拖拽/滚动条平移 · 点按块跳到列表对应行 · 「适配」看全树 · 双击还原 · 每 5 秒自动刷新", "det.tree_map_fit": "适配", "det.tree_graph_legend": "实线框=活跃,虚线框=已归档", @@ -937,9 +934,6 @@ export const MESSAGES: Record> = { "det.tree_hint": "Nested by fold parent: T1 folds raw messages, T2 folds T1 blocks, and so on. Original loads the covered bytes on demand.", "det.tree_view_list": "List", "det.tree_view_graph": "Tree map", - "det.tree_graph_hint": "Overall shape: each box is one block, top-down is which block folded which. Click a box to jump to that row in the list.", - "det.tree_graph_hint_lr": "Overall shape: each box is one block, left-to-right is which block folded which (this tree is very wide, so it is laid out vertically at full box size — scroll to see all of it). Click a box to jump to that row in the list.", - "det.tree_map_title": "Compression tree · live overview", "det.tree_map_hint": "natural-size content · wheel to zoom · drag or scrollbars to pan · click a block to jump to its list row · Fit for the whole tree · double-click resets · auto-refresh every 5 s", "det.tree_map_fit": "Fit", "det.tree_graph_legend": "solid border = active, dashed = archived", diff --git a/src/web/styles.ts b/src/web/styles.ts index 94fc611b7b..cc900057df 100644 --- a/src/web/styles.ts +++ b/src/web/styles.ts @@ -261,20 +261,18 @@ td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; font-fam .block-tree { max-height: 70vh; overflow-y: auto; border-top: 1px solid var(--border-soft); } /* #3917: list ⇄ graph switch for the compression pane, plus the graph itself (layered block boxes on a light canvas, tier-tinted borders). */ -.tree-modes { display: flex; gap: 6px; margin: 0 0 10px; } +.tree-modes { display: flex; gap: 6px; margin: 0 0 10px; align-items: center; } +.tree-modes .hint { flex: 1; font-size: 11px; color: var(--text-muted); } .tree-mode { color: var(--text-muted); } .tree-mode.active { color: var(--accent); border-color: var(--accent); background: var(--bg-muted); } .tree-graph { max-height: 70vh; overflow: auto; border-top: 1px solid var(--border-soft); padding: 12px 8px 8px; background: var(--bg-muted); border-radius: 0 0 10px 10px; } .g-svg { display: block; max-width: 100%; height: auto; } -.tm-view { position: relative; height: min(44vh, 440px); min-height: 220px; overflow: auto; cursor: grab; touch-action: none; } +.tm-view { position: relative; overflow: auto; cursor: grab; touch-action: none; } .tm-view:active { cursor: grabbing; } .tm-svg { display: block; width: 100%; height: 100%; } /* #4173: in-pane live tree panorama — natural-size drawing inside a natively scrollable viewport; zoom resizes .tm-inner so scroll ranges stay honest. */ .tm-inner { position: relative; margin: 0 auto; } -.tm-wrap { border: 1px solid var(--border-soft); border-radius: 10px; background: var(--bg-muted); margin-bottom: 12px; overflow: hidden; } -.tm-head { display: flex; align-items: center; gap: 8px; padding: 7px 10px; border-bottom: 1px solid var(--border-soft); font-size: 12px; color: var(--text-muted); } -.tm-head .hint { flex: 1; font-size: 11px; } .g-edge { stroke: var(--accent); stroke-width: 1.6; opacity: .5; } .g-node { cursor: pointer; } .g-node rect { fill: #fff; stroke: var(--border-soft); stroke-width: 1.4; } diff --git a/tests/web-blocks-tree.test.ts b/tests/web-blocks-tree.test.ts index ba4a6ab25d..e32c0f77eb 100644 --- a/tests/web-blocks-tree.test.ts +++ b/tests/web-blocks-tree.test.ts @@ -203,9 +203,6 @@ test("#3917: the tree's strings exist in both locales with identical placeholder "det.tree_hint", "det.tree_view_list", "det.tree_view_graph", - "det.tree_graph_hint", - "det.tree_graph_hint_lr", - "det.tree_map_title", "det.tree_map_hint", "det.tree_map_fit", "det.tree_graph_legend", @@ -230,7 +227,6 @@ test("#3917: the web client bundle stays parseable JS after the tree additions", // #4173: pathologically wide trees rotate instead of shrinking to sub-pixel assert.match(WEB_CLIENT, /function blockGraphLayoutVertical\(blocks\)/); assert.match(WEB_CLIENT, /g-svg-v/); - assert.match(WEB_CLIENT, /det\.tree_graph_hint_lr/); // #4173: in-pane live tree map — the full labeled drawing in wrapped mode // (natural pixel size inside a scrollable .tm-view/.tm-inner box), fed by // GET /sessions//tree on the 5s poller; wheel/pan/click bind on the @@ -239,7 +235,6 @@ test("#3917: the web client bundle stays parseable JS after the tree additions", assert.match(WEB_CLIENT, /function buildGraphSvg\(blocks, wrapped\)/); assert.match(WEB_CLIENT, /class="tm-g"/); assert.match(WEB_CLIENT, /class="tm-inner" data-nw=/); - assert.match(WEB_CLIENT, /id="tree-map"/); assert.match(WEB_CLIENT, /function treeMapInnerHtml\(graph\)/); assert.match(WEB_CLIENT, /function treeMapApply\(view\)/); assert.match(WEB_CLIENT, /function treeMapFit\(view\)/); From 7d2ba7b9563c88af5b663b4a24a52623d6970267 Mon Sep 17 00:00:00 2001 From: awork Date: Thu, 22 Oct 2026 10:22:45 +0800 Subject: [PATCH 08/16] fix: make the tree-pane Fit button reachable and keep the legend across live refreshes (#4173 review) 78a123f09 moved #tm-fit into the list/graph row starting hidden, but setMode never unhides it - the advertised Fit overview was unreachable. The 5s poller also replaced the whole #tree-graph innerHTML, wiping the legend row that now lives inside the pane after the first refresh. - setMode toggles fit.hidden with the graph mode (visible only while the tree view is active) - refreshTreeMap swaps only the .tm-inner drawing frame so the pane's other children survive live refreshes - pin both behaviors as bundle regexes in tests/web-blocks-tree.test.ts; correct the stale #tree-map comment to #tree-graph --- src/web/client.ts | 8 +++++++- tests/web-blocks-tree.test.ts | 6 +++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/web/client.ts b/src/web/client.ts index d5f70c517d..337ecfe444 100644 --- a/src/web/client.ts +++ b/src/web/client.ts @@ -2729,6 +2729,9 @@ if (d.keepalive) kv(parts, t("det.keepalive"), d.keepalive.tierLabel + " · " + const g = mode === "graph"; list.hidden = g; graph.hidden = !g; + // #4173 review: Fit only makes sense while the tree drawing is visible. + const fit = $("tm-fit"); + if (fit) fit.hidden = !g; btns.forEach(function (b) { b.classList.toggle("active", b.getAttribute("data-mode") === mode); }); }; btns.forEach(function (b) { @@ -3828,7 +3831,10 @@ if (d.keepalive) kv(parts, t("det.keepalive"), d.keepalive.tierLabel + " · " + if (sig !== lastMapSig) { lastMapSig = sig; const keepSl = view.scrollLeft, keepSt = view.scrollTop; - view.innerHTML = treeMapInnerHtml(buildGraphSvg(r.blocks, true)); + // #4173 review: swap only the drawing frame so the pane's other + // children (the legend row) survive live refreshes. + view.querySelectorAll(".tm-inner").forEach(function (el) { el.remove(); }); + view.insertAdjacentHTML("afterbegin", treeMapInnerHtml(buildGraphSvg(r.blocks, true))); treeMapApply(view); view.scrollLeft = keepSl; view.scrollTop = keepSt; diff --git a/tests/web-blocks-tree.test.ts b/tests/web-blocks-tree.test.ts index e32c0f77eb..b7c5fe0638 100644 --- a/tests/web-blocks-tree.test.ts +++ b/tests/web-blocks-tree.test.ts @@ -230,7 +230,7 @@ test("#3917: the web client bundle stays parseable JS after the tree additions", // #4173: in-pane live tree map — the full labeled drawing in wrapped mode // (natural pixel size inside a scrollable .tm-view/.tm-inner box), fed by // GET /sessions//tree on the 5s poller; wheel/pan/click bind on the - // stable #tree-map container and zoom resizes .tm-inner via treeMapApply. + // stable #tree-graph container and zoom resizes .tm-inner via treeMapApply. assert.match(WEB_CLIENT, /function graphLayouts\(blocks\)/); assert.match(WEB_CLIENT, /function buildGraphSvg\(blocks, wrapped\)/); assert.match(WEB_CLIENT, /class="tm-g"/); @@ -243,6 +243,10 @@ test("#3917: the web client bundle stays parseable JS after the tree additions", assert.match(WEB_CLIENT, /addEventListener\("wheel"/); assert.match(WEB_CLIENT, /pointerdown/); assert.match(WEB_CLIENT, /tm-fit/); + // #4173 review: Fit is mode-gated (visible only while the tree drawing shows) + // and live refreshes swap just the .tm-inner frame so the legend row survives. + assert.match(WEB_CLIENT, /fit\.hidden = !g/); + assert.match(WEB_CLIENT, /insertAdjacentHTML\("afterbegin", treeMapInnerHtml/); assert.ok(WEB_CLIENT.includes('"/sessions/" + encodeURIComponent(m[1]) + "/tree"'), "#4173 tree URL wiring present in the bundle"); assert.match(WEB_CLIENT, /"g-node tier-" \+/); assert.match(WEB_CLIENT, /data-mode="graph"/); From 3044419c84dcdb818eaada9a0641e15ff9ac3b30 Mon Sep 17 00:00:00 2001 From: ework-agent Date: Thu, 22 Oct 2026 16:03:43 +0800 Subject: [PATCH 09/16] web: fix tree-graph click-to-jump (pointer capture retargeting); stack map+list instead of hiding details (#4173) --- src/web/client.ts | 16 ++++++++++++---- tests/web-blocks-tree.test.ts | 5 +++++ 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/src/web/client.ts b/src/web/client.ts index 337ecfe444..f2e3cd437d 100644 --- a/src/web/client.ts +++ b/src/web/client.ts @@ -2727,7 +2727,11 @@ if (d.keepalive) kv(parts, t("det.keepalive"), d.keepalive.tierLabel + " · " + const btns = Array.prototype.slice.call(document.querySelectorAll(".tree-mode")); const setMode = function (mode) { const g = mode === "graph"; - list.hidden = g; + // #4173 review: graph mode STACKS the live map above the full + // block list (总揽全局 + 看细节 in one screen); list mode just + // hides the drawing. The list is never hidden anymore — it used + // to be, which read as "all the per-block details were lost". + list.hidden = false; graph.hidden = !g; // #4173 review: Fit only makes sense while the tree drawing is visible. const fit = $("tm-fit"); @@ -2740,6 +2744,8 @@ if (d.keepalive) kv(parts, t("det.keepalive"), d.keepalive.tierLabel + " · " + setMode(b.getAttribute("data-mode") === "graph" ? "graph" : "list"); }); }); + // #4173 review: default to the live map stacked over the list. + setMode("graph"); } // #4173: the in-pane live tree panorama. The drawing renders at NATURAL // size (a block box is always 118x36 px, labels readable) inside a @@ -2793,11 +2799,13 @@ if (d.keepalive) kv(parts, t("det.keepalive"), d.keepalive.tierLabel + " · " + const moved = drag.moved; drag = null; if (moved) return; - const n = e.target && e.target.closest ? e.target.closest("[data-bid]") : null; + // Pointer capture retargets pointerup at the container, so the + // node under the finger has to be hit-tested by point. + let el = e.target; + try { el = document.elementFromPoint(e.clientX, e.clientY) || e.target; } catch (err) {} + const n = el && el.closest ? el.closest("[data-bid]") : null; if (!n) return; const bid = n.getAttribute("data-bid"); - const lb = document.querySelector('.tree-mode[data-mode="list"]'); - if (lb) lb.click(); const row = document.querySelector('.block-node[data-bid="' + bid + '"]'); if (!row) return; row.open = true; diff --git a/tests/web-blocks-tree.test.ts b/tests/web-blocks-tree.test.ts index b7c5fe0638..ac22bf0904 100644 --- a/tests/web-blocks-tree.test.ts +++ b/tests/web-blocks-tree.test.ts @@ -247,6 +247,11 @@ test("#3917: the web client bundle stays parseable JS after the tree additions", // and live refreshes swap just the .tm-inner frame so the legend row survives. assert.match(WEB_CLIENT, /fit\.hidden = !g/); assert.match(WEB_CLIENT, /insertAdjacentHTML\("afterbegin", treeMapInnerHtml/); + // #4173 review: click-to-jump hit-tests by point (pointer capture + // retargets the event), and graph mode stacks map+list instead of hiding + // the detail rows. + assert.match(WEB_CLIENT, /document\.elementFromPoint\(e\.clientX, e\.clientY\)/); + assert.match(WEB_CLIENT, /list\.hidden = false/); assert.ok(WEB_CLIENT.includes('"/sessions/" + encodeURIComponent(m[1]) + "/tree"'), "#4173 tree URL wiring present in the bundle"); assert.match(WEB_CLIENT, /"g-node tier-" \+/); assert.match(WEB_CLIENT, /data-mode="graph"/); From 6098d026c2e47aa603415b60ca4cba8b61d61dd6 Mon Sep 17 00:00:00 2001 From: ework-agent Date: Thu, 22 Oct 2026 20:27:29 +0800 Subject: [PATCH 10/16] web: render the live tree map above the block list, not below it (#4173) --- src/web/client.ts | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/web/client.ts b/src/web/client.ts index f2e3cd437d..99f20c592f 100644 --- a/src/web/client.ts +++ b/src/web/client.ts @@ -2073,6 +2073,12 @@ export const WEB_CLIENT = `(function () { const idxOf = {}; blocks.forEach(function (b, i) { if (idxOf[b.blockId] === undefined) idxOf[b.blockId] = i; }); parts.push('
' + t("det.tree_map_hint") + '
"); + const mapGraph = buildGraphSvg(blocks, true); + // #4173 review: the live map comes FIRST (总揽全局), the full block + // list stacks below it — with the old order the map ended up under a + // screen of detail rows. + parts.push(''); parts.push('
'); parts.push('
'); const rootBlocks = shape.roots.length ? shape.roots : blocks; @@ -2080,11 +2086,6 @@ export const WEB_CLIENT = `(function () { parts.push("
"); parts.push('
' + t("det.tree_hint") + "
"); parts.push("
"); - const mapGraph = buildGraphSvg(blocks, true); - // #4173: one tree, natural-size nodes inside the scrollable pane: - // wheel zoom at cursor, drag/scroll pan, tm-fit overview, 5s live refresh. - parts.push(''); parts.push("
"); return parts.join(""); } From 7fd3ebb35d927d9ee47093139967005e2779f91e Mon Sep 17 00:00:00 2001 From: ework-agent Date: Thu, 22 Oct 2026 21:19:42 +0800 Subject: [PATCH 11/16] web: collapsed list rows by default, message spans on tree nodes, active/inactive contrast, raw-view toggle (#4173) --- src/web/client.ts | 15 ++++++++++++--- src/web/styles.ts | 3 ++- tests/web-blocks-tree.test.ts | 8 +++++++- 3 files changed, 21 insertions(+), 5 deletions(-) diff --git a/src/web/client.ts b/src/web/client.ts index 99f20c592f..2e9cb4408a 100644 --- a/src/web/client.ts +++ b/src/web/client.ts @@ -1958,11 +1958,14 @@ export const WEB_CLIENT = `(function () { const cls = "g-node tier-" + (tierNum > 3 ? "n" : String(tierNum)) + (b.active ? "" : " inactive"); const ratio = b.compressedTokens > 0 && b.summaryTokens > 0 ? (100 * b.summaryTokens / b.compressedTokens).toFixed(1) + "%" : ""; const meta = fmtW(b.compressedTokens) + " \u2192 " + fmtW(b.summaryTokens) + (ratio ? " " + ratio : ""); + // #4173 review: the message span (mXXXX-mYYYY) belongs on the node, + // not only in the list row; tokens stay in the hover tooltip. + const rr = refRangeOf(b); parts.push('' - + "" + escapeHtml(b.blockId + " \u00b7 T" + tierNum + " \u00b7 " + blockTopic(b)) + "" + + "" + escapeHtml(b.blockId + " \u00b7 T" + tierNum + (rr ? " \u00b7 " + rr : "") + " \u00b7 " + meta + " \u00b7 " + blockTopic(b)) + "" + '' + '' + escapeHtml(b.blockId + " \u00b7 T" + tierNum) + "" - + '' + escapeHtml(meta) + "" + + '' + escapeHtml(rr || meta) + "" + ""); }); if (wrapped) parts.push(""); @@ -2002,7 +2005,10 @@ export const WEB_CLIENT = `(function () { function blockNodeHtml(b, shape, idx, depth) { const kids = shape.children[b.blockId] || []; const tierNum = Number(b.tier) || 1; - const openAttr = depth < 2 || (b.active && depth < 3) ? " open" : ""; + // #4173 review: rows start COLLAPSED — a 200-block session must not + // open as a wall of expanded cards. The tree-map click opens the + // target row for you; expands any row on demand. + const openAttr = ""; const badge = b.active ? '' + t("det.block_active") + "" : '' + t("det.block_inactive") + ""; @@ -2671,6 +2677,9 @@ if (d.keepalive) kv(parts, t("det.keepalive"), d.keepalive.tierLabel + " · " + const view = btn.getAttribute("data-view") === "full" ? "full" : "one"; const box = $("blk-content-" + bid); if (!box) return; + // #4173 review: pressing the same button again collapses the + // raw view (it used to be one-way, so users were stuck). + if (!box.hidden && box.getAttribute("data-view") === view) { box.hidden = true; return; } if (box.getAttribute("data-state") === "ok" && box.getAttribute("data-view") === view) { box.hidden = false; return; } box.hidden = false; box.setAttribute("data-state", "loading"); diff --git a/src/web/styles.ts b/src/web/styles.ts index cc900057df..1618b34f2f 100644 --- a/src/web/styles.ts +++ b/src/web/styles.ts @@ -280,7 +280,8 @@ td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; font-fam .g-node.tier-2 rect { stroke: #7a5af8; fill: #f6f3ff; } .g-node.tier-3 rect { stroke: #bf8700; fill: #fffaf0; } .g-node.tier-n rect { stroke: #8a8f99; fill: #f7f8fa; } -.g-node.inactive rect { stroke-dasharray: 4 3; opacity: .75; } +.g-node.inactive rect { stroke: var(--border-soft); fill: var(--bg-muted); stroke-dasharray: 4 3; } +.g-node.inactive text { opacity: .5; } .g-node:hover rect { stroke-width: 2.4; } .g-id { font: 600 11px ui-monospace, SFMono-Regular, Menlo, monospace; fill: var(--text); } .g-meta { font: 10px ui-monospace, SFMono-Regular, Menlo, monospace; fill: var(--text-muted); } diff --git a/tests/web-blocks-tree.test.ts b/tests/web-blocks-tree.test.ts index ac22bf0904..17904a5d7b 100644 --- a/tests/web-blocks-tree.test.ts +++ b/tests/web-blocks-tree.test.ts @@ -252,6 +252,12 @@ test("#3917: the web client bundle stays parseable JS after the tree additions", // the detail rows. assert.match(WEB_CLIENT, /document\.elementFromPoint\(e\.clientX, e\.clientY\)/); assert.match(WEB_CLIENT, /list\.hidden = false/); + // #4173 review: list rows start collapsed; tree nodes carry the message + // span (mXXXX–mYYYY); the raw-text button can be pressed again to close. + assert.match(WEB_CLIENT, /const openAttr = "";/); + assert.match(WEB_CLIENT, /const rr = refRangeOf\(b\)/); + assert.match(WEB_CLIENT, /escapeHtml\(rr \|\| meta\)/); + assert.match(WEB_CLIENT, /if \(!box\.hidden && box\.getAttribute\("data-view"\) === view\) \{ box\.hidden = true; return; \}/); assert.ok(WEB_CLIENT.includes('"/sessions/" + encodeURIComponent(m[1]) + "/tree"'), "#4173 tree URL wiring present in the bundle"); assert.match(WEB_CLIENT, /"g-node tier-" \+/); assert.match(WEB_CLIENT, /data-mode="graph"/); @@ -264,7 +270,7 @@ test("#4173: wide trees rotate to vertical full-size instead of shrinking to sme const start = WEB_CLIENT.indexOf("function blockTreeShape("); const end = WEB_CLIENT.indexOf("function refRangeOf("); assert.ok(start > 0 && end > start, "graph section anchors present in the bundle"); - const stubs = "var escapeHtml=function(s){return String(s);};var fmtW=function(n){return String(n);};var blockTopic=function(b){return b.topic||'';};var t=function(k){return k;};"; + const stubs = "var escapeHtml=function(s){return String(s);};var fmtW=function(n){return String(n);};var blockTopic=function(b){return b.topic||'';};var t=function(k){return k;};var refRangeOf=function(b){return '';};"; const ctx = vm.createContext({}); vm.runInContext(stubs + WEB_CLIENT.slice(start, end) + "this.api={blockGraphLayout:blockGraphLayout,blockGraphLayoutVertical:blockGraphLayoutVertical,buildGraphSvg:buildGraphSvg,graphLayouts:graphLayouts};;this.api", ctx, { filename: "web-graph.js" }); const api = ctx.api; From 3779fa758de13492a9c4cb96b09b418efb5e24ce Mon Sep 17 00:00:00 2001 From: ework-agent Date: Thu, 22 Oct 2026 21:26:01 +0800 Subject: [PATCH 12/16] =?UTF-8?q?web:=20ship=20message=20spans=20in=20the?= =?UTF-8?q?=20live=20tree=20feed=20so=20tree-map=20nodes=20label=20mXXXX?= =?UTF-8?q?=E2=80=93mYYYY=20(#4173)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/web/sessions-data.ts | 25 ++++++++++++++++++------- tests/web-blocks-tree.test.ts | 12 +++++++----- 2 files changed, 25 insertions(+), 12 deletions(-) diff --git a/src/web/sessions-data.ts b/src/web/sessions-data.ts index 1ea97b01bb..b28b5b7a69 100644 --- a/src/web/sessions-data.ts +++ b/src/web/sessions-data.ts @@ -1030,6 +1030,10 @@ export interface WebSessionTreeNode { blockId: string; tier: number; active: boolean; + // #4173 review: the covered message span (canonicalized ascending) so the + // live tree-map nodes can label "mXXXX–mYYYY" without shipping summaries. + startRef?: string; + endRef?: string; parentBlockId?: string; directBlockIds: string[]; } @@ -1046,13 +1050,20 @@ export async function buildSessionTree(id: string): Promise<{ blocks: WebSession if (!parentOf.has(childId)) parentOf.set(childId, b.blockId); } } - const blocks: WebSessionTreeNode[] = found.session.state.blocks.slice(0, TREE_MAX_BLOCKS).map((b) => ({ - blockId: b.blockId, - tier: b.tier, - active: b.active !== false, - ...(parentOf.get(b.blockId) !== undefined ? { parentBlockId: parentOf.get(b.blockId)! } : {}), - directBlockIds: (b.directBlockIds || []).slice(), - })); + const blocks: WebSessionTreeNode[] = found.session.state.blocks.slice(0, TREE_MAX_BLOCKS).map((b) => { + const span = + b.startRef !== undefined && b.endRef !== undefined + ? orderedRefPair(b.startRef, b.endRef) + : null; + return { + blockId: b.blockId, + tier: b.tier, + active: b.active !== false, + ...(span ? { startRef: span[0], endRef: span[1] } : {}), + ...(parentOf.get(b.blockId) !== undefined ? { parentBlockId: parentOf.get(b.blockId)! } : {}), + directBlockIds: (b.directBlockIds || []).slice(), + }; + }); return { blocks }; } diff --git a/tests/web-blocks-tree.test.ts b/tests/web-blocks-tree.test.ts index 17904a5d7b..8e3b0ba927 100644 --- a/tests/web-blocks-tree.test.ts +++ b/tests/web-blocks-tree.test.ts @@ -168,16 +168,18 @@ test("#3917: a folded message the host pruned reports a miss instead of a guess" assert.deepEqual(await buildMessageContent("tree-pruned", "m00001"), { ok: false, reason: "unknown-message" }); }); -test("#4173: the live tree endpoint ships only ids/tiers/edges — no summaries", async () => { - const t1 = mkBlock("b1", 1, "## T1 summary\n- point one", ["rm1"], ["rm1"], []); - const t2 = mkBlock("b2", 2, "T2 summary", ["rm3"], ["rm1", "rm3"], ["b1"]); +test("#4173: the live tree endpoint ships ids/tiers/edges/spans — no summaries", async () => { + // #4173 review: nodes label their covered message span; non-monotonic + // stored spans are canonicalized ascending before leaving the server. + const t1 = mkBlock("b1", 1, "## T1 summary\n- point one", ["rm1"], ["rm1"], [], ["m00010", "m00005"]); + const t2 = mkBlock("b2", 2, "T2 summary", ["rm3"], ["rm1", "rm3"], ["b1"], ["m00001", "m00030"]); seedSession("tree-live", [t1, t2]); const tree = await buildSessionTree("tree-live"); assert.ok(tree); assert.equal(tree.blocks.length, 2); const byId = new Map(tree.blocks.map((b) => [b.blockId, b])); - assert.deepEqual(byId.get("b1"), { blockId: "b1", tier: 1, active: true, parentBlockId: "b2", directBlockIds: [] }, "the child names its fold parent"); - assert.deepEqual(byId.get("b2"), { blockId: "b2", tier: 2, active: true, directBlockIds: ["b1"] }, "the root has no parent field at all"); + assert.deepEqual(byId.get("b1"), { blockId: "b1", tier: 1, active: true, startRef: "m00005", endRef: "m00010", parentBlockId: "b2", directBlockIds: [] }, "the child names its fold parent AND its message span"); + assert.deepEqual(byId.get("b2"), { blockId: "b2", tier: 2, active: true, startRef: "m00001", endRef: "m00030", directBlockIds: ["b1"] }, "the root has no parent field at all"); // The whole point of the compact feed: no summary bytes on the wire. assert.ok(!JSON.stringify(tree).includes("point one"), "summaries never leave the server"); assert.equal(await buildSessionTree("no-such-session"), null, "unknown session resolves to a 404 payload"); From 194542ce6cc5f647cd2dcf28d970ebaa41fd80cb Mon Sep 17 00:00:00 2001 From: ework-agent Date: Thu, 22 Oct 2026 22:26:10 +0800 Subject: [PATCH 13/16] web: jump to the top of a block row; clamp long summaries to five lines with a show-all toggle (#4173) --- src/web/client.ts | 38 +++++++++++++++++++++++++++++++++-- src/web/i18n.ts | 4 ++++ src/web/styles.ts | 2 ++ tests/web-blocks-tree.test.ts | 8 ++++++++ 4 files changed, 50 insertions(+), 2 deletions(-) diff --git a/src/web/client.ts b/src/web/client.ts index 2e9cb4408a..53b0efce65 100644 --- a/src/web/client.ts +++ b/src/web/client.ts @@ -2020,6 +2020,15 @@ export const WEB_CLIENT = `(function () { if (b.effectiveMessageCount) meta.push(t("det.tree_msgs", { n: b.effectiveMessageCount })); if (refRange) meta.push(refRange); meta.push(timeAgo(b.createdAt)); + // #4173 review: long summaries open as five clamped lines + a show-all + // button. Closed
rows have no layout, so whether the clamp + // actually cut anything is measured once on first expand (below). + const sumLong = String(b.summary || "").trim().length > 64; + let bodyInner = renderBlockMd(b.summary || ""); + if (sumLong) { + bodyInner = '
' + bodyInner + '
' + + '"; + } const bid = escapeHtml(b.blockId); let html = '
" + '' + bid + "" + badge + extBadge @@ -2027,7 +2036,7 @@ export const WEB_CLIENT = `(function () { + '' + escapeHtml(meta.join(" · ")) + "" + '" + "" - + '
' + renderBlockMd(b.summary || "") + "
" + + '
' + bodyInner + "
" + '
' + '" + '" @@ -2726,6 +2735,29 @@ if (d.keepalive) kv(parts, t("det.keepalive"), d.keepalive.tierLabel + " · " + } }); }); + // #4173 review: measure each clamped summary when its row first opens — + // a closed
has no layout, so the cut-or-not verdict can only + // happen here; rows the clamp never shortened lose their button. + document.querySelectorAll(".block-node").forEach(function (det) { + det.addEventListener("toggle", function () { + if (!det.open) return; + const body = det.querySelector(":scope > .body.md"); + if (!body || body.__sumChk) return; + body.__sumChk = 1; + let sum = null, btn = null; + for (let i = 0; i < body.children.length; i++) { + const c = body.children[i]; + if (c.classList.contains("blk-sum")) sum = c; + if (c.classList.contains("blk-sum-toggle")) btn = c; + } + if (!sum || !btn) return; + if (sum.scrollHeight <= sum.clientHeight + 2) { sum.classList.remove("clamp"); btn.remove(); return; } + btn.addEventListener("click", function () { + const clamped = sum.classList.toggle("clamp"); + btn.textContent = clamped ? t("det.tree_sum_more") : t("det.tree_sum_less"); + }); + }); + }); } // #3917: the compression pane carries two readings of the same data — the // list (read concrete messages) and the graph (read the overall shape). @@ -2820,7 +2852,9 @@ if (d.keepalive) kv(parts, t("det.keepalive"), d.keepalive.tierLabel + " · " + if (!row) return; row.open = true; row.classList.add("flash"); - row.scrollIntoView({ block: "center", behavior: "smooth" }); + // #4173 review: land at the TOP of the block — long rows used to + // scroll to their middle and looked lost. + row.scrollIntoView({ block: "start", behavior: "smooth" }); setTimeout(function () { row.classList.remove("flash"); }, 1600); }); view.addEventListener("pointercancel", function () { drag = null; }); diff --git a/src/web/i18n.ts b/src/web/i18n.ts index eba358faa8..db811b6c89 100644 --- a/src/web/i18n.ts +++ b/src/web/i18n.ts @@ -387,6 +387,8 @@ export const MESSAGES: Record> = { "det.tree_msgs": "{n} 条消息", "det.tree_direct": "直属 {n} 条", "det.tree_orig_one": "原文(本层)", + "det.tree_sum_more": "查看全部", + "det.tree_sum_less": "收起", "det.tree_orig_full": "原文(全部)", "det.tree_orig_meta": "{n} 条消息 · {b}", "det.tree_orig_truncated": "已截断至 {b}", @@ -925,6 +927,8 @@ export const MESSAGES: Record> = { "det.tree_msgs": "{n} msgs", "det.tree_direct": "{n} direct", "det.tree_orig_one": "Original (this level)", + "det.tree_sum_more": "Show all", + "det.tree_sum_less": "Collapse", "det.tree_orig_full": "Original (full)", "det.tree_orig_meta": "{n} messages · {b}", "det.tree_orig_truncated": "truncated at {b}", diff --git a/src/web/styles.ts b/src/web/styles.ts index 1618b34f2f..7610c498d7 100644 --- a/src/web/styles.ts +++ b/src/web/styles.ts @@ -285,6 +285,8 @@ td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; font-fam .g-node:hover rect { stroke-width: 2.4; } .g-id { font: 600 11px ui-monospace, SFMono-Regular, Menlo, monospace; fill: var(--text); } .g-meta { font: 10px ui-monospace, SFMono-Regular, Menlo, monospace; fill: var(--text-muted); } +.blk-sum.clamp { display: -webkit-box; -webkit-line-clamp: 5; -webkit-box-orient: vertical; overflow: hidden; } +.blk-sum-toggle { margin-top: 6px; } .block-node.flash { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 8px; } .block-node .block-node { margin-left: 18px; border-left: 2px solid var(--border-soft); } .block-node summary { align-items: center; flex-wrap: wrap; row-gap: 4px; } diff --git a/tests/web-blocks-tree.test.ts b/tests/web-blocks-tree.test.ts index 8e3b0ba927..f3d2945341 100644 --- a/tests/web-blocks-tree.test.ts +++ b/tests/web-blocks-tree.test.ts @@ -206,6 +206,8 @@ test("#3917: the tree's strings exist in both locales with identical placeholder "det.tree_view_list", "det.tree_view_graph", "det.tree_map_hint", + "det.tree_sum_more", + "det.tree_sum_less", "det.tree_map_fit", "det.tree_graph_legend", ]; @@ -260,6 +262,12 @@ test("#3917: the web client bundle stays parseable JS after the tree additions", assert.match(WEB_CLIENT, /const rr = refRangeOf\(b\)/); assert.match(WEB_CLIENT, /escapeHtml\(rr \|\| meta\)/); assert.match(WEB_CLIENT, /if \(!box\.hidden && box\.getAttribute\("data-view"\) === view\) \{ box\.hidden = true; return; \}/); + // #4173 review: jump lands at the top of the target row; long summaries + // open as five clamped lines behind a show-all toggle. + assert.match(WEB_CLIENT, /row\.scrollIntoView\(\{ block: "start", behavior: "smooth" \}\)/); + assert.match(WEB_CLIENT, /blk-sum clamp/); + assert.match(WEB_CLIENT, /blk-sum-toggle/); + assert.match(WEB_CLIENT, /body\.__sumChk/); assert.ok(WEB_CLIENT.includes('"/sessions/" + encodeURIComponent(m[1]) + "/tree"'), "#4173 tree URL wiring present in the bundle"); assert.match(WEB_CLIENT, /"g-node tier-" \+/); assert.match(WEB_CLIENT, /data-mode="graph"/); From 06e280a313462d51e59750b496bd9169d77720f4 Mon Sep 17 00:00:00 2001 From: ework-agent Date: Thu, 22 Oct 2026 23:06:07 +0800 Subject: [PATCH 14/16] web: flow the tree map with the page and draw its nodes tighter (#4173) --- src/web/client.ts | 138 ++++++++++++++++++---------------- src/web/i18n.ts | 4 +- src/web/styles.ts | 12 +-- tests/web-blocks-tree.test.ts | 16 ++-- 4 files changed, 95 insertions(+), 75 deletions(-) diff --git a/src/web/client.ts b/src/web/client.ts index 53b0efce65..8c146e6b3e 100644 --- a/src/web/client.ts +++ b/src/web/client.ts @@ -1836,7 +1836,17 @@ export const WEB_CLIENT = `(function () { const GRAPH_GAP_X = 16; const GRAPH_LEVEL_H = 84; const GRAPH_FIT_W = 1120; - function blockGraphLayout(blocks) { + // #4173 review: the in-page live map draws with tighter nodes so long + // sessions stay one readable drawing; every other call site keeps the + // original full-size metrics byte-for-byte. + const MAP_NODE_W = 92; + const MAP_NODE_H = 30; + const MAP_GAP_X = 8; + const MAP_LEVEL_H = 46; + const FULL_METRICS = { w: GRAPH_NODE_W, h: GRAPH_NODE_H, gx: GRAPH_GAP_X, lh: GRAPH_LEVEL_H }; + const MAP_METRICS = { w: MAP_NODE_W, h: MAP_NODE_H, gx: MAP_GAP_X, lh: MAP_LEVEL_H }; + function blockGraphLayout(blocks, m) { + m = m || FULL_METRICS; const shape = blockTreeShape(blocks); const nodes = []; const links = []; @@ -1853,11 +1863,11 @@ export const WEB_CLIENT = `(function () { let x; if (!childNodes.length) { x = cursor; - cursor += GRAPH_NODE_W + GRAPH_GAP_X; + cursor += m.w + m.gx; } else { x = (childNodes[0].x + childNodes[childNodes.length - 1].x) / 2; } - const node = { b: b, x: x, y: depth * GRAPH_LEVEL_H }; + const node = { b: b, x: x, y: depth * m.lh }; nodes.push(node); if (depth > maxDepth) maxDepth = depth; childNodes.forEach(function (c) { links.push([node, c]); }); @@ -1866,14 +1876,15 @@ export const WEB_CLIENT = `(function () { const roots = shape.roots.length ? shape.roots : blocks; roots.forEach(function (r) { place(r, 0); }); if (!nodes.length) return { nodes: [], links: [], width: 0, height: 0 }; - return { nodes: nodes, links: links, width: cursor - GRAPH_GAP_X, height: maxDepth * GRAPH_LEVEL_H + GRAPH_NODE_H }; + return { nodes: nodes, links: links, width: cursor - m.gx, height: maxDepth * m.lh + m.h }; } // #4173: vertical mirror of blockGraphLayout — depth is the x-axis and the // shared cursor packs sibling stacks along y. Chosen when a tree is far // wider than it is tall: rotating puts the long dimension on the one axis - // the pane already scrolls (.tree-graph max-height:70vh overflow:auto) and - // keeps every box at its natural 118×36 size. - function blockGraphLayoutVertical(blocks) { + // the page scrolls, keeping every box at natural size (the in-page map's + // tighter metrics arrive from the caller). + function blockGraphLayoutVertical(blocks, m) { + m = m || FULL_METRICS; const shape = blockTreeShape(blocks); const nodes = []; const links = []; @@ -1890,11 +1901,11 @@ export const WEB_CLIENT = `(function () { let y; if (!childNodes.length) { y = cursor; - cursor += GRAPH_NODE_H + GRAPH_GAP_X; + cursor += m.h + m.gx; } else { y = (childNodes[0].y + childNodes[childNodes.length - 1].y) / 2; } - const node = { b: b, x: depth * (GRAPH_NODE_W + GRAPH_GAP_X), y: y }; + const node = { b: b, x: depth * (m.w + m.gx), y: y }; nodes.push(node); if (depth > maxDepth) maxDepth = depth; childNodes.forEach(function (c) { links.push([node, c]); }); @@ -1903,31 +1914,32 @@ export const WEB_CLIENT = `(function () { const roots = shape.roots.length ? shape.roots : blocks; roots.forEach(function (r) { place(r, 0); }); if (!nodes.length) return { nodes: [], links: [], width: 0, height: 0 }; - return { nodes: nodes, links: links, width: maxDepth * (GRAPH_NODE_W + GRAPH_GAP_X) + GRAPH_NODE_W, height: cursor - GRAPH_GAP_X }; + return { nodes: nodes, links: links, width: maxDepth * (m.w + m.gx) + m.w, height: cursor - m.gx }; } // #4173: orientation shared by the full graph and the in-pane tree map — // flat unless the tree overflows the card AND rotation shortens the long // dimension; small trees stay byte-identical to the original rendering. - function graphLayouts(blocks) { - const lh = blockGraphLayout(blocks); - const lv = lh.width > GRAPH_FIT_W ? blockGraphLayoutVertical(blocks) : null; + function graphLayouts(blocks, m) { + const lh = blockGraphLayout(blocks, m); + const lv = lh.width > GRAPH_FIT_W ? blockGraphLayoutVertical(blocks, m) : null; const vertical = !!lv && lv.height < lh.width; return { layout: vertical ? lv : lh, vertical: vertical }; } // Bezier for one parent→child edge in either orientation — shared by every // #4173 drawing (static graph and live in-pane map) so they always agree. - function graphEdgePath(l, pad, vertical) { + function graphEdgePath(l, pad, vertical, m) { + m = m || FULL_METRICS; if (vertical) { - const x1 = l[0].x + pad + GRAPH_NODE_W; - const y1 = l[0].y + pad + GRAPH_NODE_H / 2; + const x1 = l[0].x + pad + m.w; + const y1 = l[0].y + pad + m.h / 2; const x2 = l[1].x + pad; - const y2 = l[1].y + pad + GRAPH_NODE_H / 2; + const y2 = l[1].y + pad + m.h / 2; const mx = (x1 + x2) / 2; return "M" + x1 + " " + y1 + " C" + mx + " " + y1 + " " + mx + " " + y2 + " " + x2 + " " + y2; } - const x1 = l[0].x + pad + GRAPH_NODE_W / 2; - const y1 = l[0].y + pad + GRAPH_NODE_H; - const x2 = l[1].x + pad + GRAPH_NODE_W / 2; + const x1 = l[0].x + pad + m.w / 2; + const y1 = l[0].y + pad + m.h; + const x2 = l[1].x + pad + m.w / 2; const y2 = l[1].y + pad; const my = (y1 + y2) / 2; return "M" + x1 + " " + y1 + " C" + x1 + " " + my + " " + x2 + " " + my + " " + x2 + " " + y2; @@ -1937,8 +1949,9 @@ export const WEB_CLIENT = `(function () { // show it 1:1 inside a scrollable viewport; zoom resizes the wrapping // .tm-inner box (the svg fills it via CSS), which keeps scroll ranges // honest while the browser scales the drawing uniformly. - function buildGraphSvg(blocks, wrapped) { - const g = graphLayouts(blocks); + function buildGraphSvg(blocks, wrapped, m) { + m = m || FULL_METRICS; + const g = graphLayouts(blocks, m); const layout = g.layout; const vertical = g.vertical; if (!layout.nodes.length) return { html: "", vertical: false, width: 0, height: 0 }; @@ -1949,8 +1962,11 @@ export const WEB_CLIENT = `(function () { const parts = []; parts.push(''); if (wrapped) parts.push(''); + // compact rows carry the two text lines closer together + const idY = m.h >= 36 ? 15 : 12; + const metaY = m.h >= 36 ? 28 : 22; layout.links.forEach(function (l) { - parts.push(''); + parts.push(''); }); layout.nodes.forEach(function (n) { const b = n.b; @@ -1963,9 +1979,9 @@ export const WEB_CLIENT = `(function () { const rr = refRangeOf(b); parts.push('' + "" + escapeHtml(b.blockId + " \u00b7 T" + tierNum + (rr ? " \u00b7 " + rr : "") + " \u00b7 " + meta + " \u00b7 " + blockTopic(b)) + "" - + '' - + '' + escapeHtml(b.blockId + " \u00b7 T" + tierNum) + "" - + '' + escapeHtml(rr || meta) + "" + + '' + + '' + escapeHtml(b.blockId + " \u00b7 T" + tierNum) + "" + + '' + escapeHtml(rr || meta) + "" + ""); }); if (wrapped) parts.push(""); @@ -1993,10 +2009,14 @@ export const WEB_CLIENT = `(function () { const nw = parseFloat(inner.getAttribute("data-nw")) || 0; const nh = parseFloat(inner.getAttribute("data-nh")) || 0; if (!nw || !nh) return; - view.__vm = { k: Math.min(view.clientWidth / nw, view.clientHeight / nh) * 0.98 }; + // #4173 review: the map flows with the page, so Fit shrinks the whole + // tree into roughly the current viewport and centers it there. + const w = Math.max(320, document.documentElement.clientWidth - 120); + const h = Math.max(320, window.innerHeight - 180); + view.__vm = { k: Math.min(1, Math.min(w / nw, h / nh) * 0.98) }; treeMapApply(view); - view.scrollLeft = Math.max(0, (nw * view.__vm.k - view.clientWidth) / 2); - view.scrollTop = Math.max(0, (nh * view.__vm.k - view.clientHeight) / 2); + const r = inner.getBoundingClientRect(); + window.scrollBy(0, (r.top + (nh * view.__vm.k) / 2) - window.innerHeight / 2); } function refRangeOf(b) { if (!b.startRef) return ""; @@ -2088,11 +2108,11 @@ export const WEB_CLIENT = `(function () { const idxOf = {}; blocks.forEach(function (b, i) { if (idxOf[b.blockId] === undefined) idxOf[b.blockId] = i; }); parts.push('
' + t("det.tree_map_hint") + '
"); - const mapGraph = buildGraphSvg(blocks, true); + const mapGraph = buildGraphSvg(blocks, true, MAP_METRICS); // #4173 review: the live map comes FIRST (总揽全局), the full block // list stacks below it — with the old order the map ended up under a // screen of detail rows. - parts.push('