Skip to content

A local-first multi-agent app development platform, built on PenguinHarness

feat(web): pack same-name non-overlapping tool calls into shared timeline rows (#362)

Yaowei Zhengc6894d63bdac
diff --git a/changelog/unreleased/2026-08-20-trace-lane-packing.md b/changelog/unreleased/2026-08-20-trace-lane-packing.md
new file mode 100644
index 00000000..21f99c33
--- /dev/null
+++ b/changelog/unreleased/2026-08-20-trace-lane-packing.md
@@ -0,0 +1,17 @@
+# Trace timeline packs same-name tool calls into shared rows
+
+- **Date:** 2026-08-20
+- **Type:** feature
+- **Scope:** `web`
+- **PR:** [#362](https://github.com/Prism-Shadow/penguin-harness/pull/362)
+
+[中文版](2026-08-20-trace-lane-packing.zh.md)
+
+Shortened the trace observation timeline: tool-call executions with the same tool name whose time ranges don't overlap now share one row instead of taking one row each, so a burst of serial calls to the same tool (a long `exec_command` or `read_file` sequence) collapses from N rows to one. Only a different tool name, or same-name calls that overlap in time (parallel execution), still open extra rows.
+
+## Details
+
+- Packing is greedy first-fit per tool name (`lane-packing.ts`): calls are placed in start order into the first row of their name that is free at that moment; touching endpoints don't count as overlap. Rows never mix tool names, rows of one name stay adjacent, and names are ordered by their earliest call.
+- The stretch of row a call claims is the union of the two bars it actually draws — the approval wait from the call to the decision, plus the execution from the decision (or from the call, when nothing was approved) to the output — so a clock step that records a timestamp out of order cannot make two calls sharing a row draw over each other.
+- A still-running call keeps its row blocked until the task end, so later calls of the same name open a new row rather than drawing over it.
+- Bar rendering, hover/click highlighting, event-list linkage, and zoom/pan behavior were left unchanged; only the row assignment changed.
diff --git a/changelog/unreleased/2026-08-20-trace-lane-packing.zh.md b/changelog/unreleased/2026-08-20-trace-lane-packing.zh.md
new file mode 100644
index 00000000..04969dfb
--- /dev/null
+++ b/changelog/unreleased/2026-08-20-trace-lane-packing.zh.md
@@ -0,0 +1,17 @@
+# 轨迹时间线将同名工具调用合并到共享行
+
+- **Date:** 2026-08-20
+- **Type:** feature
+- **Scope:** `web`
+- **PR:** [#362](https://github.com/Prism-Shadow/penguin-harness/pull/362)
+
+[English](2026-08-20-trace-lane-packing.md)
+
+缩短了轨迹观测时间线的高度:同名工具且时间区间互不重叠的工具调用现在共享一行,不再每次调用各占一行,连续串行调用同一工具(如一长串 `exec_command` 或 `read_file`)从 N 行收敛为一行。只有不同名工具、或同名但时间重叠(并行执行)的调用才另起新行。
+
+## 细节
+
+- 按工具名做贪心 first-fit 装箱(`lane-packing.ts`):调用按开始时间依次放入该名字下第一个空闲的行;端点相接不算重叠。行内永不混入不同工具名,同名的多行保持相邻,名字按各自最早调用时间排序。
+- 一次调用占据的行区间取其实际绘制的两段之并——从调用到审批决定的等待段,加上从决定(无审批则从调用)到输出的执行段;时钟回拨导致时间戳前后颠倒时也不会让同行的两次调用互相叠画。
+- 仍在运行的调用会占用其所在行直到 Task 结束,同名的后续调用会另起新行,不会叠画在其上。
+- 条形渲染、悬停/点击高亮、与事件列表的联动、缩放/平移行为均未改动,只改变了行的分配。
diff --git a/packages/web/src/features/traces/lane-packing.ts b/packages/web/src/features/traces/lane-packing.ts
new file mode 100644
index 00000000..fe89a32a
--- /dev/null
+++ b/packages/web/src/features/traces/lane-packing.ts
@@ -0,0 +1,72 @@
+/**
+ * Lane packing for the trace timeline's tool rows: calls of the **same tool
+ * name** whose time ranges don't overlap share one row, so a burst of serial
+ * calls to one tool no longer costs one row each. A row never mixes tool
+ * names, and overlapping same-name calls (parallel execution) still split
+ * into as many rows as the overlap requires.
+ */
+
+/** A packable interval; `toolSpanBounds` derives one from a tool call's timestamps. */
+export interface PackableSpan {
+ name: string;
+ startMs: number;
+ endMs: number;
+}
+
+/**
+ * The stretch of row a tool call occupies: the union of the two bars the
+ * timeline draws for it — the approval-wait bar from the call to the decision,
+ * and the execution bar from the decision (or from the call, when nothing was
+ * approved) to the output. A call with no output yet is drawn to the task end
+ * and so blocks its row that far.
+ *
+ * The `min`/`max` rather than a plain call → output: a clock step between two
+ * appends can record a decision before the call it belongs to, or an output
+ * before the decision, and a footprint narrower than what gets drawn would let
+ * two calls sharing a row draw over each other.
+ */
+export function toolSpanBounds(
+ call: { callMs: number; approvalMs: number | null; outputMs: number | null },
+ taskEndMs: number,
+): { startMs: number; endMs: number } {
+ const startMs = Math.min(call.callMs, call.approvalMs ?? call.callMs);
+ const endMs = Math.max(startMs, call.approvalMs ?? startMs, call.outputMs ?? taskEndMs);
+ return { startMs, endMs };
+}
+
+/** One output row: every span in it has the same `name` and none overlap. */
+export interface PackedLane<T> {
+ name: string;
+ spans: T[];
+}
+
+/**
+ * Greedy first-fit packing: spans are processed in start order; each goes into
+ * the first existing lane of its name whose last span ends at or before this
+ * one's start (touching endpoints don't count as overlap), otherwise a new
+ * lane opens for that name. Lanes are returned grouped by name in order of
+ * each name's earliest start, with the lanes of one name adjacent.
+ */
+export function packToolLanes<T extends PackableSpan>(spans: readonly T[]): PackedLane<T>[] {
+ const byName = new Map<string, { spans: T[]; lastEnd: number }[]>();
+ const sorted = [...spans].sort((a, b) => a.startMs - b.startMs || a.endMs - b.endMs);
+ for (const s of sorted) {
+ let lanes = byName.get(s.name);
+ if (!lanes) {
+ lanes = [];
+ byName.set(s.name, lanes);
+ }
+ const lane = lanes.find((l) => s.startMs >= l.lastEnd);
+ if (lane) {
+ lane.spans.push(s);
+ lane.lastEnd = Math.max(lane.lastEnd, s.endMs);
+ } else {
+ lanes.push({ spans: [s], lastEnd: s.endMs });
+ }
+ }
+ const out: PackedLane<T>[] = [];
+ for (const [name, lanes] of byName) {
+ for (const lane of lanes) out.push({ name, spans: lane.spans });
+ }
+ return out;
+}
diff --git a/packages/web/src/features/traces/timeline-chart.tsx b/packages/web/src/features/traces/timeline-chart.tsx
index e9e0b5a6..d71fb4e0 100644
--- a/packages/web/src/features/traces/timeline-chart.tsx
+++ b/packages/web/src/features/traces/timeline-chart.tsx
@@ -8,7 +8,9 @@
* leave large gaps if sharing one axis);
* - Bars come in only five kinds, each with a fixed color (no gray/black/white):
* thinking, model reply, tool-call generation (model lane), approval wait,
- * tool-call execution (each tool gets its own row);
+ * tool-call execution (one row per tool name; same-name calls that don't
+ * overlap in time share the row, overlapping ones split into extra rows —
+ * see lane-packing.ts);
* - Highlighting is always expressed as "fade out the rest", never an outline:
* hovering a segment highlights just that segment (by its unique key, so
* adjacent segments at the same timestamp aren't highlighted together), and
@@ -20,7 +22,7 @@
* Premiere's timeline navigator. Scroll-wheel zoom is deliberately
* unsupported — to avoid accidentally changing zoom while scrolling the page.
*/
-import { useCallback, useLayoutEffect, useMemo, useRef, useState } from "react";
+import { Fragment, useCallback, useLayoutEffect, useMemo, useRef, useState } from "react";
import type { CSSProperties, PointerEvent as ReactPointerEvent, ReactNode } from "react";
import type {
TraceModelSegment,
@@ -29,6 +31,8 @@ import type {
} from "@prismshadow/penguin-server/api";
import { S } from "../../lib/strings";
import { humanizeDuration } from "../../lib/format";
+import { packToolLanes, toolSpanBounds } from "./lane-packing";
+import type { PackedLane } from "./lane-packing";
/**
* Linked highlighting: `ts` is the anchor shared by both sides; `key` /
@@ -132,11 +136,11 @@ interface PlacedSpan {
interface TaskGroup {
taskIndex: number;
segs: PlacedSegment[];
- spans: PlacedSpan[];
others: PlacedOther[];
t0: number;
total: number;
- toolNames: string[];
+ /** Tool rows after lane packing: one row per (name, lane), same-name lanes adjacent. */
+ toolRows: PackedLane<PlacedSpan>[];
}
/** A placed "other" bar (non-tool auxiliary phase, e.g. MCP connect): one lane per span. */
@@ -232,8 +236,8 @@ function buildGroups(
const total = Math.max(1, tEnd - t0);
spans.sort((a, b) => a.callMs - b.callMs);
others.sort((a, b) => a.startMs - b.startMs);
- const toolNames = [...new Set(spans.map((s) => s.name))];
- groups.push({ taskIndex, segs, spans, others, t0, total, toolNames });
+ const toolRows = packToolLanes(spans.map((s) => ({ ...s, ...toolSpanBounds(s, t0 + total) })));
+ groups.push({ taskIndex, segs, others, t0, total, toolRows });
}
return groups;
}
@@ -331,12 +335,16 @@ export function TimelineChart({
};
for (const g of groups) {
g.segs.forEach((s, i) => put(s.ts, `s-${g.taskIndex}-${i}`));
- for (const s of g.spans) {
- if (s.approvalMs !== null && s.approvalMs > s.callMs) {
- put(s.approvalTsRaw ?? s.callTs, `w-${s.toolCallId}`);
+ // Walked row by row, so "first bar at this timestamp" stays the topmost
+ // one on screen — packing reorders tool bars relative to their call order.
+ for (const row of g.toolRows) {
+ for (const s of row.spans) {
+ if (s.approvalMs !== null && s.approvalMs > s.callMs) {
+ put(s.approvalTsRaw ?? s.callTs, `w-${s.toolCallId}`);
+ }
+ if (s.approvalMs === null && s.outputMs === null) put(s.callTs, `p-${s.toolCallId}`);
+ else put(s.outputTsRaw ?? s.callTs, `e-${s.toolCallId}`);
}
- if (s.approvalMs === null && s.outputMs === null) put(s.callTs, `p-${s.toolCallId}`);
- else put(s.outputTsRaw ?? s.callTs, `e-${s.toolCallId}`);
}
for (const o of g.others) put(o.ts, `o-${o.key}`);
}
@@ -552,83 +560,89 @@ export function TimelineChart({
})}
</Lane>
- {/* Each tool gets its own row: approval wait → execution */}
- {g.spans.map((s) => {
- const execStart = s.approvalMs ?? s.callMs;
- const open = s.outputMs === null;
- const endMs = s.outputMs ?? g.t0 + g.total;
- const approvalTs = s.approvalTsRaw ?? s.callTs;
- const execTs = s.outputTsRaw ?? s.callTs;
- return (
- <div key={s.toolCallId} className="flex items-center">
- <span
- className={`${LABEL_STICKY} text-gray-500 dark:text-gray-400`}
- title={s.name}
- >
- <span className={LABEL_TEXT}>{s.name}</span>
- </span>
- <Track>
- {/* Approval-wait segment (positioned exactly, flush against the execution segment) */}
- {s.approvalMs !== null && s.approvalMs > s.callMs && (
- <span
- onMouseEnter={() => enter(`w-${s.toolCallId}`, approvalTs)}
- onMouseLeave={leave}
- onClick={() => onJump?.(approvalTs)}
- title={`${s.name} · ${S.traces.legendApprovalWait}${s.decision ? ` (${s.decision})` : ""} · ${humanizeDuration(s.approvalMs - s.callMs)}`}
- className={`absolute inset-y-0 min-w-[2px] cursor-pointer ${COLORS.approvalWait} ${dimClass(
- isActive(`w-${s.toolCallId}`),
- legendKey === null || legendKey === "approvalWait",
- )}`}
- style={placeExact(s.callMs, s.approvalMs, g.t0, g.total)}
- />
- )}
- {/* Whole-segment pulse while approval is pending / execution segment */}
- {s.approvalMs === null && open
- ? (() => {
- // animate-pulse's keyframes override the static opacity: the pulse animation must be removed when fading out.
- const dim = dimClass(
- isActive(`p-${s.toolCallId}`),
- legendKey === null || legendKey === "approvalWait",
- );
- return (
- <span
- onMouseEnter={() => enter(`p-${s.toolCallId}`, s.callTs)}
- onMouseLeave={leave}
- onClick={() => onJump?.(s.callTs)}
- title={`${s.name} · ${S.traces.legendApprovalWait} · ${S.traces.inProgress}`}
- className={`absolute inset-y-0 min-w-[2px] cursor-pointer ${COLORS.approvalWait} ${
- dim || "animate-pulse"
- }`}
- style={placeExact(s.callMs, endMs, g.t0, g.total)}
- />
- );
- })()
- : (() => {
- // Fade-out and the "running" translucency share the same opacity property: fade-out takes priority to avoid the two overriding each other.
- const dim = dimClass(
- isActive(`e-${s.toolCallId}`),
- legendKey === null || legendKey === "exec",
- );
- const running = open && !dim;
- return (
- <span
- onMouseEnter={() => enter(`e-${s.toolCallId}`, execTs)}
- onMouseLeave={leave}
- onClick={() => onJump?.(execTs)}
- title={`${s.name} · ${S.traces.legendToolExec} · ${
- open ? S.traces.inProgress : humanizeDuration(endMs - execStart)
- }${s.failed ? ` · ${s.status}` : ""}`}
- className={`absolute inset-y-0 min-w-[2px] cursor-pointer ${COLORS.exec} ${
- s.failed ? "ring-1 ring-red-500" : ""
- } ${running ? "animate-pulse opacity-70" : dim}`}
- style={placeExact(execStart, endMs, g.t0, g.total)}
- />
- );
- })()}
- </Track>
- </div>
- );
- })}
+ {/* Tool rows: one per (name, lane) — non-overlapping same-name calls share the row, each rendered as approval wait → execution */}
+ {g.toolRows.map((row, rowIdx) => (
+ <div key={`${rowIdx}-${row.name}`} className="flex items-center">
+ <span
+ className={`${LABEL_STICKY} text-gray-500 dark:text-gray-400`}
+ title={row.name}
+ >
+ <span className={LABEL_TEXT}>{row.name}</span>
+ </span>
+ <Track>
+ {row.spans.map((s) => {
+ const execStart = s.approvalMs ?? s.callMs;
+ const open = s.outputMs === null;
+ const endMs = s.outputMs ?? g.t0 + g.total;
+ const approvalTs = s.approvalTsRaw ?? s.callTs;
+ const execTs = s.outputTsRaw ?? s.callTs;
+ return (
+ <Fragment key={s.toolCallId}>
+ {/* Approval-wait segment (positioned exactly, flush against the execution segment) */}
+ {s.approvalMs !== null && s.approvalMs > s.callMs && (
+ <span
+ onMouseEnter={() => enter(`w-${s.toolCallId}`, approvalTs)}
+ onMouseLeave={leave}
+ onClick={() => onJump?.(approvalTs)}
+ title={`${s.name} · ${S.traces.legendApprovalWait}${s.decision ? ` (${s.decision})` : ""} · ${humanizeDuration(s.approvalMs - s.callMs)}`}
+ className={`absolute inset-y-0 min-w-[2px] cursor-pointer ${COLORS.approvalWait} ${dimClass(
+ isActive(`w-${s.toolCallId}`),
+ legendKey === null || legendKey === "approvalWait",
+ )}`}
+ style={placeExact(s.callMs, s.approvalMs, g.t0, g.total)}
+ />
+ )}
+ {/* Whole-segment pulse while approval is pending / execution segment */}
+ {s.approvalMs === null && open
+ ? (() => {
+ // animate-pulse's keyframes override the static opacity: the pulse animation must be removed when fading out.
+ const dim = dimClass(
+ isActive(`p-${s.toolCallId}`),
+ legendKey === null || legendKey === "approvalWait",
+ );
+ return (
+ <span
+ onMouseEnter={() => enter(`p-${s.toolCallId}`, s.callTs)}
+ onMouseLeave={leave}
+ onClick={() => onJump?.(s.callTs)}
+ title={`${s.name} · ${S.traces.legendApprovalWait} · ${S.traces.inProgress}`}
+ className={`absolute inset-y-0 min-w-[2px] cursor-pointer ${COLORS.approvalWait} ${
+ dim || "animate-pulse"
+ }`}
+ style={placeExact(s.callMs, endMs, g.t0, g.total)}
+ />
+ );
+ })()
+ : (() => {
+ // Fade-out and the "running" translucency share the same opacity property: fade-out takes priority to avoid the two overriding each other.
+ const dim = dimClass(
+ isActive(`e-${s.toolCallId}`),
+ legendKey === null || legendKey === "exec",
+ );
+ const running = open && !dim;
+ return (
+ <span
+ onMouseEnter={() => enter(`e-${s.toolCallId}`, execTs)}
+ onMouseLeave={leave}
+ onClick={() => onJump?.(execTs)}
+ title={`${s.name} · ${S.traces.legendToolExec} · ${
+ open
+ ? S.traces.inProgress
+ : humanizeDuration(endMs - execStart)
+ }${s.failed ? ` · ${s.status}` : ""}`}
+ className={`absolute inset-y-0 min-w-[2px] cursor-pointer ${COLORS.exec} ${
+ s.failed ? "ring-1 ring-red-500" : ""
+ } ${running ? "animate-pulse opacity-70" : dim}`}
+ style={placeExact(execStart, endMs, g.t0, g.total)}
+ />
+ );
+ })()}
+ </Fragment>
+ );
+ })}
+ </Track>
+ </div>
+ ))}
{/* Non-tool auxiliary phases (MCP connect): one lane each, own legend category */}
{g.others.map((o) => {
diff --git a/packages/web/test/lane-packing.test.ts b/packages/web/test/lane-packing.test.ts
new file mode 100644
index 00000000..87c5bea8
--- /dev/null
+++ b/packages/web/test/lane-packing.test.ts
@@ -0,0 +1,193 @@
+/**
+ * lane-packing.ts unit tests: same-name non-overlapping calls share a lane
+ * (including touching endpoints and zero-duration spans), overlapping or
+ * nested same-name calls split lanes, names never mix, lane order follows
+ * each name's earliest start with same-name lanes adjacent, greedy first-fit
+ * reuses the earliest free lane, and unsorted input is handled; plus the
+ * footprint a single call claims, including timestamps recorded out of order.
+ */
+import { describe, expect, it } from "vitest";
+import { packToolLanes, toolSpanBounds } from "../src/features/traces/lane-packing";
+
+interface Span {
+ name: string;
+ startMs: number;
+ endMs: number;
+ id: string;
+}
+
+const span = (name: string, startMs: number, endMs: number, id: string): Span => ({
+ name,
+ startMs,
+ endMs,
+ id,
+});
+
+const shape = (lanes: ReturnType<typeof packToolLanes<Span>>) =>
+ lanes.map((l) => ({ name: l.name, ids: l.spans.map((s) => s.id) }));
+
+describe("packToolLanes", () => {
+ it("returns no lanes for no spans", () => {
+ expect(packToolLanes([])).toEqual([]);
+ });
+
+ it("packs sequential same-name calls into one lane", () => {
+ const lanes = packToolLanes([
+ span("exec_command", 0, 10, "a"),
+ span("exec_command", 20, 30, "b"),
+ span("exec_command", 40, 45, "c"),
+ ]);
+ expect(shape(lanes)).toEqual([{ name: "exec_command", ids: ["a", "b", "c"] }]);
+ });
+
+ it("treats touching endpoints as non-overlapping", () => {
+ const lanes = packToolLanes([span("read_file", 0, 10, "a"), span("read_file", 10, 20, "b")]);
+ expect(shape(lanes)).toEqual([{ name: "read_file", ids: ["a", "b"] }]);
+ });
+
+ it("shares a lane with zero-duration spans", () => {
+ const lanes = packToolLanes([span("read_file", 5, 5, "a"), span("read_file", 5, 9, "b")]);
+ expect(shape(lanes)).toEqual([{ name: "read_file", ids: ["a", "b"] }]);
+ });
+
+ it("splits overlapping same-name calls into extra lanes", () => {
+ const lanes = packToolLanes([
+ span("exec_command", 0, 10, "a"),
+ span("exec_command", 5, 15, "b"),
+ ]);
+ expect(shape(lanes)).toEqual([
+ { name: "exec_command", ids: ["a"] },
+ { name: "exec_command", ids: ["b"] },
+ ]);
+ });
+
+ it("splits nested same-name calls into extra lanes", () => {
+ const lanes = packToolLanes([
+ span("run_subagent", 0, 100, "outer"),
+ span("run_subagent", 10, 20, "inner"),
+ ]);
+ expect(shape(lanes)).toEqual([
+ { name: "run_subagent", ids: ["outer"] },
+ { name: "run_subagent", ids: ["inner"] },
+ ]);
+ });
+
+ it("never mixes names in one lane, even when disjoint", () => {
+ const lanes = packToolLanes([span("read_file", 0, 10, "a"), span("write_file", 20, 30, "b")]);
+ expect(shape(lanes)).toEqual([
+ { name: "read_file", ids: ["a"] },
+ { name: "write_file", ids: ["b"] },
+ ]);
+ });
+
+ it("orders lanes by each name's earliest start and keeps same-name lanes adjacent", () => {
+ const lanes = packToolLanes([
+ span("read_file", 0, 10, "r1"),
+ span("write_file", 2, 6, "w1"),
+ span("read_file", 4, 12, "r2"),
+ span("read_file", 20, 25, "r3"),
+ span("write_file", 8, 14, "w2"),
+ ]);
+ expect(shape(lanes)).toEqual([
+ { name: "read_file", ids: ["r1", "r3"] },
+ { name: "read_file", ids: ["r2"] },
+ { name: "write_file", ids: ["w1", "w2"] },
+ ]);
+ });
+
+ it("reuses the earliest freed lane (greedy first-fit)", () => {
+ const lanes = packToolLanes([
+ span("exec_command", 0, 10, "a"),
+ span("exec_command", 5, 15, "b"),
+ span("exec_command", 20, 30, "c"),
+ ]);
+ expect(shape(lanes)).toEqual([
+ { name: "exec_command", ids: ["a", "c"] },
+ { name: "exec_command", ids: ["b"] },
+ ]);
+ });
+
+ it("sorts unsorted input by start before packing", () => {
+ const lanes = packToolLanes([
+ span("exec_command", 20, 30, "late"),
+ span("exec_command", 0, 10, "early"),
+ ]);
+ expect(shape(lanes)).toEqual([{ name: "exec_command", ids: ["early", "late"] }]);
+ });
+
+ it("keeps a still-open span (endMs at the task end) blocking its lane", () => {
+ const taskEnd = 100;
+ const lanes = packToolLanes([
+ span("exec_command", 0, taskEnd, "open"),
+ span("exec_command", 50, 60, "later"),
+ ]);
+ expect(shape(lanes)).toEqual([
+ { name: "exec_command", ids: ["open"] },
+ { name: "exec_command", ids: ["later"] },
+ ]);
+ });
+});
+
+describe("toolSpanBounds", () => {
+ const TASK_END = 1000;
+
+ it("runs from the call to the output", () => {
+ expect(toolSpanBounds({ callMs: 10, approvalMs: null, outputMs: 40 }, TASK_END)).toEqual({
+ startMs: 10,
+ endMs: 40,
+ });
+ });
+
+ it("spans the approval wait and the execution as one footprint", () => {
+ expect(toolSpanBounds({ callMs: 10, approvalMs: 25, outputMs: 40 }, TASK_END)).toEqual({
+ startMs: 10,
+ endMs: 40,
+ });
+ });
+
+ it("blocks the row through the task end while the call is still open", () => {
+ expect(toolSpanBounds({ callMs: 10, approvalMs: null, outputMs: null }, TASK_END)).toEqual({
+ startMs: 10,
+ endMs: TASK_END,
+ });
+ expect(toolSpanBounds({ callMs: 10, approvalMs: 25, outputMs: null }, TASK_END)).toEqual({
+ startMs: 10,
+ endMs: TASK_END,
+ });
+ });
+
+ it("covers a decision recorded before its own call", () => {
+ // A clock step between two appends; the execution bar is drawn from the
+ // decision, so the footprint has to start there too.
+ expect(toolSpanBounds({ callMs: 10, approvalMs: 4, outputMs: 40 }, TASK_END)).toEqual({
+ startMs: 4,
+ endMs: 40,
+ });
+ });
+
+ it("covers an output recorded before its own decision", () => {
+ // The approval-wait bar still reaches the decision, so the footprint must too.
+ expect(toolSpanBounds({ callMs: 10, approvalMs: 60, outputMs: 40 }, TASK_END)).toEqual({
+ startMs: 10,
+ endMs: 60,
+ });
+ });
+
+ it("never returns an end before its start", () => {
+ expect(toolSpanBounds({ callMs: 10, approvalMs: null, outputMs: 4 }, TASK_END)).toEqual({
+ startMs: 10,
+ endMs: 10,
+ });
+ });
+
+ it("keeps out-of-order calls from sharing a row with their neighbour", () => {
+ const taskEnd = 1000;
+ const calls = [
+ { name: "exec_command", id: "a", callMs: 0, approvalMs: null, outputMs: 200 },
+ // Approved before it was called: drawn from 150, i.e. inside "a".
+ { name: "exec_command", id: "b", callMs: 200, approvalMs: 150, outputMs: 400 },
+ ];
+ const lanes = packToolLanes(calls.map((c) => ({ ...c, ...toolSpanBounds(c, taskEnd) })));
+ expect(lanes.map((l) => l.spans.map((s) => s.id))).toEqual([["a"], ["b"]]);
+ });
+});