Skip to content

The agent that grows with you

refactor(desktop): the newest-turn exemption is a boolean, not a count

kshitijk4poorb46f2448f752
diff --git a/apps/desktop/src/components/assistant-ui/thread/list.test.ts b/apps/desktop/src/components/assistant-ui/thread/list.test.ts
index 4966d07eb6d..3b277cd1a4c 100644
--- a/apps/desktop/src/components/assistant-ui/thread/list.test.ts
+++ b/apps/desktop/src/components/assistant-ui/thread/list.test.ts
@@ -270,14 +270,14 @@ describe('firstVisibleGroupIndex', () => {
const initial = [...history, group('streaming', 1)]
const grown = [...history, group('streaming', 5_000)]
- expect(firstVisibleGroupIndex(initial, 60, 0, 1)).toBe(1)
- expect(firstVisibleGroupIndex(grown, 60, 0, 1)).toBe(1)
+ expect(firstVisibleGroupIndex(initial, 60, 0, true)).toBe(1)
+ expect(firstVisibleGroupIndex(grown, 60, 0, true)).toBe(1)
})
it('exempts exactly one newest group while older history stays budgeted', () => {
const groups = [group('a', 200), group('b', 50), group('c', 50), group('d', 50), group('e', 10_000)]
- expect(firstVisibleGroupIndex(groups, 60, 0, 1)).toBe(2)
+ expect(firstVisibleGroupIndex(groups, 60, 0, true)).toBe(2)
})
})
diff --git a/apps/desktop/src/components/assistant-ui/thread/list.tsx b/apps/desktop/src/components/assistant-ui/thread/list.tsx
index 6df0182e0dd..cef47312320 100644
--- a/apps/desktop/src/components/assistant-ui/thread/list.tsx
+++ b/apps/desktop/src/components/assistant-ui/thread/list.tsx
@@ -280,16 +280,17 @@ export function buildGroups(signature: string): MessageGroup[] {
// Walk turns newest-first, summing their render weights until the budget is met;
// everything before the first kept turn is hidden. `minVisible` turns are kept
-// regardless of weight; the newest `unbudgetedTail` turns are kept AND left out
-// of the sum, so a turn whose weight is still changing cannot move the cut.
-// Returns the index of that first visible group.
+// regardless of weight (the exempt newest turn counts as one of them). With
+// `exemptNewest` the newest turn is kept AND left out of the sum, so a turn
+// whose weight is still changing cannot move the cut. Returns the index of that
+// first visible group.
export function firstVisibleGroupIndex(
groups: readonly MessageGroup[],
budget: number,
minVisible = 0,
- unbudgetedTail = 0
+ exemptNewest = false
): number {
- const budgetedEnd = Math.max(0, groups.length - unbudgetedTail)
+ const budgetedEnd = exemptNewest ? Math.max(0, groups.length - 1) : groups.length
let firstVisible = budgetedEnd
for (let i = budgetedEnd - 1, weight = 0; i >= 0; i--) {
@@ -599,12 +600,7 @@ const ThreadMessageListInner: FC<ThreadMessageListProps> = ({
// clamp looks like a user scroll-up to use-stick-to-bottom.
const fullPage = renderBudget >= paneBudget
- const hiddenCount = firstVisibleGroupIndex(
- weightedGroups,
- renderBudget,
- fullPage ? MIN_VISIBLE_GROUPS : 0,
- fullPage ? 1 : 0
- )
+ const hiddenCount = firstVisibleGroupIndex(weightedGroups, renderBudget, fullPage ? MIN_VISIBLE_GROUPS : 0, fullPage)
// Memoized for IDENTITY, not to save the slice: `rows` below keys off this
// array, and an inline slice handed it a fresh array every render — so the