Skip to content

armgit / cindy

Public Imported from GitHub
0

Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。

fix(desktop): 锚定窗口始终包含跳转目标

david87027018bc56
diff --git a/apps/desktop/src/renderer/__tests__/messageStreamRenderWindowIntegration.test.ts b/apps/desktop/src/renderer/__tests__/messageStreamRenderWindowIntegration.test.ts
index 9ecefcf651..cf7858708e 100644
--- a/apps/desktop/src/renderer/__tests__/messageStreamRenderWindowIntegration.test.ts
+++ b/apps/desktop/src/renderer/__tests__/messageStreamRenderWindowIntegration.test.ts
@@ -32,6 +32,7 @@ import {
groupWorkRuns,
snapRenderWindowStartIdx,
isViewportAnchorWithinDefaultTail,
+ resolveAnchoredWindowItemCount,
clampTailWindowStartByBudget,
estimateRenderItemMountCost,
RENDER_WINDOW_INITIAL_ITEMS,
@@ -478,6 +479,22 @@ describe('two-phase first-paint window', () => {
});
});
+describe('anchored bounded window includes its target', () => {
+ it('adds boundary lookback distance to the desired forward count', () => {
+ // target 位于 turn 起点后第 24 个 item;15-item 窗口若不补 lookback 会漏掉 target。
+ const startIdx = 10;
+ const anchorIdx = startIdx + 24;
+ expect(resolveAnchoredWindowItemCount(startIdx, anchorIdx, 15)).toBe(39);
+ expect(startIdx + resolveAnchoredWindowItemCount(startIdx, anchorIdx, 15)).toBeGreaterThan(
+ anchorIdx,
+ );
+ });
+
+ it('does not inflate a window when snapping keeps the anchor as start', () => {
+ expect(resolveAnchoredWindowItemCount(20, 20, 15)).toBe(15);
+ });
+});
+
describe('first-paint content budget (clampTailWindowStartByBudget)', () => {
const mkItem = (id: string, contentSize: number) => ({
key: `message-${id}`,
diff --git a/apps/desktop/src/renderer/components/chat/MessageStream.tsx b/apps/desktop/src/renderer/components/chat/MessageStream.tsx
index 4228651b1e..2fb8248560 100644
--- a/apps/desktop/src/renderer/components/chat/MessageStream.tsx
+++ b/apps/desktop/src/renderer/components/chat/MessageStream.tsx
@@ -460,6 +460,14 @@ export function clampTailWindowStartByBudget(
return countStartIdx;
}
+export function resolveAnchoredWindowItemCount(
+ startIdx: number,
+ anchorIdx: number,
+ desiredForwardItems: number,
+): number {
+ return desiredForwardItems + Math.max(0, anchorIdx - startIdx);
+}
+
// export 仅供 render-window 集成单测使用。窗口默认/扩窗时如果刚好切在
// agent_task / work_group / assistant 中间,顶部会出现无上下文的卡片。
// 向前吸收同一 user turn 的开头,但限制 lookback 防止单个超长 turn 破坏首屏预算。
@@ -2686,8 +2694,13 @@ export function MessageStream({
}
const startIdx = snapRenderWindowStartIdx(allRenderItems, idx);
+ const windowItemCount = resolveAnchoredWindowItemCount(
+ startIdx,
+ idx,
+ anchoredForwardItems,
+ );
return {
- items: allRenderItems.slice(startIdx, startIdx + anchoredForwardItems),
+ items: allRenderItems.slice(startIdx, startIdx + windowItemCount),
startIdx,
};
}, [allRenderItems, firstVisibleItemKey, defaultWindowItems, anchoredForwardItems, firstMountDeferred]);
@@ -2894,7 +2907,7 @@ export function MessageStream({
const windowCoversEnd =
firstVisibleItemKey === null ||
allRenderItems.length === 0 ||
- visibleStartIdx + anchoredForwardItems >= allRenderItems.length;
+ visibleStartIdx + visibleRenderItems.length >= allRenderItems.length;
// ── 滚动位置 保存 / 还原 的辅助 ──
// unmount cleanup 与 ResizeObserver 回调里读不到最新的 visibleRenderItems /