dsh-trajectory-traceview-plus 0.11.3 → 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,11 +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`
54
+ - `test/browser/probe-en.js`
52
55
  - `test/browser/probe.js`
53
56
 
54
57
  ## 二、`lib/client.js` 函数级
55
58
 
56
- 上游 24 个函数:**9 个原样保留、15 个被修改、0 个被删除**;本仓**新增 48 个**。
59
+ 上游 24 个函数:**9 个原样保留、15 个被修改、0 个被删除**;本仓**新增 49 个**。
57
60
 
58
61
  ### 原样保留(9)
59
62
 
@@ -89,7 +92,7 @@
89
92
  - `subDetailOf`
90
93
  - `textOfContent`
91
94
 
92
- ### 本仓新增(48)
95
+ ### 本仓新增(49)
93
96
 
94
97
  上游完全没有:
95
98
 
@@ -138,6 +141,7 @@
138
141
  - `stationHay`
139
142
  - `stepOf`
140
143
  - `toolSchemaKey`
144
+ - `unknownBlockLabel`
141
145
  - `unknownNodeStats`
142
146
  - `viewStateKey`
143
147
  - `writeViewState`
package/lib/client.js CHANGED
@@ -73,6 +73,17 @@ window.__ModuleLoader__.load({
73
73
  "kpi.tokensIn": "请求 tokens",
74
74
  "kpi.tokensOut": "生成 tokens",
75
75
  "kpi.errors": "错误",
76
+ // The Token-usage chips were hardcoded English ("in" / "out" / "cache-read" …)
77
+ // inside a Chinese panel, while README §2 describes this section as
78
+ // "入站(含缓存读 / 写)与出站(含思考)". Same words as the README, compact
79
+ // enough for a chip. `fresh` = input tokens that came from the prompt rather
80
+ // than from cache (the API's `inputTokens` minus cache read/write).
81
+ "usage.in": "入站",
82
+ "usage.fresh": "未缓存",
83
+ "usage.cacheRead": "缓存读",
84
+ "usage.cacheWrite": "缓存写",
85
+ "usage.out": "出站",
86
+ "usage.think": "思考",
76
87
  "status.done": "已完成",
77
88
  "status.retry": "重试",
78
89
  "detail.args": "调用参数",
@@ -248,6 +259,12 @@ window.__ModuleLoader__.load({
248
259
  "kpi.tokensIn": "Prompt tokens",
249
260
  "kpi.tokensOut": "Output tokens",
250
261
  "kpi.errors": "Errors",
262
+ "usage.in": "in",
263
+ "usage.fresh": "fresh",
264
+ "usage.cacheRead": "cache-read",
265
+ "usage.cacheWrite": "cache-write",
266
+ "usage.out": "out",
267
+ "usage.think": "think",
251
268
  "status.done": "Done",
252
269
  "status.retry": "Retry",
253
270
  "detail.args": "Call arguments",
@@ -647,9 +664,15 @@ window.__ModuleLoader__.load({
647
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)}",
648
665
  ".dstv_tbtn[data-on=true]{color:var(--dstv-info-ink);background:color-mix(in srgb,var(--dstv-info) 14%,transparent);font-weight:700}",
649
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)}",
650
- ".dstv_station[data-seek-dim=true] .dstv_hcard{opacity:.5;filter:saturate(.3)}",
651
- ".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}",
652
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}",
653
676
  ".dstv_detail.full{max-height:82vh}",
654
677
  ".dstv_panelToggle{margin-left:4px}",
655
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}",
@@ -1987,7 +2010,7 @@ window.__ModuleLoader__.load({
1987
2010
  // `image`/`other` arrived). These used to fall through the chain and
1988
2011
  // vanish, so a future block type would render as "the model said
1989
2012
  // nothing". Name it instead of guessing at its content.
1990
- 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: "" });
1991
2014
  } else if (b.kind === "tool-call") {
1992
2015
  // every durable block is a real call, even with a repeated id
1993
2016
  claimCall(turn, b.callId);
@@ -2175,7 +2198,7 @@ window.__ModuleLoader__.load({
2175
2198
  // know must be NAMED, not dropped. The streaming branch was missed when the
2176
2199
  // durable one got the placeholder, so a live `file`/future block showed an
2177
2200
  // empty step (measured: cells [] for {kind:"future"} and {kind:"file"}).
2178
- 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: "" });
2179
2202
  } else if (b.kind === "tool-call") {
2180
2203
  if (claimedCall(turn, b.callId)) continue;
2181
2204
  claimCall(turn, b.callId);
@@ -2720,6 +2743,26 @@ window.__ModuleLoader__.load({
2720
2743
  const flat = String(raw ?? "").replace(/\s+/g, " ").trim();
2721
2744
  return flat.length > 80 ? `${flat.slice(0, 80)}…` : flat;
2722
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
+
2723
2766
  function stationAriaLabel(station, position, total, t) {
2724
2767
  // Per-turn number: `stepNo` is a window-wide counter, so this label used to
2725
2768
  // read "步骤 1" and then "步骤 5" for the same station once older history was
@@ -3600,6 +3643,32 @@ window.__ModuleLoader__.load({
3600
3643
  function TraceMapView({ useSession, useTrajectory, t, viewRequest, completeViewRequest, loadOlder, sessionKey }) {
3601
3644
  const scrollerRef = (0, react.useRef)(null);
3602
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
+ }
3603
3672
  const searchRef = (0, react.useRef)(null);
3604
3673
  const initDone = (0, react.useRef)(false);
3605
3674
  // Which session this panel is showing. The host reuses one component instance
@@ -4321,6 +4390,17 @@ window.__ModuleLoader__.load({
4321
4390
  seek(i); ev.preventDefault(); ev.stopPropagation();
4322
4391
  }
4323
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
+ });
4324
4404
  const onKeyDown = (ev) => {
4325
4405
  const k = ev.key;
4326
4406
  // Browser and OS shortcuts must win. The panel root is focusable
@@ -4633,6 +4713,77 @@ window.__ModuleLoader__.load({
4633
4713
  });
4634
4714
  }
4635
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
+ };
4636
4787
  const renderStationCard = (s, cardKey) => {
4637
4788
  if (s.kind === "user") {
4638
4789
  return jsxs("div", {
@@ -4797,6 +4948,9 @@ window.__ModuleLoader__.load({
4797
4948
  const minimapTicks = jsx("div", {
4798
4949
  className: "dstv_minimap",
4799
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,
4800
4954
  children: stations.map((s, i) => {
4801
4955
  const reached = i < R;
4802
4956
  let k = s.kind;
@@ -4804,13 +4958,34 @@ window.__ModuleLoader__.load({
4804
4958
  if (s.kind === "maxTokens") k = "error";
4805
4959
  const done = reached && (s.kind !== "step" || !s.live);
4806
4960
  const matched = searching && matchSet.has(i);
4807
- 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", {
4808
4983
  type: "button",
4809
4984
  className: "dstv_miniTick",
4810
4985
  "data-tick-idx": String(i),
4811
4986
  "data-k": k,
4812
4987
  "data-done": done ? "true" : undefined,
4813
- "data-dim": reached ? (searching && !matched ? "true" : undefined) : "true",
4988
+ "data-dim": reached ? undefined : "true",
4814
4989
  "data-active": revealed !== null && i === R - 1 ? "true" : undefined,
4815
4990
  "data-live": s.kind === "step" && s.live === true ? "true" : undefined,
4816
4991
  "data-match": matched ? "true" : undefined,
@@ -4828,11 +5003,40 @@ window.__ModuleLoader__.load({
4828
5003
  // all. Fall back to the kind and always expose aria-label.
4829
5004
  title: `${minimapTickLabel(s)}${fmtClock(s.time) !== "" ? ` · ${fmtClock(s.time)}` : ""}`,
4830
5005
  "aria-label": `${t("detail.position")} ${String(i + 1)} / ${String(stations.length)} · ${minimapTickLabel(s)}${fmtClock(s.time) !== "" ? ` · ${fmtClock(s.time)}` : ""}`,
4831
- onClick: (ev) => { ev.stopPropagation(); seek(i); }
5006
+ onClick: (ev) => { ev.stopPropagation(); handlersRef.current.seek(i); }
4832
5007
  }, `mini${i}`);
5008
+ tickElCache.current.set(i, { sig: tickSig, t, el: tickEl });
5009
+ return tickEl;
4833
5010
  })
4834
5011
  }, "rootMini");
4835
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]);
4836
5040
  const body = jsxs("div", {
4837
5041
  children: [
4838
5042
  jsx("div", {
@@ -4843,10 +5047,17 @@ window.__ModuleLoader__.load({
4843
5047
  role: "listbox",
4844
5048
  "aria-label": t("view.label"),
4845
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,
4846
5055
  children: [
4847
5056
  revealed !== null && playheadLeft !== null ? jsx("span", { className: "dstv_playhead", "aria-hidden": "true", style: { left: `${playheadLeft}px` }, children: jsx("i", {}) }, "ph") : null,
4848
5057
  stations.map((s, i) => {
4849
5058
  const reached = i < R;
5059
+ const isActive = revealed !== null && i === R - 1;
5060
+ const matched = searching && matchSet.has(i);
4850
5061
  // G4-T3: idle gap vs the previous station's end (falls back to its
4851
5062
  // start / time). Rendered as an inline band so a long pause between
4852
5063
  // two steps is visible without opening either one.
@@ -4889,14 +5100,27 @@ window.__ModuleLoader__.load({
4889
5100
  else if (s.kind === "unknown") dotCls += " unknown";
4890
5101
  else if (s.kind === "step" && s.cells.some((c) => c.kind === "tool")) dotCls += " tool";
4891
5102
  if (s.kind === "step" && s.live === true) dotCls += " live";
4892
- const matched = searching && matchSet.has(i);
4893
5103
  const clock = fmtClock(s.time);
4894
- const isActive = revealed !== null && i === R - 1;
4895
- 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", {
4896
5120
  className: "dstv_station",
4897
5121
  "data-station-idx": String(i),
4898
5122
  "data-dim": reached ? undefined : "true",
4899
- "data-seek-dim": searching && !matched && reached ? "true" : undefined,
5123
+
4900
5124
  "data-match": matched ? "true" : undefined,
4901
5125
  "data-active": isActive ? "true" : undefined,
4902
5126
  role: "option",
@@ -4909,8 +5133,8 @@ window.__ModuleLoader__.load({
4909
5133
  "aria-selected": revealed === null ? "false" : (isActive ? "true" : "false"),
4910
5134
  "aria-label": stationAriaLabel(s, i + 1, N, t),
4911
5135
  tabIndex: isActive || (revealed === null && i === 0) ? 0 : -1,
4912
- onKeyDown: (ev) => stationOnKeyDown(ev, i),
4913
- onClick: () => seek(i),
5136
+ onKeyDown: (ev) => handlersRef.current.keyDown(ev, i),
5137
+ onClick: () => handlersRef.current.seek(i),
4914
5138
  children: [
4915
5139
  ...gapPrefix,
4916
5140
  jsxs("div", {
@@ -4940,6 +5164,8 @@ window.__ModuleLoader__.load({
4940
5164
  }, `card${s.id}`)
4941
5165
  ]
4942
5166
  }, s.id);
5167
+ cardElCache.current.set(s.id, { sig, el });
5168
+ return el;
4943
5169
  })
4944
5170
  ]
4945
5171
  })
@@ -5169,9 +5395,9 @@ window.__ModuleLoader__.load({
5169
5395
  usage !== null && usage.input + usage.output > 0 ? jsxs("div", { className: "dstv_dSection", children: [
5170
5396
  jsx("span", { className: "dstv_dLabel", children: `📊 ${t("detail.usage")}` }, "uLbl"),
5171
5397
  jsx("div", { className: "dstv_cfgChips", children: [
5172
- usage.input > 0 ? jsx("span", { className: "dstv_cfgChip", children: ["in ", jsx("b", { children: fmtInt(usage.input) }, "v")] }, "uIn") : null,
5173
- usage.cacheRead > 0 ? jsx("span", { className: "dstv_cfgChip", children: ["cache-read ", jsx("b", { children: fmtInt(usage.cacheRead) }, "v")] }, "uCR") : null,
5174
- usage.output > 0 ? jsx("span", { className: "dstv_cfgChip", children: ["out ", jsx("b", { children: fmtInt(usage.output) }, "v")] }, "uOut") : null
5398
+ usage.input > 0 ? jsx("span", { className: "dstv_cfgChip", children: [`${t("usage.in")} `, jsx("b", { children: fmtInt(usage.input) }, "v")] }, "uIn") : null,
5399
+ usage.cacheRead > 0 ? jsx("span", { className: "dstv_cfgChip", children: [`${t("usage.cacheRead")} `, jsx("b", { children: fmtInt(usage.cacheRead) }, "v")] }, "uCR") : null,
5400
+ usage.output > 0 ? jsx("span", { className: "dstv_cfgChip", children: [`${t("usage.out")} `, jsx("b", { children: fmtInt(usage.output) }, "v")] }, "uOut") : null
5175
5401
  ] }, "uChips")
5176
5402
  ] }, "crUsage") : null,
5177
5403
  cr.outputText !== "" ? jsxs("div", { className: "dstv_dSection", children: [
@@ -5305,12 +5531,12 @@ window.__ModuleLoader__.load({
5305
5531
  usage !== null && usage.input + usage.output > 0 ? jsxs("div", { className: "dstv_dSection", children: [
5306
5532
  jsx("span", { className: "dstv_dLabel", children: `📊 ${t("detail.usage")}` }, "uLbl"),
5307
5533
  jsx("div", { className: "dstv_cfgChips", children: [
5308
- usage.input > 0 ? jsx("span", { className: "dstv_cfgChip", children: ["in ", jsx("b", { children: fmtInt(usage.input) }, "v")] }, "uIn") : null,
5309
- usage.raw > 0 ? jsx("span", { className: "dstv_cfgChip", children: ["fresh ", jsx("b", { children: fmtInt(usage.raw) }, "v")] }, "uFresh") : null,
5310
- usage.cacheRead > 0 ? jsx("span", { className: "dstv_cfgChip", children: ["cache-read ", jsx("b", { children: fmtInt(usage.cacheRead) }, "v")] }, "uCR") : null,
5311
- usage.cacheWrite > 0 ? jsx("span", { className: "dstv_cfgChip", children: ["cache-write ", jsx("b", { children: fmtInt(usage.cacheWrite) }, "v")] }, "uCW") : null,
5312
- usage.output > 0 ? jsx("span", { className: "dstv_cfgChip", children: ["out ", jsx("b", { children: fmtInt(usage.output) }, "v")] }, "uOut") : null,
5313
- usage.think > 0 ? jsx("span", { className: "dstv_cfgChip", children: ["think ", jsx("b", { children: fmtInt(usage.think) }, "v")] }, "uThink") : null
5534
+ usage.input > 0 ? jsx("span", { className: "dstv_cfgChip", children: [`${t("usage.in")} `, jsx("b", { children: fmtInt(usage.input) }, "v")] }, "uIn") : null,
5535
+ usage.raw > 0 ? jsx("span", { className: "dstv_cfgChip", children: [`${t("usage.fresh")} `, jsx("b", { children: fmtInt(usage.raw) }, "v")] }, "uFresh") : null,
5536
+ usage.cacheRead > 0 ? jsx("span", { className: "dstv_cfgChip", children: [`${t("usage.cacheRead")} `, jsx("b", { children: fmtInt(usage.cacheRead) }, "v")] }, "uCR") : null,
5537
+ usage.cacheWrite > 0 ? jsx("span", { className: "dstv_cfgChip", children: [`${t("usage.cacheWrite")} `, jsx("b", { children: fmtInt(usage.cacheWrite) }, "v")] }, "uCW") : null,
5538
+ usage.output > 0 ? jsx("span", { className: "dstv_cfgChip", children: [`${t("usage.out")} `, jsx("b", { children: fmtInt(usage.output) }, "v")] }, "uOut") : null,
5539
+ usage.think > 0 ? jsx("span", { className: "dstv_cfgChip", children: [`${t("usage.think")} `, jsx("b", { children: fmtInt(usage.think) }, "v")] }, "uThink") : null
5314
5540
  ] }, "uChips")
5315
5541
  ] }, "uSec") : null,
5316
5542
  // messages
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-trajectory-traceview-plus",
3
- "version": "0.11.3",
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,6 +44,36 @@ try {
40
44
  process.exit(1);
41
45
  }
42
46
 
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
61
+ // "Resource temporarily unavailable" at 30 s, and the main probe alone is close to that;
62
+ // merging the two failed as an unparsable result instead of a red assertion.
63
+ const probeEn = fs.readFileSync(path.join(root, "test/browser/probe-en.js"), "utf8");
64
+ const outEn = run("agent-browser", ["eval", "--stdin"], probeEn);
65
+ try {
66
+ const outerEn = JSON.parse((outEn.stdout || "").trim());
67
+ const parsedEn = JSON.parse(outerEn);
68
+ if (Array.isArray(parsedEn.failures)) parsed.failures.push(...parsedEn.failures);
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);
73
+ } catch {
74
+ parsed.failures.push("the English pass did not return a parsable result");
75
+ }
76
+
43
77
  if (shots) {
44
78
  fs.mkdirSync(path.join(root, "test/browser/shots"), { recursive: true });
45
79
  run("agent-browser", ["screenshot", "--screenshot-dir", "./test/browser/shots"]);
@@ -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);