dsh-trajectory-traceview-plus 0.11.4 → 0.11.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -37,6 +37,7 @@
37
37
  - `scripts/doc-heading-check.mjs`
38
38
  - `scripts/doc-ref-check.mjs`
39
39
  - `scripts/guard-check.mjs`
40
+ - `scripts/harness-stamp.mjs`
40
41
  - `scripts/provenance.mjs`
41
42
  - `scripts/readme-numbers.mjs`
42
43
  - `scripts/release-status.mjs`
@@ -49,12 +50,13 @@
49
50
  - `src/40-view.js`
50
51
  - `src/50-entry.js`
51
52
  - `test/browser/fixture.js`
53
+ - `test/browser/probe-detail.js`
52
54
  - `test/browser/probe-en.js`
53
55
  - `test/browser/probe.js`
54
56
 
55
57
  ## 二、`lib/client.js` 函数级
56
58
 
57
- 上游 24 个函数:**9 个原样保留、15 个被修改、0 个被删除**;本仓**新增 48 个**。
59
+ 上游 24 个函数:**9 个原样保留、15 个被修改、0 个被删除**;本仓**新增 49 个**。
58
60
 
59
61
  ### 原样保留(9)
60
62
 
@@ -90,7 +92,7 @@
90
92
  - `subDetailOf`
91
93
  - `textOfContent`
92
94
 
93
- ### 本仓新增(48)
95
+ ### 本仓新增(49)
94
96
 
95
97
  上游完全没有:
96
98
 
@@ -139,6 +141,7 @@
139
141
  - `stationHay`
140
142
  - `stepOf`
141
143
  - `toolSchemaKey`
144
+ - `unknownBlockLabel`
142
145
  - `unknownNodeStats`
143
146
  - `viewStateKey`
144
147
  - `writeViewState`
package/lib/client.js CHANGED
@@ -664,9 +664,15 @@ window.__ModuleLoader__.load({
664
664
  ".dstv_btn[data-on=true]{color:var(--dstv-info-ink);background:color-mix(in srgb,var(--dstv-info) 12%,transparent);box-shadow:inset 0 0 0 1px color-mix(in srgb,var(--dstv-info) 40%,transparent)}",
665
665
  ".dstv_tbtn[data-on=true]{color:var(--dstv-info-ink);background:color-mix(in srgb,var(--dstv-info) 14%,transparent);font-weight:700}",
666
666
  ".dstv_station[data-match=true] .dstv_hcard{border-color:transparent;background:linear-gradient(var(--dsw-alias-bg-layer-1),var(--dsw-alias-bg-layer-1)) padding-box,linear-gradient(135deg,var(--dstv-warn),var(--dstv-warn)) border-box;box-shadow:0 0 12px color-mix(in srgb,var(--dstv-warn) 35%,transparent)}",
667
- ".dstv_station[data-seek-dim=true] .dstv_hcard{opacity:.5;filter:saturate(.3)}",
668
- ".dstv_station[data-seek-dim=true] .dstv_hDot{opacity:.35}",
667
+ // Searching dims the non-matches. Driven from the listbox so a keystroke does not
668
+ // rewrite every station element (§13.72): reached = not [data-dim], matched =
669
+ // [data-match]. Same visual result, one attribute instead of N.
670
+ ".dstv_listbox[data-searching=true] .dstv_station:not([data-dim=true]):not([data-match=true]) .dstv_hcard{opacity:.5;filter:saturate(.3)}",
671
+ ".dstv_listbox[data-searching=true] .dstv_station:not([data-dim=true]):not([data-match=true]) .dstv_hDot{opacity:.35}",
669
672
  ".dstv_miniTick[data-match=true]{box-shadow:0 0 0 1.5px var(--dstv-warn);height:14px}",
673
+ // While searching, fade the ticks that did not match. Reached-only ticks fade via
674
+ // [data-dim]; the search fade lives here so it costs no per-tick attribute (§13.72).
675
+ ".dstv_minimap[data-searching=true] .dstv_miniTick:not([data-dim=true]):not([data-match=true]){opacity:.25}",
670
676
  ".dstv_detail.full{max-height:82vh}",
671
677
  ".dstv_panelToggle{margin-left:4px}",
672
678
  ".dstv_subCard{border:1px solid var(--dsw-alias-border-l2);border-radius:8px;padding:5px 8px;background:var(--dsw-alias-bg-layer-2);display:flex;flex-direction:column;gap:3px;margin-top:3px}",
@@ -2004,7 +2010,7 @@ window.__ModuleLoader__.load({
2004
2010
  // `image`/`other` arrived). These used to fall through the chain and
2005
2011
  // vanish, so a future block type would render as "the model said
2006
2012
  // nothing". Name it instead of guessing at its content.
2007
- st.cells.push({ id: `u${n.seq}${st.cells.length}`, kind: "assistant", text: `${t("block.unknown")} · ${String(b.kind)}`, thinking: "" });
2013
+ st.cells.push({ id: `u${n.seq}${st.cells.length}`, kind: "assistant", text: unknownBlockLabel(b, t), thinking: "" });
2008
2014
  } else if (b.kind === "tool-call") {
2009
2015
  // every durable block is a real call, even with a repeated id
2010
2016
  claimCall(turn, b.callId);
@@ -2192,7 +2198,7 @@ window.__ModuleLoader__.load({
2192
2198
  // know must be NAMED, not dropped. The streaming branch was missed when the
2193
2199
  // durable one got the placeholder, so a live `file`/future block showed an
2194
2200
  // empty step (measured: cells [] for {kind:"future"} and {kind:"file"}).
2195
- st.cells.push({ id: `pu${st.cells.length}`, kind: "assistant", text: `${t("block.unknown")} · ${String(b.kind)}`, thinking: "" });
2201
+ st.cells.push({ id: `pu${st.cells.length}`, kind: "assistant", text: unknownBlockLabel(b, t), thinking: "" });
2196
2202
  } else if (b.kind === "tool-call") {
2197
2203
  if (claimedCall(turn, b.callId)) continue;
2198
2204
  claimCall(turn, b.callId);
@@ -2737,6 +2743,26 @@ window.__ModuleLoader__.load({
2737
2743
  const flat = String(raw ?? "").replace(/\s+/g, " ").trim();
2738
2744
  return flat.length > 80 ? `${flat.slice(0, 80)}…` : flat;
2739
2745
  }
2746
+ /**
2747
+ * The label for a block kind this build does not know.
2748
+ *
2749
+ * It used to be `${t("block.unknown")} · ${String(b.kind)}`, which is fine for a
2750
+ * FUTURE kind ("未知内容 · image") but renders the literal string "undefined" when
2751
+ * the kind is missing entirely — and that label reaches both the card text and the
2752
+ * station's aria-label, so a screen-reader user heard "unknown content · undefined".
2753
+ * A record with no kind at all is a malformed record, not a future one, and naming
2754
+ * it "undefined" is worse than saying nothing.
2755
+ * @param b - the block whose kind is unknown.
2756
+ * @param t - the bound language function.
2757
+ * @returns the label to show.
2758
+ */
2759
+ function unknownBlockLabel(b, t) {
2760
+ const base = t("block.unknown");
2761
+ const kind = b !== null && b !== void 0 ? b.kind : void 0;
2762
+ if (typeof kind !== "string" || kind === "") return base;
2763
+ return `${base} · ${kind}`;
2764
+ }
2765
+
2740
2766
  function stationAriaLabel(station, position, total, t) {
2741
2767
  // Per-turn number: `stepNo` is a window-wide counter, so this label used to
2742
2768
  // read "步骤 1" and then "步骤 5" for the same station once older history was
@@ -3617,6 +3643,32 @@ window.__ModuleLoader__.load({
3617
3643
  function TraceMapView({ useSession, useTrajectory, t, viewRequest, completeViewRequest, loadOlder, sessionKey }) {
3618
3644
  const scrollerRef = (0, react.useRef)(null);
3619
3645
  const minimapRef = (0, react.useRef)(null);
3646
+ // Per-station rendered elements, so an unchanged card keeps its element identity and
3647
+ // React skips the subtree entirely. Cleared when the session changes (ids are only
3648
+ // unique within a session) — see `stationSig`'s comment.
3649
+
3650
+ const cardElCache = (0, react.useRef)(new Map());
3651
+ const tickElCache = (0, react.useRef)(new Map());
3652
+ // The caches live as long as the view, but their contents are only valid for one
3653
+ // language and one session: station ids are per-session, and a cached element holds
3654
+ // already-translated text. Clearing on change keeps `t` and `sessionKey` out of the
3655
+ // per-element signature (they would invalidate every card anyway).
3656
+ const sigCacheRef = (0, react.useRef)({ arr: null, sigs: [] });
3657
+ const cacheScopeRef = (0, react.useRef)({ t: null, sessionKey: null });
3658
+ // A cached element keeps the closures it was built with. Those closures would go
3659
+ // stale the moment the view re-renders (arrow keys read the current selection, seek
3660
+ // reads the current window) — so the cards call THROUGH this ref, which is refreshed
3661
+ // on every render. Element identity stays cacheable, behaviour stays current.
3662
+ const handlersRef = (0, react.useRef)({ seek: null, keyDown: null });
3663
+
3664
+
3665
+ if (cacheScopeRef.current.t !== t || cacheScopeRef.current.sessionKey !== sessionKey) {
3666
+ cacheScopeRef.current = { t, sessionKey };
3667
+ cardElCache.current.clear();
3668
+ tickElCache.current.clear();
3669
+ sigCacheRef.current.arr = null;
3670
+ sigCacheRef.current.sigs = [];
3671
+ }
3620
3672
  const searchRef = (0, react.useRef)(null);
3621
3673
  const initDone = (0, react.useRef)(false);
3622
3674
  // Which session this panel is showing. The host reuses one component instance
@@ -4338,6 +4390,17 @@ window.__ModuleLoader__.load({
4338
4390
  seek(i); ev.preventDefault(); ev.stopPropagation();
4339
4391
  }
4340
4392
  };
4393
+ // Refreshed after commit; a cached element reads it at click/key time. A layout
4394
+ // effect rather than a render-time assignment, because a render React throws away
4395
+ // would otherwise leave the abandoned pass's handler behind.
4396
+ //
4397
+ // DECLARED HERE, above `if (N === 0)` and its early return: a hook below that
4398
+ // branch is skipped on the empty/loading render, and React aborts the whole panel
4399
+ // with "Rendered fewer hooks than expected".
4400
+ (0, react.useLayoutEffect)(() => {
4401
+ handlersRef.current.seek = seek;
4402
+ handlersRef.current.keyDown = stationOnKeyDown;
4403
+ });
4341
4404
  const onKeyDown = (ev) => {
4342
4405
  const k = ev.key;
4343
4406
  // Browser and OS shortcuts must win. The panel root is focusable
@@ -4650,6 +4713,77 @@ window.__ModuleLoader__.load({
4650
4713
  });
4651
4714
  }
4652
4715
 
4716
+ /**
4717
+ * Element cache for the station list and the minimap.
4718
+ *
4719
+ * Why: the list renders EVERY station on every state change. Measured on a
4720
+ * 900-station window, one keystroke in the search box cost 1.3–2.2 s of main
4721
+ * thread — typing a query was unusable. The tree fold is NOT the cost (that is
4722
+ * memoised and does not re-run on a keystroke); the cost is rebuilding ~900 card
4723
+ * subtrees and ~900 minimap buttons to flip `data-seek-dim` on the handful of
4724
+ * stations that actually matched.
4725
+ *
4726
+ * Rebuilding an element and re-rendering it are different costs, and React bails
4727
+ * out of the second when the ELEMENT IS THE SAME OBJECT (referential equality).
4728
+ * So: cache the element per station and return the previous one when nothing the
4729
+ * card reads has changed. Compared by VALUE — each fold allocates fresh station
4730
+ * objects, so nothing else here can be compared by identity (§13.72).
4731
+ *
4732
+ * The signature covers exactly what the card body reads: the station fields
4733
+ * `renderStationCard` + the axis zone touch, its position, its neighbour's edge
4734
+ * (the idle band), and the four per-station booleans the parent computes.
4735
+ */
4736
+ // FNV-1a over the fields the card reads, accumulated WITHOUT building a
4737
+ // concatenated string. The first version joined every field into one string —
4738
+ // harmlessly fast on the fixture, but a real 1000-node window carries ~1.1 MB of
4739
+ // tool output, and joining that per station per render made a keystroke cost
4740
+ // 1.17 s again. A rolling hash over each field is linear either way, but it
4741
+ // allocates nothing (§13.73).
4742
+
4743
+ const stationSig = (s) => {
4744
+ if (s == null) return "";
4745
+ let h = 2166136261;
4746
+ const mix = (v) => {
4747
+ if (v === null || v === void 0) { h = (h ^ 31) * 16777619 >>> 0; return; }
4748
+ if (typeof v === "number") {
4749
+ h = (h ^ (v | 0)) * 16777619 >>> 0;
4750
+ h = (h ^ (Math.floor(v * 1000) | 0)) * 16777619 >>> 0;
4751
+ return;
4752
+ }
4753
+ if (typeof v === "boolean") { h = (h ^ (v ? 1 : 2)) * 16777619 >>> 0; return; }
4754
+ const str = String(v);
4755
+ h = (h ^ str.length) * 16777619 >>> 0;
4756
+ for (let i = 0; i < str.length; i += 1) h = ((h ^ str.charCodeAt(i)) * 16777619) >>> 0;
4757
+ };
4758
+ mix(s.kind); mix(s.id); mix(s.label); mix(s.who); mix(s.text);
4759
+ mix(s.displayText); mix(s.summary); mix(s.message); mix(s.name);
4760
+ mix(s.args); mix(s.payload); mix(s.eventType); mix(s.replace); mix(s.retry);
4761
+ mix(s.isError); mix(s.hasError); mix(s.live); mix(s.synthetic); mix(s.tag);
4762
+ mix(s.time); mix(s.startMs); mix(s.endMs); mix(s.seq); mix(s.toolMs); mix(s.maxToolMs);
4763
+ // The duration bar divides by a GLOBAL denominator (`stats.maxToolMs ||
4764
+ // stats.toolMs`), not by this station's own maximum. Mixing only the station
4765
+ // fields meant every cached bar kept its old width when a DIFFERENT station
4766
+ // became the slowest one — a stale proportion bar, caught by review.
4767
+ mix(stats.maxToolMs); mix(stats.toolMs);
4768
+ mix(s.outcomeText); mix(s.outcomeKind);
4769
+ if (Array.isArray(s.meta)) { mix(s.meta.length); for (const m of s.meta) mix(m); }
4770
+ else mix(s.meta);
4771
+ // EVERY cell field the card renders, not just the shape. The first version
4772
+ // hashed only kind/isError/running — so a settled step whose assistant cell text
4773
+ // changed kept the OLD text on the card (verified: ALPHA-ONE stayed on screen
4774
+ // while the detail panel showed ALPHA-TWO). `resultText` is deliberately absent:
4775
+ // the card does not render it and it is by far the largest field (§13.75).
4776
+ if (Array.isArray(s.cells)) {
4777
+ mix(s.cells.length);
4778
+ for (const c of s.cells) {
4779
+ mix(c.kind); mix(c.id);
4780
+ mix(c.text); mix(c.thinking);
4781
+ mix(c.name); mix(c.args); mix(c.errorName);
4782
+ mix(c.durationMs); mix(c.isError === true); mix(c.running === true);
4783
+ }
4784
+ } else mix(-1);
4785
+ return h.toString(36);
4786
+ };
4653
4787
  const renderStationCard = (s, cardKey) => {
4654
4788
  if (s.kind === "user") {
4655
4789
  return jsxs("div", {
@@ -4814,6 +4948,9 @@ window.__ModuleLoader__.load({
4814
4948
  const minimapTicks = jsx("div", {
4815
4949
  className: "dstv_minimap",
4816
4950
  ref: minimapRef,
4951
+ // Same reason as the listbox: search dimming is one attribute on the strip,
4952
+ // not one per tick, so a keystroke does not rebuild every tick element.
4953
+ "data-searching": searching ? "true" : undefined,
4817
4954
  children: stations.map((s, i) => {
4818
4955
  const reached = i < R;
4819
4956
  let k = s.kind;
@@ -4821,13 +4958,34 @@ window.__ModuleLoader__.load({
4821
4958
  if (s.kind === "maxTokens") k = "error";
4822
4959
  const done = reached && (s.kind !== "step" || !s.live);
4823
4960
  const matched = searching && matchSet.has(i);
4824
- return jsx("button", {
4961
+ // Same element-identity trick as the station cards: an unchanged tick keeps
4962
+ // its element and React skips it (§13.72).
4963
+ const tickSig = s.kind + "\u0002" + String(i) + "\u0002" + (reached ? "1" : "0")
4964
+ + (done ? "1" : "0") + (matched ? "1" : "0") + (s.live === true ? "1" : "0")
4965
+ + (k === "tool" || k === "step" ? String(s.cells.length) : "")
4966
+ // The highlight and the "N / total" part of the aria-label change with the
4967
+ // selection and with the window length. Missing either leaves the old
4968
+ // highlight cached — caught by the minimap assertion, not by reasoning.
4969
+ //
4970
+ // The tab stop is the SAME expression as `tabIndex` below, including its
4971
+ // overview half (`revealed === null && i === 0`). Hashing only the active
4972
+ // half left tick 0 with `tabIndex: 0` after any selection, so the strip had
4973
+ // TWO tab stops (measured: [0, 5] after selecting station 5).
4974
+ + "\u0002" + ((revealed !== null && i === R - 1) || (revealed === null && i === 0) ? "1" : "0")
4975
+ // `data-k` reads the DERIVED kind, which is "tool" for a step that contains
4976
+ // one — hash the value actually used rather than re-deriving it here.
4977
+ + "\u0002" + k
4978
+ + "\u0002" + minimapTickLabel(s) + "\u0002" + fmtClock(s.time)
4979
+ + "\u0002" + String(stations.length);
4980
+ const tickHit = tickElCache.current.get(i);
4981
+ if (tickHit !== undefined && tickHit.sig === tickSig && tickHit.t === t) return tickHit.el;
4982
+ const tickEl = jsx("button", {
4825
4983
  type: "button",
4826
4984
  className: "dstv_miniTick",
4827
4985
  "data-tick-idx": String(i),
4828
4986
  "data-k": k,
4829
4987
  "data-done": done ? "true" : undefined,
4830
- "data-dim": reached ? (searching && !matched ? "true" : undefined) : "true",
4988
+ "data-dim": reached ? undefined : "true",
4831
4989
  "data-active": revealed !== null && i === R - 1 ? "true" : undefined,
4832
4990
  "data-live": s.kind === "step" && s.live === true ? "true" : undefined,
4833
4991
  "data-match": matched ? "true" : undefined,
@@ -4845,11 +5003,40 @@ window.__ModuleLoader__.load({
4845
5003
  // all. Fall back to the kind and always expose aria-label.
4846
5004
  title: `${minimapTickLabel(s)}${fmtClock(s.time) !== "" ? ` · ${fmtClock(s.time)}` : ""}`,
4847
5005
  "aria-label": `${t("detail.position")} ${String(i + 1)} / ${String(stations.length)} · ${minimapTickLabel(s)}${fmtClock(s.time) !== "" ? ` · ${fmtClock(s.time)}` : ""}`,
4848
- onClick: (ev) => { ev.stopPropagation(); seek(i); }
5006
+ onClick: (ev) => { ev.stopPropagation(); handlersRef.current.seek(i); }
4849
5007
  }, `mini${i}`);
5008
+ tickElCache.current.set(i, { sig: tickSig, t, el: tickEl });
5009
+ return tickEl;
4850
5010
  })
4851
5011
  }, "rootMini");
4852
5012
 
5013
+ // One signature per station, computed once per TREE rather than once per render.
5014
+ // The per-render version re-hashed every cell body on every keystroke and replay
5015
+ // tick: a real 1.11 MB window cost 105 ms per rebuild instead of 30 ms. `stations`
5016
+ // identity only changes when the fold produces a new tree, so keying on it is
5017
+ // exactly "recompute when the content could have changed".
5018
+ //
5019
+ // A ref rather than useMemo on purpose: this sits BELOW the `if (N === 0)` early
5020
+ // return, and a hook here would be skipped on the empty/loading render (§13.75).
5021
+ const sigPack = sigCacheRef.current;
5022
+ if (sigPack.arr !== stations) {
5023
+ sigPack.arr = stations;
5024
+ sigPack.sigs = stations.map(stationSig);
5025
+ // Drop what the new window no longer contains. A live station is replaced by its
5026
+ // durable twin (new id) on every fold, and paging in older history shifts every
5027
+ // index, so without this the element maps only ever grow — each entry pinning a
5028
+ // whole card subtree and its station closure (§13.75).
5029
+ if (cardElCache.current.size > stations.length || tickElCache.current.size > stations.length) {
5030
+ const live = new Set(stations.map((st) => st.id));
5031
+ for (const key of [...cardElCache.current.keys()]) {
5032
+ if (!live.has(key)) cardElCache.current.delete(key);
5033
+ }
5034
+ for (const key of [...tickElCache.current.keys()]) {
5035
+ if (!(key >= 0 && key < stations.length)) tickElCache.current.delete(key);
5036
+ }
5037
+ }
5038
+ }
5039
+ const sigOf = (i) => (i < 0 || i >= sigPack.sigs.length ? "" : sigPack.sigs[i]);
4853
5040
  const body = jsxs("div", {
4854
5041
  children: [
4855
5042
  jsx("div", {
@@ -4860,10 +5047,17 @@ window.__ModuleLoader__.load({
4860
5047
  role: "listbox",
4861
5048
  "aria-label": t("view.label"),
4862
5049
  "aria-orientation": "horizontal",
5050
+ // Dimming non-matches while searching is a CSS job, not a per-card one.
5051
+ // Setting it per station meant the FIRST keystroke invalidated all 900
5052
+ // cards (2.4 s at 900 stations); one attribute on the list lets the
5053
+ // stylesheet do it and leaves every card's element identity intact.
5054
+ "data-searching": searching ? "true" : undefined,
4863
5055
  children: [
4864
5056
  revealed !== null && playheadLeft !== null ? jsx("span", { className: "dstv_playhead", "aria-hidden": "true", style: { left: `${playheadLeft}px` }, children: jsx("i", {}) }, "ph") : null,
4865
5057
  stations.map((s, i) => {
4866
5058
  const reached = i < R;
5059
+ const isActive = revealed !== null && i === R - 1;
5060
+ const matched = searching && matchSet.has(i);
4867
5061
  // G4-T3: idle gap vs the previous station's end (falls back to its
4868
5062
  // start / time). Rendered as an inline band so a long pause between
4869
5063
  // two steps is visible without opening either one.
@@ -4906,14 +5100,27 @@ window.__ModuleLoader__.load({
4906
5100
  else if (s.kind === "unknown") dotCls += " unknown";
4907
5101
  else if (s.kind === "step" && s.cells.some((c) => c.kind === "tool")) dotCls += " tool";
4908
5102
  if (s.kind === "step" && s.live === true) dotCls += " live";
4909
- const matched = searching && matchSet.has(i);
4910
5103
  const clock = fmtClock(s.time);
4911
- const isActive = revealed !== null && i === R - 1;
4912
- return jsxs("div", {
5104
+ // Everything below is a pure function of (station, neighbour, position,
5105
+ // N, found-in-search). If none of those moved, hand React the element
5106
+ // it already rendered and it skips the whole subtree.
5107
+ const sig = [
5108
+ sigOf(i), sigOf(i - 1), String(i), String(N),
5109
+ reached ? "1" : "0", isActive ? "1" : "0",
5110
+ matched ? "1" : "0", clockAxis ? "1" : "0",
5111
+ // The overview state is its own dependency: station 0 is the roving
5112
+ // tab stop in the overview and is not once a selection exists, even
5113
+ // though neither `reached` nor `isActive` changes for it. Caught by
5114
+ // the roving-tab-stop assertion, not by reasoning (§13.72).
5115
+ revealed === null ? "1" : "0"
5116
+ ].join("\u0002");
5117
+ const hit = cardElCache.current.get(s.id);
5118
+ if (hit !== undefined && hit.sig === sig) return hit.el;
5119
+ const el = jsxs("div", {
4913
5120
  className: "dstv_station",
4914
5121
  "data-station-idx": String(i),
4915
5122
  "data-dim": reached ? undefined : "true",
4916
- "data-seek-dim": searching && !matched && reached ? "true" : undefined,
5123
+
4917
5124
  "data-match": matched ? "true" : undefined,
4918
5125
  "data-active": isActive ? "true" : undefined,
4919
5126
  role: "option",
@@ -4926,8 +5133,8 @@ window.__ModuleLoader__.load({
4926
5133
  "aria-selected": revealed === null ? "false" : (isActive ? "true" : "false"),
4927
5134
  "aria-label": stationAriaLabel(s, i + 1, N, t),
4928
5135
  tabIndex: isActive || (revealed === null && i === 0) ? 0 : -1,
4929
- onKeyDown: (ev) => stationOnKeyDown(ev, i),
4930
- onClick: () => seek(i),
5136
+ onKeyDown: (ev) => handlersRef.current.keyDown(ev, i),
5137
+ onClick: () => handlersRef.current.seek(i),
4931
5138
  children: [
4932
5139
  ...gapPrefix,
4933
5140
  jsxs("div", {
@@ -4957,6 +5164,8 @@ window.__ModuleLoader__.load({
4957
5164
  }, `card${s.id}`)
4958
5165
  ]
4959
5166
  }, s.id);
5167
+ cardElCache.current.set(s.id, { sig, el });
5168
+ return el;
4960
5169
  })
4961
5170
  ]
4962
5171
  })
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-trajectory-traceview-plus",
3
- "version": "0.11.4",
3
+ "version": "0.11.5",
4
4
  "description": "轨迹视图增强版(Plus):在「轨迹」标签旁新增可回放的横向时间轴——minimap、窗口内检索(显式标注覆盖边界)、回放、轮次跳转、跟随模式、历史分页、步骤/子调用耗时与吞吐、时钟轴切换、稳定锚点复制与深链、孤立工具结果站点、提示词变更对比、原始请求分析与 Markdown 导出。基于 AFAP/dsh-trajectory-traceview (MIT) 改造。",
5
5
  "type": "module",
6
6
  "main": "lib/index.js",
@@ -62,7 +62,7 @@
62
62
  },
63
63
  "scripts": {
64
64
  "build": "node scripts/build-client.mjs",
65
- "check": "node scripts/build-client.mjs --check && node scripts/provenance.mjs --check && node scripts/version-check.mjs && node scripts/doc-ref-check.mjs && node scripts/doc-heading-check.mjs && node test/smoke.test.cjs && node scripts/readme-numbers.mjs && node scripts/shortcut-check.mjs",
65
+ "check": "node scripts/build-client.mjs --check && node scripts/provenance.mjs --check && node scripts/version-check.mjs && node scripts/doc-ref-check.mjs && node scripts/doc-heading-check.mjs && node test/smoke.test.cjs && node scripts/readme-numbers.mjs && node scripts/shortcut-check.mjs && node scripts/harness-stamp.mjs",
66
66
  "test": "node test/smoke.test.cjs",
67
67
  "prepublishOnly": "npm run check"
68
68
  }
@@ -26,7 +26,11 @@ const open = run("agent-browser", ["open", url]);
26
26
  if (open.status !== 0) { console.log("agent-browser open failed:\n" + open.stdout + open.stderr); process.exit(1); }
27
27
  run("agent-browser", ["wait", "1200"]);
28
28
 
29
- const probe = fs.readFileSync(path.join(root, "test/browser/probe.js"), "utf8");
29
+ // BOTH halves share one page: the browser is opened once and the evals run in order, so
30
+ // `probe-detail.js` continues from the state `probe.js` leaves. Split because
31
+ // `agent-browser eval` aborts at 30 s and the single file had reached 27.4 s (§13.70).
32
+ const probeFiles = ["test/browser/probe.js", "test/browser/probe-detail.js"];
33
+ const probe = fs.readFileSync(path.join(root, probeFiles[0]), "utf8");
30
34
  const out = run("agent-browser", ["eval", "--stdin"], probe);
31
35
  const raw = (out.stdout || "").trim();
32
36
  let parsed = null;
@@ -40,7 +44,20 @@ try {
40
44
  process.exit(1);
41
45
  }
42
46
 
43
- // The English pass runs as a second eval. `agent-browser eval` aborts with
47
+ // Second half of the assertions.
48
+ {
49
+ const outTail = run("agent-browser", ["eval", "--stdin"], fs.readFileSync(path.join(root, probeFiles[1]), "utf8"));
50
+ try {
51
+ const outerTail = JSON.parse((outTail.stdout || "").trim());
52
+ const parsedTail = JSON.parse(outerTail);
53
+ if (Array.isArray(parsedTail.failures)) parsed.failures.push(...parsedTail.failures);
54
+ Object.assign(parsed.info, parsedTail.info);
55
+ } catch {
56
+ parsed.failures.push("the second probe half did not return a parsable result");
57
+ }
58
+ }
59
+
60
+ // The English pass runs as a third eval. `agent-browser eval` aborts with
44
61
  // "Resource temporarily unavailable" at 30 s, and the main probe alone is close to that;
45
62
  // merging the two failed as an unparsable result instead of a red assertion.
46
63
  const probeEn = fs.readFileSync(path.join(root, "test/browser/probe-en.js"), "utf8");
@@ -49,7 +66,10 @@ try {
49
66
  const outerEn = JSON.parse((outEn.stdout || "").trim());
50
67
  const parsedEn = JSON.parse(outerEn);
51
68
  if (Array.isArray(parsedEn.failures)) parsed.failures.push(...parsedEn.failures);
52
- parsed.info.englishLeaks = parsedEn.info.englishLeaks;
69
+ // Merge EVERY key, not just one. Copying only `englishLeaks` made the printed group
70
+ // count (28) disagree with the number the READMEs state and readme-numbers verifies
71
+ // (29) — the gate read the three probe files, the runtime read two. One source.
72
+ Object.assign(parsed.info, parsedEn.info);
53
73
  } catch {
54
74
  parsed.failures.push("the English pass did not return a parsable result");
55
75
  }
@@ -10,6 +10,7 @@
10
10
  * Deliberately NOT part of the smoke suite: it needs a browser.
11
11
  * node scripts/browser-harness.mjs # writes test/browser/harness.html
12
12
  */
13
+ import { createHash } from "node:crypto";
13
14
  import fs from "node:fs";
14
15
  import path from "node:path";
15
16
 
@@ -78,11 +79,23 @@ for (const [id, rel] of Object.entries(MODULES)) {
78
79
  }
79
80
 
80
81
  const client = read("lib/client.js");
82
+ /**
83
+ * Stamp the bundle this page was built from.
84
+ *
85
+ * Manual browser probing goes: edit `src/` -> `build-client.mjs` -> open harness.html. That
86
+ * skips `browser-harness.mjs`, so the page keeps an OLD inlined bundle and every measurement
87
+ * or fix-verification silently describes the previous revision. It cost a real debugging
88
+ * cycle (§13.75): a correct cache fix looked broken because the page predated it.
89
+ *
90
+ * `harness-stamp.mjs` compares this stamp against the current `lib/client.js`.
91
+ */
92
+ const clientHash = createHash("sha256").update(client).digest("hex").slice(0, 16);
81
93
  const fixture = read("test/browser/fixture.js");
82
94
 
83
95
  const html = `<!doctype html>
84
96
  <html lang="zh-CN" data-ds-dark-theme="false">
85
97
  <head>
98
+ <script>window.__HARNESS_CLIENT_HASH__ = "${clientHash}";</script>
86
99
  <meta charset="utf-8">
87
100
  <title>TraceMapView harness</title>
88
101
  <style>
@@ -17,6 +17,7 @@
17
17
  * node scripts/build-client.mjs # write lib/client.js
18
18
  * node scripts/build-client.mjs --check # fail if lib/client.js is stale
19
19
  */
20
+ import { spawnSync } from "node:child_process";
20
21
  import fs from "node:fs";
21
22
  import path from "node:path";
22
23
  import { fileURLToPath } from "node:url";
@@ -93,4 +94,12 @@ if (process.argv.includes("--check")) {
93
94
  fs.mkdirSync(path.dirname(OUT), { recursive: true });
94
95
  fs.writeFileSync(OUT, built);
95
96
  console.log(`build-client: wrote ${path.relative(ROOT, OUT)} (${built.split("\n").length} lines)`);
97
+ // A hand-built bundle makes any EXISTING harness.html stale, and a stale page silently
98
+ // answers questions about the previous revision. Say so at the moment it happens (§13.75).
99
+ {
100
+ const stamp = spawnSync(process.execPath, [path.join(ROOT, "scripts/harness-stamp.mjs"), "--quiet"], { stdio: "ignore" });
101
+ if (stamp.status !== 0) {
102
+ console.log("build-client: note — test/browser/harness.html is now stale; run `node scripts/browser-harness.mjs` before probing by hand");
103
+ }
104
+ }
96
105
  }
@@ -0,0 +1,56 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * Is `test/browser/harness.html` built from the CURRENT `lib/client.js`?
4
+ *
5
+ * Why this exists: manual browser probing goes
6
+ *
7
+ * edit src/ -> build-client.mjs -> open harness.html
8
+ *
9
+ * which skips `browser-harness.mjs` — the page keeps an OLD inlined bundle, so every
10
+ * measurement and every "is the fix working?" check silently describes the previous
11
+ * revision. That cost a real debugging cycle (§13.75): a correct element-cache fix looked
12
+ * broken, and the tempting next move was to revert it.
13
+ *
14
+ * `browser-check.mjs` always regenerates the harness, so it never sees this. Only a human
15
+ * (or an agent) driving the page by hand does.
16
+ *
17
+ * node scripts/harness-stamp.mjs # explain, exit 1 when stale
18
+ * node scripts/harness-stamp.mjs --quiet # exit code only
19
+ *
20
+ * Exits 0 when the harness is absent (CI does not build one) or when it is current.
21
+ */
22
+ import { createHash } from "node:crypto";
23
+ import fs from "node:fs";
24
+ import path from "node:path";
25
+
26
+ const root = path.resolve(import.meta.dirname, "..");
27
+ const harnessPath = path.join(root, "test/browser/harness.html");
28
+ const clientPath = path.join(root, "lib/client.js");
29
+ const quiet = process.argv.includes("--quiet");
30
+
31
+ const say = (msg) => { if (!quiet) console.log(msg); };
32
+
33
+ if (!fs.existsSync(harnessPath)) {
34
+ say("harness-stamp: no test/browser/harness.html (nothing to check)");
35
+ process.exit(0);
36
+ }
37
+
38
+ const current = createHash("sha256").update(fs.readFileSync(clientPath)).digest("hex").slice(0, 16);
39
+ const html = fs.readFileSync(harnessPath, "utf8");
40
+ const found = /window\.__HARNESS_CLIENT_HASH__\s*=\s*"([0-9a-f]+)"/.exec(html);
41
+
42
+ if (found === null) {
43
+ say("harness-stamp: STALE — the page carries no bundle stamp, so it predates this guard.");
44
+ say(" before probing by hand: node scripts/browser-harness.mjs");
45
+ process.exit(1);
46
+ }
47
+
48
+ if (found[1] !== current) {
49
+ say("harness-stamp: STALE — harness.html inlines " + found[1] + " but lib/client.js is " + current + ".");
50
+ say(" Anything you observe in that page describes the OLD bundle.");
51
+ say(" before probing by hand: node scripts/browser-harness.mjs");
52
+ process.exit(1);
53
+ }
54
+
55
+ say("harness-stamp: OK (" + current + ")");
56
+ process.exit(0);
@@ -39,7 +39,7 @@ const localSteps = pkg.scripts.check.split('&&').map((s) => s.trim()).filter(Boo
39
39
  // aborts at 30 s and the language switch pushed the single file over it (§13.69) — and
40
40
  // leaving it out of this count is exactly the one-source-vs-two-sources blindness this
41
41
  // very block has already been fixed for once (§13.44).
42
- const PROBE_FILES = ['test/browser/probe.js', 'test/browser/probe-en.js'];
42
+ const PROBE_FILES = ['test/browser/probe.js', 'test/browser/probe-detail.js', 'test/browser/probe-en.js'];
43
43
  const probes = PROBE_FILES.map((f) => read(f));
44
44
  const observedGroups = new Set();
45
45
  let assertions = 0;
package/src/10-styles.js CHANGED
@@ -281,9 +281,15 @@
281
281
  ".dstv_btn[data-on=true]{color:var(--dstv-info-ink);background:color-mix(in srgb,var(--dstv-info) 12%,transparent);box-shadow:inset 0 0 0 1px color-mix(in srgb,var(--dstv-info) 40%,transparent)}",
282
282
  ".dstv_tbtn[data-on=true]{color:var(--dstv-info-ink);background:color-mix(in srgb,var(--dstv-info) 14%,transparent);font-weight:700}",
283
283
  ".dstv_station[data-match=true] .dstv_hcard{border-color:transparent;background:linear-gradient(var(--dsw-alias-bg-layer-1),var(--dsw-alias-bg-layer-1)) padding-box,linear-gradient(135deg,var(--dstv-warn),var(--dstv-warn)) border-box;box-shadow:0 0 12px color-mix(in srgb,var(--dstv-warn) 35%,transparent)}",
284
- ".dstv_station[data-seek-dim=true] .dstv_hcard{opacity:.5;filter:saturate(.3)}",
285
- ".dstv_station[data-seek-dim=true] .dstv_hDot{opacity:.35}",
284
+ // Searching dims the non-matches. Driven from the listbox so a keystroke does not
285
+ // rewrite every station element (§13.72): reached = not [data-dim], matched =
286
+ // [data-match]. Same visual result, one attribute instead of N.
287
+ ".dstv_listbox[data-searching=true] .dstv_station:not([data-dim=true]):not([data-match=true]) .dstv_hcard{opacity:.5;filter:saturate(.3)}",
288
+ ".dstv_listbox[data-searching=true] .dstv_station:not([data-dim=true]):not([data-match=true]) .dstv_hDot{opacity:.35}",
286
289
  ".dstv_miniTick[data-match=true]{box-shadow:0 0 0 1.5px var(--dstv-warn);height:14px}",
290
+ // While searching, fade the ticks that did not match. Reached-only ticks fade via
291
+ // [data-dim]; the search fade lives here so it costs no per-tick attribute (§13.72).
292
+ ".dstv_minimap[data-searching=true] .dstv_miniTick:not([data-dim=true]):not([data-match=true]){opacity:.25}",
287
293
  ".dstv_detail.full{max-height:82vh}",
288
294
  ".dstv_panelToggle{margin-left:4px}",
289
295
  ".dstv_subCard{border:1px solid var(--dsw-alias-border-l2);border-radius:8px;padding:5px 8px;background:var(--dsw-alias-bg-layer-2);display:flex;flex-direction:column;gap:3px;margin-top:3px}",
package/src/30-helpers.js CHANGED
@@ -1277,7 +1277,7 @@
1277
1277
  // `image`/`other` arrived). These used to fall through the chain and
1278
1278
  // vanish, so a future block type would render as "the model said
1279
1279
  // nothing". Name it instead of guessing at its content.
1280
- st.cells.push({ id: `u${n.seq}${st.cells.length}`, kind: "assistant", text: `${t("block.unknown")} · ${String(b.kind)}`, thinking: "" });
1280
+ st.cells.push({ id: `u${n.seq}${st.cells.length}`, kind: "assistant", text: unknownBlockLabel(b, t), thinking: "" });
1281
1281
  } else if (b.kind === "tool-call") {
1282
1282
  // every durable block is a real call, even with a repeated id
1283
1283
  claimCall(turn, b.callId);
@@ -1465,7 +1465,7 @@
1465
1465
  // know must be NAMED, not dropped. The streaming branch was missed when the
1466
1466
  // durable one got the placeholder, so a live `file`/future block showed an
1467
1467
  // empty step (measured: cells [] for {kind:"future"} and {kind:"file"}).
1468
- st.cells.push({ id: `pu${st.cells.length}`, kind: "assistant", text: `${t("block.unknown")} · ${String(b.kind)}`, thinking: "" });
1468
+ st.cells.push({ id: `pu${st.cells.length}`, kind: "assistant", text: unknownBlockLabel(b, t), thinking: "" });
1469
1469
  } else if (b.kind === "tool-call") {
1470
1470
  if (claimedCall(turn, b.callId)) continue;
1471
1471
  claimCall(turn, b.callId);
@@ -2010,6 +2010,26 @@
2010
2010
  const flat = String(raw ?? "").replace(/\s+/g, " ").trim();
2011
2011
  return flat.length > 80 ? `${flat.slice(0, 80)}…` : flat;
2012
2012
  }
2013
+ /**
2014
+ * The label for a block kind this build does not know.
2015
+ *
2016
+ * It used to be `${t("block.unknown")} · ${String(b.kind)}`, which is fine for a
2017
+ * FUTURE kind ("未知内容 · image") but renders the literal string "undefined" when
2018
+ * the kind is missing entirely — and that label reaches both the card text and the
2019
+ * station's aria-label, so a screen-reader user heard "unknown content · undefined".
2020
+ * A record with no kind at all is a malformed record, not a future one, and naming
2021
+ * it "undefined" is worse than saying nothing.
2022
+ * @param b - the block whose kind is unknown.
2023
+ * @param t - the bound language function.
2024
+ * @returns the label to show.
2025
+ */
2026
+ function unknownBlockLabel(b, t) {
2027
+ const base = t("block.unknown");
2028
+ const kind = b !== null && b !== void 0 ? b.kind : void 0;
2029
+ if (typeof kind !== "string" || kind === "") return base;
2030
+ return `${base} · ${kind}`;
2031
+ }
2032
+
2013
2033
  function stationAriaLabel(station, position, total, t) {
2014
2034
  // Per-turn number: `stepNo` is a window-wide counter, so this label used to
2015
2035
  // read "步骤 1" and then "步骤 5" for the same station once older history was