Multiplayer agent harness for work.
Fix pinned prompt flicker during auto-follow (#1574)
Joshua France157adc573226
diff --git a/plugins/web-ui/src/transcript-viewport.ts b/plugins/web-ui/src/transcript-viewport.tsindex 10d785039..c76d5b3cf 100644--- a/plugins/web-ui/src/transcript-viewport.ts+++ b/plugins/web-ui/src/transcript-viewport.ts@@ -47,6 +47,8 @@ export function createTranscriptViewport() {let condensedHeight = 0;let gap: number | null = null;let contentMax = "";+ let collapseDistance = 0;+ let geometryDistance: number | null = null;const contentUpdates = new Set<Promise<void>>();function setFollowing(value: boolean): void {@@ -69,6 +71,8 @@ export function createTranscriptViewport() {restContent = condensedContent = contentHeight = condensedHeight = 0;gap = null;contentMax = "";+ collapseDistance = 0;+ geometryDistance = null;remeasure = true;const toggle = prompt?.querySelector<HTMLButtonElement>(".pin-toggle");if (toggle) toggle.hidden = true;@@ -170,6 +174,16 @@ export function createTranscriptViewport() {function condense(active: boolean, distance: number): void {if (!prompt || !content) return;+ if (!active) {+ collapseDistance = 0;+ geometryDistance = null;+ } else {+ if (geometryDistance === null) collapseDistance = Math.max(0, distance);+ else if (following) collapseDistance = Math.max(collapseDistance, distance);+ else collapseDistance = Math.max(0, collapseDistance + distance - geometryDistance);+ geometryDistance = distance;+ }+ distance = collapseDistance;const span = restContent - condensedContent;const settled = span <= 0.5 || span - distance < 0.5;if (active && settled && !prompt.classList.contains("pin-condensed")) {@@ -188,10 +202,11 @@ export function createTranscriptViewport() {if (!scroller || contentUpdates.size > 0) return;const movingUp = scroller.scrollTop < lastTop;const atBottom = scroller.scrollHeight - scroller.clientHeight - scroller.scrollTop <= 1;- if (atBottom && (following || !movingUp)) setFollowing(true);- else if (movingUp) cancelFollow();+ const resumeFollowing = atBottom && (following || !movingUp);+ if (!resumeFollowing && movingUp) cancelFollow();lastTop = scroller.scrollTop;syncSticky();+ if (resumeFollowing) setFollowing(true);if (movingUp) loadEarlier();}diff --git a/plugins/web-ui/test/pinned-prompt-collapse.test.ts b/plugins/web-ui/test/pinned-prompt-collapse.test.tsindex c6b64170c..b509ed864 100644--- a/plugins/web-ui/test/pinned-prompt-collapse.test.ts+++ b/plugins/web-ui/test/pinned-prompt-collapse.test.ts@@ -15,10 +15,11 @@ function fixture() {const toggle = row.querySelector<HTMLButtonElement>("button")!;let height = 300;let fullHeight = 600;+ let scrollHeight = 2000;let pinsHeight = 0;scroller.querySelector<HTMLElement>(".pinned-strip")!.getBoundingClientRect = () =>({ height: pinsHeight }) as DOMRect;- Object.defineProperties(scroller, { clientHeight: { get: () => height }, scrollHeight: { value: 2000 } });+ Object.defineProperties(scroller, { clientHeight: { get: () => height }, scrollHeight: { get: () => scrollHeight } });Object.defineProperties(content, {scrollHeight: { get: () => fullHeight },clientHeight: {@@ -74,6 +75,12 @@ function fixture() {height = next;resize([{ target: scroller }]);},+ setScrollHeight: (next: number) => {+ scrollHeight = next;+ },+ wheel: (deltaY: number) => {+ scroller.dispatchEvent(new dom.window.WheelEvent("wheel", { deltaY }));+ },setPins: (next: number) => {pinsHeight = next;resize([{ target: scroller.querySelector(".pinned-strip")! }]);@@ -287,6 +294,27 @@ test("the prompt condenses in step with the scroll, one pixel of height per pixe}});+test("auto-follow layout clamps do not reverse an in-progress prompt collapse", () => {+ const f = fixture();+ try {+ f.setScrollHeight(349.75);+ f.scroll(49.75);+ assert.equal(f.row.style.getPropertyValue("--pin-content-max"), "89.75px");++ f.setScrollHeight(340);+ f.scroll(40);+ assert.equal(f.row.style.getPropertyValue("--pin-content-max"), "89.75px");++ f.wheel(-10);+ f.scroll(30);+ assert.equal(f.row.style.getPropertyValue("--pin-content-max"), "99.75px");+ f.scroll(40);+ assert.equal(f.row.style.getPropertyValue("--pin-content-max"), "89.75px");+ } finally {+ f.close();+ }+});+test("the collapse is measured from the row's resting place, so it survives being opened mid-scroll", () => {const f = fixture();try {