From 81b82f42fbe15000eb835d9cd313378be3d847ea Mon Sep 17 00:00:00 2001 From: Lisa Rosenberg Date: Wed, 4 Nov 2026 20:06:13 +0100 Subject: [PATCH 01/66] feat: add subagent pet --- .../chat/browser/widget/chatPetWidget.ts | 90 +++++++++++++++++++ .../chat/browser/widget/media/chatPet.css | 30 +++++++ .../test/browser/widget/chatPetWidget.test.ts | 67 ++++++++++++++ 3 files changed, 187 insertions(+) diff --git a/src/vs/workbench/contrib/chat/browser/widget/chatPetWidget.ts b/src/vs/workbench/contrib/chat/browser/widget/chatPetWidget.ts index b1fdecc9e6a5c4..2d567b1d877312 100644 --- a/src/vs/workbench/contrib/chat/browser/widget/chatPetWidget.ts +++ b/src/vs/workbench/contrib/chat/browser/widget/chatPetWidget.ts @@ -27,6 +27,7 @@ import { IInstantiationService } from '../../../../../platform/instantiation/com import { ILogService } from '../../../../../platform/log/common/log.js'; import { IHostService } from '../../../../services/host/browser/host.js'; import { IChatModel } from '../../common/model/chatModel.js'; +import { getSubagentIsActive, IChatToolInvocation } from '../../common/chatService/chatService.js'; import { CHAT_PET_OPEN_ACHIEVEMENTS_COMMAND_ID, ChatPetAccessoryId, getChatPetAccessory, getChatPetAchievement } from '../chatPetAchievements.js'; import { CHAT_PET_DEFAULT_SCALE, ChatPetHorizontalAnchor, ChatPetHorizontalPosition, ChatPetVariant, IChatPetService } from '../chatPetService.js'; import { CHAT_PET_CHANGE_COLOR_COMMAND_ID, ChatPetColor, getChatPetBodyColor, getChatPetColoredSprite, getChatPetColorVariant, getChatPetEyeColor, setChatPetImageSource } from '../chatPetColors.js'; @@ -1245,6 +1246,8 @@ export class ChatPetHopController extends Disposable { export class ChatPetWidget extends Disposable { + private readonly _subagentPets: { element: HTMLElement; canvas: HTMLCanvasElement }[] = []; + private readonly _subagentEffects = this._register(new DisposableStore()); private parent: HTMLElement; private dragBounds: HTMLElement; private movementBounds: HTMLElement; @@ -1475,6 +1478,34 @@ export class ChatPetWidget extends Disposable { const eye = dom.append(this._eyes, dom.$(`.chat-pet-eye.${side}`)); this._pupils.push(dom.append(eye, dom.$('.chat-pet-pupil'))); } + this._register(autorun(reader => { + const model = this._host.read(reader).model.read(reader); + if (!model) { + this._updateSubagentPets(0); + return; + } + observableSignalFromEvent(this, model.onDidChange).read(reader); + let count = 0; + for (const request of model.getRequests()) { + const response = request.response; + if (!response) { + continue; + } + observableSignalFromEvent(this, response.onDidChange).read(reader); + for (const part of response.response.value) { + if (part.kind !== 'toolInvocation') { + continue; + } + part.toolSpecificDataKind.read(reader); + part.state.read(reader); + const data = part.toolSpecificData; + if (data?.kind === 'subagent' && data.presentation !== 'phase' && data.hasStarted !== false && (getSubagentIsActive(data) ?? !IChatToolInvocation.isComplete(part, reader))) { + count++; + } + } + } + this._updateSubagentPets(count); + })); this._propellerPoseContainer = dom.append(this._visual, dom.$('.chat-pet-propeller-pose', { 'aria-hidden': 'true' })); this._propellerContainer = dom.append(this._propellerPoseContainer, dom.$('.chat-pet-propeller.hidden')); this._propeller = dom.append(this._propellerContainer, dom.$('canvas.chat-pet-propeller-canvas')) as HTMLCanvasElement; @@ -2811,6 +2842,64 @@ export class ChatPetWidget extends Disposable { return this._button.element.offsetLeft; } + private _updateSubagentPets(count: number): void { + while (this._subagentPets.length > count) { + this._despawnSubagentPet(this._subagentPets.pop()!); + } + while (this._subagentPets.length < count) { + const element = dom.append(this._visual, dom.$('.chat-pet-subagent', { 'aria-hidden': 'true' })); + element.style.left = `${-24 * (this._subagentPets.length + 1)}px`; + const distance = Math.max(0, this._visual.getBoundingClientRect().bottom / (this._scale || 1)); + element.style.setProperty('--chat-pet-subagent-fall-distance', `${distance}px`); + element.style.setProperty('--chat-pet-subagent-fall-duration', `${getChatPetFallDuration(distance)}ms`); + if (!this._motionReduced) { + element.classList.add('arriving'); + } + const canvas = dom.append(element, dom.$('canvas.chat-pet-subagent-canvas')) as HTMLCanvasElement; + canvas.width = CHAT_PET_SOURCE_SIZE; + canvas.height = CHAT_PET_SOURCE_SIZE; + element.appendChild(this._eyes.cloneNode(true)); + this._subagentPets.push({ element, canvas }); + } + if (this._activeSprite) { + this._drawSubagentPets(this._activeSprite.canvas); + } + } + + private _despawnSubagentPet(pet: { element: HTMLElement; canvas: HTMLCanvasElement }): void { + pet.element.classList.remove('chat-pet-subagent', 'arriving'); + pet.element.classList.add('chat-pet-subagent-despawning'); + pet.element.querySelector('.chat-pet-eyes')?.remove(); + const effects = this._subagentEffects.add(new DisposableStore()); + const image = dom.append(pet.element, dom.$('img.chat-pet-spritesheet')) as HTMLImageElement; + image.alt = ''; + const sources = getRespawnSpriteSources(this._variant); + const source = this._motionReduced ? sources.reducedMotion : sources.animated; + const animation = effects.add(new MutableDisposable()); + const sprite: ChatPetSpriteElement = { container: pet.element, canvas: pet.canvas, image, color: this._color }; + const finish = () => { + pet.element.remove(); + this._subagentEffects.delete(effects); + }; + effects.add(toDisposable(() => pet.element.remove())); + effects.add(dom.addDisposableListener(image, 'load', () => this._startSpriteAnimation(source, sprite, animation, finish, true))); + effects.add(dom.addDisposableListener(image, 'error', finish)); + const targetWindow = dom.getWindow(pet.element); + const timer = targetWindow.setTimeout(finish, this._motionReduced ? RESPAWN_EFFECT_REDUCED_MOTION_DURATION : RESPAWN_EFFECT_DURATION); + effects.add(toDisposable(() => targetWindow.clearTimeout(timer))); + setChatPetImageSource(image, source.url); + } + + private _drawSubagentPets(source: HTMLCanvasElement): void { + for (const pet of this._subagentPets) { + const context = pet.canvas.getContext('2d'); + if (context) { + context.clearRect(0, 0, pet.canvas.width, pet.canvas.height); + context.drawImage(source, 0, 0, pet.canvas.width, pet.canvas.height); + } + } + } + private _getDisplaySize(): number { return CHAT_PET_SOURCE_SIZE / 2 * this._scale; } @@ -3829,6 +3918,7 @@ export class ChatPetWidget extends Disposable { } if (sprite === this._activeSprite) { this._activeFrameIndex = frameIndex; + this._drawSubagentPets(canvas); } onFrame?.(frameIndex); }; diff --git a/src/vs/workbench/contrib/chat/browser/widget/media/chatPet.css b/src/vs/workbench/contrib/chat/browser/widget/media/chatPet.css index 7d6271fcd62777..ff09db46c7bdb7 100644 --- a/src/vs/workbench/contrib/chat/browser/widget/media/chatPet.css +++ b/src/vs/workbench/contrib/chat/browser/widget/media/chatPet.css @@ -170,6 +170,36 @@ pointer-events: none; } +.chat-pet-subagent, +.chat-pet-subagent-despawning { + position: absolute; + bottom: 0; + width: 48px; + height: 48px; + transform: scale(0.5); + transform-origin: bottom left; + pointer-events: none; +} + +.chat-pet-subagent.arriving { + animation: chat-pet-subagent-fall var(--chat-pet-subagent-fall-duration) cubic-bezier(0.42, 0, 1, 1) both; +} + +@keyframes chat-pet-subagent-fall { + from { transform: translateY(calc(-1 * var(--chat-pet-subagent-fall-distance))) scale(0.5); } + to { transform: translateY(0) scale(0.5); } +} + +.monaco-workbench.monaco-reduce-motion .chat-pet-subagent.arriving { + animation: none; +} + +.chat-pet-subagent-canvas { + width: 48px; + height: 48px; + image-rendering: pixelated; +} + .chat-pet-sprite { position: absolute; bottom: 0; diff --git a/src/vs/workbench/contrib/chat/test/browser/widget/chatPetWidget.test.ts b/src/vs/workbench/contrib/chat/test/browser/widget/chatPetWidget.test.ts index 3c7c900c15e20f..f60c667820c703 100644 --- a/src/vs/workbench/contrib/chat/test/browser/widget/chatPetWidget.test.ts +++ b/src/vs/workbench/contrib/chat/test/browser/widget/chatPetWidget.test.ts @@ -156,6 +156,8 @@ suite('ChatPetWidget', () => { const secondHost: IChatPetWidgetHost = { ...createHost(secondParent, 'fall'), model: constObservable(new class extends mock() { + override readonly onDidChange = Event.None; + override getRequests(): IChatRequestModel[] { return []; } override readonly hasActiveRequest = constObservable(true); override readonly lastRequestObs = constObservable(undefined); }()), @@ -2253,6 +2255,69 @@ suite('ChatPetWidget', () => { ]); }); + test('shows one mini pet per active subagent and removes it when it stops', async () => { + const { widget, firstHost, button } = createHostTransitionHarness(); + const responseChanged = disposables.add(new Emitter()); + const parts: IChatProgressResponseContent[] = []; + const response = new class extends mock() { + override readonly onDidChange = responseChanged.event; + override readonly isPendingConfirmation = constObservable(undefined); + override readonly response = new class extends mock() { override readonly value = parts; }(); + }(); + const request = new class extends mock() { override readonly response = response; }(); + const model = new class extends mock() { + override readonly onDidChange = Event.None; + override readonly hasActiveRequest = constObservable(true); + override readonly lastRequestObs = constObservable(request); + override getRequests(): IChatRequestModel[] { return [request]; } + }(); + const modelValue = observableValue('model', model); + widget.setHost({ ...firstHost, model: modelValue }); + const createSubagent = (id: string) => { + const tool = new ChatToolInvocation(undefined, { id, displayName: id, modelDescription: 'Subagent', source: ToolDataSource.Internal }, id, undefined, {}); + tool.toolSpecificData = { kind: 'subagent', isActive: true }; + parts.push(tool); + responseChanged.fire({ reason: 'other' }); + return tool; + }; + const first = createSubagent('first'); + createSubagent('second'); + assert.strictEqual(button.querySelectorAll('.chat-pet-subagent').length, 2); + assert.strictEqual(button.querySelectorAll('.chat-pet-subagent.arriving').length, 2); + first.toolSpecificData = { kind: 'subagent', isActive: false }; + responseChanged.fire({ reason: 'other' }); + assert.strictEqual(button.querySelectorAll('.chat-pet-subagent').length, 1); + assert.ok(button.querySelector('.chat-pet-subagent-despawning img')?.getAttribute('src')?.includes('buddy-respawn-')); + modelValue.set(undefined, undefined); + assert.strictEqual(button.querySelectorAll('.chat-pet-subagent').length, 0); + await timeout(900); + assert.strictEqual(button.querySelectorAll('.chat-pet-subagent-despawning').length, 0); + }); + + test('mini pets use the reduced-motion disappearance sprite', () => { + const { widget, firstHost, button } = createHostTransitionHarness(true); + const changed = disposables.add(new Emitter()); + const tool = new ChatToolInvocation(undefined, { id: 'subagent', displayName: 'Subagent', modelDescription: 'Subagent', source: ToolDataSource.Internal }, 'subagent', undefined, {}); + tool.toolSpecificData = { kind: 'subagent', isActive: true }; + const response = new class extends mock() { + override readonly onDidChange = changed.event; + override readonly isPendingConfirmation = constObservable(undefined); + override readonly response = new class extends mock() { override readonly value = [tool]; }(); + }(); + const request = new class extends mock() { override readonly response = response; }(); + const model = new class extends mock() { + override readonly onDidChange = Event.None; + override readonly hasActiveRequest = constObservable(true); + override readonly lastRequestObs = constObservable(request); + override getRequests(): IChatRequestModel[] { return [request]; } + }(); + widget.setHost({ ...firstHost, model: constObservable(model) }); + assert.ok(button.querySelector('.chat-pet-subagent:not(.arriving)')); + tool.toolSpecificData = { kind: 'subagent', isActive: false }; + changed.fire({ reason: 'other' }); + assert.ok(button.querySelector('.chat-pet-subagent-despawning img')?.getAttribute('src')?.endsWith('-96.png')); + }); + for (const variant of ['stable', 'insiders'] as const) { for (const reducedMotion of [false, true]) { test(`paints only while a visible image-generation tool is active (${variant}, ${reducedMotion ? 'reduced motion' : 'animated'})`, async () => { @@ -2271,6 +2336,8 @@ suite('ChatPetWidget', () => { override readonly response = response; }(); const model = new class extends mock() { + override readonly onDidChange = Event.None; + override getRequests(): IChatRequestModel[] { return [request]; } override readonly hasActiveRequest = hasActiveRequest; override readonly lastRequestObs = constObservable(request); }(); From 1eb113cd56edc2764c5049b993e8cfac2a2eef8e Mon Sep 17 00:00:00 2001 From: Lisa Rosenberg Date: Wed, 4 Nov 2026 20:35:35 +0100 Subject: [PATCH 02/66] feat: use separate subagent pet --- .../chat/browser/widget/chatPetWidget.ts | 46 ++++++++++--------- .../chat/browser/widget/media/chatPet.css | 23 ++++++++-- .../test/browser/widget/chatPetWidget.test.ts | 31 +++++++++---- 3 files changed, 64 insertions(+), 36 deletions(-) diff --git a/src/vs/workbench/contrib/chat/browser/widget/chatPetWidget.ts b/src/vs/workbench/contrib/chat/browser/widget/chatPetWidget.ts index 2d567b1d877312..e0562164d45d7d 100644 --- a/src/vs/workbench/contrib/chat/browser/widget/chatPetWidget.ts +++ b/src/vs/workbench/contrib/chat/browser/widget/chatPetWidget.ts @@ -1246,8 +1246,9 @@ export class ChatPetHopController extends Disposable { export class ChatPetWidget extends Disposable { - private readonly _subagentPets: { element: HTMLElement; canvas: HTMLCanvasElement }[] = []; + private readonly _subagentPets: { element: HTMLElement; canvas: HTMLCanvasElement; disposables: DisposableStore }[] = []; private readonly _subagentEffects = this._register(new DisposableStore()); + private readonly _subagentLayer: HTMLElement; private parent: HTMLElement; private dragBounds: HTMLElement; private movementBounds: HTMLElement; @@ -1411,6 +1412,7 @@ export class ChatPetWidget extends Disposable { this.parent.classList.add('chat-pet-host'); this._overlay = dom.$(`.${CHAT_PET_OVERLAY_CLASS}`); this.parent.prepend(this._overlay); + this._subagentLayer = dom.append(this._overlay, dom.$('.chat-pet-subagent-layer')); this._register(toDisposable(() => { this.parent.classList.remove('chat-pet-host'); this._overlay.remove(); @@ -1732,6 +1734,7 @@ export class ChatPetWidget extends Disposable { this._setScale(scale); } const enabled = isChatPetVisible(serviceEnabled, isWindowActive); + this._subagentLayer.classList.toggle('hidden', !enabled); const color = this.chatPetService.color.read(reader); const colorChanged = color !== this._color; this._color = color; @@ -2847,9 +2850,12 @@ export class ChatPetWidget extends Disposable { this._despawnSubagentPet(this._subagentPets.pop()!); } while (this._subagentPets.length < count) { - const element = dom.append(this._visual, dom.$('.chat-pet-subagent', { 'aria-hidden': 'true' })); - element.style.left = `${-24 * (this._subagentPets.length + 1)}px`; - const distance = Math.max(0, this._visual.getBoundingClientRect().bottom / (this._scale || 1)); + const element = dom.append(this._subagentLayer, dom.$('.chat-pet-subagent', { 'aria-hidden': 'true' })); + const miniScale = 0.5 * (this._scale || 1); + element.style.left = `${this._button.element.offsetLeft - 48 * miniScale * (this._subagentPets.length + 1)}px`; + element.style.top = `${this._button.element.offsetTop + this._getDisplaySize() - 48 * miniScale}px`; + element.style.setProperty('--chat-pet-subagent-scale', String(miniScale)); + const distance = Math.max(0, this._overlay.getBoundingClientRect().top + this._button.element.offsetTop + this._getDisplaySize() - 48 * miniScale); element.style.setProperty('--chat-pet-subagent-fall-distance', `${distance}px`); element.style.setProperty('--chat-pet-subagent-fall-duration', `${getChatPetFallDuration(distance)}ms`); if (!this._motionReduced) { @@ -2858,15 +2864,24 @@ export class ChatPetWidget extends Disposable { const canvas = dom.append(element, dom.$('canvas.chat-pet-subagent-canvas')) as HTMLCanvasElement; canvas.width = CHAT_PET_SOURCE_SIZE; canvas.height = CHAT_PET_SOURCE_SIZE; - element.appendChild(this._eyes.cloneNode(true)); - this._subagentPets.push({ element, canvas }); - } - if (this._activeSprite) { - this._drawSubagentPets(this._activeSprite.canvas); + const eyes = element.appendChild(this._eyes.cloneNode(true)) as HTMLElement; + eyes.classList.add('tracking'); + const disposables = this._subagentEffects.add(new DisposableStore()); + const animation = disposables.add(new MutableDisposable()); + const image = dom.append(element, dom.$('img.chat-pet-spritesheet')) as HTMLImageElement; + image.alt = ''; + const sources = getChatPetSpriteSources(this._variant).idle; + const source = this._motionReduced ? sources.reducedMotion : sources.animated; + const sprite: ChatPetSpriteElement = { container: element, canvas, image, color: this._color }; + disposables.add(dom.addDisposableListener(image, 'load', () => this._startSpriteAnimation(source, sprite, animation))); + setChatPetImageSource(image, source.url); + this._subagentPets.push({ element, canvas, disposables }); } } - private _despawnSubagentPet(pet: { element: HTMLElement; canvas: HTMLCanvasElement }): void { + private _despawnSubagentPet(pet: { element: HTMLElement; canvas: HTMLCanvasElement; disposables: DisposableStore }): void { + this._subagentEffects.delete(pet.disposables); + pet.element.querySelector('img')?.remove(); pet.element.classList.remove('chat-pet-subagent', 'arriving'); pet.element.classList.add('chat-pet-subagent-despawning'); pet.element.querySelector('.chat-pet-eyes')?.remove(); @@ -2890,16 +2905,6 @@ export class ChatPetWidget extends Disposable { setChatPetImageSource(image, source.url); } - private _drawSubagentPets(source: HTMLCanvasElement): void { - for (const pet of this._subagentPets) { - const context = pet.canvas.getContext('2d'); - if (context) { - context.clearRect(0, 0, pet.canvas.width, pet.canvas.height); - context.drawImage(source, 0, 0, pet.canvas.width, pet.canvas.height); - } - } - } - private _getDisplaySize(): number { return CHAT_PET_SOURCE_SIZE / 2 * this._scale; } @@ -3918,7 +3923,6 @@ export class ChatPetWidget extends Disposable { } if (sprite === this._activeSprite) { this._activeFrameIndex = frameIndex; - this._drawSubagentPets(canvas); } onFrame?.(frameIndex); }; diff --git a/src/vs/workbench/contrib/chat/browser/widget/media/chatPet.css b/src/vs/workbench/contrib/chat/browser/widget/media/chatPet.css index ff09db46c7bdb7..188f37b319bad9 100644 --- a/src/vs/workbench/contrib/chat/browser/widget/media/chatPet.css +++ b/src/vs/workbench/contrib/chat/browser/widget/media/chatPet.css @@ -170,14 +170,23 @@ pointer-events: none; } +.chat-pet-subagent-layer { + position: absolute; + inset: 0; + pointer-events: none; +} + +.chat-pet-subagent-layer.hidden { + display: none; +} + .chat-pet-subagent, .chat-pet-subagent-despawning { position: absolute; - bottom: 0; width: 48px; height: 48px; - transform: scale(0.5); - transform-origin: bottom left; + transform: scale(var(--chat-pet-subagent-scale)); + transform-origin: top left; pointer-events: none; } @@ -186,8 +195,8 @@ } @keyframes chat-pet-subagent-fall { - from { transform: translateY(calc(-1 * var(--chat-pet-subagent-fall-distance))) scale(0.5); } - to { transform: translateY(0) scale(0.5); } + from { transform: translateY(calc(-1 * var(--chat-pet-subagent-fall-distance))) scale(var(--chat-pet-subagent-scale)); } + to { transform: translateY(0) scale(var(--chat-pet-subagent-scale)); } } .monaco-workbench.monaco-reduce-motion .chat-pet-subagent.arriving { @@ -200,6 +209,10 @@ image-rendering: pixelated; } +.chat-pet-subagent .chat-pet-eye { + height: 12px; +} + .chat-pet-sprite { position: absolute; bottom: 0; diff --git a/src/vs/workbench/contrib/chat/test/browser/widget/chatPetWidget.test.ts b/src/vs/workbench/contrib/chat/test/browser/widget/chatPetWidget.test.ts index f60c667820c703..fb55d24fcd5c3a 100644 --- a/src/vs/workbench/contrib/chat/test/browser/widget/chatPetWidget.test.ts +++ b/src/vs/workbench/contrib/chat/test/browser/widget/chatPetWidget.test.ts @@ -2256,7 +2256,7 @@ suite('ChatPetWidget', () => { }); test('shows one mini pet per active subagent and removes it when it stops', async () => { - const { widget, firstHost, button } = createHostTransitionHarness(); + const { widget, firstHost, button, overlay, service } = createHostTransitionHarness(); const responseChanged = disposables.add(new Emitter()); const parts: IChatProgressResponseContent[] = []; const response = new class extends mock() { @@ -2282,20 +2282,31 @@ suite('ChatPetWidget', () => { }; const first = createSubagent('first'); createSubagent('second'); - assert.strictEqual(button.querySelectorAll('.chat-pet-subagent').length, 2); - assert.strictEqual(button.querySelectorAll('.chat-pet-subagent.arriving').length, 2); + assert.strictEqual(overlay.querySelectorAll('.chat-pet-subagent').length, 2); + assert.strictEqual(overlay.querySelectorAll('.chat-pet-subagent.arriving').length, 2); + assert.strictEqual(button.querySelectorAll('.chat-pet-subagent').length, 0); + assert.ok(overlay.querySelector('.chat-pet-subagent img')?.getAttribute('src')?.includes('buddy-')); + const mini = overlay.querySelector('.chat-pet-subagent')!; + const position = mini.style.left; + button.style.left = '300px'; + button.style.transform = 'rotate(45deg)'; + assert.strictEqual(mini.style.left, position); + service.toggle(); + assert.ok(overlay.querySelector('.chat-pet-subagent-layer.hidden')); + service.toggle(); + assert.ok(overlay.querySelector('.chat-pet-subagent-layer:not(.hidden)')); first.toolSpecificData = { kind: 'subagent', isActive: false }; responseChanged.fire({ reason: 'other' }); - assert.strictEqual(button.querySelectorAll('.chat-pet-subagent').length, 1); - assert.ok(button.querySelector('.chat-pet-subagent-despawning img')?.getAttribute('src')?.includes('buddy-respawn-')); + assert.strictEqual(overlay.querySelectorAll('.chat-pet-subagent').length, 1); + assert.ok(overlay.querySelector('.chat-pet-subagent-despawning img')?.getAttribute('src')?.includes('buddy-respawn-')); modelValue.set(undefined, undefined); - assert.strictEqual(button.querySelectorAll('.chat-pet-subagent').length, 0); + assert.strictEqual(overlay.querySelectorAll('.chat-pet-subagent').length, 0); await timeout(900); - assert.strictEqual(button.querySelectorAll('.chat-pet-subagent-despawning').length, 0); + assert.strictEqual(overlay.querySelectorAll('.chat-pet-subagent-despawning').length, 0); }); test('mini pets use the reduced-motion disappearance sprite', () => { - const { widget, firstHost, button } = createHostTransitionHarness(true); + const { widget, firstHost, overlay } = createHostTransitionHarness(true); const changed = disposables.add(new Emitter()); const tool = new ChatToolInvocation(undefined, { id: 'subagent', displayName: 'Subagent', modelDescription: 'Subagent', source: ToolDataSource.Internal }, 'subagent', undefined, {}); tool.toolSpecificData = { kind: 'subagent', isActive: true }; @@ -2312,10 +2323,10 @@ suite('ChatPetWidget', () => { override getRequests(): IChatRequestModel[] { return [request]; } }(); widget.setHost({ ...firstHost, model: constObservable(model) }); - assert.ok(button.querySelector('.chat-pet-subagent:not(.arriving)')); + assert.ok(overlay.querySelector('.chat-pet-subagent:not(.arriving)')); tool.toolSpecificData = { kind: 'subagent', isActive: false }; changed.fire({ reason: 'other' }); - assert.ok(button.querySelector('.chat-pet-subagent-despawning img')?.getAttribute('src')?.endsWith('-96.png')); + assert.ok(overlay.querySelector('.chat-pet-subagent-despawning img')?.getAttribute('src')?.endsWith('-96.png')); }); for (const variant of ['stable', 'insiders'] as const) { From af6a67b8bed5793900f28558a9068e8a57c453a7 Mon Sep 17 00:00:00 2001 From: Lisa Rosenberg Date: Wed, 4 Nov 2026 21:12:07 +0100 Subject: [PATCH 03/66] feat: spawn subagent pet on side with more available room --- .../contrib/chat/browser/widget/chatPetWidget.ts | 9 ++++++++- .../chat/test/browser/widget/chatPetWidget.test.ts | 6 ++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/vs/workbench/contrib/chat/browser/widget/chatPetWidget.ts b/src/vs/workbench/contrib/chat/browser/widget/chatPetWidget.ts index e0562164d45d7d..62ccb52f3e9c28 100644 --- a/src/vs/workbench/contrib/chat/browser/widget/chatPetWidget.ts +++ b/src/vs/workbench/contrib/chat/browser/widget/chatPetWidget.ts @@ -2852,7 +2852,14 @@ export class ChatPetWidget extends Disposable { while (this._subagentPets.length < count) { const element = dom.append(this._subagentLayer, dom.$('.chat-pet-subagent', { 'aria-hidden': 'true' })); const miniScale = 0.5 * (this._scale || 1); - element.style.left = `${this._button.element.offsetLeft - 48 * miniScale * (this._subagentPets.length + 1)}px`; + const petLeft = this._button.element.offsetLeft; + const bounds = this._getHorizontalBounds(); + const midpoint = bounds ? (bounds.minimumLeft + bounds.maximumLeft) / 2 : (this._overlay.clientWidth - this._getDisplaySize()) / 2; + const miniWidth = 48 * miniScale; + const left = petLeft < midpoint + ? petLeft + this._getDisplaySize() + miniWidth * this._subagentPets.length + : petLeft - miniWidth * (this._subagentPets.length + 1); + element.style.left = `${left}px`; element.style.top = `${this._button.element.offsetTop + this._getDisplaySize() - 48 * miniScale}px`; element.style.setProperty('--chat-pet-subagent-scale', String(miniScale)); const distance = Math.max(0, this._overlay.getBoundingClientRect().top + this._button.element.offsetTop + this._getDisplaySize() - 48 * miniScale); diff --git a/src/vs/workbench/contrib/chat/test/browser/widget/chatPetWidget.test.ts b/src/vs/workbench/contrib/chat/test/browser/widget/chatPetWidget.test.ts index fb55d24fcd5c3a..e16f755f412804 100644 --- a/src/vs/workbench/contrib/chat/test/browser/widget/chatPetWidget.test.ts +++ b/src/vs/workbench/contrib/chat/test/browser/widget/chatPetWidget.test.ts @@ -2280,8 +2280,14 @@ suite('ChatPetWidget', () => { responseChanged.fire({ reason: 'other' }); return tool; }; + button.style.left = '0px'; const first = createSubagent('first'); + const firstMini = overlay.querySelector('.chat-pet-subagent')!; + assert.ok(firstMini.offsetLeft >= button.offsetLeft + button.offsetWidth); + button.style.left = '300px'; createSubagent('second'); + const minis = overlay.querySelectorAll('.chat-pet-subagent'); + assert.ok(minis[1].offsetLeft < button.offsetLeft); assert.strictEqual(overlay.querySelectorAll('.chat-pet-subagent').length, 2); assert.strictEqual(overlay.querySelectorAll('.chat-pet-subagent.arriving').length, 2); assert.strictEqual(button.querySelectorAll('.chat-pet-subagent').length, 0); From 7b095f980c2f8ee97ce4c32bd2d77f332d4049d4 Mon Sep 17 00:00:00 2001 From: Lisa Rosenberg Date: Wed, 4 Nov 2026 21:26:07 +0100 Subject: [PATCH 04/66] feat: subagent pets use own lifecycle id --- .../chat/browser/widget/chatPetWidget.ts | 48 ++++++++++++------- .../test/browser/widget/chatPetWidget.test.ts | 16 ++++++- 2 files changed, 46 insertions(+), 18 deletions(-) diff --git a/src/vs/workbench/contrib/chat/browser/widget/chatPetWidget.ts b/src/vs/workbench/contrib/chat/browser/widget/chatPetWidget.ts index 62ccb52f3e9c28..b3eda2fb8a1552 100644 --- a/src/vs/workbench/contrib/chat/browser/widget/chatPetWidget.ts +++ b/src/vs/workbench/contrib/chat/browser/widget/chatPetWidget.ts @@ -1246,7 +1246,8 @@ export class ChatPetHopController extends Disposable { export class ChatPetWidget extends Disposable { - private readonly _subagentPets: { element: HTMLElement; canvas: HTMLCanvasElement; disposables: DisposableStore }[] = []; + private readonly _subagentPets = new Map(); + private _subagentModel: IChatModel | undefined; private readonly _subagentEffects = this._register(new DisposableStore()); private readonly _subagentLayer: HTMLElement; private parent: HTMLElement; @@ -1482,12 +1483,15 @@ export class ChatPetWidget extends Disposable { } this._register(autorun(reader => { const model = this._host.read(reader).model.read(reader); + if (model !== this._subagentModel) { + this._updateSubagentPets(new Set()); + this._subagentModel = model; + } if (!model) { - this._updateSubagentPets(0); return; } observableSignalFromEvent(this, model.onDidChange).read(reader); - let count = 0; + const subagents = new Set(); for (const request of model.getRequests()) { const response = request.response; if (!response) { @@ -1502,11 +1506,11 @@ export class ChatPetWidget extends Disposable { part.state.read(reader); const data = part.toolSpecificData; if (data?.kind === 'subagent' && data.presentation !== 'phase' && data.hasStarted !== false && (getSubagentIsActive(data) ?? !IChatToolInvocation.isComplete(part, reader))) { - count++; + subagents.add(JSON.stringify([request.id, part.toolCallId])); } } } - this._updateSubagentPets(count); + this._updateSubagentPets(subagents); })); this._propellerPoseContainer = dom.append(this._visual, dom.$('.chat-pet-propeller-pose', { 'aria-hidden': 'true' })); this._propellerContainer = dom.append(this._propellerPoseContainer, dom.$('.chat-pet-propeller.hidden')); @@ -2845,20 +2849,32 @@ export class ChatPetWidget extends Disposable { return this._button.element.offsetLeft; } - private _updateSubagentPets(count: number): void { - while (this._subagentPets.length > count) { - this._despawnSubagentPet(this._subagentPets.pop()!); + private _updateSubagentPets(subagents: ReadonlySet): void { + for (const [id, pet] of this._subagentPets) { + if (!subagents.has(id)) { + this._subagentPets.delete(id); + this._despawnSubagentPet(pet); + } } - while (this._subagentPets.length < count) { + for (const id of subagents) { + if (this._subagentPets.has(id)) { + continue; + } const element = dom.append(this._subagentLayer, dom.$('.chat-pet-subagent', { 'aria-hidden': 'true' })); const miniScale = 0.5 * (this._scale || 1); const petLeft = this._button.element.offsetLeft; const bounds = this._getHorizontalBounds(); const midpoint = bounds ? (bounds.minimumLeft + bounds.maximumLeft) / 2 : (this._overlay.clientWidth - this._getDisplaySize()) / 2; const miniWidth = 48 * miniScale; - const left = petLeft < midpoint - ? petLeft + this._getDisplaySize() + miniWidth * this._subagentPets.length - : petLeft - miniWidth * (this._subagentPets.length + 1); + const side = petLeft < midpoint ? 'right' : 'left'; + const occupiedSlots = new Set([...this._subagentPets.values()].filter(pet => pet.side === side).map(pet => pet.slot)); + let slot = 0; + while (occupiedSlots.has(slot)) { + slot++; + } + const left = side === 'right' + ? petLeft + this._getDisplaySize() + miniWidth * slot + : petLeft - miniWidth * (slot + 1); element.style.left = `${left}px`; element.style.top = `${this._button.element.offsetTop + this._getDisplaySize() - 48 * miniScale}px`; element.style.setProperty('--chat-pet-subagent-scale', String(miniScale)); @@ -2882,16 +2898,16 @@ export class ChatPetWidget extends Disposable { const sprite: ChatPetSpriteElement = { container: element, canvas, image, color: this._color }; disposables.add(dom.addDisposableListener(image, 'load', () => this._startSpriteAnimation(source, sprite, animation))); setChatPetImageSource(image, source.url); - this._subagentPets.push({ element, canvas, disposables }); + this._subagentPets.set(id, { element, canvas, image, eyes, disposables, slot, side }); } } - private _despawnSubagentPet(pet: { element: HTMLElement; canvas: HTMLCanvasElement; disposables: DisposableStore }): void { + private _despawnSubagentPet(pet: { element: HTMLElement; canvas: HTMLCanvasElement; image: HTMLImageElement; eyes: HTMLElement; disposables: DisposableStore }): void { this._subagentEffects.delete(pet.disposables); - pet.element.querySelector('img')?.remove(); + pet.image.remove(); pet.element.classList.remove('chat-pet-subagent', 'arriving'); pet.element.classList.add('chat-pet-subagent-despawning'); - pet.element.querySelector('.chat-pet-eyes')?.remove(); + pet.eyes.remove(); const effects = this._subagentEffects.add(new DisposableStore()); const image = dom.append(pet.element, dom.$('img.chat-pet-spritesheet')) as HTMLImageElement; image.alt = ''; diff --git a/src/vs/workbench/contrib/chat/test/browser/widget/chatPetWidget.test.ts b/src/vs/workbench/contrib/chat/test/browser/widget/chatPetWidget.test.ts index e16f755f412804..c2d15fc7e49101 100644 --- a/src/vs/workbench/contrib/chat/test/browser/widget/chatPetWidget.test.ts +++ b/src/vs/workbench/contrib/chat/test/browser/widget/chatPetWidget.test.ts @@ -2264,7 +2264,7 @@ suite('ChatPetWidget', () => { override readonly isPendingConfirmation = constObservable(undefined); override readonly response = new class extends mock() { override readonly value = parts; }(); }(); - const request = new class extends mock() { override readonly response = response; }(); + const request = new class extends mock() { override readonly id = 'request'; override readonly response = response; }(); const model = new class extends mock() { override readonly onDidChange = Event.None; override readonly hasActiveRequest = constObservable(true); @@ -2304,6 +2304,18 @@ suite('ChatPetWidget', () => { first.toolSpecificData = { kind: 'subagent', isActive: false }; responseChanged.fire({ reason: 'other' }); assert.strictEqual(overlay.querySelectorAll('.chat-pet-subagent').length, 1); + assert.ok(firstMini.classList.contains('chat-pet-subagent-despawning')); + assert.strictEqual(overlay.querySelector('.chat-pet-subagent'), minis[1]); + const third = createSubagent('third'); + const thirdMini = overlay.querySelectorAll('.chat-pet-subagent')[1]; + parts.splice(parts.indexOf(third), 1); + const replacement = new ChatToolInvocation(undefined, { id: 'replacement', displayName: 'Replacement', modelDescription: 'Subagent', source: ToolDataSource.Internal }, 'replacement', undefined, {}); + replacement.toolSpecificData = { kind: 'subagent', isActive: true }; + parts.push(replacement); + responseChanged.fire({ reason: 'other' }); + assert.ok(thirdMini.classList.contains('chat-pet-subagent-despawning')); + assert.strictEqual(overlay.querySelector('.chat-pet-subagent'), minis[1]); + assert.strictEqual(overlay.querySelectorAll('.chat-pet-subagent').length, 2); assert.ok(overlay.querySelector('.chat-pet-subagent-despawning img')?.getAttribute('src')?.includes('buddy-respawn-')); modelValue.set(undefined, undefined); assert.strictEqual(overlay.querySelectorAll('.chat-pet-subagent').length, 0); @@ -2321,7 +2333,7 @@ suite('ChatPetWidget', () => { override readonly isPendingConfirmation = constObservable(undefined); override readonly response = new class extends mock() { override readonly value = [tool]; }(); }(); - const request = new class extends mock() { override readonly response = response; }(); + const request = new class extends mock() { override readonly id = 'request'; override readonly response = response; }(); const model = new class extends mock() { override readonly onDidChange = Event.None; override readonly hasActiveRequest = constObservable(true); From 63c55854967f527ee2b8dbf4cc8c5d28ca7111f7 Mon Sep 17 00:00:00 2001 From: Lisa Rosenberg Date: Wed, 4 Nov 2026 21:47:39 +0100 Subject: [PATCH 05/66] feat: update pet's eyes --- .../workbench/contrib/chat/browser/widget/media/chatPet.css | 4 ++++ .../contrib/chat/test/browser/widget/chatPetWidget.test.ts | 5 +++++ 2 files changed, 9 insertions(+) diff --git a/src/vs/workbench/contrib/chat/browser/widget/media/chatPet.css b/src/vs/workbench/contrib/chat/browser/widget/media/chatPet.css index 188f37b319bad9..f5e5467e20267a 100644 --- a/src/vs/workbench/contrib/chat/browser/widget/media/chatPet.css +++ b/src/vs/workbench/contrib/chat/browser/widget/media/chatPet.css @@ -213,6 +213,10 @@ height: 12px; } +.chat-pet-subagent .chat-pet-pupil { + height: 8px; +} + .chat-pet-sprite { position: absolute; bottom: 0; diff --git a/src/vs/workbench/contrib/chat/test/browser/widget/chatPetWidget.test.ts b/src/vs/workbench/contrib/chat/test/browser/widget/chatPetWidget.test.ts index c2d15fc7e49101..d61fd262bc2904 100644 --- a/src/vs/workbench/contrib/chat/test/browser/widget/chatPetWidget.test.ts +++ b/src/vs/workbench/contrib/chat/test/browser/widget/chatPetWidget.test.ts @@ -2284,6 +2284,11 @@ suite('ChatPetWidget', () => { const first = createSubagent('first'); const firstMini = overlay.querySelector('.chat-pet-subagent')!; assert.ok(firstMini.offsetLeft >= button.offsetLeft + button.offsetWidth); + button.dataset.state = 'idle'; + const miniPupil = firstMini.querySelector('.chat-pet-pupil')!; + const mainPupil = button.querySelector('.chat-pet-pupil')!; + assert.strictEqual(mainWindow.getComputedStyle(miniPupil).height, mainWindow.getComputedStyle(mainPupil).height); + assert.strictEqual(mainWindow.getComputedStyle(miniPupil).height, '8px'); button.style.left = '300px'; createSubagent('second'); const minis = overlay.querySelectorAll('.chat-pet-subagent'); From a523af36d9e2fec310f05633002c6fae1ea2a59e Mon Sep 17 00:00:00 2001 From: Lisa Rosenberg Date: Wed, 4 Nov 2026 23:59:57 +0100 Subject: [PATCH 06/66] feat: use main pet's accessory --- .../chat/browser/widget/chatPetWidget.ts | 23 +++++++++++++++---- .../test/browser/widget/chatPetWidget.test.ts | 10 ++++++++ 2 files changed, 29 insertions(+), 4 deletions(-) diff --git a/src/vs/workbench/contrib/chat/browser/widget/chatPetWidget.ts b/src/vs/workbench/contrib/chat/browser/widget/chatPetWidget.ts index b3eda2fb8a1552..d4458c3acd2921 100644 --- a/src/vs/workbench/contrib/chat/browser/widget/chatPetWidget.ts +++ b/src/vs/workbench/contrib/chat/browser/widget/chatPetWidget.ts @@ -1246,7 +1246,7 @@ export class ChatPetHopController extends Disposable { export class ChatPetWidget extends Disposable { - private readonly _subagentPets = new Map(); + private readonly _subagentPets = new Map(); private _subagentModel: IChatModel | undefined; private readonly _subagentEffects = this._register(new DisposableStore()); private readonly _subagentLayer: HTMLElement; @@ -2896,15 +2896,30 @@ export class ChatPetWidget extends Disposable { const sources = getChatPetSpriteSources(this._variant).idle; const source = this._motionReduced ? sources.reducedMotion : sources.animated; const sprite: ChatPetSpriteElement = { container: element, canvas, image, color: this._color }; - disposables.add(dom.addDisposableListener(image, 'load', () => this._startSpriteAnimation(source, sprite, animation))); + const accessory = this._selectedAccessory ? getChatPetAccessory(this._selectedAccessory) : undefined; + const accessoryImage = accessory ? dom.append(element, dom.$('img.chat-pet-spritesheet')) as HTMLImageElement : undefined; + if (accessoryImage && accessory) { + accessoryImage.alt = ''; + disposables.add(dom.addDisposableListener(accessoryImage, 'load', () => sprite.redrawFrame?.())); + setChatPetImageSource(accessoryImage, getChatPetAccessoryImageSource(accessory).url); + } + disposables.add(dom.addDisposableListener(image, 'load', () => this._startSpriteAnimation(source, sprite, animation, undefined, false, frameIndex => { + if (accessoryImage?.complete && accessoryImage.naturalWidth > 0 && accessory) { + const context = canvas.getContext('2d'); + if (context) { + drawChatPetComposite(context, image, accessoryImage, frameIndex, source.accessoryRigFrame ?? frameIndex, source.frameWidth, source.frameHeight ?? CHAT_PET_SOURCE_SIZE, 'right', 'idle', source.fixedOrientationDecorations, true, accessory.eyeAccessoryMirrorsWithFacing !== false, accessory.coversAntennae === true, sprite.color); + } + } + }))); setChatPetImageSource(image, source.url); - this._subagentPets.set(id, { element, canvas, image, eyes, disposables, slot, side }); + this._subagentPets.set(id, { element, canvas, image, accessoryImage, eyes, disposables, slot, side }); } } - private _despawnSubagentPet(pet: { element: HTMLElement; canvas: HTMLCanvasElement; image: HTMLImageElement; eyes: HTMLElement; disposables: DisposableStore }): void { + private _despawnSubagentPet(pet: { element: HTMLElement; canvas: HTMLCanvasElement; image: HTMLImageElement; accessoryImage: HTMLImageElement | undefined; eyes: HTMLElement; disposables: DisposableStore }): void { this._subagentEffects.delete(pet.disposables); pet.image.remove(); + pet.accessoryImage?.remove(); pet.element.classList.remove('chat-pet-subagent', 'arriving'); pet.element.classList.add('chat-pet-subagent-despawning'); pet.eyes.remove(); diff --git a/src/vs/workbench/contrib/chat/test/browser/widget/chatPetWidget.test.ts b/src/vs/workbench/contrib/chat/test/browser/widget/chatPetWidget.test.ts index d61fd262bc2904..97d9fbd0cc3f4b 100644 --- a/src/vs/workbench/contrib/chat/test/browser/widget/chatPetWidget.test.ts +++ b/src/vs/workbench/contrib/chat/test/browser/widget/chatPetWidget.test.ts @@ -2273,6 +2273,8 @@ suite('ChatPetWidget', () => { }(); const modelValue = observableValue('model', model); widget.setHost({ ...firstHost, model: modelValue }); + service.unlockAchievement(getChatPetAchievementForAccessory(ChatPetAccessoryIds.CowboyHat).id); + service.setAccessory(ChatPetAccessoryIds.CowboyHat); const createSubagent = (id: string) => { const tool = new ChatToolInvocation(undefined, { id, displayName: id, modelDescription: 'Subagent', source: ToolDataSource.Internal }, id, undefined, {}); tool.toolSpecificData = { kind: 'subagent', isActive: true }; @@ -2284,6 +2286,14 @@ suite('ChatPetWidget', () => { const first = createSubagent('first'); const firstMini = overlay.querySelector('.chat-pet-subagent')!; assert.ok(firstMini.offsetLeft >= button.offsetLeft + button.offsetWidth); + const [bodyImage, accessoryImage] = firstMini.querySelectorAll('img'); + assert.ok(accessoryImage?.src.includes('/accessories/')); + await Promise.all([bodyImage.decode(), accessoryImage.decode()]); + const miniCanvas = firstMini.querySelector('canvas')!; + const draws = sinon.spy(miniCanvas.getContext('2d')!, 'drawImage'); + bodyImage.dispatchEvent(new mainWindow.Event('load')); + assert.ok(draws.calledWith(accessoryImage)); + draws.restore(); button.dataset.state = 'idle'; const miniPupil = firstMini.querySelector('.chat-pet-pupil')!; const mainPupil = button.querySelector('.chat-pet-pupil')!; From 29560a17bfb18ede641cde98ec24a408ffe70449 Mon Sep 17 00:00:00 2001 From: Lisa Rosenberg Date: Thu, 5 Nov 2026 00:09:01 +0100 Subject: [PATCH 07/66] feat: fix landing position --- .../contrib/chat/browser/widget/chatPetWidget.ts | 6 ++++-- .../chat/test/browser/widget/chatPetWidget.test.ts | 12 ++++++++++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/vs/workbench/contrib/chat/browser/widget/chatPetWidget.ts b/src/vs/workbench/contrib/chat/browser/widget/chatPetWidget.ts index d4458c3acd2921..03da094fb8ebbf 100644 --- a/src/vs/workbench/contrib/chat/browser/widget/chatPetWidget.ts +++ b/src/vs/workbench/contrib/chat/browser/widget/chatPetWidget.ts @@ -2875,10 +2875,12 @@ export class ChatPetWidget extends Disposable { const left = side === 'right' ? petLeft + this._getDisplaySize() + miniWidth * slot : petLeft - miniWidth * (slot + 1); + const overlayBounds = this._overlay.getBoundingClientRect(); + const landing = getChatPetFallTarget(overlayBounds.left + left, -miniWidth, miniWidth, miniWidth, this._getPlatforms(), this.movementBounds.getBoundingClientRect().bottom); element.style.left = `${left}px`; - element.style.top = `${this._button.element.offsetTop + this._getDisplaySize() - 48 * miniScale}px`; + element.style.top = `${landing.top - overlayBounds.top}px`; element.style.setProperty('--chat-pet-subagent-scale', String(miniScale)); - const distance = Math.max(0, this._overlay.getBoundingClientRect().top + this._button.element.offsetTop + this._getDisplaySize() - 48 * miniScale); + const distance = Math.max(0, landing.top + miniWidth); element.style.setProperty('--chat-pet-subagent-fall-distance', `${distance}px`); element.style.setProperty('--chat-pet-subagent-fall-duration', `${getChatPetFallDuration(distance)}ms`); if (!this._motionReduced) { diff --git a/src/vs/workbench/contrib/chat/test/browser/widget/chatPetWidget.test.ts b/src/vs/workbench/contrib/chat/test/browser/widget/chatPetWidget.test.ts index 97d9fbd0cc3f4b..280622b8ae58ae 100644 --- a/src/vs/workbench/contrib/chat/test/browser/widget/chatPetWidget.test.ts +++ b/src/vs/workbench/contrib/chat/test/browser/widget/chatPetWidget.test.ts @@ -2283,9 +2283,12 @@ suite('ChatPetWidget', () => { return tool; }; button.style.left = '0px'; + button.style.top = '-100px'; const first = createSubagent('first'); const firstMini = overlay.querySelector('.chat-pet-subagent')!; assert.ok(firstMini.offsetLeft >= button.offsetLeft + button.offsetWidth); + const miniSize = 48 * Number.parseFloat(firstMini.style.getPropertyValue('--chat-pet-subagent-scale')); + assert.strictEqual(Number.parseFloat(firstMini.style.top) + miniSize, 0); const [bodyImage, accessoryImage] = firstMini.querySelectorAll('img'); assert.ok(accessoryImage?.src.includes('/accessories/')); await Promise.all([bodyImage.decode(), accessoryImage.decode()]); @@ -2299,10 +2302,19 @@ suite('ChatPetWidget', () => { const mainPupil = button.querySelector('.chat-pet-pupil')!; assert.strictEqual(mainWindow.getComputedStyle(miniPupil).height, mainWindow.getComputedStyle(mainPupil).height); assert.strictEqual(mainWindow.getComputedStyle(miniPupil).height, '8px'); + widget.setHost({ ...firstHost, transition: undefined, model: modelValue, getPlatforms: () => { + const bounds = overlay.getBoundingClientRect(); + return [ + { left: bounds.left, right: bounds.right, top: bounds.top - 60 }, + { left: bounds.left, right: bounds.right, top: bounds.top, isDefault: true }, + ]; + } }); button.style.left = '300px'; + button.style.top = '-140px'; createSubagent('second'); const minis = overlay.querySelectorAll('.chat-pet-subagent'); assert.ok(minis[1].offsetLeft < button.offsetLeft); + assert.strictEqual(Number.parseFloat(minis[1].style.top) + miniSize, -60); assert.strictEqual(overlay.querySelectorAll('.chat-pet-subagent').length, 2); assert.strictEqual(overlay.querySelectorAll('.chat-pet-subagent.arriving').length, 2); assert.strictEqual(button.querySelectorAll('.chat-pet-subagent').length, 0); From adebb3fc613dc997f7830d6751d0ee1fda5357ee Mon Sep 17 00:00:00 2001 From: Lisa Rosenberg Date: Thu, 5 Nov 2026 00:17:08 +0100 Subject: [PATCH 08/66] feat: add idle animation --- .../chat/browser/widget/chatPetWidget.ts | 24 ++++++++++- .../chat/browser/widget/media/chatPet.css | 3 +- .../test/browser/widget/chatPetWidget.test.ts | 41 +++++++++++++++++++ 3 files changed, 65 insertions(+), 3 deletions(-) diff --git a/src/vs/workbench/contrib/chat/browser/widget/chatPetWidget.ts b/src/vs/workbench/contrib/chat/browser/widget/chatPetWidget.ts index 03da094fb8ebbf..81a80b17a6c431 100644 --- a/src/vs/workbench/contrib/chat/browser/widget/chatPetWidget.ts +++ b/src/vs/workbench/contrib/chat/browser/widget/chatPetWidget.ts @@ -1246,7 +1246,7 @@ export class ChatPetHopController extends Disposable { export class ChatPetWidget extends Disposable { - private readonly _subagentPets = new Map(); + private readonly _subagentPets = new Map void; slot: number; side: 'left' | 'right' }>(); private _subagentModel: IChatModel | undefined; private readonly _subagentEffects = this._register(new DisposableStore()); private readonly _subagentLayer: HTMLElement; @@ -1813,6 +1813,12 @@ export class ChatPetWidget extends Disposable { this._finishDisable(); } } + for (const pet of this._subagentPets.values()) { + pet.updateBlink(); + if (this._motionReduced) { + pet.eyes.classList.remove('bobbed'); + } + } if (!enabled) { this._hopController.cancel(); @@ -2890,8 +2896,21 @@ export class ChatPetWidget extends Disposable { canvas.width = CHAT_PET_SOURCE_SIZE; canvas.height = CHAT_PET_SOURCE_SIZE; const eyes = element.appendChild(this._eyes.cloneNode(true)) as HTMLElement; + eyes.classList.remove('blink', 'blinking', 'bobbed'); eyes.classList.add('tracking'); const disposables = this._subagentEffects.add(new DisposableStore()); + const blink = disposables.add(new ChatPetBlinkController(blinking => eyes.classList.toggle('blink', blinking))); + const updateBlink = () => blink.setEnabled(this._enabled && !this._motionReduced && this._isAnimationVisible(this._visual) && this._isAnimationVisible(element)); + disposables.add(this._onDidChangeAnimationVisibility.event(updateBlink)); + const firstPupil = eyes.firstElementChild?.firstElementChild; + if (firstPupil) { + disposables.add(dom.addDisposableListener(firstPupil, 'animationend', event => { + if ((event as AnimationEvent).animationName === 'chat-pet-tall-eye-blink') { + blink.onAnimationComplete(); + } + })); + } + updateBlink(); const animation = disposables.add(new MutableDisposable()); const image = dom.append(element, dom.$('img.chat-pet-spritesheet')) as HTMLImageElement; image.alt = ''; @@ -2906,6 +2925,7 @@ export class ChatPetWidget extends Disposable { setChatPetImageSource(accessoryImage, getChatPetAccessoryImageSource(accessory).url); } disposables.add(dom.addDisposableListener(image, 'load', () => this._startSpriteAnimation(source, sprite, animation, undefined, false, frameIndex => { + eyes.classList.toggle('bobbed', !this._motionReduced && (source.accessoryRigFrame ?? frameIndex) >= 20); if (accessoryImage?.complete && accessoryImage.naturalWidth > 0 && accessory) { const context = canvas.getContext('2d'); if (context) { @@ -2914,7 +2934,7 @@ export class ChatPetWidget extends Disposable { } }))); setChatPetImageSource(image, source.url); - this._subagentPets.set(id, { element, canvas, image, accessoryImage, eyes, disposables, slot, side }); + this._subagentPets.set(id, { element, canvas, image, accessoryImage, eyes, disposables, updateBlink, slot, side }); } } diff --git a/src/vs/workbench/contrib/chat/browser/widget/media/chatPet.css b/src/vs/workbench/contrib/chat/browser/widget/media/chatPet.css index f5e5467e20267a..87d305c3635836 100644 --- a/src/vs/workbench/contrib/chat/browser/widget/media/chatPet.css +++ b/src/vs/workbench/contrib/chat/browser/widget/media/chatPet.css @@ -509,7 +509,8 @@ .chat-pet-button[data-state='typing'] .chat-pet-eyes.blink .chat-pet-pupil, .chat-pet-button[data-state='painting'] .chat-pet-eyes.blink .chat-pet-pupil, .chat-pet-button[data-state='buttonPress'] .chat-pet-eyes.blink .chat-pet-pupil, -.chat-pet-button[data-state='love'] .chat-pet-eyes.blink .chat-pet-pupil { +.chat-pet-button[data-state='love'] .chat-pet-eyes.blink .chat-pet-pupil, +.chat-pet-subagent .chat-pet-eyes.blink .chat-pet-pupil { animation-name: chat-pet-tall-eye-blink; } diff --git a/src/vs/workbench/contrib/chat/test/browser/widget/chatPetWidget.test.ts b/src/vs/workbench/contrib/chat/test/browser/widget/chatPetWidget.test.ts index 280622b8ae58ae..f8f8bd9f70dee2 100644 --- a/src/vs/workbench/contrib/chat/test/browser/widget/chatPetWidget.test.ts +++ b/src/vs/workbench/contrib/chat/test/browser/widget/chatPetWidget.test.ts @@ -2374,6 +2374,47 @@ suite('ChatPetWidget', () => { assert.ok(overlay.querySelector('.chat-pet-subagent-despawning img')?.getAttribute('src')?.endsWith('-96.png')); }); + test('mini pets blink and move their eyes with their own idle frames', async () => { + const clock = sinon.useFakeTimers({ toFake: ['setTimeout', 'clearTimeout', 'performance'] }); + disposables.add(toDisposable(() => clock.restore())); + sinon.stub(Math, 'random').returns(0); + const { widget, firstHost, overlay, setReducedMotion } = createHostTransitionHarness(); + const tool = new ChatToolInvocation(undefined, { id: 'subagent', displayName: 'Subagent', modelDescription: 'Subagent', source: ToolDataSource.Internal }, 'subagent', undefined, {}); + tool.toolSpecificData = { kind: 'subagent', isActive: true }; + const response = new class extends mock() { + override readonly onDidChange = Event.None; + override readonly isPendingConfirmation = constObservable(undefined); + override readonly response = new class extends mock() { override readonly value = [tool]; }(); + }(); + const request = new class extends mock() { override readonly id = 'request'; override readonly response = response; }(); + const model = new class extends mock() { + override readonly onDidChange = Event.None; + override readonly hasActiveRequest = constObservable(true); + override readonly lastRequestObs = constObservable(request); + override getRequests(): IChatRequestModel[] { return [request]; } + }(); + widget.setHost({ ...firstHost, model: constObservable(model) }); + const pet = overlay.querySelector('.chat-pet-subagent')!; + const eyes = pet.querySelector('.chat-pet-eyes')!; + const pupil = pet.querySelector('.chat-pet-pupil')!; + await pet.querySelector('img')!.decode(); + await Promise.resolve(); + assert.ok(!eyes.classList.contains('bobbed')); + clock.tick(800); + assert.ok(eyes.classList.contains('bobbed')); + clock.tick(600); + assert.ok(eyes.classList.contains('blink')); + assert.strictEqual(mainWindow.getComputedStyle(pupil).animationName, 'chat-pet-tall-eye-blink'); + pupil.dispatchEvent(new mainWindow.AnimationEvent('animationend', { animationName: 'chat-pet-tall-eye-blink' })); + assert.ok(!eyes.classList.contains('blink')); + clock.tick(600); + assert.ok(!eyes.classList.contains('bobbed')); + setReducedMotion(true); + clock.tick(3_400); + assert.ok(!eyes.classList.contains('blink')); + assert.ok(!eyes.classList.contains('bobbed')); + }); + for (const variant of ['stable', 'insiders'] as const) { for (const reducedMotion of [false, true]) { test(`paints only while a visible image-generation tool is active (${variant}, ${reducedMotion ? 'reduced motion' : 'animated'})`, async () => { From 7606d73320a60869ec6294da9e7a059fd1f99f0e Mon Sep 17 00:00:00 2001 From: Lisa Rosenberg Date: Thu, 5 Nov 2026 00:34:06 +0100 Subject: [PATCH 09/66] feat: fix eye position --- .../workbench/contrib/chat/browser/widget/chatPetWidget.ts | 3 +++ .../contrib/chat/test/browser/widget/chatPetWidget.test.ts | 6 ++++++ 2 files changed, 9 insertions(+) diff --git a/src/vs/workbench/contrib/chat/browser/widget/chatPetWidget.ts b/src/vs/workbench/contrib/chat/browser/widget/chatPetWidget.ts index 81a80b17a6c431..8bba032098946e 100644 --- a/src/vs/workbench/contrib/chat/browser/widget/chatPetWidget.ts +++ b/src/vs/workbench/contrib/chat/browser/widget/chatPetWidget.ts @@ -2898,6 +2898,9 @@ export class ChatPetWidget extends Disposable { const eyes = element.appendChild(this._eyes.cloneNode(true)) as HTMLElement; eyes.classList.remove('blink', 'blinking', 'bobbed'); eyes.classList.add('tracking'); + for (const eye of eyes.children) { + (eye.firstElementChild as HTMLElement | null)?.style.removeProperty('transform'); + } const disposables = this._subagentEffects.add(new DisposableStore()); const blink = disposables.add(new ChatPetBlinkController(blinking => eyes.classList.toggle('blink', blinking))); const updateBlink = () => blink.setEnabled(this._enabled && !this._motionReduced && this._isAnimationVisible(this._visual) && this._isAnimationVisible(element)); diff --git a/src/vs/workbench/contrib/chat/test/browser/widget/chatPetWidget.test.ts b/src/vs/workbench/contrib/chat/test/browser/widget/chatPetWidget.test.ts index f8f8bd9f70dee2..39d27cb73ce39b 100644 --- a/src/vs/workbench/contrib/chat/test/browser/widget/chatPetWidget.test.ts +++ b/src/vs/workbench/contrib/chat/test/browser/widget/chatPetWidget.test.ts @@ -2284,8 +2284,14 @@ suite('ChatPetWidget', () => { }; button.style.left = '0px'; button.style.top = '-100px'; + const mainPupils = button.querySelectorAll('.chat-pet-pupil'); + for (const pupil of mainPupils) { + pupil.style.transform = 'translate(2px, -2px)'; + } const first = createSubagent('first'); const firstMini = overlay.querySelector('.chat-pet-subagent')!; + assert.deepStrictEqual([...firstMini.querySelectorAll('.chat-pet-pupil')].map(pupil => pupil.style.transform), ['', '']); + assert.deepStrictEqual([...mainPupils].map(pupil => pupil.style.transform), ['translate(2px, -2px)', 'translate(2px, -2px)']); assert.ok(firstMini.offsetLeft >= button.offsetLeft + button.offsetWidth); const miniSize = 48 * Number.parseFloat(firstMini.style.getPropertyValue('--chat-pet-subagent-scale')); assert.strictEqual(Number.parseFloat(firstMini.style.top) + miniSize, 0); From 61bd78318cc13fca0a5f124cc37516ebe1049bd3 Mon Sep 17 00:00:00 2001 From: Lisa Rosenberg Date: Thu, 5 Nov 2026 00:50:05 +0100 Subject: [PATCH 10/66] refactor: simplify code --- .../chat/browser/widget/chatPetWidget.ts | 16 ++++++- .../test/browser/widget/chatPetWidget.test.ts | 45 +++++-------------- 2 files changed, 26 insertions(+), 35 deletions(-) diff --git a/src/vs/workbench/contrib/chat/browser/widget/chatPetWidget.ts b/src/vs/workbench/contrib/chat/browser/widget/chatPetWidget.ts index 8bba032098946e..890fe075e4a4c0 100644 --- a/src/vs/workbench/contrib/chat/browser/widget/chatPetWidget.ts +++ b/src/vs/workbench/contrib/chat/browser/widget/chatPetWidget.ts @@ -214,6 +214,18 @@ interface ChatPetSpriteElement { redrawFrame?: () => void; } +interface ChatPetSubagent { + readonly element: HTMLElement; + readonly canvas: HTMLCanvasElement; + readonly image: HTMLImageElement; + readonly accessoryImage: HTMLImageElement | undefined; + readonly eyes: HTMLElement; + readonly disposables: DisposableStore; + readonly updateBlink: () => void; + readonly slot: number; + readonly side: 'left' | 'right'; +} + interface ChatPetPendingRender { readonly generation: number; readonly sprite: ChatPetSpriteElement; @@ -1246,7 +1258,7 @@ export class ChatPetHopController extends Disposable { export class ChatPetWidget extends Disposable { - private readonly _subagentPets = new Map void; slot: number; side: 'left' | 'right' }>(); + private readonly _subagentPets = new Map(); private _subagentModel: IChatModel | undefined; private readonly _subagentEffects = this._register(new DisposableStore()); private readonly _subagentLayer: HTMLElement; @@ -2941,7 +2953,7 @@ export class ChatPetWidget extends Disposable { } } - private _despawnSubagentPet(pet: { element: HTMLElement; canvas: HTMLCanvasElement; image: HTMLImageElement; accessoryImage: HTMLImageElement | undefined; eyes: HTMLElement; disposables: DisposableStore }): void { + private _despawnSubagentPet(pet: ChatPetSubagent): void { this._subagentEffects.delete(pet.disposables); pet.image.remove(); pet.accessoryImage?.remove(); diff --git a/src/vs/workbench/contrib/chat/test/browser/widget/chatPetWidget.test.ts b/src/vs/workbench/contrib/chat/test/browser/widget/chatPetWidget.test.ts index 39d27cb73ce39b..514e700de03989 100644 --- a/src/vs/workbench/contrib/chat/test/browser/widget/chatPetWidget.test.ts +++ b/src/vs/workbench/contrib/chat/test/browser/widget/chatPetWidget.test.ts @@ -2255,23 +2255,26 @@ suite('ChatPetWidget', () => { ]); }); - test('shows one mini pet per active subagent and removes it when it stops', async () => { - const { widget, firstHost, button, overlay, service } = createHostTransitionHarness(); - const responseChanged = disposables.add(new Emitter()); - const parts: IChatProgressResponseContent[] = []; + function createSubagentTestModel(parts: IChatProgressResponseContent[], onDidChange: Event = Event.None): IChatModel { const response = new class extends mock() { - override readonly onDidChange = responseChanged.event; + override readonly onDidChange = onDidChange; override readonly isPendingConfirmation = constObservable(undefined); override readonly response = new class extends mock() { override readonly value = parts; }(); }(); const request = new class extends mock() { override readonly id = 'request'; override readonly response = response; }(); - const model = new class extends mock() { + return new class extends mock() { override readonly onDidChange = Event.None; override readonly hasActiveRequest = constObservable(true); override readonly lastRequestObs = constObservable(request); override getRequests(): IChatRequestModel[] { return [request]; } }(); - const modelValue = observableValue('model', model); + } + + test('shows one mini pet per active subagent and removes it when it stops', async () => { + const { widget, firstHost, button, overlay, service } = createHostTransitionHarness(); + const responseChanged = disposables.add(new Emitter()); + const parts: IChatProgressResponseContent[] = []; + const modelValue = observableValue('model', createSubagentTestModel(parts, responseChanged.event)); widget.setHost({ ...firstHost, model: modelValue }); service.unlockAchievement(getChatPetAchievementForAccessory(ChatPetAccessoryIds.CowboyHat).id); service.setAccessory(ChatPetAccessoryIds.CowboyHat); @@ -2361,19 +2364,7 @@ suite('ChatPetWidget', () => { const changed = disposables.add(new Emitter()); const tool = new ChatToolInvocation(undefined, { id: 'subagent', displayName: 'Subagent', modelDescription: 'Subagent', source: ToolDataSource.Internal }, 'subagent', undefined, {}); tool.toolSpecificData = { kind: 'subagent', isActive: true }; - const response = new class extends mock() { - override readonly onDidChange = changed.event; - override readonly isPendingConfirmation = constObservable(undefined); - override readonly response = new class extends mock() { override readonly value = [tool]; }(); - }(); - const request = new class extends mock() { override readonly id = 'request'; override readonly response = response; }(); - const model = new class extends mock() { - override readonly onDidChange = Event.None; - override readonly hasActiveRequest = constObservable(true); - override readonly lastRequestObs = constObservable(request); - override getRequests(): IChatRequestModel[] { return [request]; } - }(); - widget.setHost({ ...firstHost, model: constObservable(model) }); + widget.setHost({ ...firstHost, model: constObservable(createSubagentTestModel([tool], changed.event)) }); assert.ok(overlay.querySelector('.chat-pet-subagent:not(.arriving)')); tool.toolSpecificData = { kind: 'subagent', isActive: false }; changed.fire({ reason: 'other' }); @@ -2387,19 +2378,7 @@ suite('ChatPetWidget', () => { const { widget, firstHost, overlay, setReducedMotion } = createHostTransitionHarness(); const tool = new ChatToolInvocation(undefined, { id: 'subagent', displayName: 'Subagent', modelDescription: 'Subagent', source: ToolDataSource.Internal }, 'subagent', undefined, {}); tool.toolSpecificData = { kind: 'subagent', isActive: true }; - const response = new class extends mock() { - override readonly onDidChange = Event.None; - override readonly isPendingConfirmation = constObservable(undefined); - override readonly response = new class extends mock() { override readonly value = [tool]; }(); - }(); - const request = new class extends mock() { override readonly id = 'request'; override readonly response = response; }(); - const model = new class extends mock() { - override readonly onDidChange = Event.None; - override readonly hasActiveRequest = constObservable(true); - override readonly lastRequestObs = constObservable(request); - override getRequests(): IChatRequestModel[] { return [request]; } - }(); - widget.setHost({ ...firstHost, model: constObservable(model) }); + widget.setHost({ ...firstHost, model: constObservable(createSubagentTestModel([tool])) }); const pet = overlay.querySelector('.chat-pet-subagent')!; const eyes = pet.querySelector('.chat-pet-eyes')!; const pupil = pet.querySelector('.chat-pet-pupil')!; From b1ec1f775e59379574faeabc2814faabf882074b Mon Sep 17 00:00:00 2001 From: Lisa Rosenberg Date: Thu, 5 Nov 2026 20:25:01 +0100 Subject: [PATCH 11/66] feat: add splat animation --- .../chat/browser/widget/chatPetWidget.ts | 45 ++++++++++++---- .../test/browser/widget/chatPetWidget.test.ts | 53 ++++++++++++++++++- 2 files changed, 85 insertions(+), 13 deletions(-) diff --git a/src/vs/workbench/contrib/chat/browser/widget/chatPetWidget.ts b/src/vs/workbench/contrib/chat/browser/widget/chatPetWidget.ts index 890fe075e4a4c0..1f9c19384dbdde 100644 --- a/src/vs/workbench/contrib/chat/browser/widget/chatPetWidget.ts +++ b/src/vs/workbench/contrib/chat/browser/widget/chatPetWidget.ts @@ -2914,8 +2914,9 @@ export class ChatPetWidget extends Disposable { (eye.firstElementChild as HTMLElement | null)?.style.removeProperty('transform'); } const disposables = this._subagentEffects.add(new DisposableStore()); + let state: 'idle' | 'splat' = 'idle'; const blink = disposables.add(new ChatPetBlinkController(blinking => eyes.classList.toggle('blink', blinking))); - const updateBlink = () => blink.setEnabled(this._enabled && !this._motionReduced && this._isAnimationVisible(this._visual) && this._isAnimationVisible(element)); + const updateBlink = () => blink.setEnabled(state === 'idle' && this._enabled && !this._motionReduced && this._isAnimationVisible(this._visual) && this._isAnimationVisible(element)); disposables.add(this._onDidChangeAnimationVisibility.event(updateBlink)); const firstPupil = eyes.firstElementChild?.firstElementChild; if (firstPupil) { @@ -2929,8 +2930,13 @@ export class ChatPetWidget extends Disposable { const animation = disposables.add(new MutableDisposable()); const image = dom.append(element, dom.$('img.chat-pet-spritesheet')) as HTMLImageElement; image.alt = ''; - const sources = getChatPetSpriteSources(this._variant).idle; - const source = this._motionReduced ? sources.reducedMotion : sources.animated; + const setState = (nextState: 'idle' | 'splat') => { + animation.clear(); + state = nextState; + updateBlink(); + const sources = getChatPetSpriteSources(this._variant)[state]; + setChatPetImageSource(image, (this._motionReduced ? sources.reducedMotion : sources.animated).url); + }; const sprite: ChatPetSpriteElement = { container: element, canvas, image, color: this._color }; const accessory = this._selectedAccessory ? getChatPetAccessory(this._selectedAccessory) : undefined; const accessoryImage = accessory ? dom.append(element, dom.$('img.chat-pet-spritesheet')) as HTMLImageElement : undefined; @@ -2939,16 +2945,33 @@ export class ChatPetWidget extends Disposable { disposables.add(dom.addDisposableListener(accessoryImage, 'load', () => sprite.redrawFrame?.())); setChatPetImageSource(accessoryImage, getChatPetAccessoryImageSource(accessory).url); } - disposables.add(dom.addDisposableListener(image, 'load', () => this._startSpriteAnimation(source, sprite, animation, undefined, false, frameIndex => { - eyes.classList.toggle('bobbed', !this._motionReduced && (source.accessoryRigFrame ?? frameIndex) >= 20); - if (accessoryImage?.complete && accessoryImage.naturalWidth > 0 && accessory) { - const context = canvas.getContext('2d'); - if (context) { - drawChatPetComposite(context, image, accessoryImage, frameIndex, source.accessoryRigFrame ?? frameIndex, source.frameWidth, source.frameHeight ?? CHAT_PET_SOURCE_SIZE, 'right', 'idle', source.fixedOrientationDecorations, true, accessory.eyeAccessoryMirrorsWithFacing !== false, accessory.coversAntennae === true, sprite.color); + disposables.add(dom.addDisposableListener(image, 'load', () => { + if (state === 'splat' && this._motionReduced) { + setState('idle'); + return; + } + const sources = getChatPetSpriteSources(this._variant)[state]; + const source = this._motionReduced ? sources.reducedMotion : sources.animated; + eyes.classList.toggle('tracking', state === 'idle'); + this._startSpriteAnimation(source, sprite, animation, state === 'splat' ? () => setState('idle') : undefined, false, frameIndex => { + eyes.classList.toggle('bobbed', state === 'idle' && !this._motionReduced && (source.accessoryRigFrame ?? frameIndex) >= 20); + if (accessoryImage?.complete && accessoryImage.naturalWidth > 0 && accessory) { + const context = canvas.getContext('2d'); + if (context) { + drawChatPetComposite(context, image, accessoryImage, frameIndex, source.accessoryRigFrame ?? frameIndex, source.frameWidth, source.frameHeight ?? CHAT_PET_SOURCE_SIZE, 'right', state, source.fixedOrientationDecorations, true, accessory.eyeAccessoryMirrorsWithFacing !== false, accessory.coversAntennae === true, sprite.color); + } + } + }); + })); + disposables.add(dom.addDisposableListener(element, 'animationend', event => { + if (event.target === element && (event as AnimationEvent).animationName === 'chat-pet-subagent-fall') { + element.classList.remove('arriving'); + if (!this._motionReduced) { + setState('splat'); } } - }))); - setChatPetImageSource(image, source.url); + })); + setState('idle'); this._subagentPets.set(id, { element, canvas, image, accessoryImage, eyes, disposables, updateBlink, slot, side }); } } diff --git a/src/vs/workbench/contrib/chat/test/browser/widget/chatPetWidget.test.ts b/src/vs/workbench/contrib/chat/test/browser/widget/chatPetWidget.test.ts index 514e700de03989..dbda94125c5412 100644 --- a/src/vs/workbench/contrib/chat/test/browser/widget/chatPetWidget.test.ts +++ b/src/vs/workbench/contrib/chat/test/browser/widget/chatPetWidget.test.ts @@ -2359,6 +2359,49 @@ suite('ChatPetWidget', () => { assert.strictEqual(overlay.querySelectorAll('.chat-pet-subagent-despawning').length, 0); }); + test('mini pets squish on landing and return to their own idle animation', async () => { + const clock = sinon.useFakeTimers({ toFake: ['setTimeout', 'clearTimeout', 'performance'] }); + disposables.add(toDisposable(() => clock.restore())); + const { widget, firstHost, overlay } = createHostTransitionHarness(); + const changed = disposables.add(new Emitter()); + const tools = ['first', 'second'].map(id => { + const tool = new ChatToolInvocation(undefined, { id, displayName: id, modelDescription: 'Subagent', source: ToolDataSource.Internal }, id, undefined, {}); + tool.toolSpecificData = { kind: 'subagent', isActive: true }; + return tool; + }); + widget.setHost({ ...firstHost, model: constObservable(createSubagentTestModel(tools, changed.event)) }); + const [first, second] = overlay.querySelectorAll('.chat-pet-subagent'); + for (const pet of [first, second]) { + for (const animation of pet.getAnimations()) { + animation.pause(); + } + } + const image = first.querySelector('img')!; + const secondImage = second.querySelector('img')!; + const eyes = first.querySelector('.chat-pet-eyes')!; + await Promise.all([whenSpriteLoaded(image), whenSpriteLoaded(secondImage)]); + const idleSource = image.getAttribute('src'); + const land = (pet: HTMLElement) => pet.dispatchEvent(new mainWindow.AnimationEvent('animationend', { animationName: 'chat-pet-subagent-fall' })); + land(first); + await whenSpriteLoaded(image); + assert.deepStrictEqual({ + squishing: image.getAttribute('src')?.includes('buddy-splat-'), + arriving: first.classList.contains('arriving'), + idleEyes: eyes.classList.contains('tracking'), + otherSource: secondImage.getAttribute('src'), + }, { squishing: true, arriving: false, idleEyes: false, otherSource: idleSource }); + clock.tick(520); + await whenSpriteLoaded(image); + assert.deepStrictEqual({ source: image.getAttribute('src'), idleEyes: eyes.classList.contains('tracking') }, { source: idleSource, idleEyes: true }); + land(second); + await whenSpriteLoaded(secondImage); + tools[1].toolSpecificData = { kind: 'subagent', isActive: false }; + changed.fire({ reason: 'other' }); + land(second); + clock.tick(900); + assert.deepStrictEqual({ active: [...overlay.querySelectorAll('.chat-pet-subagent')], removed: !second.isConnected }, { active: [first], removed: true }); + }); + test('mini pets use the reduced-motion disappearance sprite', () => { const { widget, firstHost, overlay } = createHostTransitionHarness(true); const changed = disposables.add(new Emitter()); @@ -2366,6 +2409,11 @@ suite('ChatPetWidget', () => { tool.toolSpecificData = { kind: 'subagent', isActive: true }; widget.setHost({ ...firstHost, model: constObservable(createSubagentTestModel([tool], changed.event)) }); assert.ok(overlay.querySelector('.chat-pet-subagent:not(.arriving)')); + const pet = overlay.querySelector('.chat-pet-subagent')!; + const image = pet.querySelector('img')!; + const idleSource = image.getAttribute('src'); + pet.dispatchEvent(new mainWindow.AnimationEvent('animationend', { animationName: 'chat-pet-subagent-fall' })); + assert.strictEqual(image.getAttribute('src'), idleSource); tool.toolSpecificData = { kind: 'subagent', isActive: false }; changed.fire({ reason: 'other' }); assert.ok(overlay.querySelector('.chat-pet-subagent-despawning img')?.getAttribute('src')?.endsWith('-96.png')); @@ -2380,10 +2428,11 @@ suite('ChatPetWidget', () => { tool.toolSpecificData = { kind: 'subagent', isActive: true }; widget.setHost({ ...firstHost, model: constObservable(createSubagentTestModel([tool])) }); const pet = overlay.querySelector('.chat-pet-subagent')!; + // Exercise idle frames independently of the CSS arrival and landing animation. + pet.classList.remove('arriving'); const eyes = pet.querySelector('.chat-pet-eyes')!; const pupil = pet.querySelector('.chat-pet-pupil')!; - await pet.querySelector('img')!.decode(); - await Promise.resolve(); + await whenSpriteLoaded(pet.querySelector('img')!); assert.ok(!eyes.classList.contains('bobbed')); clock.tick(800); assert.ok(eyes.classList.contains('bobbed')); From c5bf79fc81326bda9ded226bbe3addd91ce976e5 Mon Sep 17 00:00:00 2001 From: Lisa Rosenberg Date: Thu, 5 Nov 2026 22:11:48 +0100 Subject: [PATCH 12/66] feat: add suggested changes --- .../lib/stylelint/vscode-known-variables.json | 3 + .../chat/browser/widget/chatPetWidget.ts | 133 ++++++++++++------ .../test/browser/widget/chatPetWidget.test.ts | 109 +++++++++++++- 3 files changed, 193 insertions(+), 52 deletions(-) diff --git a/build/lib/stylelint/vscode-known-variables.json b/build/lib/stylelint/vscode-known-variables.json index 84be8c1704e72a..3e236463cf8053 100644 --- a/build/lib/stylelint/vscode-known-variables.json +++ b/build/lib/stylelint/vscode-known-variables.json @@ -1014,6 +1014,9 @@ "--agents-session-frame-inset", "--agents-side-pane-frame-inset", "--agents-window-corner-radius", + "--chat-pet-subagent-fall-distance", + "--chat-pet-subagent-fall-duration", + "--chat-pet-subagent-scale", "--chat-window-controls-right-width", "--chat-window-controls-width", "--chat-window-outer-inset-left", diff --git a/src/vs/workbench/contrib/chat/browser/widget/chatPetWidget.ts b/src/vs/workbench/contrib/chat/browser/widget/chatPetWidget.ts index 1f9c19384dbdde..25308e29f0e1d9 100644 --- a/src/vs/workbench/contrib/chat/browser/widget/chatPetWidget.ts +++ b/src/vs/workbench/contrib/chat/browser/widget/chatPetWidget.ts @@ -222,8 +222,7 @@ interface ChatPetSubagent { readonly eyes: HTMLElement; readonly disposables: DisposableStore; readonly updateBlink: () => void; - readonly slot: number; - readonly side: 'left' | 'right'; + readonly updateAppearance: (motionChanged: boolean, variantChanged: boolean, accessoryChanged: boolean) => void; } interface ChatPetPendingRender { @@ -1493,37 +1492,6 @@ export class ChatPetWidget extends Disposable { const eye = dom.append(this._eyes, dom.$(`.chat-pet-eye.${side}`)); this._pupils.push(dom.append(eye, dom.$('.chat-pet-pupil'))); } - this._register(autorun(reader => { - const model = this._host.read(reader).model.read(reader); - if (model !== this._subagentModel) { - this._updateSubagentPets(new Set()); - this._subagentModel = model; - } - if (!model) { - return; - } - observableSignalFromEvent(this, model.onDidChange).read(reader); - const subagents = new Set(); - for (const request of model.getRequests()) { - const response = request.response; - if (!response) { - continue; - } - observableSignalFromEvent(this, response.onDidChange).read(reader); - for (const part of response.response.value) { - if (part.kind !== 'toolInvocation') { - continue; - } - part.toolSpecificDataKind.read(reader); - part.state.read(reader); - const data = part.toolSpecificData; - if (data?.kind === 'subagent' && data.presentation !== 'phase' && data.hasStarted !== false && (getSubagentIsActive(data) ?? !IChatToolInvocation.isComplete(part, reader))) { - subagents.add(JSON.stringify([request.id, part.toolCallId])); - } - } - } - this._updateSubagentPets(subagents); - })); this._propellerPoseContainer = dom.append(this._visual, dom.$('.chat-pet-propeller-pose', { 'aria-hidden': 'true' })); this._propellerContainer = dom.append(this._propellerPoseContainer, dom.$('.chat-pet-propeller.hidden')); this._propeller = dom.append(this._propellerContainer, dom.$('canvas.chat-pet-propeller-canvas')) as HTMLCanvasElement; @@ -1827,12 +1795,20 @@ export class ChatPetWidget extends Disposable { } for (const pet of this._subagentPets.values()) { pet.updateBlink(); + if (enabled && (wasMotionReduced !== this._motionReduced || colorChanged || accessoryChanged)) { + pet.updateAppearance(wasMotionReduced !== this._motionReduced, variantChanged, accessoryChanged); + } if (this._motionReduced) { pet.eyes.classList.remove('bobbed'); } } if (!enabled) { + for (const pet of this._subagentPets.values()) { + pet.element.remove(); + } + this._subagentPets.clear(); + this._subagentEffects.clear(); this._hopController.cancel(); this._idleScheduler.cancel(); this._transientScheduler.cancel(); @@ -1893,6 +1869,39 @@ export class ChatPetWidget extends Disposable { this._renderState(renderedState, variantChanged, isDragging); })); + this._register(autorun(reader => { + const enabled = isChatPetVisible(this.chatPetService.enabled.read(reader), windowActive.read(reader)); + const model = this._host.read(reader).model.read(reader); + if (model !== this._subagentModel) { + this._updateSubagentPets(new Set()); + this._subagentModel = model; + } + if (!enabled || !model) { + return; + } + observableSignalFromEvent(this, model.onDidChange).read(reader); + const subagents = new Set(); + for (const request of model.getRequests()) { + const response = request.response; + if (!response) { + continue; + } + observableSignalFromEvent(this, response.onDidChange).read(reader); + for (const part of response.response.value) { + if (part.kind !== 'toolInvocation') { + continue; + } + part.toolSpecificDataKind.read(reader); + part.state.read(reader); + const data = part.toolSpecificData; + if (data?.kind === 'subagent' && data.presentation !== 'phase' && data.hasStarted !== false && (getSubagentIsActive(data) ?? !IChatToolInvocation.isComplete(part, reader))) { + subagents.add(JSON.stringify([request.id, part.toolCallId])); + } + } + } + this._updateSubagentPets(subagents); + })); + this._register(autorun(reader => { const chatModel = this._host.read(reader).model.read(reader); const response = chatModel?.lastRequestObs.read(reader)?.response; @@ -2885,14 +2894,18 @@ export class ChatPetWidget extends Disposable { const midpoint = bounds ? (bounds.minimumLeft + bounds.maximumLeft) / 2 : (this._overlay.clientWidth - this._getDisplaySize()) / 2; const miniWidth = 48 * miniScale; const side = petLeft < midpoint ? 'right' : 'left'; - const occupiedSlots = new Set([...this._subagentPets.values()].filter(pet => pet.side === side).map(pet => pet.slot)); let slot = 0; - while (occupiedSlots.has(slot)) { - slot++; - } - const left = side === 'right' + const getLeft = () => side === 'right' ? petLeft + this._getDisplaySize() + miniWidth * slot : petLeft - miniWidth * (slot + 1); + while ([...this._subagentPets.values()].some(pet => { + const otherLeft = Number.parseFloat(pet.element.style.left); + const otherWidth = 48 * Number.parseFloat(pet.element.style.getPropertyValue('--chat-pet-subagent-scale')); + return getLeft() < otherLeft + otherWidth && getLeft() + miniWidth > otherLeft; + })) { + slot++; + } + const left = getLeft(); const overlayBounds = this._overlay.getBoundingClientRect(); const landing = getChatPetFallTarget(overlayBounds.left + left, -miniWidth, miniWidth, miniWidth, this._getPlatforms(), this.movementBounds.getBoundingClientRect().bottom); element.style.left = `${left}px`; @@ -2938,13 +2951,26 @@ export class ChatPetWidget extends Disposable { setChatPetImageSource(image, (this._motionReduced ? sources.reducedMotion : sources.animated).url); }; const sprite: ChatPetSpriteElement = { container: element, canvas, image, color: this._color }; - const accessory = this._selectedAccessory ? getChatPetAccessory(this._selectedAccessory) : undefined; - const accessoryImage = accessory ? dom.append(element, dom.$('img.chat-pet-spritesheet')) as HTMLImageElement : undefined; - if (accessoryImage && accessory) { - accessoryImage.alt = ''; - disposables.add(dom.addDisposableListener(accessoryImage, 'load', () => sprite.redrawFrame?.())); - setChatPetImageSource(accessoryImage, getChatPetAccessoryImageSource(accessory).url); - } + let accessory = this._selectedAccessory ? getChatPetAccessory(this._selectedAccessory) : undefined; + let accessoryImage: HTMLImageElement | undefined; + const accessoryListener = disposables.add(new MutableDisposable()); + const updateAccessory = () => { + accessory = this._selectedAccessory ? getChatPetAccessory(this._selectedAccessory) : undefined; + if (!accessory) { + accessoryListener.clear(); + accessoryImage?.remove(); + accessoryImage = undefined; + } else { + if (!accessoryImage) { + accessoryImage = dom.append(element, dom.$('img.chat-pet-spritesheet')) as HTMLImageElement; + accessoryImage.alt = ''; + accessoryListener.value = dom.addDisposableListener(accessoryImage, 'load', () => sprite.redrawFrame?.()); + } + setChatPetImageSource(accessoryImage, getChatPetAccessoryImageSource(accessory).url); + } + sprite.redrawFrame?.(); + }; + updateAccessory(); disposables.add(dom.addDisposableListener(image, 'load', () => { if (state === 'splat' && this._motionReduced) { setState('idle'); @@ -2971,8 +2997,23 @@ export class ChatPetWidget extends Disposable { } } })); + const updateAppearance = (motionChanged: boolean, variantChanged: boolean, accessoryChanged: boolean) => { + sprite.color = this._color; + eyes.style.color = getChatPetEyeColor(this._color); + if (accessoryChanged) { + updateAccessory(); + } + if (motionChanged || variantChanged) { + if (this._motionReduced) { + element.classList.remove('arriving'); + } + setState(this._motionReduced ? 'idle' : state); + } else { + sprite.redrawFrame?.(); + } + }; setState('idle'); - this._subagentPets.set(id, { element, canvas, image, accessoryImage, eyes, disposables, updateBlink, slot, side }); + this._subagentPets.set(id, { element, canvas, image, get accessoryImage() { return accessoryImage; }, eyes, disposables, updateBlink, updateAppearance }); } } diff --git a/src/vs/workbench/contrib/chat/test/browser/widget/chatPetWidget.test.ts b/src/vs/workbench/contrib/chat/test/browser/widget/chatPetWidget.test.ts index dbda94125c5412..f074f2305ae0a6 100644 --- a/src/vs/workbench/contrib/chat/test/browser/widget/chatPetWidget.test.ts +++ b/src/vs/workbench/contrib/chat/test/browser/widget/chatPetWidget.test.ts @@ -111,7 +111,7 @@ suite('ChatPetWidget', () => { } } - function createHostTransitionHarness(motionReduced = false, initialTransition: IChatPetWidgetHost['transition'] = 'teleport', color?: ChatPetColor, intersectionObserverCtor?: typeof IntersectionObserver, setPlatformOccupation?: IChatPetWidgetHost['setPlatformOccupation'], supportsJumpGame = false, initializeService?: (service: ChatPetService) => void) { + function createHostTransitionHarness(motionReduced = false, initialTransition: IChatPetWidgetHost['transition'] = 'teleport', color?: ChatPetColor, intersectionObserverCtor?: typeof IntersectionObserver, setPlatformOccupation?: IChatPetWidgetHost['setPlatformOccupation'], supportsJumpGame = false, initializeService?: (service: ChatPetService) => void, initialModel?: IChatModel) { const root = mainWindow.document.createElement('div'); root.style.cssText = 'position:fixed;left:0;top:0;width:800px;height:640px'; if (supportsJumpGame) { @@ -152,7 +152,7 @@ suite('ChatPetWidget', () => { onDidChangePlatform: platformChanged.event, setPlatformOccupation, }); - const firstHost = createHost(firstParent, initialTransition); + const firstHost = { ...createHost(firstParent, initialTransition), model: constObservable(initialModel) }; const secondHost: IChatPetWidgetHost = { ...createHost(secondParent, 'fall'), model: constObservable(new class extends mock() { @@ -2333,10 +2333,6 @@ suite('ChatPetWidget', () => { button.style.left = '300px'; button.style.transform = 'rotate(45deg)'; assert.strictEqual(mini.style.left, position); - service.toggle(); - assert.ok(overlay.querySelector('.chat-pet-subagent-layer.hidden')); - service.toggle(); - assert.ok(overlay.querySelector('.chat-pet-subagent-layer:not(.hidden)')); first.toolSpecificData = { kind: 'subagent', isActive: false }; responseChanged.fire({ reason: 'other' }); assert.strictEqual(overlay.querySelectorAll('.chat-pet-subagent').length, 1); @@ -2359,6 +2355,107 @@ suite('ChatPetWidget', () => { assert.strictEqual(overlay.querySelectorAll('.chat-pet-subagent-despawning').length, 0); }); + test('mini pets use restored geometry when the initial model already has a subagent', () => { + const tool = new ChatToolInvocation(undefined, { id: 'subagent', displayName: 'Subagent', modelDescription: 'Subagent', source: ToolDataSource.Internal }, 'subagent', undefined, {}); + tool.toolSpecificData = { kind: 'subagent', isActive: true }; + const model = createSubagentTestModel([tool]); + const { button, overlay } = createHostTransitionHarness(true, 'teleport', undefined, undefined, undefined, false, service => { + service.setScale(2); + service.setHorizontalPosition(0.8); + }, model); + const pet = overlay.querySelector('.chat-pet-subagent')!; + assert.strictEqual(Number.parseFloat(pet.style.getPropertyValue('--chat-pet-subagent-scale')), 1); + assert.ok(pet.offsetLeft < button.offsetLeft); + }); + + test('mini pets stop when disabled and return for active subagents when re-enabled', async () => { + const { widget, firstHost, overlay, service } = createHostTransitionHarness(); + const changed = disposables.add(new Emitter()); + const parts: IChatProgressResponseContent[] = []; + widget.setHost({ ...firstHost, model: constObservable(createSubagentTestModel(parts, changed.event)) }); + const tool = new ChatToolInvocation(undefined, { id: 'first', displayName: 'First', modelDescription: 'Subagent', source: ToolDataSource.Internal }, 'first', undefined, {}); + tool.toolSpecificData = { kind: 'subagent', isActive: true }; + parts.push(tool); + changed.fire({ reason: 'other' }); + const first = overlay.querySelector('.chat-pet-subagent')!; + await whenSpriteLoaded(first.querySelector('img')!); + service.toggle(); + assert.strictEqual(first.isConnected, false); + const second = new ChatToolInvocation(undefined, { id: 'second', displayName: 'Second', modelDescription: 'Subagent', source: ToolDataSource.Internal }, 'second', undefined, {}); + second.toolSpecificData = { kind: 'subagent', isActive: true }; + parts.push(second); + changed.fire({ reason: 'other' }); + assert.strictEqual(overlay.querySelectorAll('.chat-pet-subagent').length, 0); + service.toggle(); + assert.strictEqual(overlay.querySelectorAll('.chat-pet-subagent').length, 2); + }); + + test('mini pets avoid existing positions when the main pet moves between subagents', () => { + const { widget, firstHost, button, overlay } = createHostTransitionHarness(true); + const changed = disposables.add(new Emitter()); + const parts: IChatProgressResponseContent[] = []; + widget.setHost({ ...firstHost, model: constObservable(createSubagentTestModel(parts, changed.event)) }); + const add = (id: string) => { + const tool = new ChatToolInvocation(undefined, { id, displayName: id, modelDescription: 'Subagent', source: ToolDataSource.Internal }, id, undefined, {}); + tool.toolSpecificData = { kind: 'subagent', isActive: true }; + parts.push(tool); + changed.fire({ reason: 'other' }); + }; + button.style.left = '300px'; + add('first'); + button.style.left = '324px'; + add('second'); + const [first, second] = overlay.querySelectorAll('.chat-pet-subagent'); + assert.ok(second.offsetLeft + 24 <= first.offsetLeft || first.offsetLeft + 24 <= second.offsetLeft); + }); + + test('mini pets update appearance and motion settings while active', async () => { + const { widget, firstHost, button, overlay, service, setReducedMotion } = createHostTransitionHarness(); + const tool = new ChatToolInvocation(undefined, { id: 'subagent', displayName: 'Subagent', modelDescription: 'Subagent', source: ToolDataSource.Internal }, 'subagent', undefined, {}); + tool.toolSpecificData = { kind: 'subagent', isActive: true }; + widget.setHost({ ...firstHost, model: constObservable(createSubagentTestModel([tool])) }); + const pet = overlay.querySelector('.chat-pet-subagent')!; + pet.classList.remove('arriving'); + const body = pet.querySelector('img')!; + await whenSpriteLoaded(body); + setReducedMotion(true); + await whenSpriteLoaded(body); + assert.ok(body.getAttribute('src')?.endsWith('-96.png')); + setReducedMotion(false); + await whenSpriteLoaded(body); + assert.ok(body.getAttribute('src')?.endsWith('.spritesheet.png')); + service.unlockAchievement(ChatPetAchievementIds.Blobby); + service.setColor('stable'); + await whenSpriteLoaded(body); + assert.ok(body.getAttribute('src')?.includes('buddy-idle-stable')); + service.setColor('#12abcd'); + assert.strictEqual(pet.querySelector('.chat-pet-eyes')!.style.color, button.querySelector('.chat-pet-eyes')!.style.color); + service.unlockAchievement(getChatPetAchievementForAccessory(ChatPetAccessoryIds.CowboyHat).id); + service.setAccessory(ChatPetAccessoryIds.CowboyHat); + const hat = pet.querySelectorAll('img')[1]; + assert.ok(hat?.src.includes('/accessories/')); + service.setAccessory(undefined); + assert.strictEqual(pet.querySelectorAll('img').length, 1); + }); + + test('mini pets stop squishing when reduced motion is enabled during landing', async () => { + const { widget, firstHost, overlay, setReducedMotion } = createHostTransitionHarness(); + const tool = new ChatToolInvocation(undefined, { id: 'subagent', displayName: 'Subagent', modelDescription: 'Subagent', source: ToolDataSource.Internal }, 'subagent', undefined, {}); + tool.toolSpecificData = { kind: 'subagent', isActive: true }; + widget.setHost({ ...firstHost, model: constObservable(createSubagentTestModel([tool])) }); + const pet = overlay.querySelector('.chat-pet-subagent')!; + const image = pet.querySelector('img')!; + await whenSpriteLoaded(image); + pet.dispatchEvent(new mainWindow.AnimationEvent('animationend', { animationName: 'chat-pet-subagent-fall' })); + await whenSpriteLoaded(image); + assert.ok(image.getAttribute('src')?.includes('buddy-splat-')); + setReducedMotion(true); + await whenSpriteLoaded(image); + assert.ok(image.getAttribute('src')?.includes('buddy-idle-')); + assert.ok(image.getAttribute('src')?.endsWith('-96.png')); + assert.ok(pet.querySelector('.chat-pet-eyes.tracking')); + }); + test('mini pets squish on landing and return to their own idle animation', async () => { const clock = sinon.useFakeTimers({ toFake: ['setTimeout', 'clearTimeout', 'performance'] }); disposables.add(toDisposable(() => clock.restore())); From 03aaf923c20b2959496a27b96f4484d92efc29e7 Mon Sep 17 00:00:00 2001 From: Lisa Rosenberg Date: Wed, 11 Nov 2026 23:21:47 +0100 Subject: [PATCH 13/66] feat: revert changes to vscode-known-variables.json since that file is forbidden to be changed --- .../lib/stylelint/vscode-known-variables.json | 3 -- .../chat/browser/widget/chatPetWidget.ts | 40 +++++++++------- .../chat/browser/widget/media/chatPet.css | 14 ------ .../test/browser/widget/chatPetWidget.test.ts | 48 ++++++++++++++++--- 4 files changed, 63 insertions(+), 42 deletions(-) diff --git a/build/lib/stylelint/vscode-known-variables.json b/build/lib/stylelint/vscode-known-variables.json index 3e236463cf8053..84be8c1704e72a 100644 --- a/build/lib/stylelint/vscode-known-variables.json +++ b/build/lib/stylelint/vscode-known-variables.json @@ -1014,9 +1014,6 @@ "--agents-session-frame-inset", "--agents-side-pane-frame-inset", "--agents-window-corner-radius", - "--chat-pet-subagent-fall-distance", - "--chat-pet-subagent-fall-duration", - "--chat-pet-subagent-scale", "--chat-window-controls-right-width", "--chat-window-controls-width", "--chat-window-outer-inset-left", diff --git a/src/vs/workbench/contrib/chat/browser/widget/chatPetWidget.ts b/src/vs/workbench/contrib/chat/browser/widget/chatPetWidget.ts index 25308e29f0e1d9..860512d52f0823 100644 --- a/src/vs/workbench/contrib/chat/browser/widget/chatPetWidget.ts +++ b/src/vs/workbench/contrib/chat/browser/widget/chatPetWidget.ts @@ -216,6 +216,7 @@ interface ChatPetSpriteElement { interface ChatPetSubagent { readonly element: HTMLElement; + readonly width: number; readonly canvas: HTMLCanvasElement; readonly image: HTMLImageElement; readonly accessoryImage: HTMLImageElement | undefined; @@ -2900,8 +2901,7 @@ export class ChatPetWidget extends Disposable { : petLeft - miniWidth * (slot + 1); while ([...this._subagentPets.values()].some(pet => { const otherLeft = Number.parseFloat(pet.element.style.left); - const otherWidth = 48 * Number.parseFloat(pet.element.style.getPropertyValue('--chat-pet-subagent-scale')); - return getLeft() < otherLeft + otherWidth && getLeft() + miniWidth > otherLeft; + return getLeft() < otherLeft + pet.width && getLeft() + miniWidth > otherLeft; })) { slot++; } @@ -2910,13 +2910,8 @@ export class ChatPetWidget extends Disposable { const landing = getChatPetFallTarget(overlayBounds.left + left, -miniWidth, miniWidth, miniWidth, this._getPlatforms(), this.movementBounds.getBoundingClientRect().bottom); element.style.left = `${left}px`; element.style.top = `${landing.top - overlayBounds.top}px`; - element.style.setProperty('--chat-pet-subagent-scale', String(miniScale)); + element.style.transform = `scale(${miniScale})`; const distance = Math.max(0, landing.top + miniWidth); - element.style.setProperty('--chat-pet-subagent-fall-distance', `${distance}px`); - element.style.setProperty('--chat-pet-subagent-fall-duration', `${getChatPetFallDuration(distance)}ms`); - if (!this._motionReduced) { - element.classList.add('arriving'); - } const canvas = dom.append(element, dom.$('canvas.chat-pet-subagent-canvas')) as HTMLCanvasElement; canvas.width = CHAT_PET_SOURCE_SIZE; canvas.height = CHAT_PET_SOURCE_SIZE; @@ -2927,6 +2922,7 @@ export class ChatPetWidget extends Disposable { (eye.firstElementChild as HTMLElement | null)?.style.removeProperty('transform'); } const disposables = this._subagentEffects.add(new DisposableStore()); + const arrival = disposables.add(new MutableDisposable()); let state: 'idle' | 'splat' = 'idle'; const blink = disposables.add(new ChatPetBlinkController(blinking => eyes.classList.toggle('blink', blinking))); const updateBlink = () => blink.setEnabled(state === 'idle' && this._enabled && !this._motionReduced && this._isAnimationVisible(this._visual) && this._isAnimationVisible(element)); @@ -2989,14 +2985,6 @@ export class ChatPetWidget extends Disposable { } }); })); - disposables.add(dom.addDisposableListener(element, 'animationend', event => { - if (event.target === element && (event as AnimationEvent).animationName === 'chat-pet-subagent-fall') { - element.classList.remove('arriving'); - if (!this._motionReduced) { - setState('splat'); - } - } - })); const updateAppearance = (motionChanged: boolean, variantChanged: boolean, accessoryChanged: boolean) => { sprite.color = this._color; eyes.style.color = getChatPetEyeColor(this._color); @@ -3005,7 +2993,7 @@ export class ChatPetWidget extends Disposable { } if (motionChanged || variantChanged) { if (this._motionReduced) { - element.classList.remove('arriving'); + arrival.clear(); } setState(this._motionReduced ? 'idle' : state); } else { @@ -3013,7 +3001,23 @@ export class ChatPetWidget extends Disposable { } }; setState('idle'); - this._subagentPets.set(id, { element, canvas, image, get accessoryImage() { return accessoryImage; }, eyes, disposables, updateBlink, updateAppearance }); + if (!this._motionReduced) { + const effects = arrival.value = new DisposableStore(); + element.classList.add('arriving'); + const fall = element.animate([ + { transform: `translateY(${-distance}px) scale(${miniScale})` }, + { transform: `translateY(0) scale(${miniScale})` }, + ], { duration: getChatPetFallDuration(distance), easing: 'cubic-bezier(0.42, 0, 1, 1)', fill: 'both' }); + effects.add(toDisposable(() => { + fall.cancel(); + element.classList.remove('arriving'); + })); + effects.add(dom.addDisposableListener(fall, 'finish', () => { + arrival.clear(); + setState('splat'); + })); + } + this._subagentPets.set(id, { element, width: miniWidth, canvas, image, get accessoryImage() { return accessoryImage; }, eyes, disposables, updateBlink, updateAppearance }); } } diff --git a/src/vs/workbench/contrib/chat/browser/widget/media/chatPet.css b/src/vs/workbench/contrib/chat/browser/widget/media/chatPet.css index 87d305c3635836..51342a872bfa3f 100644 --- a/src/vs/workbench/contrib/chat/browser/widget/media/chatPet.css +++ b/src/vs/workbench/contrib/chat/browser/widget/media/chatPet.css @@ -185,24 +185,10 @@ position: absolute; width: 48px; height: 48px; - transform: scale(var(--chat-pet-subagent-scale)); transform-origin: top left; pointer-events: none; } -.chat-pet-subagent.arriving { - animation: chat-pet-subagent-fall var(--chat-pet-subagent-fall-duration) cubic-bezier(0.42, 0, 1, 1) both; -} - -@keyframes chat-pet-subagent-fall { - from { transform: translateY(calc(-1 * var(--chat-pet-subagent-fall-distance))) scale(var(--chat-pet-subagent-scale)); } - to { transform: translateY(0) scale(var(--chat-pet-subagent-scale)); } -} - -.monaco-workbench.monaco-reduce-motion .chat-pet-subagent.arriving { - animation: none; -} - .chat-pet-subagent-canvas { width: 48px; height: 48px; diff --git a/src/vs/workbench/contrib/chat/test/browser/widget/chatPetWidget.test.ts b/src/vs/workbench/contrib/chat/test/browser/widget/chatPetWidget.test.ts index f074f2305ae0a6..e9e02a67520511 100644 --- a/src/vs/workbench/contrib/chat/test/browser/widget/chatPetWidget.test.ts +++ b/src/vs/workbench/contrib/chat/test/browser/widget/chatPetWidget.test.ts @@ -2296,7 +2296,7 @@ suite('ChatPetWidget', () => { assert.deepStrictEqual([...firstMini.querySelectorAll('.chat-pet-pupil')].map(pupil => pupil.style.transform), ['', '']); assert.deepStrictEqual([...mainPupils].map(pupil => pupil.style.transform), ['translate(2px, -2px)', 'translate(2px, -2px)']); assert.ok(firstMini.offsetLeft >= button.offsetLeft + button.offsetWidth); - const miniSize = 48 * Number.parseFloat(firstMini.style.getPropertyValue('--chat-pet-subagent-scale')); + const miniSize = firstMini.getBoundingClientRect().width; assert.strictEqual(Number.parseFloat(firstMini.style.top) + miniSize, 0); const [bodyImage, accessoryImage] = firstMini.querySelectorAll('img'); assert.ok(accessoryImage?.src.includes('/accessories/')); @@ -2364,7 +2364,7 @@ suite('ChatPetWidget', () => { service.setHorizontalPosition(0.8); }, model); const pet = overlay.querySelector('.chat-pet-subagent')!; - assert.strictEqual(Number.parseFloat(pet.style.getPropertyValue('--chat-pet-subagent-scale')), 1); + assert.strictEqual(pet.getBoundingClientRect().width, 48); assert.ok(pet.offsetLeft < button.offsetLeft); }); @@ -2378,9 +2378,12 @@ suite('ChatPetWidget', () => { parts.push(tool); changed.fire({ reason: 'other' }); const first = overlay.querySelector('.chat-pet-subagent')!; + const arrival = first.getAnimations()[0]; + arrival.pause(); await whenSpriteLoaded(first.querySelector('img')!); service.toggle(); assert.strictEqual(first.isConnected, false); + assert.strictEqual(arrival.playState, 'idle'); const second = new ChatToolInvocation(undefined, { id: 'second', displayName: 'Second', modelDescription: 'Subagent', source: ToolDataSource.Internal }, 'second', undefined, {}); second.toolSpecificData = { kind: 'subagent', isActive: true }; parts.push(second); @@ -2415,6 +2418,9 @@ suite('ChatPetWidget', () => { tool.toolSpecificData = { kind: 'subagent', isActive: true }; widget.setHost({ ...firstHost, model: constObservable(createSubagentTestModel([tool])) }); const pet = overlay.querySelector('.chat-pet-subagent')!; + for (const animation of pet.getAnimations()) { + animation.cancel(); + } pet.classList.remove('arriving'); const body = pet.querySelector('img')!; await whenSpriteLoaded(body); @@ -2438,6 +2444,28 @@ suite('ChatPetWidget', () => { assert.strictEqual(pet.querySelectorAll('img').length, 1); }); + test('mini pets cancel their arrival when reduced motion is enabled mid-fall', async () => { + const { widget, firstHost, overlay, setReducedMotion } = createHostTransitionHarness(); + const tool = new ChatToolInvocation(undefined, { id: 'subagent', displayName: 'Subagent', modelDescription: 'Subagent', source: ToolDataSource.Internal }, 'subagent', undefined, {}); + tool.toolSpecificData = { kind: 'subagent', isActive: true }; + widget.setHost({ ...firstHost, model: constObservable(createSubagentTestModel([tool])) }); + const pet = overlay.querySelector('.chat-pet-subagent')!; + const arrival = pet.getAnimations()[0]; + arrival.pause(); + const image = pet.querySelector('img')!; + await whenSpriteLoaded(image); + setReducedMotion(true); + await whenSpriteLoaded(image); + const idleSource = image.getAttribute('src'); + arrival.dispatchEvent(new mainWindow.Event('finish')); + assert.deepStrictEqual({ + playState: arrival.playState, + arriving: pet.classList.contains('arriving'), + bottom: pet.getBoundingClientRect().bottom, + source: image.getAttribute('src'), + }, { playState: 'idle', arriving: false, bottom: overlay.getBoundingClientRect().top, source: idleSource }); + }); + test('mini pets stop squishing when reduced motion is enabled during landing', async () => { const { widget, firstHost, overlay, setReducedMotion } = createHostTransitionHarness(); const tool = new ChatToolInvocation(undefined, { id: 'subagent', displayName: 'Subagent', modelDescription: 'Subagent', source: ToolDataSource.Internal }, 'subagent', undefined, {}); @@ -2445,8 +2473,10 @@ suite('ChatPetWidget', () => { widget.setHost({ ...firstHost, model: constObservable(createSubagentTestModel([tool])) }); const pet = overlay.querySelector('.chat-pet-subagent')!; const image = pet.querySelector('img')!; + const arrival = pet.getAnimations()[0]; + arrival.pause(); await whenSpriteLoaded(image); - pet.dispatchEvent(new mainWindow.AnimationEvent('animationend', { animationName: 'chat-pet-subagent-fall' })); + arrival.finish(); await whenSpriteLoaded(image); assert.ok(image.getAttribute('src')?.includes('buddy-splat-')); setReducedMotion(true); @@ -2478,7 +2508,8 @@ suite('ChatPetWidget', () => { const eyes = first.querySelector('.chat-pet-eyes')!; await Promise.all([whenSpriteLoaded(image), whenSpriteLoaded(secondImage)]); const idleSource = image.getAttribute('src'); - const land = (pet: HTMLElement) => pet.dispatchEvent(new mainWindow.AnimationEvent('animationend', { animationName: 'chat-pet-subagent-fall' })); + const secondArrival = second.getAnimations()[0]; + const land = (pet: HTMLElement) => pet.getAnimations()[0].finish(); land(first); await whenSpriteLoaded(image); assert.deepStrictEqual({ @@ -2494,7 +2525,7 @@ suite('ChatPetWidget', () => { await whenSpriteLoaded(secondImage); tools[1].toolSpecificData = { kind: 'subagent', isActive: false }; changed.fire({ reason: 'other' }); - land(second); + secondArrival.dispatchEvent(new mainWindow.Event('finish')); clock.tick(900); assert.deepStrictEqual({ active: [...overlay.querySelectorAll('.chat-pet-subagent')], removed: !second.isConnected }, { active: [first], removed: true }); }); @@ -2509,7 +2540,7 @@ suite('ChatPetWidget', () => { const pet = overlay.querySelector('.chat-pet-subagent')!; const image = pet.querySelector('img')!; const idleSource = image.getAttribute('src'); - pet.dispatchEvent(new mainWindow.AnimationEvent('animationend', { animationName: 'chat-pet-subagent-fall' })); + assert.strictEqual(pet.getAnimations().length, 0); assert.strictEqual(image.getAttribute('src'), idleSource); tool.toolSpecificData = { kind: 'subagent', isActive: false }; changed.fire({ reason: 'other' }); @@ -2525,7 +2556,10 @@ suite('ChatPetWidget', () => { tool.toolSpecificData = { kind: 'subagent', isActive: true }; widget.setHost({ ...firstHost, model: constObservable(createSubagentTestModel([tool])) }); const pet = overlay.querySelector('.chat-pet-subagent')!; - // Exercise idle frames independently of the CSS arrival and landing animation. + // Exercise idle frames independently of the arrival and landing animation. + for (const animation of pet.getAnimations()) { + animation.cancel(); + } pet.classList.remove('arriving'); const eyes = pet.querySelector('.chat-pet-eyes')!; const pupil = pet.querySelector('.chat-pet-pupil')!; From 5466b28ad1f1d091119340508356baaf4a7e9b2b Mon Sep 17 00:00:00 2001 From: Lisa Rosenberg Date: Thu, 12 Nov 2026 17:56:29 +0100 Subject: [PATCH 14/66] feat: undo revert of accidental files --- .../chat/browser/widget/chatPetWidget.ts | 40 +++++++--------- .../chat/browser/widget/media/chatPet.css | 14 ++++++ .../test/browser/widget/chatPetWidget.test.ts | 48 +++---------------- 3 files changed, 39 insertions(+), 63 deletions(-) diff --git a/src/vs/workbench/contrib/chat/browser/widget/chatPetWidget.ts b/src/vs/workbench/contrib/chat/browser/widget/chatPetWidget.ts index 860512d52f0823..25308e29f0e1d9 100644 --- a/src/vs/workbench/contrib/chat/browser/widget/chatPetWidget.ts +++ b/src/vs/workbench/contrib/chat/browser/widget/chatPetWidget.ts @@ -216,7 +216,6 @@ interface ChatPetSpriteElement { interface ChatPetSubagent { readonly element: HTMLElement; - readonly width: number; readonly canvas: HTMLCanvasElement; readonly image: HTMLImageElement; readonly accessoryImage: HTMLImageElement | undefined; @@ -2901,7 +2900,8 @@ export class ChatPetWidget extends Disposable { : petLeft - miniWidth * (slot + 1); while ([...this._subagentPets.values()].some(pet => { const otherLeft = Number.parseFloat(pet.element.style.left); - return getLeft() < otherLeft + pet.width && getLeft() + miniWidth > otherLeft; + const otherWidth = 48 * Number.parseFloat(pet.element.style.getPropertyValue('--chat-pet-subagent-scale')); + return getLeft() < otherLeft + otherWidth && getLeft() + miniWidth > otherLeft; })) { slot++; } @@ -2910,8 +2910,13 @@ export class ChatPetWidget extends Disposable { const landing = getChatPetFallTarget(overlayBounds.left + left, -miniWidth, miniWidth, miniWidth, this._getPlatforms(), this.movementBounds.getBoundingClientRect().bottom); element.style.left = `${left}px`; element.style.top = `${landing.top - overlayBounds.top}px`; - element.style.transform = `scale(${miniScale})`; + element.style.setProperty('--chat-pet-subagent-scale', String(miniScale)); const distance = Math.max(0, landing.top + miniWidth); + element.style.setProperty('--chat-pet-subagent-fall-distance', `${distance}px`); + element.style.setProperty('--chat-pet-subagent-fall-duration', `${getChatPetFallDuration(distance)}ms`); + if (!this._motionReduced) { + element.classList.add('arriving'); + } const canvas = dom.append(element, dom.$('canvas.chat-pet-subagent-canvas')) as HTMLCanvasElement; canvas.width = CHAT_PET_SOURCE_SIZE; canvas.height = CHAT_PET_SOURCE_SIZE; @@ -2922,7 +2927,6 @@ export class ChatPetWidget extends Disposable { (eye.firstElementChild as HTMLElement | null)?.style.removeProperty('transform'); } const disposables = this._subagentEffects.add(new DisposableStore()); - const arrival = disposables.add(new MutableDisposable()); let state: 'idle' | 'splat' = 'idle'; const blink = disposables.add(new ChatPetBlinkController(blinking => eyes.classList.toggle('blink', blinking))); const updateBlink = () => blink.setEnabled(state === 'idle' && this._enabled && !this._motionReduced && this._isAnimationVisible(this._visual) && this._isAnimationVisible(element)); @@ -2985,6 +2989,14 @@ export class ChatPetWidget extends Disposable { } }); })); + disposables.add(dom.addDisposableListener(element, 'animationend', event => { + if (event.target === element && (event as AnimationEvent).animationName === 'chat-pet-subagent-fall') { + element.classList.remove('arriving'); + if (!this._motionReduced) { + setState('splat'); + } + } + })); const updateAppearance = (motionChanged: boolean, variantChanged: boolean, accessoryChanged: boolean) => { sprite.color = this._color; eyes.style.color = getChatPetEyeColor(this._color); @@ -2993,7 +3005,7 @@ export class ChatPetWidget extends Disposable { } if (motionChanged || variantChanged) { if (this._motionReduced) { - arrival.clear(); + element.classList.remove('arriving'); } setState(this._motionReduced ? 'idle' : state); } else { @@ -3001,23 +3013,7 @@ export class ChatPetWidget extends Disposable { } }; setState('idle'); - if (!this._motionReduced) { - const effects = arrival.value = new DisposableStore(); - element.classList.add('arriving'); - const fall = element.animate([ - { transform: `translateY(${-distance}px) scale(${miniScale})` }, - { transform: `translateY(0) scale(${miniScale})` }, - ], { duration: getChatPetFallDuration(distance), easing: 'cubic-bezier(0.42, 0, 1, 1)', fill: 'both' }); - effects.add(toDisposable(() => { - fall.cancel(); - element.classList.remove('arriving'); - })); - effects.add(dom.addDisposableListener(fall, 'finish', () => { - arrival.clear(); - setState('splat'); - })); - } - this._subagentPets.set(id, { element, width: miniWidth, canvas, image, get accessoryImage() { return accessoryImage; }, eyes, disposables, updateBlink, updateAppearance }); + this._subagentPets.set(id, { element, canvas, image, get accessoryImage() { return accessoryImage; }, eyes, disposables, updateBlink, updateAppearance }); } } diff --git a/src/vs/workbench/contrib/chat/browser/widget/media/chatPet.css b/src/vs/workbench/contrib/chat/browser/widget/media/chatPet.css index 51342a872bfa3f..87d305c3635836 100644 --- a/src/vs/workbench/contrib/chat/browser/widget/media/chatPet.css +++ b/src/vs/workbench/contrib/chat/browser/widget/media/chatPet.css @@ -185,10 +185,24 @@ position: absolute; width: 48px; height: 48px; + transform: scale(var(--chat-pet-subagent-scale)); transform-origin: top left; pointer-events: none; } +.chat-pet-subagent.arriving { + animation: chat-pet-subagent-fall var(--chat-pet-subagent-fall-duration) cubic-bezier(0.42, 0, 1, 1) both; +} + +@keyframes chat-pet-subagent-fall { + from { transform: translateY(calc(-1 * var(--chat-pet-subagent-fall-distance))) scale(var(--chat-pet-subagent-scale)); } + to { transform: translateY(0) scale(var(--chat-pet-subagent-scale)); } +} + +.monaco-workbench.monaco-reduce-motion .chat-pet-subagent.arriving { + animation: none; +} + .chat-pet-subagent-canvas { width: 48px; height: 48px; diff --git a/src/vs/workbench/contrib/chat/test/browser/widget/chatPetWidget.test.ts b/src/vs/workbench/contrib/chat/test/browser/widget/chatPetWidget.test.ts index e9e02a67520511..f074f2305ae0a6 100644 --- a/src/vs/workbench/contrib/chat/test/browser/widget/chatPetWidget.test.ts +++ b/src/vs/workbench/contrib/chat/test/browser/widget/chatPetWidget.test.ts @@ -2296,7 +2296,7 @@ suite('ChatPetWidget', () => { assert.deepStrictEqual([...firstMini.querySelectorAll('.chat-pet-pupil')].map(pupil => pupil.style.transform), ['', '']); assert.deepStrictEqual([...mainPupils].map(pupil => pupil.style.transform), ['translate(2px, -2px)', 'translate(2px, -2px)']); assert.ok(firstMini.offsetLeft >= button.offsetLeft + button.offsetWidth); - const miniSize = firstMini.getBoundingClientRect().width; + const miniSize = 48 * Number.parseFloat(firstMini.style.getPropertyValue('--chat-pet-subagent-scale')); assert.strictEqual(Number.parseFloat(firstMini.style.top) + miniSize, 0); const [bodyImage, accessoryImage] = firstMini.querySelectorAll('img'); assert.ok(accessoryImage?.src.includes('/accessories/')); @@ -2364,7 +2364,7 @@ suite('ChatPetWidget', () => { service.setHorizontalPosition(0.8); }, model); const pet = overlay.querySelector('.chat-pet-subagent')!; - assert.strictEqual(pet.getBoundingClientRect().width, 48); + assert.strictEqual(Number.parseFloat(pet.style.getPropertyValue('--chat-pet-subagent-scale')), 1); assert.ok(pet.offsetLeft < button.offsetLeft); }); @@ -2378,12 +2378,9 @@ suite('ChatPetWidget', () => { parts.push(tool); changed.fire({ reason: 'other' }); const first = overlay.querySelector('.chat-pet-subagent')!; - const arrival = first.getAnimations()[0]; - arrival.pause(); await whenSpriteLoaded(first.querySelector('img')!); service.toggle(); assert.strictEqual(first.isConnected, false); - assert.strictEqual(arrival.playState, 'idle'); const second = new ChatToolInvocation(undefined, { id: 'second', displayName: 'Second', modelDescription: 'Subagent', source: ToolDataSource.Internal }, 'second', undefined, {}); second.toolSpecificData = { kind: 'subagent', isActive: true }; parts.push(second); @@ -2418,9 +2415,6 @@ suite('ChatPetWidget', () => { tool.toolSpecificData = { kind: 'subagent', isActive: true }; widget.setHost({ ...firstHost, model: constObservable(createSubagentTestModel([tool])) }); const pet = overlay.querySelector('.chat-pet-subagent')!; - for (const animation of pet.getAnimations()) { - animation.cancel(); - } pet.classList.remove('arriving'); const body = pet.querySelector('img')!; await whenSpriteLoaded(body); @@ -2444,28 +2438,6 @@ suite('ChatPetWidget', () => { assert.strictEqual(pet.querySelectorAll('img').length, 1); }); - test('mini pets cancel their arrival when reduced motion is enabled mid-fall', async () => { - const { widget, firstHost, overlay, setReducedMotion } = createHostTransitionHarness(); - const tool = new ChatToolInvocation(undefined, { id: 'subagent', displayName: 'Subagent', modelDescription: 'Subagent', source: ToolDataSource.Internal }, 'subagent', undefined, {}); - tool.toolSpecificData = { kind: 'subagent', isActive: true }; - widget.setHost({ ...firstHost, model: constObservable(createSubagentTestModel([tool])) }); - const pet = overlay.querySelector('.chat-pet-subagent')!; - const arrival = pet.getAnimations()[0]; - arrival.pause(); - const image = pet.querySelector('img')!; - await whenSpriteLoaded(image); - setReducedMotion(true); - await whenSpriteLoaded(image); - const idleSource = image.getAttribute('src'); - arrival.dispatchEvent(new mainWindow.Event('finish')); - assert.deepStrictEqual({ - playState: arrival.playState, - arriving: pet.classList.contains('arriving'), - bottom: pet.getBoundingClientRect().bottom, - source: image.getAttribute('src'), - }, { playState: 'idle', arriving: false, bottom: overlay.getBoundingClientRect().top, source: idleSource }); - }); - test('mini pets stop squishing when reduced motion is enabled during landing', async () => { const { widget, firstHost, overlay, setReducedMotion } = createHostTransitionHarness(); const tool = new ChatToolInvocation(undefined, { id: 'subagent', displayName: 'Subagent', modelDescription: 'Subagent', source: ToolDataSource.Internal }, 'subagent', undefined, {}); @@ -2473,10 +2445,8 @@ suite('ChatPetWidget', () => { widget.setHost({ ...firstHost, model: constObservable(createSubagentTestModel([tool])) }); const pet = overlay.querySelector('.chat-pet-subagent')!; const image = pet.querySelector('img')!; - const arrival = pet.getAnimations()[0]; - arrival.pause(); await whenSpriteLoaded(image); - arrival.finish(); + pet.dispatchEvent(new mainWindow.AnimationEvent('animationend', { animationName: 'chat-pet-subagent-fall' })); await whenSpriteLoaded(image); assert.ok(image.getAttribute('src')?.includes('buddy-splat-')); setReducedMotion(true); @@ -2508,8 +2478,7 @@ suite('ChatPetWidget', () => { const eyes = first.querySelector('.chat-pet-eyes')!; await Promise.all([whenSpriteLoaded(image), whenSpriteLoaded(secondImage)]); const idleSource = image.getAttribute('src'); - const secondArrival = second.getAnimations()[0]; - const land = (pet: HTMLElement) => pet.getAnimations()[0].finish(); + const land = (pet: HTMLElement) => pet.dispatchEvent(new mainWindow.AnimationEvent('animationend', { animationName: 'chat-pet-subagent-fall' })); land(first); await whenSpriteLoaded(image); assert.deepStrictEqual({ @@ -2525,7 +2494,7 @@ suite('ChatPetWidget', () => { await whenSpriteLoaded(secondImage); tools[1].toolSpecificData = { kind: 'subagent', isActive: false }; changed.fire({ reason: 'other' }); - secondArrival.dispatchEvent(new mainWindow.Event('finish')); + land(second); clock.tick(900); assert.deepStrictEqual({ active: [...overlay.querySelectorAll('.chat-pet-subagent')], removed: !second.isConnected }, { active: [first], removed: true }); }); @@ -2540,7 +2509,7 @@ suite('ChatPetWidget', () => { const pet = overlay.querySelector('.chat-pet-subagent')!; const image = pet.querySelector('img')!; const idleSource = image.getAttribute('src'); - assert.strictEqual(pet.getAnimations().length, 0); + pet.dispatchEvent(new mainWindow.AnimationEvent('animationend', { animationName: 'chat-pet-subagent-fall' })); assert.strictEqual(image.getAttribute('src'), idleSource); tool.toolSpecificData = { kind: 'subagent', isActive: false }; changed.fire({ reason: 'other' }); @@ -2556,10 +2525,7 @@ suite('ChatPetWidget', () => { tool.toolSpecificData = { kind: 'subagent', isActive: true }; widget.setHost({ ...firstHost, model: constObservable(createSubagentTestModel([tool])) }); const pet = overlay.querySelector('.chat-pet-subagent')!; - // Exercise idle frames independently of the arrival and landing animation. - for (const animation of pet.getAnimations()) { - animation.cancel(); - } + // Exercise idle frames independently of the CSS arrival and landing animation. pet.classList.remove('arriving'); const eyes = pet.querySelector('.chat-pet-eyes')!; const pupil = pet.querySelector('.chat-pet-pupil')!; From f362cfdc5344054623c54dd38b44d805a2c534d1 Mon Sep 17 00:00:00 2001 From: Lisa Rosenberg Date: Thu, 12 Nov 2026 18:39:09 +0100 Subject: [PATCH 15/66] feat: apply review comments - add bounded placements and shrinking if chat area is smaller --- .../chat/browser/widget/chatPetWidget.ts | 50 +++++++++++++++++++ .../test/browser/widget/chatPetWidget.test.ts | 49 ++++++++++++++++++ 2 files changed, 99 insertions(+) diff --git a/src/vs/workbench/contrib/chat/browser/widget/chatPetWidget.ts b/src/vs/workbench/contrib/chat/browser/widget/chatPetWidget.ts index 25308e29f0e1d9..9df58f069326d9 100644 --- a/src/vs/workbench/contrib/chat/browser/widget/chatPetWidget.ts +++ b/src/vs/workbench/contrib/chat/browser/widget/chatPetWidget.ts @@ -144,6 +144,8 @@ const MOUSE_BOUNCE_HORIZONTAL_TRANSFER = 0.35; const MOUSE_BOUNCE_EDGE_KICK = 320; const MOUSE_BOUNCE_MAX_HORIZONTAL_VELOCITY = 1_800; const CHAT_PET_DISPLAY_SIZE = 48; +const CHAT_PET_SUBAGENT_MAX_WIDTH = 288; +const CHAT_PET_SUBAGENT_MAX_HEIGHT = 96; const CHAT_PET_SOURCE_SIZE = 96; const CHAT_PET_SLEEP_SOURCE_WIDTH = 120; const CHAT_PET_TYPING_SOURCE_WIDTH = 168; @@ -2241,6 +2243,7 @@ export class ChatPetWidget extends Disposable { } private _handleHostLayoutChange(): void { + this._constrainSubagentPets(); if (this._jumpGame.value) { this._jumpGame.value.layout(); return; @@ -3015,6 +3018,53 @@ export class ChatPetWidget extends Disposable { setState('idle'); this._subagentPets.set(id, { element, canvas, image, get accessoryImage() { return accessoryImage; }, eyes, disposables, updateBlink, updateAppearance }); } + this._constrainSubagentPets(); + } + + /** Keep settled mini pets in a bounded area without coupling them to the main pet's movement. */ + private _constrainSubagentPets(): void { + if (!this._subagentPets.size) { + return; + } + const overlay = this._overlay.getBoundingClientRect(); + const input = this.dragBounds.getBoundingClientRect(); + const movement = this.movementBounds.getBoundingClientRect(); + const minimumLeft = Math.max(input.left, movement.left) - overlay.left; + const maximumRight = Math.min(input.right, movement.right) - overlay.left; + const minimumTop = movement.top - overlay.top; + const maximumBottom = movement.bottom - overlay.top; + const width = Math.min(CHAT_PET_SUBAGENT_MAX_WIDTH, maximumRight - minimumLeft); + const height = Math.min(CHAT_PET_SUBAGENT_MAX_HEIGHT, maximumBottom - minimumTop); + if (width <= 0 || height <= 0) { + return; + } + const pets = [...this._subagentPets.values()].map(pet => ({ + element: pet.element, + left: Number.parseFloat(pet.element.style.left), + top: Number.parseFloat(pet.element.style.top), + size: CHAT_PET_DISPLAY_SIZE * Number.parseFloat(pet.element.style.getPropertyValue('--chat-pet-subagent-scale')), + })); + const left = Math.min(...pets.map(pet => pet.left)); + const right = Math.max(...pets.map(pet => pet.left + pet.size)); + const top = Math.min(...pets.map(pet => pet.top)); + const bottom = Math.max(...pets.map(pet => pet.top + pet.size)); + if (left >= minimumLeft && right <= maximumRight && top >= minimumTop && bottom <= maximumBottom && right - left <= width && bottom - top <= height) { + return; + } + const columns = Math.min(pets.length, Math.ceil(Math.sqrt(pets.length * width / height))); + const rows = Math.ceil(pets.length / columns); + const size = Math.min(Math.max(...pets.map(pet => pet.size)), width / columns, height / rows); + const gridLeft = Math.max(minimumLeft, Math.min(left, maximumRight - columns * size)); + const gridBottom = Math.max(minimumTop + rows * size, Math.min(bottom, maximumBottom)); + for (const [index, pet] of pets.entries()) { + const petTop = gridBottom - (Math.floor(index / columns) + 1) * size; + const distance = Math.max(0, overlay.top + petTop + size); + pet.element.style.left = `${gridLeft + index % columns * size}px`; + pet.element.style.top = `${petTop}px`; + pet.element.style.setProperty('--chat-pet-subagent-scale', String(size / CHAT_PET_DISPLAY_SIZE)); + pet.element.style.setProperty('--chat-pet-subagent-fall-distance', `${distance}px`); + pet.element.style.setProperty('--chat-pet-subagent-fall-duration', `${getChatPetFallDuration(distance)}ms`); + } } private _despawnSubagentPet(pet: ChatPetSubagent): void { diff --git a/src/vs/workbench/contrib/chat/test/browser/widget/chatPetWidget.test.ts b/src/vs/workbench/contrib/chat/test/browser/widget/chatPetWidget.test.ts index f074f2305ae0a6..2a4217272ebcdb 100644 --- a/src/vs/workbench/contrib/chat/test/browser/widget/chatPetWidget.test.ts +++ b/src/vs/workbench/contrib/chat/test/browser/widget/chatPetWidget.test.ts @@ -2409,6 +2409,55 @@ suite('ChatPetWidget', () => { assert.ok(second.offsetLeft + 24 <= first.offsetLeft || first.offsetLeft + 24 <= second.offsetLeft); }); + for (const petLeft of [0, 300]) { + test(`mini pets stay in a bounded area with many subagents (main pet at ${petLeft})`, () => { + const { widget, firstHost, button, overlay, firstParent, root, layout } = createHostTransitionHarness(true); + const changed = disposables.add(new Emitter()); + const tools = Array.from({ length: 100 }, (_, index) => { + const id = `subagent-${index}`; + const tool = new ChatToolInvocation(undefined, { id, displayName: id, modelDescription: 'Subagent', source: ToolDataSource.Internal }, id, undefined, {}); + tool.toolSpecificData = { kind: 'subagent', isActive: true }; + return tool; + }); + button.style.left = `${petLeft}px`; + widget.setHost({ ...firstHost, transition: undefined, model: constObservable(createSubagentTestModel(tools, changed.event)) }); + const pets = [...overlay.querySelectorAll('.chat-pet-subagent')]; + const checkBounds = (count: number) => { + const rects = [...overlay.querySelectorAll('.chat-pet-subagent')].map(pet => pet.getBoundingClientRect()); + const input = firstParent.getBoundingClientRect(); + const movement = root.getBoundingClientRect(); + const left = Math.min(...rects.map(rect => rect.left)); + const right = Math.max(...rects.map(rect => rect.right)); + const top = Math.min(...rects.map(rect => rect.top)); + const bottom = Math.max(...rects.map(rect => rect.bottom)); + const overlaps = rects.some((rect, index) => rects.slice(index + 1).some(other => + rect.left < other.right - 0.1 && rect.right > other.left + 0.1 && rect.top < other.bottom - 0.1 && rect.bottom > other.top + 0.1)); + assert.deepStrictEqual({ + count: rects.length, + withinChat: left >= input.left - 0.1 && right <= input.right + 0.1 && top >= movement.top - 0.1 && bottom <= movement.bottom + 0.1, + bounded: right - left <= 288.1 && bottom - top <= 96.1, + visible: rects.every(rect => rect.width > 0 && rect.height > 0), + overlaps, + }, { count, withinChat: true, bounded: true, visible: true, overlaps: false }); + }; + checkBounds(100); + firstParent.style.width = '120px'; + layout(); + checkBounds(100); + root.style.height = '64px'; + firstParent.style.top = '32px'; + layout(); + checkBounds(100); + tools[0].toolSpecificData = { kind: 'subagent', isActive: false }; + changed.fire({ reason: 'other' }); + checkBounds(99); + assert.deepStrictEqual([...overlay.querySelectorAll('.chat-pet-subagent')], pets.slice(1)); + tools[0].toolSpecificData = { kind: 'subagent', isActive: true }; + changed.fire({ reason: 'other' }); + checkBounds(100); + }); + } + test('mini pets update appearance and motion settings while active', async () => { const { widget, firstHost, button, overlay, service, setReducedMotion } = createHostTransitionHarness(); const tool = new ChatToolInvocation(undefined, { id: 'subagent', displayName: 'Subagent', modelDescription: 'Subagent', source: ToolDataSource.Internal }, 'subagent', undefined, {}); From a7968be6756d8567ad5883da16f75b2ecb4efa03 Mon Sep 17 00:00:00 2001 From: Lisa Rosenberg Date: Thu, 12 Nov 2026 18:48:07 +0100 Subject: [PATCH 16/66] feat: let upper stacked subagent fall to bottom if the bottom one finishes first --- .../chat/browser/widget/chatPetWidget.ts | 49 ++++++++++++++++++- .../test/browser/widget/chatPetWidget.test.ts | 47 ++++++++++++++++++ 2 files changed, 95 insertions(+), 1 deletion(-) diff --git a/src/vs/workbench/contrib/chat/browser/widget/chatPetWidget.ts b/src/vs/workbench/contrib/chat/browser/widget/chatPetWidget.ts index 9df58f069326d9..63c76158e6ae0d 100644 --- a/src/vs/workbench/contrib/chat/browser/widget/chatPetWidget.ts +++ b/src/vs/workbench/contrib/chat/browser/widget/chatPetWidget.ts @@ -225,6 +225,7 @@ interface ChatPetSubagent { readonly disposables: DisposableStore; readonly updateBlink: () => void; readonly updateAppearance: (motionChanged: boolean, variantChanged: boolean, accessoryChanged: boolean) => void; + readonly fallTo: (top: number) => void; } interface ChatPetPendingRender { @@ -2880,8 +2881,10 @@ export class ChatPetWidget extends Disposable { } private _updateSubagentPets(subagents: ReadonlySet): void { + let removed = false; for (const [id, pet] of this._subagentPets) { if (!subagents.has(id)) { + removed = true; this._subagentPets.delete(id); this._despawnSubagentPet(pet); } @@ -3015,10 +3018,54 @@ export class ChatPetWidget extends Disposable { sprite.redrawFrame?.(); } }; + const fallTo = (top: number) => { + const previousTop = element.getBoundingClientRect().top - this._overlay.getBoundingClientRect().top; + element.classList.remove('arriving'); + element.style.top = `${top}px`; + setState('idle'); + if (!this._motionReduced && top > previousTop) { + const distance = top - previousTop; + element.style.setProperty('--chat-pet-subagent-fall-distance', `${distance}px`); + element.style.setProperty('--chat-pet-subagent-fall-duration', `${getChatPetFallDuration(distance)}ms`); + // Restart the existing fall animation, including when another support disappears mid-fall. + void element.offsetWidth; + element.classList.add('arriving'); + } + }; setState('idle'); - this._subagentPets.set(id, { element, canvas, image, get accessoryImage() { return accessoryImage; }, eyes, disposables, updateBlink, updateAppearance }); + this._subagentPets.set(id, { element, canvas, image, get accessoryImage() { return accessoryImage; }, eyes, disposables, updateBlink, updateAppearance, fallTo }); } this._constrainSubagentPets(); + if (removed) { + this._settleSubagentPets(); + } + } + + /** Settle each column from the bottom up so remaining mini pets can support those above them. */ + private _settleSubagentPets(): void { + const overlay = this._overlay.getBoundingClientRect(); + const platforms = this._getPlatforms(); + const floor = this.movementBounds.getBoundingClientRect().bottom; + const pets = [...this._subagentPets.values()].map(pet => ({ + pet, + left: Number.parseFloat(pet.element.style.left), + top: Number.parseFloat(pet.element.style.top), + size: CHAT_PET_DISPLAY_SIZE * Number.parseFloat(pet.element.style.getPropertyValue('--chat-pet-subagent-scale')), + })).sort((a, b) => b.top - a.top); + for (const [index, pet] of pets.entries()) { + const landing = getChatPetFallTarget(overlay.left + pet.left, overlay.top + pet.top - POSITION_EPSILON, pet.size, pet.size, platforms, floor); + let top = Math.max(pet.top, landing.top - overlay.top); + for (let below = 0; below < index; below++) { + const support = pets[below]; + if (pet.left < support.left + support.size - POSITION_EPSILON && pet.left + pet.size > support.left + POSITION_EPSILON && support.top >= pet.top + pet.size - POSITION_EPSILON) { + top = Math.min(top, support.top - pet.size); + } + } + if (top > pet.top + POSITION_EPSILON) { + pet.pet.fallTo(top); + pet.top = top; + } + } } /** Keep settled mini pets in a bounded area without coupling them to the main pet's movement. */ diff --git a/src/vs/workbench/contrib/chat/test/browser/widget/chatPetWidget.test.ts b/src/vs/workbench/contrib/chat/test/browser/widget/chatPetWidget.test.ts index 2a4217272ebcdb..0c94e1bb082577 100644 --- a/src/vs/workbench/contrib/chat/test/browser/widget/chatPetWidget.test.ts +++ b/src/vs/workbench/contrib/chat/test/browser/widget/chatPetWidget.test.ts @@ -2458,6 +2458,53 @@ suite('ChatPetWidget', () => { }); } + for (const reducedMotion of [false, true]) { + for (const removedIndex of [0, 1]) { + test(`mini pets fall when their ${removedIndex === 0 ? 'bottom' : 'middle'} support finishes (${reducedMotion ? 'reduced motion' : 'animated'})`, () => { + const { widget, firstHost, overlay, setReducedMotion } = createHostTransitionHarness(reducedMotion); + const changed = disposables.add(new Emitter()); + const tools = ['bottom', 'middle', 'top', 'neighbor'].map(id => { + const tool = new ChatToolInvocation(undefined, { id, displayName: id, modelDescription: 'Subagent', source: ToolDataSource.Internal }, id, undefined, {}); + tool.toolSpecificData = { kind: 'subagent', isActive: true }; + return tool; + }); + widget.setHost({ ...firstHost, model: constObservable(createSubagentTestModel(tools, changed.event)) }); + const pets = [...overlay.querySelectorAll('.chat-pet-subagent')]; + // A three-high stack on the input platform and an independent neighbor on the ground. + pets.forEach((pet, index) => { + pet.classList.remove('arriving'); + pet.style.left = index === 3 ? '96px' : '48px'; + pet.style.top = `${index === 3 ? -24 : -(index + 1) * 24}px`; + }); + const neighborPosition = pets[3].getBoundingClientRect().toJSON(); + tools[removedIndex].toolSpecificData = { kind: 'subagent', isActive: false }; + changed.fire({ reason: 'other' }); + assert.deepStrictEqual({ + remaining: [...overlay.querySelectorAll('.chat-pet-subagent')], + tops: pets.filter((_, index) => index !== removedIndex).map(pet => pet.style.top), + falling: pets[2].classList.contains('arriving'), + neighbor: pets[3].getBoundingClientRect().toJSON(), + }, { remaining: pets.filter((_, index) => index !== removedIndex), tops: ['-24px', '-48px', '-24px'], falling: !reducedMotion, neighbor: neighborPosition }); + // Removing the next support mid-fall must continue from the currently rendered position. + for (const animation of pets[2].getAnimations()) { + animation.pause(); + } + const previousTop = pets[2].getBoundingClientRect().top - overlay.getBoundingClientRect().top; + tools[1 - removedIndex].toolSpecificData = { kind: 'subagent', isActive: false }; + changed.fire({ reason: 'other' }); + assert.strictEqual(pets[2].style.top, '-24px'); + if (!reducedMotion) { + assert.ok(Math.abs(Number.parseFloat(pets[2].style.getPropertyValue('--chat-pet-subagent-fall-distance')) - (-24 - previousTop)) < 0.1); + setReducedMotion(true); + } + assert.deepStrictEqual({ + falling: pets[2].classList.contains('arriving'), + bottom: pets[2].getBoundingClientRect().bottom, + }, { falling: false, bottom: overlay.getBoundingClientRect().top }); + }); + } + } + test('mini pets update appearance and motion settings while active', async () => { const { widget, firstHost, button, overlay, service, setReducedMotion } = createHostTransitionHarness(); const tool = new ChatToolInvocation(undefined, { id: 'subagent', displayName: 'Subagent', modelDescription: 'Subagent', source: ToolDataSource.Internal }, 'subagent', undefined, {}); From 2d35642f4a9bc7dcd8b0300bf4bcfe3db7ede3ee Mon Sep 17 00:00:00 2001 From: Lisa Rosenberg Date: Thu, 12 Nov 2026 18:49:51 +0100 Subject: [PATCH 17/66] feat: have the bottom subagent have folded antennae --- .../chat/browser/widget/chatPetWidget.ts | 54 +++++++++++++++--- .../test/browser/widget/chatPetWidget.test.ts | 56 +++++++++++++++++++ 2 files changed, 101 insertions(+), 9 deletions(-) diff --git a/src/vs/workbench/contrib/chat/browser/widget/chatPetWidget.ts b/src/vs/workbench/contrib/chat/browser/widget/chatPetWidget.ts index 63c76158e6ae0d..fa61be04d4dc75 100644 --- a/src/vs/workbench/contrib/chat/browser/widget/chatPetWidget.ts +++ b/src/vs/workbench/contrib/chat/browser/widget/chatPetWidget.ts @@ -146,6 +146,7 @@ const MOUSE_BOUNCE_MAX_HORIZONTAL_VELOCITY = 1_800; const CHAT_PET_DISPLAY_SIZE = 48; const CHAT_PET_SUBAGENT_MAX_WIDTH = 288; const CHAT_PET_SUBAGENT_MAX_HEIGHT = 96; +const CHAT_PET_FOLDED_ANTENNAE_FRAME = 20; const CHAT_PET_SOURCE_SIZE = 96; const CHAT_PET_SLEEP_SOURCE_WIDTH = 120; const CHAT_PET_TYPING_SOURCE_WIDTH = 168; @@ -226,6 +227,7 @@ interface ChatPetSubagent { readonly updateBlink: () => void; readonly updateAppearance: (motionChanged: boolean, variantChanged: boolean, accessoryChanged: boolean) => void; readonly fallTo: (top: number) => void; + readonly updateStacked: (stacked: boolean) => void; } interface ChatPetPendingRender { @@ -1801,9 +1803,9 @@ export class ChatPetWidget extends Disposable { if (enabled && (wasMotionReduced !== this._motionReduced || colorChanged || accessoryChanged)) { pet.updateAppearance(wasMotionReduced !== this._motionReduced, variantChanged, accessoryChanged); } - if (this._motionReduced) { - pet.eyes.classList.remove('bobbed'); - } + } + if (wasMotionReduced !== this._motionReduced) { + this._updateSubagentStacking(); } if (!enabled) { @@ -2245,6 +2247,7 @@ export class ChatPetWidget extends Disposable { private _handleHostLayoutChange(): void { this._constrainSubagentPets(); + this._updateSubagentStacking(); if (this._jumpGame.value) { this._jumpGame.value.layout(); return; @@ -2934,6 +2937,7 @@ export class ChatPetWidget extends Disposable { } const disposables = this._subagentEffects.add(new DisposableStore()); let state: 'idle' | 'splat' = 'idle'; + let stacked = false; const blink = disposables.add(new ChatPetBlinkController(blinking => eyes.classList.toggle('blink', blinking))); const updateBlink = () => blink.setEnabled(state === 'idle' && this._enabled && !this._motionReduced && this._isAnimationVisible(this._visual) && this._isAnimationVisible(element)); disposables.add(this._onDidChangeAnimationVisibility.event(updateBlink)); @@ -2949,12 +2953,20 @@ export class ChatPetWidget extends Disposable { const animation = disposables.add(new MutableDisposable()); const image = dom.append(element, dom.$('img.chat-pet-spritesheet')) as HTMLImageElement; image.alt = ''; + const getSource = (): ChatPetSpriteSource => { + const sources = getChatPetSpriteSources(this._variant)[state]; + return stacked && state === 'idle' + ? { ...sources.animated, frameIndices: [CHAT_PET_FOLDED_ANTENNAE_FRAME], frameDurations: [], iterations: 1 } + : this._motionReduced ? sources.reducedMotion : sources.animated; + }; const setState = (nextState: 'idle' | 'splat') => { animation.clear(); state = nextState; updateBlink(); - const sources = getChatPetSpriteSources(this._variant)[state]; - setChatPetImageSource(image, (this._motionReduced ? sources.reducedMotion : sources.animated).url); + if (this._motionReduced) { + eyes.classList.toggle('bobbed', stacked && state === 'idle'); + } + setChatPetImageSource(image, getSource().url); }; const sprite: ChatPetSpriteElement = { container: element, canvas, image, color: this._color }; let accessory = this._selectedAccessory ? getChatPetAccessory(this._selectedAccessory) : undefined; @@ -2982,11 +2994,10 @@ export class ChatPetWidget extends Disposable { setState('idle'); return; } - const sources = getChatPetSpriteSources(this._variant)[state]; - const source = this._motionReduced ? sources.reducedMotion : sources.animated; + const source = getSource(); eyes.classList.toggle('tracking', state === 'idle'); this._startSpriteAnimation(source, sprite, animation, state === 'splat' ? () => setState('idle') : undefined, false, frameIndex => { - eyes.classList.toggle('bobbed', state === 'idle' && !this._motionReduced && (source.accessoryRigFrame ?? frameIndex) >= 20); + eyes.classList.toggle('bobbed', state === 'idle' && (stacked || !this._motionReduced) && (source.accessoryRigFrame ?? frameIndex) >= CHAT_PET_FOLDED_ANTENNAE_FRAME); if (accessoryImage?.complete && accessoryImage.naturalWidth > 0 && accessory) { const context = canvas.getContext('2d'); if (context) { @@ -3001,6 +3012,7 @@ export class ChatPetWidget extends Disposable { if (!this._motionReduced) { setState('splat'); } + this._updateSubagentStacking(); } })); const updateAppearance = (motionChanged: boolean, variantChanged: boolean, accessoryChanged: boolean) => { @@ -3032,13 +3044,37 @@ export class ChatPetWidget extends Disposable { element.classList.add('arriving'); } }; + const updateStacked = (value: boolean) => { + if (stacked !== value) { + stacked = value; + if (state === 'idle') { + setState('idle'); + } + } + }; setState('idle'); - this._subagentPets.set(id, { element, canvas, image, get accessoryImage() { return accessoryImage; }, eyes, disposables, updateBlink, updateAppearance, fallTo }); + this._subagentPets.set(id, { element, canvas, image, get accessoryImage() { return accessoryImage; }, eyes, disposables, updateBlink, updateAppearance, fallTo, updateStacked }); } this._constrainSubagentPets(); if (removed) { this._settleSubagentPets(); } + this._updateSubagentStacking(); + } + + /** Hold the folded idle pose only while another mini pet is resting directly on this one. */ + private _updateSubagentStacking(): void { + const pets = [...this._subagentPets.values()].map(pet => ({ + pet, + left: Number.parseFloat(pet.element.style.left), + top: Number.parseFloat(pet.element.style.top), + size: CHAT_PET_DISPLAY_SIZE * Number.parseFloat(pet.element.style.getPropertyValue('--chat-pet-subagent-scale')), + })); + for (const pet of pets) { + pet.pet.updateStacked(pets.some(above => above !== pet && !above.pet.element.classList.contains('arriving') + && Math.abs(above.top + above.size - pet.top) <= POSITION_EPSILON + && pet.left < above.left + above.size - POSITION_EPSILON && pet.left + pet.size > above.left + POSITION_EPSILON)); + } } /** Settle each column from the bottom up so remaining mini pets can support those above them. */ diff --git a/src/vs/workbench/contrib/chat/test/browser/widget/chatPetWidget.test.ts b/src/vs/workbench/contrib/chat/test/browser/widget/chatPetWidget.test.ts index 0c94e1bb082577..677b4b4a925493 100644 --- a/src/vs/workbench/contrib/chat/test/browser/widget/chatPetWidget.test.ts +++ b/src/vs/workbench/contrib/chat/test/browser/widget/chatPetWidget.test.ts @@ -2505,6 +2505,62 @@ suite('ChatPetWidget', () => { } } + for (const variant of ['stable', 'insiders'] as const) { + for (const reducedMotion of [false, true]) { + test(`mini pets hold folded antennae while supporting another pet (${variant}, ${reducedMotion ? 'reduced motion' : 'animated'})`, async () => { + const clock = sinon.useFakeTimers({ toFake: ['setTimeout', 'clearTimeout', 'performance'] }); + disposables.add(toDisposable(() => clock.restore())); + const { widget, firstHost, overlay, setReducedMotion } = createHostTransitionHarness(reducedMotion, 'teleport', variant); + const changed = disposables.add(new Emitter()); + const tools = ['bottom', 'top'].map(id => { + const tool = new ChatToolInvocation(undefined, { id, displayName: id, modelDescription: 'Subagent', source: ToolDataSource.Internal }, id, undefined, {}); + tool.toolSpecificData = { kind: 'subagent', isActive: true }; + return tool; + }); + widget.setHost({ ...firstHost, model: constObservable(createSubagentTestModel(tools, changed.event)) }); + const [bottom, top] = overlay.querySelectorAll('.chat-pet-subagent'); + const image = bottom.querySelector('img')!; + await Promise.all([whenSpriteLoaded(image), whenSpriteLoaded(top.querySelector('img')!)]); + bottom.classList.remove('arriving'); + bottom.style.left = top.style.left = '48px'; + bottom.style.top = '-24px'; + top.style.top = '-48px'; + changed.fire({ reason: 'other' }); + if (!reducedMotion) { + assert.ok(!bottom.querySelector('.chat-pet-eyes.bobbed')); + top.dispatchEvent(new mainWindow.AnimationEvent('animationend', { animationName: 'chat-pet-subagent-fall' })); + } + await whenSpriteLoaded(image); + const canvas = bottom.querySelector('canvas')!; + const expected = mainWindow.document.createElement('canvas'); + expected.width = expected.height = 96; + const checkFrame = (frame: number) => { + const context = expected.getContext('2d')!; + context.clearRect(0, 0, 96, 96); + context.drawImage(image, frame * 96, 0, 96, 96, 0, 0, 96, 96); + assert.deepStrictEqual({ pixels: canvas.toDataURL(), eyesLowered: !!bottom.querySelector('.chat-pet-eyes.bobbed') }, + { pixels: expected.toDataURL(), eyesLowered: frame === 20 }); + }; + checkFrame(20); + clock.tick(2_500); + checkFrame(20); + setReducedMotion(!reducedMotion); + await whenSpriteLoaded(image); + checkFrame(20); + setReducedMotion(reducedMotion); + await whenSpriteLoaded(image); + tools[1].toolSpecificData = { kind: 'subagent', isActive: false }; + changed.fire({ reason: 'other' }); + await whenSpriteLoaded(image); + checkFrame(0); + if (!reducedMotion) { + clock.tick(800); + checkFrame(20); + } + }); + } + } + test('mini pets update appearance and motion settings while active', async () => { const { widget, firstHost, button, overlay, service, setReducedMotion } = createHostTransitionHarness(); const tool = new ChatToolInvocation(undefined, { id: 'subagent', displayName: 'Subagent', modelDescription: 'Subagent', source: ToolDataSource.Internal }, 'subagent', undefined, {}); From 93ebb7741df0f0c1aefaaf575fc6697a320cee8f Mon Sep 17 00:00:00 2001 From: Lisa Rosenberg Date: Thu, 12 Nov 2026 18:55:30 +0100 Subject: [PATCH 18/66] feat: fix landing issue --- .../chat/browser/widget/chatPetWidget.ts | 8 ++-- .../test/browser/widget/chatPetWidget.test.ts | 39 ++++++++++++++++++- 2 files changed, 43 insertions(+), 4 deletions(-) diff --git a/src/vs/workbench/contrib/chat/browser/widget/chatPetWidget.ts b/src/vs/workbench/contrib/chat/browser/widget/chatPetWidget.ts index fa61be04d4dc75..a635c81d20d60c 100644 --- a/src/vs/workbench/contrib/chat/browser/widget/chatPetWidget.ts +++ b/src/vs/workbench/contrib/chat/browser/widget/chatPetWidget.ts @@ -2916,7 +2916,8 @@ export class ChatPetWidget extends Disposable { } const left = getLeft(); const overlayBounds = this._overlay.getBoundingClientRect(); - const landing = getChatPetFallTarget(overlayBounds.left + left, -miniWidth, miniWidth, miniWidth, this._getPlatforms(), this.movementBounds.getBoundingClientRect().bottom); + const floor = Math.min(this.dragBounds.getBoundingClientRect().top, this.movementBounds.getBoundingClientRect().bottom); + const landing = getChatPetFallTarget(overlayBounds.left + left, -miniWidth, miniWidth, miniWidth, this._getPlatforms(), floor); element.style.left = `${left}px`; element.style.top = `${landing.top - overlayBounds.top}px`; element.style.setProperty('--chat-pet-subagent-scale', String(miniScale)); @@ -3081,7 +3082,7 @@ export class ChatPetWidget extends Disposable { private _settleSubagentPets(): void { const overlay = this._overlay.getBoundingClientRect(); const platforms = this._getPlatforms(); - const floor = this.movementBounds.getBoundingClientRect().bottom; + const floor = Math.min(this.dragBounds.getBoundingClientRect().top, this.movementBounds.getBoundingClientRect().bottom); const pets = [...this._subagentPets.values()].map(pet => ({ pet, left: Number.parseFloat(pet.element.style.left), @@ -3115,7 +3116,8 @@ export class ChatPetWidget extends Disposable { const minimumLeft = Math.max(input.left, movement.left) - overlay.left; const maximumRight = Math.min(input.right, movement.right) - overlay.left; const minimumTop = movement.top - overlay.top; - const maximumBottom = movement.bottom - overlay.top; + // The input's top edge is the floor; the movement bounds also include the input itself. + const maximumBottom = Math.min(input.top, movement.bottom) - overlay.top; const width = Math.min(CHAT_PET_SUBAGENT_MAX_WIDTH, maximumRight - minimumLeft); const height = Math.min(CHAT_PET_SUBAGENT_MAX_HEIGHT, maximumBottom - minimumTop); if (width <= 0 || height <= 0) { diff --git a/src/vs/workbench/contrib/chat/test/browser/widget/chatPetWidget.test.ts b/src/vs/workbench/contrib/chat/test/browser/widget/chatPetWidget.test.ts index 677b4b4a925493..2ac5c09f4f4b75 100644 --- a/src/vs/workbench/contrib/chat/test/browser/widget/chatPetWidget.test.ts +++ b/src/vs/workbench/contrib/chat/test/browser/widget/chatPetWidget.test.ts @@ -2409,6 +2409,43 @@ suite('ChatPetWidget', () => { assert.ok(second.offsetLeft + 24 <= first.offsetLeft || first.offsetLeft + 24 <= second.offsetLeft); }); + for (const petLeft of [0, 192]) { + for (const staggered of [false, true]) { + test(`mini pets land above the input without a resize (main pet at ${petLeft}, ${staggered ? 'staggered' : 'together'})`, () => { + const { widget, firstHost, button, overlay, firstParent } = createHostTransitionHarness(true); + firstParent.style.width = '240px'; + button.style.left = `${petLeft}px`; + const changed = disposables.add(new Emitter()); + const tools: ChatToolInvocation[] = []; + widget.setHost({ ...firstHost, transition: undefined, model: constObservable(createSubagentTestModel(tools, changed.event)) }); + const checkLanding = (count: number) => { + const input = firstParent.getBoundingClientRect(); + const pets = [...overlay.querySelectorAll('.chat-pet-subagent')].map(pet => pet.getBoundingClientRect()); + assert.deepStrictEqual({ + count: pets.length, + aboveInput: pets.every(pet => pet.bottom <= input.top + 0.1), + withinWidth: pets.every(pet => pet.left >= input.left - 0.1 && pet.right <= input.right + 0.1), + }, { count, aboveInput: true, withinWidth: true }); + }; + for (let index = 0; index < 10; index++) { + const id = `subagent-${index}`; + const tool = new ChatToolInvocation(undefined, { id, displayName: id, modelDescription: 'Subagent', source: ToolDataSource.Internal }, id, undefined, {}); + tool.toolSpecificData = { kind: 'subagent', isActive: true }; + tools.push(tool); + if (staggered) { + changed.fire({ reason: 'other' }); + checkLanding(index + 1); + } + } + changed.fire({ reason: 'other' }); + checkLanding(10); + tools[0].toolSpecificData = { kind: 'subagent', isActive: false }; + changed.fire({ reason: 'other' }); + checkLanding(9); + }); + } + } + for (const petLeft of [0, 300]) { test(`mini pets stay in a bounded area with many subagents (main pet at ${petLeft})`, () => { const { widget, firstHost, button, overlay, firstParent, root, layout } = createHostTransitionHarness(true); @@ -2434,7 +2471,7 @@ suite('ChatPetWidget', () => { rect.left < other.right - 0.1 && rect.right > other.left + 0.1 && rect.top < other.bottom - 0.1 && rect.bottom > other.top + 0.1)); assert.deepStrictEqual({ count: rects.length, - withinChat: left >= input.left - 0.1 && right <= input.right + 0.1 && top >= movement.top - 0.1 && bottom <= movement.bottom + 0.1, + withinChat: left >= input.left - 0.1 && right <= input.right + 0.1 && top >= movement.top - 0.1 && bottom <= Math.min(input.top, movement.bottom) + 0.1, bounded: right - left <= 288.1 && bottom - top <= 96.1, visible: rects.every(rect => rect.width > 0 && rect.height > 0), overlaps, From d59f50c6f0f5d8912d526e01a8c6ae0d4d9068c9 Mon Sep 17 00:00:00 2001 From: Lisa Rosenberg Date: Thu, 12 Nov 2026 19:36:02 +0100 Subject: [PATCH 19/66] feat: fix background prompt behavior --- .../chat/browser/widget/chatPetWidget.ts | 91 +++++++++++--- .../test/browser/widget/chatPetWidget.test.ts | 117 ++++++++++++++++++ 2 files changed, 190 insertions(+), 18 deletions(-) diff --git a/src/vs/workbench/contrib/chat/browser/widget/chatPetWidget.ts b/src/vs/workbench/contrib/chat/browser/widget/chatPetWidget.ts index a635c81d20d60c..c47451549977d2 100644 --- a/src/vs/workbench/contrib/chat/browser/widget/chatPetWidget.ts +++ b/src/vs/workbench/contrib/chat/browser/widget/chatPetWidget.ts @@ -226,7 +226,8 @@ interface ChatPetSubagent { readonly disposables: DisposableStore; readonly updateBlink: () => void; readonly updateAppearance: (motionChanged: boolean, variantChanged: boolean, accessoryChanged: boolean) => void; - readonly fallTo: (top: number) => void; + readonly fallTo: (top: number, respawn?: boolean) => void; + readonly isRespawning: () => boolean; readonly updateStacked: (stacked: boolean) => void; } @@ -2277,6 +2278,10 @@ export class ChatPetWidget extends Disposable { } private _updatePlatformPosition(): void { + if (this._enabled) { + this._settleSubagentPets(true); + this._updateSubagentStacking(); + } if (this._jumpGame.value) { this._jumpGame.value.layout(); return; @@ -2939,8 +2944,10 @@ export class ChatPetWidget extends Disposable { const disposables = this._subagentEffects.add(new DisposableStore()); let state: 'idle' | 'splat' = 'idle'; let stacked = false; + let respawnPhase: 'none' | 'falling' | 'despawning' | 'respawning' = 'none'; + const respawnTimer = disposables.add(new RunOnceScheduler(() => advanceRespawn(), RESPAWN_EFFECT_REDUCED_MOTION_DURATION)); const blink = disposables.add(new ChatPetBlinkController(blinking => eyes.classList.toggle('blink', blinking))); - const updateBlink = () => blink.setEnabled(state === 'idle' && this._enabled && !this._motionReduced && this._isAnimationVisible(this._visual) && this._isAnimationVisible(element)); + const updateBlink = () => blink.setEnabled(respawnPhase === 'none' && state === 'idle' && this._enabled && !this._motionReduced && this._isAnimationVisible(this._visual) && this._isAnimationVisible(element)); disposables.add(this._onDidChangeAnimationVisibility.event(updateBlink)); const firstPupil = eyes.firstElementChild?.firstElementChild; if (firstPupil) { @@ -2955,12 +2962,17 @@ export class ChatPetWidget extends Disposable { const image = dom.append(element, dom.$('img.chat-pet-spritesheet')) as HTMLImageElement; image.alt = ''; const getSource = (): ChatPetSpriteSource => { + if (respawnPhase === 'despawning' || respawnPhase === 'respawning') { + const sources = getRespawnSpriteSources(this._variant); + return this._motionReduced ? sources.reducedMotion : sources.animated; + } const sources = getChatPetSpriteSources(this._variant)[state]; return stacked && state === 'idle' ? { ...sources.animated, frameIndices: [CHAT_PET_FOLDED_ANTENNAE_FRAME], frameDurations: [], iterations: 1 } : this._motionReduced ? sources.reducedMotion : sources.animated; }; const setState = (nextState: 'idle' | 'splat') => { + respawnTimer.cancel(); animation.clear(); state = nextState; updateBlink(); @@ -2991,6 +3003,14 @@ export class ChatPetWidget extends Disposable { }; updateAccessory(); disposables.add(dom.addDisposableListener(image, 'load', () => { + if (respawnPhase === 'despawning' || respawnPhase === 'respawning') { + eyes.classList.remove('tracking', 'bobbed'); + this._startSpriteAnimation(getSource(), sprite, animation, advanceRespawn, respawnPhase === 'despawning'); + if (this._motionReduced) { + respawnTimer.schedule(); + } + return; + } if (state === 'splat' && this._motionReduced) { setState('idle'); return; @@ -3010,7 +3030,10 @@ export class ChatPetWidget extends Disposable { disposables.add(dom.addDisposableListener(element, 'animationend', event => { if (event.target === element && (event as AnimationEvent).animationName === 'chat-pet-subagent-fall') { element.classList.remove('arriving'); - if (!this._motionReduced) { + if (respawnPhase === 'falling') { + respawnPhase = 'despawning'; + setState('idle'); + } else if (!this._motionReduced && !stacked) { setState('splat'); } this._updateSubagentStacking(); @@ -3025,14 +3048,21 @@ export class ChatPetWidget extends Disposable { if (motionChanged || variantChanged) { if (this._motionReduced) { element.classList.remove('arriving'); + if (respawnPhase === 'falling') { + respawnPhase = 'despawning'; + } } setState(this._motionReduced ? 'idle' : state); } else { sprite.redrawFrame?.(); } }; - const fallTo = (top: number) => { + const fallTo = (top: number, respawn = false) => { const previousTop = element.getBoundingClientRect().top - this._overlay.getBoundingClientRect().top; + respawnPhase = respawn ? 'falling' : 'none'; + if (respawn) { + stacked = false; + } element.classList.remove('arriving'); element.style.top = `${top}px`; setState('idle'); @@ -3043,18 +3073,37 @@ export class ChatPetWidget extends Disposable { // Restart the existing fall animation, including when another support disappears mid-fall. void element.offsetWidth; element.classList.add('arriving'); + } else if (respawn) { + respawnPhase = 'despawning'; + setState('idle'); + } + }; + const advanceRespawn = () => { + const overlay = this._overlay.getBoundingClientRect(); + const input = this.dragBounds.getBoundingClientRect(); + const size = CHAT_PET_DISPLAY_SIZE * Number.parseFloat(element.style.getPropertyValue('--chat-pet-subagent-scale')); + if (respawnPhase === 'despawning') { + respawnPhase = 'respawning'; + element.style.left = `${Math.max(input.left - overlay.left, Math.min(Number.parseFloat(element.style.left), input.right - overlay.left - size))}px`; + element.style.top = `${this.movementBounds.getBoundingClientRect().top - overlay.top}px`; + setState('idle'); + } else if (respawnPhase === 'respawning') { + const landing = getChatPetFallTarget(overlay.left + Number.parseFloat(element.style.left), -size, size, size, this._getPlatforms(), input.top); + fallTo(landing.top - overlay.top); + this._constrainSubagentPets(); + this._updateSubagentStacking(); } }; const updateStacked = (value: boolean) => { if (stacked !== value) { stacked = value; - if (state === 'idle') { + if (respawnPhase === 'none' && (state === 'idle' || stacked)) { setState('idle'); } } }; setState('idle'); - this._subagentPets.set(id, { element, canvas, image, get accessoryImage() { return accessoryImage; }, eyes, disposables, updateBlink, updateAppearance, fallTo, updateStacked }); + this._subagentPets.set(id, { element, canvas, image, get accessoryImage() { return accessoryImage; }, eyes, disposables, updateBlink, updateAppearance, fallTo, updateStacked, isRespawning: () => respawnPhase !== 'none' }); } this._constrainSubagentPets(); if (removed) { @@ -3065,7 +3114,7 @@ export class ChatPetWidget extends Disposable { /** Hold the folded idle pose only while another mini pet is resting directly on this one. */ private _updateSubagentStacking(): void { - const pets = [...this._subagentPets.values()].map(pet => ({ + const pets = [...this._subagentPets.values()].filter(pet => !pet.isRespawning()).map(pet => ({ pet, left: Number.parseFloat(pet.element.style.left), top: Number.parseFloat(pet.element.style.top), @@ -3079,11 +3128,11 @@ export class ChatPetWidget extends Disposable { } /** Settle each column from the bottom up so remaining mini pets can support those above them. */ - private _settleSubagentPets(): void { + private _settleSubagentPets(platformChanged = false): void { const overlay = this._overlay.getBoundingClientRect(); const platforms = this._getPlatforms(); - const floor = Math.min(this.dragBounds.getBoundingClientRect().top, this.movementBounds.getBoundingClientRect().bottom); - const pets = [...this._subagentPets.values()].map(pet => ({ + const floor = platformChanged ? this.movementBounds.getBoundingClientRect().bottom : Math.min(this.dragBounds.getBoundingClientRect().top, this.movementBounds.getBoundingClientRect().bottom); + const pets = [...this._subagentPets.values()].filter(pet => !pet.isRespawning()).map(pet => ({ pet, left: Number.parseFloat(pet.element.style.left), top: Number.parseFloat(pet.element.style.top), @@ -3092,14 +3141,16 @@ export class ChatPetWidget extends Disposable { for (const [index, pet] of pets.entries()) { const landing = getChatPetFallTarget(overlay.left + pet.left, overlay.top + pet.top - POSITION_EPSILON, pet.size, pet.size, platforms, floor); let top = Math.max(pet.top, landing.top - overlay.top); + let supported = !!landing.platform; for (let below = 0; below < index; below++) { const support = pets[below]; - if (pet.left < support.left + support.size - POSITION_EPSILON && pet.left + pet.size > support.left + POSITION_EPSILON && support.top >= pet.top + pet.size - POSITION_EPSILON) { + if (!support.pet.isRespawning() && pet.left < support.left + support.size - POSITION_EPSILON && pet.left + pet.size > support.left + POSITION_EPSILON && support.top >= pet.top + pet.size - POSITION_EPSILON && support.top - pet.size <= top) { top = Math.min(top, support.top - pet.size); + supported = true; } } if (top > pet.top + POSITION_EPSILON) { - pet.pet.fallTo(top); + pet.pet.fallTo(top, platformChanged && !supported); pet.top = top; } } @@ -3107,23 +3158,25 @@ export class ChatPetWidget extends Disposable { /** Keep settled mini pets in a bounded area without coupling them to the main pet's movement. */ private _constrainSubagentPets(): void { - if (!this._subagentPets.size) { + const activePets = [...this._subagentPets.values()].filter(pet => !pet.isRespawning()); + if (!activePets.length) { return; } const overlay = this._overlay.getBoundingClientRect(); const input = this.dragBounds.getBoundingClientRect(); const movement = this.movementBounds.getBoundingClientRect(); - const minimumLeft = Math.max(input.left, movement.left) - overlay.left; - const maximumRight = Math.min(input.right, movement.right) - overlay.left; + const platform = getChatPetFallTarget(input.left + input.width / 2, movement.top - 1, 0, 0, this._getPlatforms(), input.top).platform; + const minimumLeft = Math.max(input.left, movement.left, platform?.left ?? input.left) - overlay.left; + const maximumRight = Math.min(input.right, movement.right, platform?.right ?? input.right) - overlay.left; const minimumTop = movement.top - overlay.top; // The input's top edge is the floor; the movement bounds also include the input itself. - const maximumBottom = Math.min(input.top, movement.bottom) - overlay.top; + const maximumBottom = Math.min(platform?.top ?? input.top, input.top, movement.bottom) - overlay.top; const width = Math.min(CHAT_PET_SUBAGENT_MAX_WIDTH, maximumRight - minimumLeft); const height = Math.min(CHAT_PET_SUBAGENT_MAX_HEIGHT, maximumBottom - minimumTop); if (width <= 0 || height <= 0) { return; } - const pets = [...this._subagentPets.values()].map(pet => ({ + const pets = activePets.map(pet => ({ element: pet.element, left: Number.parseFloat(pet.element.style.left), top: Number.parseFloat(pet.element.style.top), @@ -3133,7 +3186,9 @@ export class ChatPetWidget extends Disposable { const right = Math.max(...pets.map(pet => pet.left + pet.size)); const top = Math.min(...pets.map(pet => pet.top)); const bottom = Math.max(...pets.map(pet => pet.top + pet.size)); - if (left >= minimumLeft && right <= maximumRight && top >= minimumTop && bottom <= maximumBottom && right - left <= width && bottom - top <= height) { + const overlapping = pets.some((pet, index) => pets.slice(index + 1).some(other => pet.left < other.left + other.size - POSITION_EPSILON + && pet.left + pet.size > other.left + POSITION_EPSILON && pet.top < other.top + other.size - POSITION_EPSILON && pet.top + pet.size > other.top + POSITION_EPSILON)); + if (!overlapping && left >= minimumLeft && right <= maximumRight && top >= minimumTop && bottom <= maximumBottom && right - left <= width && bottom - top <= height) { return; } const columns = Math.min(pets.length, Math.ceil(Math.sqrt(pets.length * width / height))); diff --git a/src/vs/workbench/contrib/chat/test/browser/widget/chatPetWidget.test.ts b/src/vs/workbench/contrib/chat/test/browser/widget/chatPetWidget.test.ts index 2ac5c09f4f4b75..ae01a3fff6d9dc 100644 --- a/src/vs/workbench/contrib/chat/test/browser/widget/chatPetWidget.test.ts +++ b/src/vs/workbench/contrib/chat/test/browser/widget/chatPetWidget.test.ts @@ -2542,6 +2542,119 @@ suite('ChatPetWidget', () => { } } + test('mini pets keep a large initial group on the approval prompt', () => { + const { widget, firstHost, overlay, firstParent, button } = createHostTransitionHarness(true); + firstParent.style.width = '240px'; + button.style.left = '192px'; + const tools = Array.from({ length: 20 }, (_, index) => { + const id = `subagent-${index}`; + const tool = new ChatToolInvocation(undefined, { id, displayName: id, modelDescription: 'Subagent', source: ToolDataSource.Internal }, id, undefined, {}); + tool.toolSpecificData = { kind: 'subagent', isActive: true }; + return tool; + }); + widget.setHost({ ...firstHost, model: constObservable(createSubagentTestModel(tools)), getPlatforms: () => { + const bounds = firstParent.getBoundingClientRect(); + return [{ left: bounds.left + 20, right: bounds.right - 20, top: bounds.top - 60, isDefault: true }]; + } }); + const bounds = firstParent.getBoundingClientRect(); + const pets = [...overlay.querySelectorAll('.chat-pet-subagent')]; + assert.deepStrictEqual({ + count: pets.length, + onPrompt: pets.every(pet => { + const rect = pet.getBoundingClientRect(); + return rect.bottom <= bounds.top - 60 + 0.1 && rect.left >= bounds.left + 20 - 0.1 && rect.right <= bounds.right - 20 + 0.1; + }), + }, { count: 20, onPrompt: true }); + }); + + for (const reducedMotion of [false, true]) { + test(`mini pets fall and respawn when a prompt replaces their support (${reducedMotion ? 'reduced motion' : 'animated'})`, async () => { + const { widget, firstHost, overlay, firstParent, root, platformChanged } = createHostTransitionHarness(reducedMotion); + let promptVisible = false; + const tools = ['first', 'second'].map(id => { + const tool = new ChatToolInvocation(undefined, { id, displayName: id, modelDescription: 'Subagent', source: ToolDataSource.Internal }, id, undefined, {}); + tool.toolSpecificData = { kind: 'subagent', isActive: true }; + return tool; + }); + widget.setHost({ ...firstHost, model: constObservable(createSubagentTestModel(tools)), getPlatforms: () => { + const bounds = firstParent.getBoundingClientRect(); + return [{ left: bounds.left, right: bounds.right, top: bounds.top - (promptVisible ? 60 : 0), isDefault: true }]; + } }); + await timeout(1_300); + const pets = [...overlay.querySelectorAll('.chat-pet-subagent')]; + promptVisible = true; + platformChanged.fire(); + assert.ok(pets.every(pet => Math.abs(Number.parseFloat(pet.style.top) + 24 + overlay.getBoundingClientRect().top - root.getBoundingClientRect().bottom) < 0.1)); + await waitForPetAnimation(() => pets.every(pet => pet.querySelector('img')?.getAttribute('src')?.includes('buddy-respawn-') === true)); + await waitForPetAnimation(() => pets.every(pet => !pet.classList.contains('arriving') && pet.querySelector('img')?.getAttribute('src')?.includes('buddy-idle-') === true)); + assert.deepStrictEqual({ + identity: [...overlay.querySelectorAll('.chat-pet-subagent')], + onPrompt: pets.every(pet => Math.abs(pet.getBoundingClientRect().bottom - firstParent.getBoundingClientRect().top + 60) < 0.1), + }, { identity: pets, onPrompt: true }); + promptVisible = false; + platformChanged.fire(); + await waitForPetAnimation(() => pets.every(pet => !pet.classList.contains('arriving'))); + assert.ok(pets.every(pet => Math.abs(pet.getBoundingClientRect().bottom - firstParent.getBoundingClientRect().top) < 0.1)); + }); + } + + test('mini pets cancel a pending prompt respawn when their subagent finishes', async () => { + const { widget, firstHost, overlay, firstParent, platformChanged } = createHostTransitionHarness(true); + const changed = disposables.add(new Emitter()); + let promptVisible = false; + const tool = new ChatToolInvocation(undefined, { id: 'subagent', displayName: 'Subagent', modelDescription: 'Subagent', source: ToolDataSource.Internal }, 'subagent', undefined, {}); + tool.toolSpecificData = { kind: 'subagent', isActive: true }; + widget.setHost({ ...firstHost, model: constObservable(createSubagentTestModel([tool], changed.event)), getPlatforms: () => { + const bounds = firstParent.getBoundingClientRect(); + return [{ left: bounds.left, right: bounds.right, top: bounds.top - (promptVisible ? 60 : 0), isDefault: true }]; + } }); + promptVisible = true; + platformChanged.fire(); + const image = overlay.querySelector('.chat-pet-subagent img')!; + await whenSpriteLoaded(image); + assert.ok(image.getAttribute('src')?.includes('buddy-respawn-')); + tool.toolSpecificData = { kind: 'subagent', isActive: false }; + changed.fire({ reason: 'other' }); + await timeout(1_000); + assert.strictEqual(overlay.querySelectorAll('.chat-pet-subagent, .chat-pet-subagent-despawning').length, 0); + }); + + test('mini pets fold antennae after real arrivals and subsequent stacking', async () => { + const color = '#ec80ee'; + const { widget, firstHost, overlay } = createHostTransitionHarness(false, 'teleport', color); + const changed = disposables.add(new Emitter()); + const tools: ChatToolInvocation[] = []; + widget.setHost({ ...firstHost, model: constObservable(createSubagentTestModel(tools, changed.event)) }); + for (let index = 0; index < 20; index++) { + const id = `subagent-${index}`; + const tool = new ChatToolInvocation(undefined, { id, displayName: id, modelDescription: 'Subagent', source: ToolDataSource.Internal }, id, undefined, {}); + tool.toolSpecificData = { kind: 'subagent', isActive: true }; + tools.push(tool); + changed.fire({ reason: 'other' }); + await timeout(60); + } + const pets = [...overlay.querySelectorAll('.chat-pet-subagent')]; + await waitForPetAnimation(() => pets.every(pet => !pet.classList.contains('arriving') && pet.querySelector('img')?.getAttribute('src')?.includes('buddy-idle-') === true)); + const supporting = pets.filter(pet => pets.some(above => above !== pet + && Math.abs(above.getBoundingClientRect().bottom - pet.getBoundingClientRect().top) < 0.5 + && above.getBoundingClientRect().left < pet.getBoundingClientRect().right - 0.5 + && above.getBoundingClientRect().right > pet.getBoundingClientRect().left + 0.5)); + assert.ok(supporting.length > 0, JSON.stringify(pets.map(pet => ({ left: pet.style.left, top: pet.style.top, scale: pet.style.getPropertyValue('--chat-pet-subagent-scale'), rect: pet.getBoundingClientRect().toJSON() })))); + assert.deepStrictEqual(supporting.map(pet => ({ + arriving: pet.classList.contains('arriving'), + folded: !!pet.querySelector('.chat-pet-eyes.bobbed'), + idle: pet.querySelector('img')?.getAttribute('src')?.includes('buddy-idle-'), + })), supporting.map(() => ({ arriving: false, folded: true, idle: true }))); + for (const pet of supporting) { + const image = pet.querySelector('img')!; + await image.decode(); + const expected = mainWindow.document.createElement('canvas'); + expected.width = expected.height = 96; + expected.getContext('2d')!.drawImage(getChatPetColoredSprite(image, color), 20 * 96, 0, 96, 96, 0, 0, 96, 96); + assert.strictEqual(pet.querySelector('canvas')!.toDataURL(), expected.toDataURL()); + } + }); + for (const variant of ['stable', 'insiders'] as const) { for (const reducedMotion of [false, true]) { test(`mini pets hold folded antennae while supporting another pet (${variant}, ${reducedMotion ? 'reduced motion' : 'animated'})`, async () => { @@ -2579,6 +2692,10 @@ suite('ChatPetWidget', () => { { pixels: expected.toDataURL(), eyesLowered: frame === 20 }); }; checkFrame(20); + // The lower pet may finish its longer fall after the upper one has already landed. + bottom.dispatchEvent(new mainWindow.AnimationEvent('animationend', { animationName: 'chat-pet-subagent-fall' })); + assert.ok(image.getAttribute('src')?.includes('buddy-idle-')); + checkFrame(20); clock.tick(2_500); checkFrame(20); setReducedMotion(!reducedMotion); From 3786bbaaec61f7409399d3aaa15144931b05d210 Mon Sep 17 00:00:00 2001 From: Lisa Rosenberg Date: Thu, 12 Nov 2026 19:38:44 +0100 Subject: [PATCH 20/66] feat: remove folded antennae feature --- .../chat/browser/widget/chatPetWidget.ts | 49 +--------- .../test/browser/widget/chatPetWidget.test.ts | 96 ------------------- 2 files changed, 5 insertions(+), 140 deletions(-) diff --git a/src/vs/workbench/contrib/chat/browser/widget/chatPetWidget.ts b/src/vs/workbench/contrib/chat/browser/widget/chatPetWidget.ts index c47451549977d2..6e76b4dd35d0e2 100644 --- a/src/vs/workbench/contrib/chat/browser/widget/chatPetWidget.ts +++ b/src/vs/workbench/contrib/chat/browser/widget/chatPetWidget.ts @@ -146,7 +146,6 @@ const MOUSE_BOUNCE_MAX_HORIZONTAL_VELOCITY = 1_800; const CHAT_PET_DISPLAY_SIZE = 48; const CHAT_PET_SUBAGENT_MAX_WIDTH = 288; const CHAT_PET_SUBAGENT_MAX_HEIGHT = 96; -const CHAT_PET_FOLDED_ANTENNAE_FRAME = 20; const CHAT_PET_SOURCE_SIZE = 96; const CHAT_PET_SLEEP_SOURCE_WIDTH = 120; const CHAT_PET_TYPING_SOURCE_WIDTH = 168; @@ -228,7 +227,6 @@ interface ChatPetSubagent { readonly updateAppearance: (motionChanged: boolean, variantChanged: boolean, accessoryChanged: boolean) => void; readonly fallTo: (top: number, respawn?: boolean) => void; readonly isRespawning: () => boolean; - readonly updateStacked: (stacked: boolean) => void; } interface ChatPetPendingRender { @@ -1805,9 +1803,6 @@ export class ChatPetWidget extends Disposable { pet.updateAppearance(wasMotionReduced !== this._motionReduced, variantChanged, accessoryChanged); } } - if (wasMotionReduced !== this._motionReduced) { - this._updateSubagentStacking(); - } if (!enabled) { for (const pet of this._subagentPets.values()) { @@ -2248,7 +2243,6 @@ export class ChatPetWidget extends Disposable { private _handleHostLayoutChange(): void { this._constrainSubagentPets(); - this._updateSubagentStacking(); if (this._jumpGame.value) { this._jumpGame.value.layout(); return; @@ -2280,7 +2274,6 @@ export class ChatPetWidget extends Disposable { private _updatePlatformPosition(): void { if (this._enabled) { this._settleSubagentPets(true); - this._updateSubagentStacking(); } if (this._jumpGame.value) { this._jumpGame.value.layout(); @@ -2943,7 +2936,6 @@ export class ChatPetWidget extends Disposable { } const disposables = this._subagentEffects.add(new DisposableStore()); let state: 'idle' | 'splat' = 'idle'; - let stacked = false; let respawnPhase: 'none' | 'falling' | 'despawning' | 'respawning' = 'none'; const respawnTimer = disposables.add(new RunOnceScheduler(() => advanceRespawn(), RESPAWN_EFFECT_REDUCED_MOTION_DURATION)); const blink = disposables.add(new ChatPetBlinkController(blinking => eyes.classList.toggle('blink', blinking))); @@ -2967,9 +2959,7 @@ export class ChatPetWidget extends Disposable { return this._motionReduced ? sources.reducedMotion : sources.animated; } const sources = getChatPetSpriteSources(this._variant)[state]; - return stacked && state === 'idle' - ? { ...sources.animated, frameIndices: [CHAT_PET_FOLDED_ANTENNAE_FRAME], frameDurations: [], iterations: 1 } - : this._motionReduced ? sources.reducedMotion : sources.animated; + return this._motionReduced ? sources.reducedMotion : sources.animated; }; const setState = (nextState: 'idle' | 'splat') => { respawnTimer.cancel(); @@ -2977,7 +2967,7 @@ export class ChatPetWidget extends Disposable { state = nextState; updateBlink(); if (this._motionReduced) { - eyes.classList.toggle('bobbed', stacked && state === 'idle'); + eyes.classList.remove('bobbed'); } setChatPetImageSource(image, getSource().url); }; @@ -3018,7 +3008,7 @@ export class ChatPetWidget extends Disposable { const source = getSource(); eyes.classList.toggle('tracking', state === 'idle'); this._startSpriteAnimation(source, sprite, animation, state === 'splat' ? () => setState('idle') : undefined, false, frameIndex => { - eyes.classList.toggle('bobbed', state === 'idle' && (stacked || !this._motionReduced) && (source.accessoryRigFrame ?? frameIndex) >= CHAT_PET_FOLDED_ANTENNAE_FRAME); + eyes.classList.toggle('bobbed', state === 'idle' && !this._motionReduced && (source.accessoryRigFrame ?? frameIndex) >= 20); if (accessoryImage?.complete && accessoryImage.naturalWidth > 0 && accessory) { const context = canvas.getContext('2d'); if (context) { @@ -3033,10 +3023,9 @@ export class ChatPetWidget extends Disposable { if (respawnPhase === 'falling') { respawnPhase = 'despawning'; setState('idle'); - } else if (!this._motionReduced && !stacked) { + } else if (!this._motionReduced) { setState('splat'); } - this._updateSubagentStacking(); } })); const updateAppearance = (motionChanged: boolean, variantChanged: boolean, accessoryChanged: boolean) => { @@ -3060,9 +3049,6 @@ export class ChatPetWidget extends Disposable { const fallTo = (top: number, respawn = false) => { const previousTop = element.getBoundingClientRect().top - this._overlay.getBoundingClientRect().top; respawnPhase = respawn ? 'falling' : 'none'; - if (respawn) { - stacked = false; - } element.classList.remove('arriving'); element.style.top = `${top}px`; setState('idle'); @@ -3091,40 +3077,15 @@ export class ChatPetWidget extends Disposable { const landing = getChatPetFallTarget(overlay.left + Number.parseFloat(element.style.left), -size, size, size, this._getPlatforms(), input.top); fallTo(landing.top - overlay.top); this._constrainSubagentPets(); - this._updateSubagentStacking(); - } - }; - const updateStacked = (value: boolean) => { - if (stacked !== value) { - stacked = value; - if (respawnPhase === 'none' && (state === 'idle' || stacked)) { - setState('idle'); - } } }; setState('idle'); - this._subagentPets.set(id, { element, canvas, image, get accessoryImage() { return accessoryImage; }, eyes, disposables, updateBlink, updateAppearance, fallTo, updateStacked, isRespawning: () => respawnPhase !== 'none' }); + this._subagentPets.set(id, { element, canvas, image, get accessoryImage() { return accessoryImage; }, eyes, disposables, updateBlink, updateAppearance, fallTo, isRespawning: () => respawnPhase !== 'none' }); } this._constrainSubagentPets(); if (removed) { this._settleSubagentPets(); } - this._updateSubagentStacking(); - } - - /** Hold the folded idle pose only while another mini pet is resting directly on this one. */ - private _updateSubagentStacking(): void { - const pets = [...this._subagentPets.values()].filter(pet => !pet.isRespawning()).map(pet => ({ - pet, - left: Number.parseFloat(pet.element.style.left), - top: Number.parseFloat(pet.element.style.top), - size: CHAT_PET_DISPLAY_SIZE * Number.parseFloat(pet.element.style.getPropertyValue('--chat-pet-subagent-scale')), - })); - for (const pet of pets) { - pet.pet.updateStacked(pets.some(above => above !== pet && !above.pet.element.classList.contains('arriving') - && Math.abs(above.top + above.size - pet.top) <= POSITION_EPSILON - && pet.left < above.left + above.size - POSITION_EPSILON && pet.left + pet.size > above.left + POSITION_EPSILON)); - } } /** Settle each column from the bottom up so remaining mini pets can support those above them. */ diff --git a/src/vs/workbench/contrib/chat/test/browser/widget/chatPetWidget.test.ts b/src/vs/workbench/contrib/chat/test/browser/widget/chatPetWidget.test.ts index ae01a3fff6d9dc..9418ed1b30b056 100644 --- a/src/vs/workbench/contrib/chat/test/browser/widget/chatPetWidget.test.ts +++ b/src/vs/workbench/contrib/chat/test/browser/widget/chatPetWidget.test.ts @@ -2619,102 +2619,6 @@ suite('ChatPetWidget', () => { assert.strictEqual(overlay.querySelectorAll('.chat-pet-subagent, .chat-pet-subagent-despawning').length, 0); }); - test('mini pets fold antennae after real arrivals and subsequent stacking', async () => { - const color = '#ec80ee'; - const { widget, firstHost, overlay } = createHostTransitionHarness(false, 'teleport', color); - const changed = disposables.add(new Emitter()); - const tools: ChatToolInvocation[] = []; - widget.setHost({ ...firstHost, model: constObservable(createSubagentTestModel(tools, changed.event)) }); - for (let index = 0; index < 20; index++) { - const id = `subagent-${index}`; - const tool = new ChatToolInvocation(undefined, { id, displayName: id, modelDescription: 'Subagent', source: ToolDataSource.Internal }, id, undefined, {}); - tool.toolSpecificData = { kind: 'subagent', isActive: true }; - tools.push(tool); - changed.fire({ reason: 'other' }); - await timeout(60); - } - const pets = [...overlay.querySelectorAll('.chat-pet-subagent')]; - await waitForPetAnimation(() => pets.every(pet => !pet.classList.contains('arriving') && pet.querySelector('img')?.getAttribute('src')?.includes('buddy-idle-') === true)); - const supporting = pets.filter(pet => pets.some(above => above !== pet - && Math.abs(above.getBoundingClientRect().bottom - pet.getBoundingClientRect().top) < 0.5 - && above.getBoundingClientRect().left < pet.getBoundingClientRect().right - 0.5 - && above.getBoundingClientRect().right > pet.getBoundingClientRect().left + 0.5)); - assert.ok(supporting.length > 0, JSON.stringify(pets.map(pet => ({ left: pet.style.left, top: pet.style.top, scale: pet.style.getPropertyValue('--chat-pet-subagent-scale'), rect: pet.getBoundingClientRect().toJSON() })))); - assert.deepStrictEqual(supporting.map(pet => ({ - arriving: pet.classList.contains('arriving'), - folded: !!pet.querySelector('.chat-pet-eyes.bobbed'), - idle: pet.querySelector('img')?.getAttribute('src')?.includes('buddy-idle-'), - })), supporting.map(() => ({ arriving: false, folded: true, idle: true }))); - for (const pet of supporting) { - const image = pet.querySelector('img')!; - await image.decode(); - const expected = mainWindow.document.createElement('canvas'); - expected.width = expected.height = 96; - expected.getContext('2d')!.drawImage(getChatPetColoredSprite(image, color), 20 * 96, 0, 96, 96, 0, 0, 96, 96); - assert.strictEqual(pet.querySelector('canvas')!.toDataURL(), expected.toDataURL()); - } - }); - - for (const variant of ['stable', 'insiders'] as const) { - for (const reducedMotion of [false, true]) { - test(`mini pets hold folded antennae while supporting another pet (${variant}, ${reducedMotion ? 'reduced motion' : 'animated'})`, async () => { - const clock = sinon.useFakeTimers({ toFake: ['setTimeout', 'clearTimeout', 'performance'] }); - disposables.add(toDisposable(() => clock.restore())); - const { widget, firstHost, overlay, setReducedMotion } = createHostTransitionHarness(reducedMotion, 'teleport', variant); - const changed = disposables.add(new Emitter()); - const tools = ['bottom', 'top'].map(id => { - const tool = new ChatToolInvocation(undefined, { id, displayName: id, modelDescription: 'Subagent', source: ToolDataSource.Internal }, id, undefined, {}); - tool.toolSpecificData = { kind: 'subagent', isActive: true }; - return tool; - }); - widget.setHost({ ...firstHost, model: constObservable(createSubagentTestModel(tools, changed.event)) }); - const [bottom, top] = overlay.querySelectorAll('.chat-pet-subagent'); - const image = bottom.querySelector('img')!; - await Promise.all([whenSpriteLoaded(image), whenSpriteLoaded(top.querySelector('img')!)]); - bottom.classList.remove('arriving'); - bottom.style.left = top.style.left = '48px'; - bottom.style.top = '-24px'; - top.style.top = '-48px'; - changed.fire({ reason: 'other' }); - if (!reducedMotion) { - assert.ok(!bottom.querySelector('.chat-pet-eyes.bobbed')); - top.dispatchEvent(new mainWindow.AnimationEvent('animationend', { animationName: 'chat-pet-subagent-fall' })); - } - await whenSpriteLoaded(image); - const canvas = bottom.querySelector('canvas')!; - const expected = mainWindow.document.createElement('canvas'); - expected.width = expected.height = 96; - const checkFrame = (frame: number) => { - const context = expected.getContext('2d')!; - context.clearRect(0, 0, 96, 96); - context.drawImage(image, frame * 96, 0, 96, 96, 0, 0, 96, 96); - assert.deepStrictEqual({ pixels: canvas.toDataURL(), eyesLowered: !!bottom.querySelector('.chat-pet-eyes.bobbed') }, - { pixels: expected.toDataURL(), eyesLowered: frame === 20 }); - }; - checkFrame(20); - // The lower pet may finish its longer fall after the upper one has already landed. - bottom.dispatchEvent(new mainWindow.AnimationEvent('animationend', { animationName: 'chat-pet-subagent-fall' })); - assert.ok(image.getAttribute('src')?.includes('buddy-idle-')); - checkFrame(20); - clock.tick(2_500); - checkFrame(20); - setReducedMotion(!reducedMotion); - await whenSpriteLoaded(image); - checkFrame(20); - setReducedMotion(reducedMotion); - await whenSpriteLoaded(image); - tools[1].toolSpecificData = { kind: 'subagent', isActive: false }; - changed.fire({ reason: 'other' }); - await whenSpriteLoaded(image); - checkFrame(0); - if (!reducedMotion) { - clock.tick(800); - checkFrame(20); - } - }); - } - } - test('mini pets update appearance and motion settings while active', async () => { const { widget, firstHost, button, overlay, service, setReducedMotion } = createHostTransitionHarness(); const tool = new ChatToolInvocation(undefined, { id: 'subagent', displayName: 'Subagent', modelDescription: 'Subagent', source: ToolDataSource.Internal }, 'subagent', undefined, {}); From b907b641fb035b5f6c7865d79dc3b420ad108aaa Mon Sep 17 00:00:00 2001 From: Lisa Rosenberg Date: Thu, 12 Nov 2026 20:13:34 +0100 Subject: [PATCH 21/66] feat: make subagent pets appear more randomly --- .../chat/browser/widget/chatPetWidget.ts | 49 +++++++++++-------- .../test/browser/widget/chatPetWidget.test.ts | 43 +++++++++++++--- 2 files changed, 65 insertions(+), 27 deletions(-) diff --git a/src/vs/workbench/contrib/chat/browser/widget/chatPetWidget.ts b/src/vs/workbench/contrib/chat/browser/widget/chatPetWidget.ts index 6e76b4dd35d0e2..fb50dbdd41b54a 100644 --- a/src/vs/workbench/contrib/chat/browser/widget/chatPetWidget.ts +++ b/src/vs/workbench/contrib/chat/browser/widget/chatPetWidget.ts @@ -144,7 +144,6 @@ const MOUSE_BOUNCE_HORIZONTAL_TRANSFER = 0.35; const MOUSE_BOUNCE_EDGE_KICK = 320; const MOUSE_BOUNCE_MAX_HORIZONTAL_VELOCITY = 1_800; const CHAT_PET_DISPLAY_SIZE = 48; -const CHAT_PET_SUBAGENT_MAX_WIDTH = 288; const CHAT_PET_SUBAGENT_MAX_HEIGHT = 96; const CHAT_PET_SOURCE_SIZE = 96; const CHAT_PET_SLEEP_SOURCE_WIDTH = 120; @@ -2897,29 +2896,37 @@ export class ChatPetWidget extends Disposable { const element = dom.append(this._subagentLayer, dom.$('.chat-pet-subagent', { 'aria-hidden': 'true' })); const miniScale = 0.5 * (this._scale || 1); const petLeft = this._button.element.offsetLeft; - const bounds = this._getHorizontalBounds(); - const midpoint = bounds ? (bounds.minimumLeft + bounds.maximumLeft) / 2 : (this._overlay.clientWidth - this._getDisplaySize()) / 2; const miniWidth = 48 * miniScale; - const side = petLeft < midpoint ? 'right' : 'left'; - let slot = 0; - const getLeft = () => side === 'right' - ? petLeft + this._getDisplaySize() + miniWidth * slot - : petLeft - miniWidth * (slot + 1); - while ([...this._subagentPets.values()].some(pet => { - const otherLeft = Number.parseFloat(pet.element.style.left); - const otherWidth = 48 * Number.parseFloat(pet.element.style.getPropertyValue('--chat-pet-subagent-scale')); - return getLeft() < otherLeft + otherWidth && getLeft() + miniWidth > otherLeft; - })) { - slot++; - } - const left = getLeft(); const overlayBounds = this._overlay.getBoundingClientRect(); - const floor = Math.min(this.dragBounds.getBoundingClientRect().top, this.movementBounds.getBoundingClientRect().bottom); - const landing = getChatPetFallTarget(overlayBounds.left + left, -miniWidth, miniWidth, miniWidth, this._getPlatforms(), floor); + const input = this.dragBounds.getBoundingClientRect(); + const movement = this.movementBounds.getBoundingClientRect(); + const platforms = this._getPlatforms(); + const platform = getChatPetFallTarget(input.left + input.width / 2, movement.top - 1, 0, 0, platforms, input.top).platform; + const minimumLeft = Math.max(input.left, movement.left, platform?.left ?? input.left) - overlayBounds.left; + const maximumLeft = Math.max(minimumLeft, Math.min(input.right, movement.right, platform?.right ?? input.right) - overlayBounds.left - miniWidth); + const beforePet = Math.max(0, Math.min(maximumLeft, petLeft - miniWidth) - minimumLeft); + const afterPetStart = Math.max(minimumLeft, petLeft + this._getDisplaySize()); + const afterPet = Math.max(0, maximumLeft - afterPetStart); + const available = beforePet + afterPet; + const offset = Math.random() * available; + const left = available > 0 ? (offset < beforePet ? minimumLeft + offset : afterPetStart + offset - beforePet) : minimumLeft; + const floor = Math.min(input.top, movement.bottom); + const landing = getChatPetFallTarget(overlayBounds.left + left, -miniWidth, miniWidth, miniWidth, platforms, floor); + let top = landing.top - overlayBounds.top; + for (const other of this._subagentPets.values()) { + if (other.isRespawning()) { + continue; + } + const otherLeft = Number.parseFloat(other.element.style.left); + const otherWidth = 48 * Number.parseFloat(other.element.style.getPropertyValue('--chat-pet-subagent-scale')); + if (left < otherLeft + otherWidth - POSITION_EPSILON && left + miniWidth > otherLeft + POSITION_EPSILON) { + top = Math.min(top, Number.parseFloat(other.element.style.top) - miniWidth); + } + } element.style.left = `${left}px`; - element.style.top = `${landing.top - overlayBounds.top}px`; + element.style.top = `${top}px`; element.style.setProperty('--chat-pet-subagent-scale', String(miniScale)); - const distance = Math.max(0, landing.top + miniWidth); + const distance = Math.max(0, overlayBounds.top + top + miniWidth); element.style.setProperty('--chat-pet-subagent-fall-distance', `${distance}px`); element.style.setProperty('--chat-pet-subagent-fall-duration', `${getChatPetFallDuration(distance)}ms`); if (!this._motionReduced) { @@ -3132,7 +3139,7 @@ export class ChatPetWidget extends Disposable { const minimumTop = movement.top - overlay.top; // The input's top edge is the floor; the movement bounds also include the input itself. const maximumBottom = Math.min(platform?.top ?? input.top, input.top, movement.bottom) - overlay.top; - const width = Math.min(CHAT_PET_SUBAGENT_MAX_WIDTH, maximumRight - minimumLeft); + const width = maximumRight - minimumLeft; const height = Math.min(CHAT_PET_SUBAGENT_MAX_HEIGHT, maximumBottom - minimumTop); if (width <= 0 || height <= 0) { return; diff --git a/src/vs/workbench/contrib/chat/test/browser/widget/chatPetWidget.test.ts b/src/vs/workbench/contrib/chat/test/browser/widget/chatPetWidget.test.ts index 9418ed1b30b056..206a905bf92cd7 100644 --- a/src/vs/workbench/contrib/chat/test/browser/widget/chatPetWidget.test.ts +++ b/src/vs/workbench/contrib/chat/test/browser/widget/chatPetWidget.test.ts @@ -2322,7 +2322,7 @@ suite('ChatPetWidget', () => { button.style.top = '-140px'; createSubagent('second'); const minis = overlay.querySelectorAll('.chat-pet-subagent'); - assert.ok(minis[1].offsetLeft < button.offsetLeft); + assert.ok(minis[1].offsetLeft + miniSize <= button.offsetLeft || minis[1].offsetLeft >= button.offsetLeft + button.offsetWidth); assert.strictEqual(Number.parseFloat(minis[1].style.top) + miniSize, -60); assert.strictEqual(overlay.querySelectorAll('.chat-pet-subagent').length, 2); assert.strictEqual(overlay.querySelectorAll('.chat-pet-subagent.arriving').length, 2); @@ -2365,7 +2365,7 @@ suite('ChatPetWidget', () => { }, model); const pet = overlay.querySelector('.chat-pet-subagent')!; assert.strictEqual(Number.parseFloat(pet.style.getPropertyValue('--chat-pet-subagent-scale')), 1); - assert.ok(pet.offsetLeft < button.offsetLeft); + assert.ok(pet.offsetLeft + 48 <= button.offsetLeft || pet.offsetLeft >= button.offsetLeft + button.offsetWidth); }); test('mini pets stop when disabled and return for active subagents when re-enabled', async () => { @@ -2406,7 +2406,38 @@ suite('ChatPetWidget', () => { button.style.left = '324px'; add('second'); const [first, second] = overlay.querySelectorAll('.chat-pet-subagent'); - assert.ok(second.offsetLeft + 24 <= first.offsetLeft || first.offsetLeft + 24 <= second.offsetLeft); + assert.ok(second.offsetLeft + 24 <= first.offsetLeft || first.offsetLeft + 24 <= second.offsetLeft + || Number.parseFloat(second.style.top) + 24 <= Number.parseFloat(first.style.top) || Number.parseFloat(first.style.top) + 24 <= Number.parseFloat(second.style.top)); + }); + + test('mini pets spawn across the platform and stack where their paths overlap', () => { + const { widget, firstHost, button, overlay, firstParent, layout } = createHostTransitionHarness(true); + const changed = disposables.add(new Emitter()); + const parts: IChatProgressResponseContent[] = []; + widget.setHost({ ...firstHost, model: constObservable(createSubagentTestModel(parts, changed.event)) }); + button.style.left = '300px'; + const random = sinon.stub(Math, 'random'); + const add = (id: string, position: number) => { + random.returns(position); + const tool = new ChatToolInvocation(undefined, { id, displayName: id, modelDescription: 'Subagent', source: ToolDataSource.Internal }, id, undefined, {}); + tool.toolSpecificData = { kind: 'subagent', isActive: true }; + parts.push(tool); + changed.fire({ reason: 'other' }); + }; + add('left', 0.1); + add('right', 0.9); + add('above', 0.1); + const [left, right, above] = [...overlay.querySelectorAll('.chat-pet-subagent')]; + assert.ok(right.offsetLeft - left.offsetLeft > 200); + assert.strictEqual(above.style.left, left.style.left); + assert.strictEqual(Number.parseFloat(above.style.top) + 24, Number.parseFloat(left.style.top)); + firstParent.style.width = '120px'; + layout(); + const bounds = firstParent.getBoundingClientRect(); + const rects = [left, right, above].map(pet => pet.getBoundingClientRect()); + assert.ok(rects.every(rect => rect.left >= bounds.left - 0.1 && rect.right <= bounds.right + 0.1 && rect.bottom <= bounds.top + 0.1)); + assert.ok(rects.every((rect, index) => rects.slice(index + 1).every(other => + rect.right <= other.left + 0.1 || other.right <= rect.left + 0.1 || rect.bottom <= other.top + 0.1 || other.bottom <= rect.top + 0.1))); }); for (const petLeft of [0, 192]) { @@ -2472,7 +2503,7 @@ suite('ChatPetWidget', () => { assert.deepStrictEqual({ count: rects.length, withinChat: left >= input.left - 0.1 && right <= input.right + 0.1 && top >= movement.top - 0.1 && bottom <= Math.min(input.top, movement.bottom) + 0.1, - bounded: right - left <= 288.1 && bottom - top <= 96.1, + bounded: right - left <= input.width + 0.1 && bottom - top <= 96.1, visible: rects.every(rect => rect.width > 0 && rect.height > 0), overlaps, }, { count, withinChat: true, bounded: true, visible: true, overlaps: false }); @@ -2589,12 +2620,12 @@ suite('ChatPetWidget', () => { await waitForPetAnimation(() => pets.every(pet => !pet.classList.contains('arriving') && pet.querySelector('img')?.getAttribute('src')?.includes('buddy-idle-') === true)); assert.deepStrictEqual({ identity: [...overlay.querySelectorAll('.chat-pet-subagent')], - onPrompt: pets.every(pet => Math.abs(pet.getBoundingClientRect().bottom - firstParent.getBoundingClientRect().top + 60) < 0.1), + onPrompt: pets.every(pet => pet.getBoundingClientRect().bottom <= firstParent.getBoundingClientRect().top - 60 + 0.1), }, { identity: pets, onPrompt: true }); promptVisible = false; platformChanged.fire(); await waitForPetAnimation(() => pets.every(pet => !pet.classList.contains('arriving'))); - assert.ok(pets.every(pet => Math.abs(pet.getBoundingClientRect().bottom - firstParent.getBoundingClientRect().top) < 0.1)); + assert.ok(pets.every(pet => pet.getBoundingClientRect().bottom <= firstParent.getBoundingClientRect().top + 0.1)); }); } From 9b8d04b031b72b15a879e14eed2bf4e682abb8b7 Mon Sep 17 00:00:00 2001 From: Lisa Rosenberg Date: Thu, 12 Nov 2026 20:28:14 +0100 Subject: [PATCH 22/66] feat: let blobbys which do not fit fall and respawn --- .../chat/browser/widget/chatPetWidget.ts | 163 +++++++++++++----- .../test/browser/widget/chatPetWidget.test.ts | 55 +++++- 2 files changed, 172 insertions(+), 46 deletions(-) diff --git a/src/vs/workbench/contrib/chat/browser/widget/chatPetWidget.ts b/src/vs/workbench/contrib/chat/browser/widget/chatPetWidget.ts index fb50dbdd41b54a..b8938205da3565 100644 --- a/src/vs/workbench/contrib/chat/browser/widget/chatPetWidget.ts +++ b/src/vs/workbench/contrib/chat/browser/widget/chatPetWidget.ts @@ -145,6 +145,7 @@ const MOUSE_BOUNCE_EDGE_KICK = 320; const MOUSE_BOUNCE_MAX_HORIZONTAL_VELOCITY = 1_800; const CHAT_PET_DISPLAY_SIZE = 48; const CHAT_PET_SUBAGENT_MAX_HEIGHT = 96; +const CHAT_PET_SUBAGENT_BOUNDARY_EPSILON = 0.01; const CHAT_PET_SOURCE_SIZE = 96; const CHAT_PET_SLEEP_SOURCE_WIDTH = 120; const CHAT_PET_TYPING_SOURCE_WIDTH = 168; @@ -1263,6 +1264,7 @@ export class ChatPetWidget extends Disposable { private readonly _subagentPets = new Map(); private _subagentModel: IChatModel | undefined; private readonly _subagentEffects = this._register(new DisposableStore()); + private readonly _subagentResizeScheduler = this._register(new RunOnceScheduler(() => this._reconcileSubagentResize(), 120)); private readonly _subagentLayer: HTMLElement; private parent: HTMLElement; private dragBounds: HTMLElement; @@ -1804,6 +1806,7 @@ export class ChatPetWidget extends Disposable { } if (!enabled) { + this._subagentResizeScheduler.cancel(); for (const pet of this._subagentPets.values()) { pet.element.remove(); } @@ -2241,7 +2244,9 @@ export class ChatPetWidget extends Disposable { } private _handleHostLayoutChange(): void { - this._constrainSubagentPets(); + if (this._subagentPets.size) { + this._subagentResizeScheduler.schedule(); + } if (this._jumpGame.value) { this._jumpGame.value.layout(); return; @@ -2880,6 +2885,50 @@ export class ChatPetWidget extends Disposable { return this._button.element.offsetLeft; } + /** Choose a random landing point, accounting for mini pets already on the platform. */ + private _getSubagentLanding(size: number): { left: number; top: number } { + const overlay = this._overlay.getBoundingClientRect(); + const input = this.dragBounds.getBoundingClientRect(); + const movement = this.movementBounds.getBoundingClientRect(); + const platforms = this._getPlatforms(); + const platform = getChatPetFallTarget(input.left + input.width / 2, movement.top - 1, 0, 0, platforms, input.top).platform; + const minimumLeft = Math.max(input.left, movement.left, platform?.left ?? input.left) - overlay.left; + const maximumLeft = Math.max(minimumLeft, Math.min(input.right, movement.right, platform?.right ?? input.right) - overlay.left - size); + const petLeft = this._button.element.offsetLeft; + const beforePet = Math.max(0, Math.min(maximumLeft, petLeft - size) - minimumLeft); + const afterPetStart = Math.max(minimumLeft, petLeft + this._getDisplaySize()); + const afterPet = Math.max(0, maximumLeft - afterPetStart); + const available = beforePet + afterPet; + const floor = Math.min(input.top, movement.bottom); + const minimumTop = Math.max(movement.top, Math.min(platform?.top ?? input.top, floor) - CHAT_PET_SUBAGENT_MAX_HEIGHT) - overlay.top; + const attempts = Math.max(1, Math.ceil(available / Math.max(1, size / 2))); + const start = Math.random() * available; + let best: { left: number; top: number } | undefined; + for (let index = 0; index < attempts; index++) { + const offset = available > 0 ? (start + index * available / attempts) % available : 0; + const left = available > 0 ? (offset < beforePet ? minimumLeft + offset : afterPetStart + offset - beforePet) : minimumLeft; + const landing = getChatPetFallTarget(overlay.left + left, -size, size, size, platforms, floor); + let top = landing.top - overlay.top; + for (const other of this._subagentPets.values()) { + if (other.isRespawning()) { + continue; + } + const otherLeft = Number.parseFloat(other.element.style.left); + const otherWidth = CHAT_PET_DISPLAY_SIZE * Number.parseFloat(other.element.style.getPropertyValue('--chat-pet-subagent-scale')); + if (left < otherLeft + otherWidth && left + size > otherLeft) { + top = Math.min(top, Number.parseFloat(other.element.style.top) - size); + } + } + if (top >= minimumTop - CHAT_PET_SUBAGENT_BOUNDARY_EPSILON) { + return { left, top }; + } + if (!best || top > best.top) { + best = { left, top }; + } + } + return best!; + } + private _updateSubagentPets(subagents: ReadonlySet): void { let removed = false; for (const [id, pet] of this._subagentPets) { @@ -2895,34 +2944,9 @@ export class ChatPetWidget extends Disposable { } const element = dom.append(this._subagentLayer, dom.$('.chat-pet-subagent', { 'aria-hidden': 'true' })); const miniScale = 0.5 * (this._scale || 1); - const petLeft = this._button.element.offsetLeft; const miniWidth = 48 * miniScale; const overlayBounds = this._overlay.getBoundingClientRect(); - const input = this.dragBounds.getBoundingClientRect(); - const movement = this.movementBounds.getBoundingClientRect(); - const platforms = this._getPlatforms(); - const platform = getChatPetFallTarget(input.left + input.width / 2, movement.top - 1, 0, 0, platforms, input.top).platform; - const minimumLeft = Math.max(input.left, movement.left, platform?.left ?? input.left) - overlayBounds.left; - const maximumLeft = Math.max(minimumLeft, Math.min(input.right, movement.right, platform?.right ?? input.right) - overlayBounds.left - miniWidth); - const beforePet = Math.max(0, Math.min(maximumLeft, petLeft - miniWidth) - minimumLeft); - const afterPetStart = Math.max(minimumLeft, petLeft + this._getDisplaySize()); - const afterPet = Math.max(0, maximumLeft - afterPetStart); - const available = beforePet + afterPet; - const offset = Math.random() * available; - const left = available > 0 ? (offset < beforePet ? minimumLeft + offset : afterPetStart + offset - beforePet) : minimumLeft; - const floor = Math.min(input.top, movement.bottom); - const landing = getChatPetFallTarget(overlayBounds.left + left, -miniWidth, miniWidth, miniWidth, platforms, floor); - let top = landing.top - overlayBounds.top; - for (const other of this._subagentPets.values()) { - if (other.isRespawning()) { - continue; - } - const otherLeft = Number.parseFloat(other.element.style.left); - const otherWidth = 48 * Number.parseFloat(other.element.style.getPropertyValue('--chat-pet-subagent-scale')); - if (left < otherLeft + otherWidth - POSITION_EPSILON && left + miniWidth > otherLeft + POSITION_EPSILON) { - top = Math.min(top, Number.parseFloat(other.element.style.top) - miniWidth); - } - } + const { left, top } = this._getSubagentLanding(miniWidth); element.style.left = `${left}px`; element.style.top = `${top}px`; element.style.setProperty('--chat-pet-subagent-scale', String(miniScale)); @@ -3081,8 +3105,9 @@ export class ChatPetWidget extends Disposable { element.style.top = `${this.movementBounds.getBoundingClientRect().top - overlay.top}px`; setState('idle'); } else if (respawnPhase === 'respawning') { - const landing = getChatPetFallTarget(overlay.left + Number.parseFloat(element.style.left), -size, size, size, this._getPlatforms(), input.top); - fallTo(landing.top - overlay.top); + const landing = this._getSubagentLanding(size); + element.style.left = `${landing.left}px`; + fallTo(landing.top); this._constrainSubagentPets(); } }; @@ -3112,7 +3137,7 @@ export class ChatPetWidget extends Disposable { let supported = !!landing.platform; for (let below = 0; below < index; below++) { const support = pets[below]; - if (!support.pet.isRespawning() && pet.left < support.left + support.size - POSITION_EPSILON && pet.left + pet.size > support.left + POSITION_EPSILON && support.top >= pet.top + pet.size - POSITION_EPSILON && support.top - pet.size <= top) { + if (!support.pet.isRespawning() && pet.left < support.left + support.size && pet.left + pet.size > support.left && support.top >= pet.top + pet.size - POSITION_EPSILON && support.top - pet.size <= top) { top = Math.min(top, support.top - pet.size); supported = true; } @@ -3124,7 +3149,59 @@ export class ChatPetWidget extends Disposable { } } - /** Keep settled mini pets in a bounded area without coupling them to the main pet's movement. */ + /** Relocate only mini pets that no longer fit after resizing has settled. */ + private _reconcileSubagentResize(): void { + const pets = [...this._subagentPets.values()].filter(pet => !pet.isRespawning()); + if (!pets.length) { + return; + } + const overlay = this._overlay.getBoundingClientRect(); + const input = this.dragBounds.getBoundingClientRect(); + const movement = this.movementBounds.getBoundingClientRect(); + const platform = getChatPetFallTarget(input.left + input.width / 2, movement.top - 1, 0, 0, this._getPlatforms(), input.top).platform; + const left = Math.max(input.left, movement.left, platform?.left ?? input.left) - overlay.left; + const right = Math.min(input.right, movement.right, platform?.right ?? input.right) - overlay.left; + const bottom = Math.min(platform?.top ?? input.top, input.top, movement.bottom) - overlay.top; + const height = Math.min(CHAT_PET_SUBAGENT_MAX_HEIGHT, bottom - (movement.top - overlay.top)); + const width = right - left; + if (width <= 0 || height <= 0) { + return; + } + const maxSize = Math.max(...pets.map(pet => CHAT_PET_DISPLAY_SIZE * Number.parseFloat(pet.element.style.getPropertyValue('--chat-pet-subagent-scale')))); + const count = this._subagentPets.size; + const mainLeft = this._button.element.offsetLeft; + const blockedWidth = Math.max(0, Math.min(right, mainLeft + this._getDisplaySize()) - Math.max(left, mainLeft)); + const placementWidth = width > blockedWidth ? width - blockedWidth : width; + if (Math.floor(placementWidth / maxSize) * Math.floor(height / maxSize) < count) { + let fitSize = 0; + for (let columns = 1; columns <= count; columns++) { + fitSize = Math.max(fitSize, Math.min(placementWidth / columns, height / Math.ceil(count / columns))); + } + // Leave room for irregular, randomly positioned stacks rather than assuming a packed grid. + const factor = Math.min(1, fitSize * 0.8 / maxSize); + for (const pet of pets) { + const scale = Number.parseFloat(pet.element.style.getPropertyValue('--chat-pet-subagent-scale')); + const size = CHAT_PET_DISPLAY_SIZE * scale; + pet.element.style.top = `${Number.parseFloat(pet.element.style.top) + size * (1 - factor)}px`; + pet.element.style.setProperty('--chat-pet-subagent-scale', String(scale * factor)); + } + } + let displaced = false; + for (const pet of pets) { + const petLeft = Number.parseFloat(pet.element.style.left); + const petTop = Number.parseFloat(pet.element.style.top); + const size = CHAT_PET_DISPLAY_SIZE * Number.parseFloat(pet.element.style.getPropertyValue('--chat-pet-subagent-scale')); + if (petLeft < left - CHAT_PET_SUBAGENT_BOUNDARY_EPSILON || petLeft + size > right + CHAT_PET_SUBAGENT_BOUNDARY_EPSILON || petTop < movement.top - overlay.top - CHAT_PET_SUBAGENT_BOUNDARY_EPSILON || petTop + size > bottom + CHAT_PET_SUBAGENT_BOUNDARY_EPSILON) { + displaced = true; + pet.fallTo(movement.bottom - overlay.top - size, true); + } + } + if (displaced) { + this._settleSubagentPets(); + } + } + + /** Shrink an unusually tall group without rearranging it into a grid. */ private _constrainSubagentPets(): void { const activePets = [...this._subagentPets.values()].filter(pet => !pet.isRespawning()); if (!activePets.length) { @@ -3154,22 +3231,22 @@ export class ChatPetWidget extends Disposable { const right = Math.max(...pets.map(pet => pet.left + pet.size)); const top = Math.min(...pets.map(pet => pet.top)); const bottom = Math.max(...pets.map(pet => pet.top + pet.size)); - const overlapping = pets.some((pet, index) => pets.slice(index + 1).some(other => pet.left < other.left + other.size - POSITION_EPSILON - && pet.left + pet.size > other.left + POSITION_EPSILON && pet.top < other.top + other.size - POSITION_EPSILON && pet.top + pet.size > other.top + POSITION_EPSILON)); - if (!overlapping && left >= minimumLeft && right <= maximumRight && top >= minimumTop && bottom <= maximumBottom && right - left <= width && bottom - top <= height) { + if (left < minimumLeft - CHAT_PET_SUBAGENT_BOUNDARY_EPSILON || right > maximumRight + CHAT_PET_SUBAGENT_BOUNDARY_EPSILON || bottom > maximumBottom + CHAT_PET_SUBAGENT_BOUNDARY_EPSILON) { + this._subagentResizeScheduler.schedule(); return; } - const columns = Math.min(pets.length, Math.ceil(Math.sqrt(pets.length * width / height))); - const rows = Math.ceil(pets.length / columns); - const size = Math.min(Math.max(...pets.map(pet => pet.size)), width / columns, height / rows); - const gridLeft = Math.max(minimumLeft, Math.min(left, maximumRight - columns * size)); - const gridBottom = Math.max(minimumTop + rows * size, Math.min(bottom, maximumBottom)); - for (const [index, pet] of pets.entries()) { - const petTop = gridBottom - (Math.floor(index / columns) + 1) * size; - const distance = Math.max(0, overlay.top + petTop + size); - pet.element.style.left = `${gridLeft + index % columns * size}px`; + if (bottom - top <= height) { + return; + } + const factor = Math.min(1, height / (bottom - top), width / Math.max(1, right - left)); + const scaledLeft = Math.max(minimumLeft, Math.min(left, maximumRight - (right - left) * factor)); + for (const pet of pets) { + const petTop = bottom - (bottom - pet.top) * factor; + const size = pet.size * factor; + pet.element.style.left = `${scaledLeft + (pet.left - left) * factor}px`; pet.element.style.top = `${petTop}px`; pet.element.style.setProperty('--chat-pet-subagent-scale', String(size / CHAT_PET_DISPLAY_SIZE)); + const distance = Math.max(0, overlay.top + petTop + size); pet.element.style.setProperty('--chat-pet-subagent-fall-distance', `${distance}px`); pet.element.style.setProperty('--chat-pet-subagent-fall-duration', `${getChatPetFallDuration(distance)}ms`); } diff --git a/src/vs/workbench/contrib/chat/test/browser/widget/chatPetWidget.test.ts b/src/vs/workbench/contrib/chat/test/browser/widget/chatPetWidget.test.ts index 206a905bf92cd7..329af24dbe4ac8 100644 --- a/src/vs/workbench/contrib/chat/test/browser/widget/chatPetWidget.test.ts +++ b/src/vs/workbench/contrib/chat/test/browser/widget/chatPetWidget.test.ts @@ -2410,7 +2410,7 @@ suite('ChatPetWidget', () => { || Number.parseFloat(second.style.top) + 24 <= Number.parseFloat(first.style.top) || Number.parseFloat(first.style.top) + 24 <= Number.parseFloat(second.style.top)); }); - test('mini pets spawn across the platform and stack where their paths overlap', () => { + test('mini pets spawn across the platform and stack where their paths overlap', async () => { const { widget, firstHost, button, overlay, firstParent, layout } = createHostTransitionHarness(true); const changed = disposables.add(new Emitter()); const parts: IChatProgressResponseContent[] = []; @@ -2434,12 +2434,51 @@ suite('ChatPetWidget', () => { firstParent.style.width = '120px'; layout(); const bounds = firstParent.getBoundingClientRect(); + await waitForPetAnimation(() => [left, right, above].every(pet => { + const rect = pet.getBoundingClientRect(); + return rect.left >= bounds.left - 0.1 && rect.right <= bounds.right + 0.1 && rect.bottom <= bounds.top + 0.1 && pet.querySelector('img')?.getAttribute('src')?.includes('buddy-idle-'); + })); const rects = [left, right, above].map(pet => pet.getBoundingClientRect()); assert.ok(rects.every(rect => rect.left >= bounds.left - 0.1 && rect.right <= bounds.right + 0.1 && rect.bottom <= bounds.top + 0.1)); assert.ok(rects.every((rect, index) => rects.slice(index + 1).every(other => rect.right <= other.left + 0.1 || other.right <= rect.left + 0.1 || rect.bottom <= other.top + 0.1 || other.bottom <= rect.top + 0.1))); }); + for (const reducedMotion of [false, true]) { + test(`mini pets resize once and only displaced pets respawn (${reducedMotion ? 'reduced motion' : 'animated'})`, async () => { + const { widget, firstHost, overlay, firstParent, layout } = createHostTransitionHarness(reducedMotion); + const tools = ['stays', 'upper', 'support', 'outside'].map(id => { + const tool = new ChatToolInvocation(undefined, { id, displayName: id, modelDescription: 'Subagent', source: ToolDataSource.Internal }, id, undefined, {}); + tool.toolSpecificData = { kind: 'subagent', isActive: true }; + return tool; + }); + widget.setHost({ ...firstHost, model: constObservable(createSubagentTestModel(tools)) }); + const pets = [...overlay.querySelectorAll('.chat-pet-subagent')]; + for (const [index, pet] of pets.entries()) { + pet.classList.remove('arriving'); + pet.style.left = `${[20, 90, 100, 220][index]}px`; + pet.style.top = `${index === 1 ? -48 : -24}px`; + } + firstParent.style.width = '120px'; + layout(); + layout(); + layout(); + assert.deepStrictEqual(pets.map(pet => pet.style.left), ['20px', '90px', '100px', '220px']); + await waitForPetAnimation(() => pets[2].querySelector('img')?.getAttribute('src')?.includes('buddy-respawn-') === true + && pets[3].querySelector('img')?.getAttribute('src')?.includes('buddy-respawn-') === true); + assert.deepStrictEqual({ + stays: [pets[0].style.left, pets[0].style.top], + upper: [pets[1].style.left, pets[1].style.top], + }, { stays: ['20px', '-24px'], upper: ['90px', '-24px'] }); + await waitForPetAnimation(() => pets.every(pet => !pet.classList.contains('arriving') && pet.querySelector('img')?.getAttribute('src')?.includes('buddy-idle-') === true)); + const input = firstParent.getBoundingClientRect(); + const rects = pets.map(pet => pet.getBoundingClientRect()); + assert.ok(rects.every(rect => rect.left >= input.left - 0.1 && rect.right <= input.right + 0.1 && rect.bottom <= input.top + 0.1)); + assert.ok(rects.every((rect, index) => rects.slice(index + 1).every(other => + rect.right <= other.left + 0.1 || other.right <= rect.left + 0.1 || rect.bottom <= other.top + 0.1 || other.bottom <= rect.top + 0.1))); + }); + } + for (const petLeft of [0, 192]) { for (const staggered of [false, true]) { test(`mini pets land above the input without a resize (main pet at ${petLeft}, ${staggered ? 'staggered' : 'together'})`, () => { @@ -2478,7 +2517,7 @@ suite('ChatPetWidget', () => { } for (const petLeft of [0, 300]) { - test(`mini pets stay in a bounded area with many subagents (main pet at ${petLeft})`, () => { + test(`mini pets stay in a bounded area with many subagents (main pet at ${petLeft})`, async () => { const { widget, firstHost, button, overlay, firstParent, root, layout } = createHostTransitionHarness(true); const changed = disposables.add(new Emitter()); const tools = Array.from({ length: 100 }, (_, index) => { @@ -2506,15 +2545,25 @@ suite('ChatPetWidget', () => { bounded: right - left <= input.width + 0.1 && bottom - top <= 96.1, visible: rects.every(rect => rect.width > 0 && rect.height > 0), overlaps, - }, { count, withinChat: true, bounded: true, visible: true, overlaps: false }); + }, { count, withinChat: true, bounded: true, visible: true, overlaps: false }, JSON.stringify({ left, right, top, bottom, input: input.toJSON(), movement: movement.toJSON() })); }; checkBounds(100); firstParent.style.width = '120px'; layout(); + await waitForPetAnimation(() => pets.every(pet => { + const rect = pet.getBoundingClientRect(); + const input = firstParent.getBoundingClientRect(); + return rect.left >= input.left - 0.1 && rect.right <= input.right + 0.1 && rect.bottom <= input.top + 0.1 && pet.querySelector('img')?.getAttribute('src')?.includes('buddy-idle-'); + })); checkBounds(100); root.style.height = '64px'; firstParent.style.top = '32px'; layout(); + await waitForPetAnimation(() => pets.every(pet => { + const rect = pet.getBoundingClientRect(); + const input = firstParent.getBoundingClientRect(); + return rect.left >= input.left - 0.1 && rect.right <= input.right + 0.1 && rect.top >= root.getBoundingClientRect().top - 0.1 && rect.bottom <= input.top + 0.1 && pet.querySelector('img')?.getAttribute('src')?.includes('buddy-idle-'); + })); checkBounds(100); tools[0].toolSpecificData = { kind: 'subagent', isActive: false }; changed.fire({ reason: 'other' }); From 604b6aeae99d473290c51c61dbc125d76f5edbbb Mon Sep 17 00:00:00 2001 From: Lisa Rosenberg Date: Thu, 12 Nov 2026 20:37:51 +0100 Subject: [PATCH 23/66] feat: fix subagent pet's respawning timing --- .../chat/browser/widget/chatPetWidget.ts | 29 +++++++++---- .../test/browser/widget/chatPetWidget.test.ts | 43 +++++++++++++++++-- 2 files changed, 60 insertions(+), 12 deletions(-) diff --git a/src/vs/workbench/contrib/chat/browser/widget/chatPetWidget.ts b/src/vs/workbench/contrib/chat/browser/widget/chatPetWidget.ts index b8938205da3565..ec7db798d74d2b 100644 --- a/src/vs/workbench/contrib/chat/browser/widget/chatPetWidget.ts +++ b/src/vs/workbench/contrib/chat/browser/widget/chatPetWidget.ts @@ -146,6 +146,7 @@ const MOUSE_BOUNCE_MAX_HORIZONTAL_VELOCITY = 1_800; const CHAT_PET_DISPLAY_SIZE = 48; const CHAT_PET_SUBAGENT_MAX_HEIGHT = 96; const CHAT_PET_SUBAGENT_BOUNDARY_EPSILON = 0.01; +const CHAT_PET_SUBAGENT_EDGE_INSET = 12; const CHAT_PET_SOURCE_SIZE = 96; const CHAT_PET_SLEEP_SOURCE_WIDTH = 120; const CHAT_PET_TYPING_SOURCE_WIDTH = 168; @@ -1264,7 +1265,7 @@ export class ChatPetWidget extends Disposable { private readonly _subagentPets = new Map(); private _subagentModel: IChatModel | undefined; private readonly _subagentEffects = this._register(new DisposableStore()); - private readonly _subagentResizeScheduler = this._register(new RunOnceScheduler(() => this._reconcileSubagentResize(), 120)); + private readonly _subagentResizeScheduler = this._register(new RunOnceScheduler(() => this._reconcileSubagentResize(), 16)); private readonly _subagentLayer: HTMLElement; private parent: HTMLElement; private dragBounds: HTMLElement; @@ -2244,7 +2245,7 @@ export class ChatPetWidget extends Disposable { } private _handleHostLayoutChange(): void { - if (this._subagentPets.size) { + if (this._subagentPets.size && !this._subagentResizeScheduler.isScheduled()) { this._subagentResizeScheduler.schedule(); } if (this._jumpGame.value) { @@ -2885,6 +2886,13 @@ export class ChatPetWidget extends Disposable { return this._button.element.offsetLeft; } + private _getSubagentHorizontalBounds(overlay: DOMRect, input: DOMRect, movement: DOMRect, platform: IChatPetPlatform | undefined): { left: number; right: number } { + const left = Math.max(0, input.left, movement.left, platform?.left ?? input.left); + const right = Math.min(dom.getWindow(this._overlay).innerWidth, input.right, movement.right, platform?.right ?? input.right); + const inset = Math.min(CHAT_PET_SUBAGENT_EDGE_INSET, Math.max(0, (right - left) / 4)); + return { left: left + inset - overlay.left, right: right - inset - overlay.left }; + } + /** Choose a random landing point, accounting for mini pets already on the platform. */ private _getSubagentLanding(size: number): { left: number; top: number } { const overlay = this._overlay.getBoundingClientRect(); @@ -2892,8 +2900,9 @@ export class ChatPetWidget extends Disposable { const movement = this.movementBounds.getBoundingClientRect(); const platforms = this._getPlatforms(); const platform = getChatPetFallTarget(input.left + input.width / 2, movement.top - 1, 0, 0, platforms, input.top).platform; - const minimumLeft = Math.max(input.left, movement.left, platform?.left ?? input.left) - overlay.left; - const maximumLeft = Math.max(minimumLeft, Math.min(input.right, movement.right, platform?.right ?? input.right) - overlay.left - size); + const bounds = this._getSubagentHorizontalBounds(overlay, input, movement, platform); + const minimumLeft = bounds.left; + const maximumLeft = Math.max(minimumLeft, bounds.right - size); const petLeft = this._button.element.offsetLeft; const beforePet = Math.max(0, Math.min(maximumLeft, petLeft - size) - minimumLeft); const afterPetStart = Math.max(minimumLeft, petLeft + this._getDisplaySize()); @@ -3159,8 +3168,7 @@ export class ChatPetWidget extends Disposable { const input = this.dragBounds.getBoundingClientRect(); const movement = this.movementBounds.getBoundingClientRect(); const platform = getChatPetFallTarget(input.left + input.width / 2, movement.top - 1, 0, 0, this._getPlatforms(), input.top).platform; - const left = Math.max(input.left, movement.left, platform?.left ?? input.left) - overlay.left; - const right = Math.min(input.right, movement.right, platform?.right ?? input.right) - overlay.left; + const { left, right } = this._getSubagentHorizontalBounds(overlay, input, movement, platform); const bottom = Math.min(platform?.top ?? input.top, input.top, movement.bottom) - overlay.top; const height = Math.min(CHAT_PET_SUBAGENT_MAX_HEIGHT, bottom - (movement.top - overlay.top)); const width = right - left; @@ -3211,8 +3219,9 @@ export class ChatPetWidget extends Disposable { const input = this.dragBounds.getBoundingClientRect(); const movement = this.movementBounds.getBoundingClientRect(); const platform = getChatPetFallTarget(input.left + input.width / 2, movement.top - 1, 0, 0, this._getPlatforms(), input.top).platform; - const minimumLeft = Math.max(input.left, movement.left, platform?.left ?? input.left) - overlay.left; - const maximumRight = Math.min(input.right, movement.right, platform?.right ?? input.right) - overlay.left; + const bounds = this._getSubagentHorizontalBounds(overlay, input, movement, platform); + const minimumLeft = bounds.left; + const maximumRight = bounds.right; const minimumTop = movement.top - overlay.top; // The input's top edge is the floor; the movement bounds also include the input itself. const maximumBottom = Math.min(platform?.top ?? input.top, input.top, movement.bottom) - overlay.top; @@ -3232,7 +3241,9 @@ export class ChatPetWidget extends Disposable { const top = Math.min(...pets.map(pet => pet.top)); const bottom = Math.max(...pets.map(pet => pet.top + pet.size)); if (left < minimumLeft - CHAT_PET_SUBAGENT_BOUNDARY_EPSILON || right > maximumRight + CHAT_PET_SUBAGENT_BOUNDARY_EPSILON || bottom > maximumBottom + CHAT_PET_SUBAGENT_BOUNDARY_EPSILON) { - this._subagentResizeScheduler.schedule(); + if (!this._subagentResizeScheduler.isScheduled()) { + this._subagentResizeScheduler.schedule(); + } return; } if (bottom - top <= height) { diff --git a/src/vs/workbench/contrib/chat/test/browser/widget/chatPetWidget.test.ts b/src/vs/workbench/contrib/chat/test/browser/widget/chatPetWidget.test.ts index 329af24dbe4ac8..91b0302a966688 100644 --- a/src/vs/workbench/contrib/chat/test/browser/widget/chatPetWidget.test.ts +++ b/src/vs/workbench/contrib/chat/test/browser/widget/chatPetWidget.test.ts @@ -2456,20 +2456,20 @@ suite('ChatPetWidget', () => { const pets = [...overlay.querySelectorAll('.chat-pet-subagent')]; for (const [index, pet] of pets.entries()) { pet.classList.remove('arriving'); - pet.style.left = `${[20, 90, 100, 220][index]}px`; + pet.style.left = `${[20, 80, 90, 220][index]}px`; pet.style.top = `${index === 1 ? -48 : -24}px`; } firstParent.style.width = '120px'; layout(); layout(); layout(); - assert.deepStrictEqual(pets.map(pet => pet.style.left), ['20px', '90px', '100px', '220px']); + assert.deepStrictEqual(pets.map(pet => pet.style.left), ['20px', '80px', '90px', '220px']); await waitForPetAnimation(() => pets[2].querySelector('img')?.getAttribute('src')?.includes('buddy-respawn-') === true && pets[3].querySelector('img')?.getAttribute('src')?.includes('buddy-respawn-') === true); assert.deepStrictEqual({ stays: [pets[0].style.left, pets[0].style.top], upper: [pets[1].style.left, pets[1].style.top], - }, { stays: ['20px', '-24px'], upper: ['90px', '-24px'] }); + }, { stays: ['20px', '-24px'], upper: ['80px', '-24px'] }); await waitForPetAnimation(() => pets.every(pet => !pet.classList.contains('arriving') && pet.querySelector('img')?.getAttribute('src')?.includes('buddy-idle-') === true)); const input = firstParent.getBoundingClientRect(); const rects = pets.map(pet => pet.getBoundingClientRect()); @@ -2479,6 +2479,43 @@ suite('ChatPetWidget', () => { }); } + test('mini pets start falling near the edge while resizing continues', () => { + const clock = sinon.useFakeTimers({ toFake: ['setTimeout', 'clearTimeout'] }); + disposables.add(toDisposable(() => clock.restore())); + const { widget, firstHost, firstParent, overlay, layout } = createHostTransitionHarness(true); + const tool = new ChatToolInvocation(undefined, { id: 'edge', displayName: 'Edge', modelDescription: 'Subagent', source: ToolDataSource.Internal }, 'edge', undefined, {}); + tool.toolSpecificData = { kind: 'subagent', isActive: true }; + widget.setHost({ ...firstHost, model: constObservable(createSubagentTestModel([tool])) }); + const pet = overlay.querySelector('.chat-pet-subagent')!; + pet.style.left = '98px'; + pet.style.top = '-24px'; + firstParent.style.width = '120px'; + layout(); + clock.tick(8); + layout(); + assert.ok(pet.querySelector('img')?.getAttribute('src')?.includes('buddy-idle-')); + clock.tick(8); + assert.ok(pet.querySelector('img')?.getAttribute('src')?.includes('buddy-respawn-')); + }); + + test('mini pets spawn inside the visible window when their platform extends beyond it', () => { + const { widget, firstHost, root, firstParent, button, overlay } = createHostTransitionHarness(true); + root.style.width = `${mainWindow.innerWidth + 240}px`; + firstParent.style.left = `${mainWindow.innerWidth - 80}px`; + firstParent.style.width = '240px'; + const changed = disposables.add(new Emitter()); + const tools: ChatToolInvocation[] = []; + widget.setHost({ ...firstHost, model: constObservable(createSubagentTestModel(tools, changed.event)) }); + button.style.left = '0px'; + sinon.stub(Math, 'random').returns(0.99); + const tool = new ChatToolInvocation(undefined, { id: 'edge', displayName: 'Edge', modelDescription: 'Subagent', source: ToolDataSource.Internal }, 'edge', undefined, {}); + tool.toolSpecificData = { kind: 'subagent', isActive: true }; + tools.push(tool); + changed.fire({ reason: 'other' }); + const rect = overlay.querySelector('.chat-pet-subagent')!.getBoundingClientRect(); + assert.ok(rect.right <= mainWindow.innerWidth - 12 + 0.1); + }); + for (const petLeft of [0, 192]) { for (const staggered of [false, true]) { test(`mini pets land above the input without a resize (main pet at ${petLeft}, ${staggered ? 'staggered' : 'together'})`, () => { From cd06910e5fa7294d09ae3cd06830165510b4b2a6 Mon Sep 17 00:00:00 2001 From: Lisa Rosenberg Date: Thu, 12 Nov 2026 21:17:14 +0100 Subject: [PATCH 24/66] feat: fix decreasing sizing of subagent pets --- .../chat/browser/widget/chatPetWidget.ts | 42 ++++++++++++------- .../test/browser/widget/chatPetWidget.test.ts | 31 +++++++++++--- 2 files changed, 54 insertions(+), 19 deletions(-) diff --git a/src/vs/workbench/contrib/chat/browser/widget/chatPetWidget.ts b/src/vs/workbench/contrib/chat/browser/widget/chatPetWidget.ts index 13c4a2b6bb5aa9..df4913d51de708 100644 --- a/src/vs/workbench/contrib/chat/browser/widget/chatPetWidget.ts +++ b/src/vs/workbench/contrib/chat/browser/widget/chatPetWidget.ts @@ -159,6 +159,7 @@ const CHAT_PET_DIZZY_SOURCE_HEIGHT = 128; const CHAT_PET_MAX_VERTICAL_OFFSET = 10; const CHAT_PET_DEFAULT_RIGHT_INSET = 32; const CHAT_PET_MIN_SCALE = 0.4; +const CHAT_PET_MIN_SUBAGENT_SCALE = CHAT_PET_MIN_SCALE * 0.5; const CHAT_PET_SCALE_STEP = 0.2; const CHAT_PET_SPEECH_BUBBLE_RIGHT_OVERHANG = 20; const CHAT_PET_SLEEP_RIGHT_OVERHANG = (CHAT_PET_SLEEP_SOURCE_WIDTH - CHAT_PET_SOURCE_SIZE) / 2; @@ -2965,7 +2966,7 @@ export class ChatPetWidget extends Disposable { } /** Choose a random landing point, accounting for mini pets already on the platform. */ - private _getSubagentLanding(size: number): { left: number; top: number } { + private _getSubagentLanding(size: number): { left: number; top: number; fits: boolean } { const overlay = this._overlay.getBoundingClientRect(); const input = this.dragBounds.getBoundingClientRect(); const movement = this.movementBounds.getBoundingClientRect(); @@ -3000,13 +3001,14 @@ export class ChatPetWidget extends Disposable { } } if (top >= minimumTop - CHAT_PET_SUBAGENT_BOUNDARY_EPSILON) { - return { left, top }; + return { left, top, fits: true }; } if (!best || top > best.top) { best = { left, top }; } } - return best!; + // When even the minimum size cannot fit, keep pets visible within the bounded area. + return { ...best!, top: size <= CHAT_PET_DISPLAY_SIZE * CHAT_PET_MIN_SUBAGENT_SCALE ? Math.max(best!.top, minimumTop) : best!.top, fits: false }; } private _updateSubagentPets(subagents: ReadonlySet): void { @@ -3023,10 +3025,16 @@ export class ChatPetWidget extends Disposable { continue; } const element = dom.append(this._subagentLayer, dom.$('.chat-pet-subagent', { 'aria-hidden': 'true' })); - const miniScale = 0.5 * (this._scale || 1); - const miniWidth = 48 * miniScale; + let miniScale = Math.max(CHAT_PET_MIN_SUBAGENT_SCALE, 0.5 * (this._scale || 1)); + let miniWidth = CHAT_PET_DISPLAY_SIZE * miniScale; const overlayBounds = this._overlay.getBoundingClientRect(); - const { left, top } = this._getSubagentLanding(miniWidth); + let landing = this._getSubagentLanding(miniWidth); + if (!landing.fits && miniScale > CHAT_PET_MIN_SUBAGENT_SCALE) { + miniScale = CHAT_PET_MIN_SUBAGENT_SCALE; + miniWidth = CHAT_PET_DISPLAY_SIZE * miniScale; + landing = this._getSubagentLanding(miniWidth); + } + const { left, top } = landing; element.style.left = `${left}px`; element.style.top = `${top}px`; element.style.setProperty('--chat-pet-subagent-scale', String(miniScale)); @@ -3185,7 +3193,11 @@ export class ChatPetWidget extends Disposable { element.style.top = `${this.movementBounds.getBoundingClientRect().top - overlay.top}px`; setState('idle'); } else if (respawnPhase === 'respawning') { - const landing = this._getSubagentLanding(size); + let landing = this._getSubagentLanding(size); + if (!landing.fits && size > CHAT_PET_DISPLAY_SIZE * CHAT_PET_MIN_SUBAGENT_SCALE) { + element.style.setProperty('--chat-pet-subagent-scale', String(CHAT_PET_MIN_SUBAGENT_SCALE)); + landing = this._getSubagentLanding(CHAT_PET_DISPLAY_SIZE * CHAT_PET_MIN_SUBAGENT_SCALE); + } element.style.left = `${landing.left}px`; fallTo(landing.top); this._constrainSubagentPets(); @@ -3243,7 +3255,7 @@ export class ChatPetWidget extends Disposable { const bottom = Math.min(platform?.top ?? input.top, input.top, movement.bottom) - overlay.top; const height = Math.min(CHAT_PET_SUBAGENT_MAX_HEIGHT, bottom - (movement.top - overlay.top)); const width = right - left; - if (width <= 0 || height <= 0) { + if (width < CHAT_PET_DISPLAY_SIZE * CHAT_PET_MIN_SUBAGENT_SCALE || height < CHAT_PET_DISPLAY_SIZE * CHAT_PET_MIN_SUBAGENT_SCALE) { return; } const maxSize = Math.max(...pets.map(pet => CHAT_PET_DISPLAY_SIZE * Number.parseFloat(pet.element.style.getPropertyValue('--chat-pet-subagent-scale')))); @@ -3261,8 +3273,9 @@ export class ChatPetWidget extends Disposable { for (const pet of pets) { const scale = Number.parseFloat(pet.element.style.getPropertyValue('--chat-pet-subagent-scale')); const size = CHAT_PET_DISPLAY_SIZE * scale; - pet.element.style.top = `${Number.parseFloat(pet.element.style.top) + size * (1 - factor)}px`; - pet.element.style.setProperty('--chat-pet-subagent-scale', String(scale * factor)); + const nextScale = Math.max(CHAT_PET_MIN_SUBAGENT_SCALE, scale * factor); + pet.element.style.top = `${Number.parseFloat(pet.element.style.top) + size - CHAT_PET_DISPLAY_SIZE * nextScale}px`; + pet.element.style.setProperty('--chat-pet-subagent-scale', String(nextScale)); } } let displaced = false; @@ -3298,7 +3311,7 @@ export class ChatPetWidget extends Disposable { const maximumBottom = Math.min(platform?.top ?? input.top, input.top, movement.bottom) - overlay.top; const width = maximumRight - minimumLeft; const height = Math.min(CHAT_PET_SUBAGENT_MAX_HEIGHT, maximumBottom - minimumTop); - if (width <= 0 || height <= 0) { + if (width < CHAT_PET_DISPLAY_SIZE * CHAT_PET_MIN_SUBAGENT_SCALE || height < CHAT_PET_DISPLAY_SIZE * CHAT_PET_MIN_SUBAGENT_SCALE) { return; } const pets = activePets.map(pet => ({ @@ -3320,11 +3333,12 @@ export class ChatPetWidget extends Disposable { if (bottom - top <= height) { return; } - const factor = Math.min(1, height / (bottom - top), width / Math.max(1, right - left)); + const minimumFactor = Math.max(...pets.map(pet => CHAT_PET_DISPLAY_SIZE * CHAT_PET_MIN_SUBAGENT_SCALE / pet.size)); + const factor = Math.min(1, Math.max(minimumFactor, Math.min(height / (bottom - top), width / Math.max(1, right - left)))); const scaledLeft = Math.max(minimumLeft, Math.min(left, maximumRight - (right - left) * factor)); for (const pet of pets) { - const petTop = bottom - (bottom - pet.top) * factor; - const size = pet.size * factor; + const petTop = Math.max(minimumTop, bottom - height, bottom - (bottom - pet.top) * factor); + const size = Math.max(CHAT_PET_DISPLAY_SIZE * CHAT_PET_MIN_SUBAGENT_SCALE, pet.size * factor); pet.element.style.left = `${scaledLeft + (pet.left - left) * factor}px`; pet.element.style.top = `${petTop}px`; pet.element.style.setProperty('--chat-pet-subagent-scale', String(size / CHAT_PET_DISPLAY_SIZE)); diff --git a/src/vs/workbench/contrib/chat/test/browser/widget/chatPetWidget.test.ts b/src/vs/workbench/contrib/chat/test/browser/widget/chatPetWidget.test.ts index e684be2e8c387b..b3ce0929f2ecfa 100644 --- a/src/vs/workbench/contrib/chat/test/browser/widget/chatPetWidget.test.ts +++ b/src/vs/workbench/contrib/chat/test/browser/widget/chatPetWidget.test.ts @@ -3112,6 +3112,29 @@ suite('ChatPetWidget', () => { } } + test('mini pets never shrink below the size of a mini pet at minimum main pet scale', async () => { + const { widget, firstHost, overlay, firstParent, root, layout } = createHostTransitionHarness(true, 'teleport', undefined, undefined, undefined, false, service => service.setScale(0.4)); + const changed = disposables.add(new Emitter()); + const tools = Array.from({ length: 100 }, (_, index) => { + const id = `subagent-${index}`; + const tool = new ChatToolInvocation(undefined, { id, displayName: id, modelDescription: 'Subagent', source: ToolDataSource.Internal }, id, undefined, {}); + tool.toolSpecificData = { kind: 'subagent', isActive: true }; + return tool; + }); + widget.setHost({ ...firstHost, transition: undefined, model: constObservable(createSubagentTestModel(tools, changed.event)) }); + const pets = [...overlay.querySelectorAll('.chat-pet-subagent')]; + const minimumSize = pets[0].getBoundingClientRect().width; + assert.ok(Math.abs(minimumSize - 9.6) < 0.1); + for (const width of [120, 80, 120]) { + firstParent.style.width = `${width}px`; + root.style.height = '64px'; + firstParent.style.top = '32px'; + layout(); + await timeout(50); + assert.ok(pets.every(pet => pet.getBoundingClientRect().width >= minimumSize - 0.1)); + } + }); + for (const petLeft of [0, 300]) { test(`mini pets stay in a bounded area with many subagents (main pet at ${petLeft})`, async () => { const { widget, firstHost, button, overlay, firstParent, root, layout } = createHostTransitionHarness(true); @@ -3133,15 +3156,13 @@ suite('ChatPetWidget', () => { const right = Math.max(...rects.map(rect => rect.right)); const top = Math.min(...rects.map(rect => rect.top)); const bottom = Math.max(...rects.map(rect => rect.bottom)); - const overlaps = rects.some((rect, index) => rects.slice(index + 1).some(other => - rect.left < other.right - 0.1 && rect.right > other.left + 0.1 && rect.top < other.bottom - 0.1 && rect.bottom > other.top + 0.1)); + // At the minimum size, this many pets cannot fit in the narrowest area without overlapping. assert.deepStrictEqual({ count: rects.length, withinChat: left >= input.left - 0.1 && right <= input.right + 0.1 && top >= movement.top - 0.1 && bottom <= Math.min(input.top, movement.bottom) + 0.1, bounded: right - left <= input.width + 0.1 && bottom - top <= 96.1, - visible: rects.every(rect => rect.width > 0 && rect.height > 0), - overlaps, - }, { count, withinChat: true, bounded: true, visible: true, overlaps: false }, JSON.stringify({ left, right, top, bottom, input: input.toJSON(), movement: movement.toJSON() })); + largeEnough: rects.every(rect => rect.width >= 9.5 && rect.height >= 9.5), + }, { count, withinChat: true, bounded: true, largeEnough: true }, JSON.stringify({ left, right, top, bottom, input: input.toJSON(), movement: movement.toJSON() })); }; checkBounds(100); firstParent.style.width = '120px'; From e2c6e9cf3c5c2915fc2ed9d1d2639c2131f2214b Mon Sep 17 00:00:00 2001 From: Lisa Rosenberg Date: Thu, 12 Nov 2026 21:47:23 +0100 Subject: [PATCH 25/66] feat: cap max subagent pet size --- .../contrib/chat/browser/widget/chatPetWidget.ts | 3 ++- .../chat/test/browser/widget/chatPetWidget.test.ts | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/vs/workbench/contrib/chat/browser/widget/chatPetWidget.ts b/src/vs/workbench/contrib/chat/browser/widget/chatPetWidget.ts index df4913d51de708..d8c5235120445d 100644 --- a/src/vs/workbench/contrib/chat/browser/widget/chatPetWidget.ts +++ b/src/vs/workbench/contrib/chat/browser/widget/chatPetWidget.ts @@ -161,6 +161,7 @@ const CHAT_PET_DEFAULT_RIGHT_INSET = 32; const CHAT_PET_MIN_SCALE = 0.4; const CHAT_PET_MIN_SUBAGENT_SCALE = CHAT_PET_MIN_SCALE * 0.5; const CHAT_PET_SCALE_STEP = 0.2; +const CHAT_PET_MAX_SUBAGENT_SCALE = (1 + 3 * CHAT_PET_SCALE_STEP) * 0.5; const CHAT_PET_SPEECH_BUBBLE_RIGHT_OVERHANG = 20; const CHAT_PET_SLEEP_RIGHT_OVERHANG = (CHAT_PET_SLEEP_SOURCE_WIDTH - CHAT_PET_SOURCE_SIZE) / 2; const CHAT_PET_TYPING_RIGHT_OVERHANG = (CHAT_PET_TYPING_SOURCE_WIDTH - CHAT_PET_SOURCE_SIZE) / 2; @@ -3025,7 +3026,7 @@ export class ChatPetWidget extends Disposable { continue; } const element = dom.append(this._subagentLayer, dom.$('.chat-pet-subagent', { 'aria-hidden': 'true' })); - let miniScale = Math.max(CHAT_PET_MIN_SUBAGENT_SCALE, 0.5 * (this._scale || 1)); + let miniScale = Math.max(CHAT_PET_MIN_SUBAGENT_SCALE, Math.min(CHAT_PET_MAX_SUBAGENT_SCALE, 0.5 * (this._scale || 1))); let miniWidth = CHAT_PET_DISPLAY_SIZE * miniScale; const overlayBounds = this._overlay.getBoundingClientRect(); let landing = this._getSubagentLanding(miniWidth); diff --git a/src/vs/workbench/contrib/chat/test/browser/widget/chatPetWidget.test.ts b/src/vs/workbench/contrib/chat/test/browser/widget/chatPetWidget.test.ts index b3ce0929f2ecfa..a308f5a1581574 100644 --- a/src/vs/workbench/contrib/chat/test/browser/widget/chatPetWidget.test.ts +++ b/src/vs/workbench/contrib/chat/test/browser/widget/chatPetWidget.test.ts @@ -2923,10 +2923,20 @@ suite('ChatPetWidget', () => { service.setHorizontalPosition(0.8); }, model); const pet = overlay.querySelector('.chat-pet-subagent')!; - assert.strictEqual(Number.parseFloat(pet.style.getPropertyValue('--chat-pet-subagent-scale')), 1); - assert.ok(pet.offsetLeft + 48 <= button.offsetLeft || pet.offsetLeft >= button.offsetLeft + button.offsetWidth); + assert.strictEqual(Number.parseFloat(pet.style.getPropertyValue('--chat-pet-subagent-scale')), 0.8); + assert.ok(pet.offsetLeft + pet.getBoundingClientRect().width <= button.offsetLeft || pet.offsetLeft >= button.offsetLeft + button.offsetWidth); }); + for (const [mainScale, miniScale] of [[0.4, 0.2], [1, 0.5], [1.4, 0.7], [1.6, 0.8], [8.6, 0.8]]) { + test(`mini pets use the capped initial size at main pet scale ${mainScale}`, () => { + const tool = new ChatToolInvocation(undefined, { id: 'subagent', displayName: 'Subagent', modelDescription: 'Subagent', source: ToolDataSource.Internal }, 'subagent', undefined, {}); + tool.toolSpecificData = { kind: 'subagent', isActive: true }; + const { overlay } = createHostTransitionHarness(true, 'teleport', undefined, undefined, undefined, false, service => service.setScale(mainScale), createSubagentTestModel([tool])); + const pet = overlay.querySelector('.chat-pet-subagent')!; + assert.strictEqual(Number.parseFloat(pet.style.getPropertyValue('--chat-pet-subagent-scale')), miniScale); + }); + } + test('mini pets stop when disabled and return for active subagents when re-enabled', async () => { const { widget, firstHost, overlay, service } = createHostTransitionHarness(); const changed = disposables.add(new Emitter()); From 19eb4657e88b7c4c6a9b12f69a9476ec6d92fb71 Mon Sep 17 00:00:00 2001 From: Lisa Rosenberg Date: Thu, 12 Nov 2026 21:52:22 +0100 Subject: [PATCH 26/66] Revert "feat: cap max subagent pet size" This reverts commit e2c6e9cf3c5c2915fc2ed9d1d2639c2131f2214b. --- .../contrib/chat/browser/widget/chatPetWidget.ts | 3 +-- .../chat/test/browser/widget/chatPetWidget.test.ts | 14 ++------------ 2 files changed, 3 insertions(+), 14 deletions(-) diff --git a/src/vs/workbench/contrib/chat/browser/widget/chatPetWidget.ts b/src/vs/workbench/contrib/chat/browser/widget/chatPetWidget.ts index d8c5235120445d..df4913d51de708 100644 --- a/src/vs/workbench/contrib/chat/browser/widget/chatPetWidget.ts +++ b/src/vs/workbench/contrib/chat/browser/widget/chatPetWidget.ts @@ -161,7 +161,6 @@ const CHAT_PET_DEFAULT_RIGHT_INSET = 32; const CHAT_PET_MIN_SCALE = 0.4; const CHAT_PET_MIN_SUBAGENT_SCALE = CHAT_PET_MIN_SCALE * 0.5; const CHAT_PET_SCALE_STEP = 0.2; -const CHAT_PET_MAX_SUBAGENT_SCALE = (1 + 3 * CHAT_PET_SCALE_STEP) * 0.5; const CHAT_PET_SPEECH_BUBBLE_RIGHT_OVERHANG = 20; const CHAT_PET_SLEEP_RIGHT_OVERHANG = (CHAT_PET_SLEEP_SOURCE_WIDTH - CHAT_PET_SOURCE_SIZE) / 2; const CHAT_PET_TYPING_RIGHT_OVERHANG = (CHAT_PET_TYPING_SOURCE_WIDTH - CHAT_PET_SOURCE_SIZE) / 2; @@ -3026,7 +3025,7 @@ export class ChatPetWidget extends Disposable { continue; } const element = dom.append(this._subagentLayer, dom.$('.chat-pet-subagent', { 'aria-hidden': 'true' })); - let miniScale = Math.max(CHAT_PET_MIN_SUBAGENT_SCALE, Math.min(CHAT_PET_MAX_SUBAGENT_SCALE, 0.5 * (this._scale || 1))); + let miniScale = Math.max(CHAT_PET_MIN_SUBAGENT_SCALE, 0.5 * (this._scale || 1)); let miniWidth = CHAT_PET_DISPLAY_SIZE * miniScale; const overlayBounds = this._overlay.getBoundingClientRect(); let landing = this._getSubagentLanding(miniWidth); diff --git a/src/vs/workbench/contrib/chat/test/browser/widget/chatPetWidget.test.ts b/src/vs/workbench/contrib/chat/test/browser/widget/chatPetWidget.test.ts index a308f5a1581574..b3ce0929f2ecfa 100644 --- a/src/vs/workbench/contrib/chat/test/browser/widget/chatPetWidget.test.ts +++ b/src/vs/workbench/contrib/chat/test/browser/widget/chatPetWidget.test.ts @@ -2923,20 +2923,10 @@ suite('ChatPetWidget', () => { service.setHorizontalPosition(0.8); }, model); const pet = overlay.querySelector('.chat-pet-subagent')!; - assert.strictEqual(Number.parseFloat(pet.style.getPropertyValue('--chat-pet-subagent-scale')), 0.8); - assert.ok(pet.offsetLeft + pet.getBoundingClientRect().width <= button.offsetLeft || pet.offsetLeft >= button.offsetLeft + button.offsetWidth); + assert.strictEqual(Number.parseFloat(pet.style.getPropertyValue('--chat-pet-subagent-scale')), 1); + assert.ok(pet.offsetLeft + 48 <= button.offsetLeft || pet.offsetLeft >= button.offsetLeft + button.offsetWidth); }); - for (const [mainScale, miniScale] of [[0.4, 0.2], [1, 0.5], [1.4, 0.7], [1.6, 0.8], [8.6, 0.8]]) { - test(`mini pets use the capped initial size at main pet scale ${mainScale}`, () => { - const tool = new ChatToolInvocation(undefined, { id: 'subagent', displayName: 'Subagent', modelDescription: 'Subagent', source: ToolDataSource.Internal }, 'subagent', undefined, {}); - tool.toolSpecificData = { kind: 'subagent', isActive: true }; - const { overlay } = createHostTransitionHarness(true, 'teleport', undefined, undefined, undefined, false, service => service.setScale(mainScale), createSubagentTestModel([tool])); - const pet = overlay.querySelector('.chat-pet-subagent')!; - assert.strictEqual(Number.parseFloat(pet.style.getPropertyValue('--chat-pet-subagent-scale')), miniScale); - }); - } - test('mini pets stop when disabled and return for active subagents when re-enabled', async () => { const { widget, firstHost, overlay, service } = createHostTransitionHarness(); const changed = disposables.add(new Emitter()); From 44345d6e3359c17e3e18d7c26b8d7d5c532e4f6e Mon Sep 17 00:00:00 2001 From: Lisa Rosenberg Date: Thu, 12 Nov 2026 21:55:37 +0100 Subject: [PATCH 27/66] feat: remove shrinking feature when space get's too tight --- .../chat/browser/widget/chatPetWidget.ts | 65 +++---------------- .../test/browser/widget/chatPetWidget.test.ts | 17 +++-- 2 files changed, 19 insertions(+), 63 deletions(-) diff --git a/src/vs/workbench/contrib/chat/browser/widget/chatPetWidget.ts b/src/vs/workbench/contrib/chat/browser/widget/chatPetWidget.ts index df4913d51de708..d26ae8ddd44539 100644 --- a/src/vs/workbench/contrib/chat/browser/widget/chatPetWidget.ts +++ b/src/vs/workbench/contrib/chat/browser/widget/chatPetWidget.ts @@ -2966,7 +2966,7 @@ export class ChatPetWidget extends Disposable { } /** Choose a random landing point, accounting for mini pets already on the platform. */ - private _getSubagentLanding(size: number): { left: number; top: number; fits: boolean } { + private _getSubagentLanding(size: number): { left: number; top: number } { const overlay = this._overlay.getBoundingClientRect(); const input = this.dragBounds.getBoundingClientRect(); const movement = this.movementBounds.getBoundingClientRect(); @@ -3001,14 +3001,14 @@ export class ChatPetWidget extends Disposable { } } if (top >= minimumTop - CHAT_PET_SUBAGENT_BOUNDARY_EPSILON) { - return { left, top, fits: true }; + return { left, top }; } if (!best || top > best.top) { best = { left, top }; } } - // When even the minimum size cannot fit, keep pets visible within the bounded area. - return { ...best!, top: size <= CHAT_PET_DISPLAY_SIZE * CHAT_PET_MIN_SUBAGENT_SCALE ? Math.max(best!.top, minimumTop) : best!.top, fits: false }; + // If the area is full, allow overlap instead of shrinking the pets. + return { ...best!, top: Math.max(best!.top, minimumTop) }; } private _updateSubagentPets(subagents: ReadonlySet): void { @@ -3025,16 +3025,10 @@ export class ChatPetWidget extends Disposable { continue; } const element = dom.append(this._subagentLayer, dom.$('.chat-pet-subagent', { 'aria-hidden': 'true' })); - let miniScale = Math.max(CHAT_PET_MIN_SUBAGENT_SCALE, 0.5 * (this._scale || 1)); - let miniWidth = CHAT_PET_DISPLAY_SIZE * miniScale; + const miniScale = Math.max(CHAT_PET_MIN_SUBAGENT_SCALE, 0.5 * (this._scale || 1)); + const miniWidth = CHAT_PET_DISPLAY_SIZE * miniScale; const overlayBounds = this._overlay.getBoundingClientRect(); - let landing = this._getSubagentLanding(miniWidth); - if (!landing.fits && miniScale > CHAT_PET_MIN_SUBAGENT_SCALE) { - miniScale = CHAT_PET_MIN_SUBAGENT_SCALE; - miniWidth = CHAT_PET_DISPLAY_SIZE * miniScale; - landing = this._getSubagentLanding(miniWidth); - } - const { left, top } = landing; + const { left, top } = this._getSubagentLanding(miniWidth); element.style.left = `${left}px`; element.style.top = `${top}px`; element.style.setProperty('--chat-pet-subagent-scale', String(miniScale)); @@ -3193,11 +3187,7 @@ export class ChatPetWidget extends Disposable { element.style.top = `${this.movementBounds.getBoundingClientRect().top - overlay.top}px`; setState('idle'); } else if (respawnPhase === 'respawning') { - let landing = this._getSubagentLanding(size); - if (!landing.fits && size > CHAT_PET_DISPLAY_SIZE * CHAT_PET_MIN_SUBAGENT_SCALE) { - element.style.setProperty('--chat-pet-subagent-scale', String(CHAT_PET_MIN_SUBAGENT_SCALE)); - landing = this._getSubagentLanding(CHAT_PET_DISPLAY_SIZE * CHAT_PET_MIN_SUBAGENT_SCALE); - } + const landing = this._getSubagentLanding(size); element.style.left = `${landing.left}px`; fallTo(landing.top); this._constrainSubagentPets(); @@ -3258,26 +3248,6 @@ export class ChatPetWidget extends Disposable { if (width < CHAT_PET_DISPLAY_SIZE * CHAT_PET_MIN_SUBAGENT_SCALE || height < CHAT_PET_DISPLAY_SIZE * CHAT_PET_MIN_SUBAGENT_SCALE) { return; } - const maxSize = Math.max(...pets.map(pet => CHAT_PET_DISPLAY_SIZE * Number.parseFloat(pet.element.style.getPropertyValue('--chat-pet-subagent-scale')))); - const count = this._subagentPets.size; - const mainLeft = this._button.element.offsetLeft; - const blockedWidth = Math.max(0, Math.min(right, mainLeft + this._getDisplaySize()) - Math.max(left, mainLeft)); - const placementWidth = width > blockedWidth ? width - blockedWidth : width; - if (Math.floor(placementWidth / maxSize) * Math.floor(height / maxSize) < count) { - let fitSize = 0; - for (let columns = 1; columns <= count; columns++) { - fitSize = Math.max(fitSize, Math.min(placementWidth / columns, height / Math.ceil(count / columns))); - } - // Leave room for irregular, randomly positioned stacks rather than assuming a packed grid. - const factor = Math.min(1, fitSize * 0.8 / maxSize); - for (const pet of pets) { - const scale = Number.parseFloat(pet.element.style.getPropertyValue('--chat-pet-subagent-scale')); - const size = CHAT_PET_DISPLAY_SIZE * scale; - const nextScale = Math.max(CHAT_PET_MIN_SUBAGENT_SCALE, scale * factor); - pet.element.style.top = `${Number.parseFloat(pet.element.style.top) + size - CHAT_PET_DISPLAY_SIZE * nextScale}px`; - pet.element.style.setProperty('--chat-pet-subagent-scale', String(nextScale)); - } - } let displaced = false; for (const pet of pets) { const petLeft = Number.parseFloat(pet.element.style.left); @@ -3293,7 +3263,7 @@ export class ChatPetWidget extends Disposable { } } - /** Shrink an unusually tall group without rearranging it into a grid. */ + /** Check whether pets need to fall after their bounds change. */ private _constrainSubagentPets(): void { const activePets = [...this._subagentPets.values()].filter(pet => !pet.isRespawning()); if (!activePets.length) { @@ -3322,7 +3292,6 @@ export class ChatPetWidget extends Disposable { })); const left = Math.min(...pets.map(pet => pet.left)); const right = Math.max(...pets.map(pet => pet.left + pet.size)); - const top = Math.min(...pets.map(pet => pet.top)); const bottom = Math.max(...pets.map(pet => pet.top + pet.size)); if (left < minimumLeft - CHAT_PET_SUBAGENT_BOUNDARY_EPSILON || right > maximumRight + CHAT_PET_SUBAGENT_BOUNDARY_EPSILON || bottom > maximumBottom + CHAT_PET_SUBAGENT_BOUNDARY_EPSILON) { if (!this._subagentResizeScheduler.isScheduled()) { @@ -3330,22 +3299,6 @@ export class ChatPetWidget extends Disposable { } return; } - if (bottom - top <= height) { - return; - } - const minimumFactor = Math.max(...pets.map(pet => CHAT_PET_DISPLAY_SIZE * CHAT_PET_MIN_SUBAGENT_SCALE / pet.size)); - const factor = Math.min(1, Math.max(minimumFactor, Math.min(height / (bottom - top), width / Math.max(1, right - left)))); - const scaledLeft = Math.max(minimumLeft, Math.min(left, maximumRight - (right - left) * factor)); - for (const pet of pets) { - const petTop = Math.max(minimumTop, bottom - height, bottom - (bottom - pet.top) * factor); - const size = Math.max(CHAT_PET_DISPLAY_SIZE * CHAT_PET_MIN_SUBAGENT_SCALE, pet.size * factor); - pet.element.style.left = `${scaledLeft + (pet.left - left) * factor}px`; - pet.element.style.top = `${petTop}px`; - pet.element.style.setProperty('--chat-pet-subagent-scale', String(size / CHAT_PET_DISPLAY_SIZE)); - const distance = Math.max(0, overlay.top + petTop + size); - pet.element.style.setProperty('--chat-pet-subagent-fall-distance', `${distance}px`); - pet.element.style.setProperty('--chat-pet-subagent-fall-duration', `${getChatPetFallDuration(distance)}ms`); - } } private _despawnSubagentPet(pet: ChatPetSubagent): void { diff --git a/src/vs/workbench/contrib/chat/test/browser/widget/chatPetWidget.test.ts b/src/vs/workbench/contrib/chat/test/browser/widget/chatPetWidget.test.ts index b3ce0929f2ecfa..739efe1fe4ac29 100644 --- a/src/vs/workbench/contrib/chat/test/browser/widget/chatPetWidget.test.ts +++ b/src/vs/workbench/contrib/chat/test/browser/widget/chatPetWidget.test.ts @@ -3004,7 +3004,7 @@ suite('ChatPetWidget', () => { }); for (const reducedMotion of [false, true]) { - test(`mini pets resize once and only displaced pets respawn (${reducedMotion ? 'reduced motion' : 'animated'})`, async () => { + test(`mini pets keep their size and only displaced pets respawn (${reducedMotion ? 'reduced motion' : 'animated'})`, async () => { const { widget, firstHost, overlay, firstParent, layout } = createHostTransitionHarness(reducedMotion); const tools = ['stays', 'upper', 'support', 'outside'].map(id => { const tool = new ChatToolInvocation(undefined, { id, displayName: id, modelDescription: 'Subagent', source: ToolDataSource.Internal }, id, undefined, {}); @@ -3013,6 +3013,7 @@ suite('ChatPetWidget', () => { }); widget.setHost({ ...firstHost, model: constObservable(createSubagentTestModel(tools)) }); const pets = [...overlay.querySelectorAll('.chat-pet-subagent')]; + const scales = pets.map(pet => pet.style.getPropertyValue('--chat-pet-subagent-scale')); for (const [index, pet] of pets.entries()) { pet.classList.remove('arriving'); pet.style.left = `${[20, 80, 90, 220][index]}px`; @@ -3030,6 +3031,7 @@ suite('ChatPetWidget', () => { upper: [pets[1].style.left, pets[1].style.top], }, { stays: ['20px', '-24px'], upper: ['80px', '-24px'] }); await waitForPetAnimation(() => pets.every(pet => !pet.classList.contains('arriving') && pet.querySelector('img')?.getAttribute('src')?.includes('buddy-idle-') === true)); + assert.deepStrictEqual(pets.map(pet => pet.style.getPropertyValue('--chat-pet-subagent-scale')), scales); const input = firstParent.getBoundingClientRect(); const rects = pets.map(pet => pet.getBoundingClientRect()); assert.ok(rects.every(rect => rect.left >= input.left - 0.1 && rect.right <= input.right + 0.1 && rect.bottom <= input.top + 0.1)); @@ -3112,8 +3114,8 @@ suite('ChatPetWidget', () => { } } - test('mini pets never shrink below the size of a mini pet at minimum main pet scale', async () => { - const { widget, firstHost, overlay, firstParent, root, layout } = createHostTransitionHarness(true, 'teleport', undefined, undefined, undefined, false, service => service.setScale(0.4)); + test('mini pets keep their initial size when crowded and resized', async () => { + const { widget, firstHost, overlay, firstParent, root, layout } = createHostTransitionHarness(true); const changed = disposables.add(new Emitter()); const tools = Array.from({ length: 100 }, (_, index) => { const id = `subagent-${index}`; @@ -3123,15 +3125,16 @@ suite('ChatPetWidget', () => { }); widget.setHost({ ...firstHost, transition: undefined, model: constObservable(createSubagentTestModel(tools, changed.event)) }); const pets = [...overlay.querySelectorAll('.chat-pet-subagent')]; - const minimumSize = pets[0].getBoundingClientRect().width; - assert.ok(Math.abs(minimumSize - 9.6) < 0.1); + const initialSize = pets[0].getBoundingClientRect().width; + assert.ok(Math.abs(initialSize - 24) < 0.1); + assert.ok(pets.every(pet => Math.abs(pet.getBoundingClientRect().width - initialSize) < 0.1)); for (const width of [120, 80, 120]) { firstParent.style.width = `${width}px`; root.style.height = '64px'; firstParent.style.top = '32px'; layout(); await timeout(50); - assert.ok(pets.every(pet => pet.getBoundingClientRect().width >= minimumSize - 0.1)); + assert.ok(pets.every(pet => Math.abs(pet.getBoundingClientRect().width - initialSize) < 0.1)); } }); @@ -3156,7 +3159,7 @@ suite('ChatPetWidget', () => { const right = Math.max(...rects.map(rect => rect.right)); const top = Math.min(...rects.map(rect => rect.top)); const bottom = Math.max(...rects.map(rect => rect.bottom)); - // At the minimum size, this many pets cannot fit in the narrowest area without overlapping. + // This many pets cannot fit in the narrowest area without overlapping. assert.deepStrictEqual({ count: rects.length, withinChat: left >= input.left - 0.1 && right <= input.right + 0.1 && top >= movement.top - 0.1 && bottom <= Math.min(input.top, movement.bottom) + 0.1, From 27702205996dad41d8a7dc50c97c65a2567b1099 Mon Sep 17 00:00:00 2001 From: Lisa Rosenberg Date: Thu, 12 Nov 2026 22:04:34 +0100 Subject: [PATCH 28/66] feat: keep subagent pet's size synchronized with main pet --- .../contrib/chat/browser/widget/chatPetWidget.ts | 11 ++++++++++- .../chat/test/browser/widget/chatPetWidget.test.ts | 5 +++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/vs/workbench/contrib/chat/browser/widget/chatPetWidget.ts b/src/vs/workbench/contrib/chat/browser/widget/chatPetWidget.ts index d26ae8ddd44539..b7ee793d91cabf 100644 --- a/src/vs/workbench/contrib/chat/browser/widget/chatPetWidget.ts +++ b/src/vs/workbench/contrib/chat/browser/widget/chatPetWidget.ts @@ -3025,7 +3025,7 @@ export class ChatPetWidget extends Disposable { continue; } const element = dom.append(this._subagentLayer, dom.$('.chat-pet-subagent', { 'aria-hidden': 'true' })); - const miniScale = Math.max(CHAT_PET_MIN_SUBAGENT_SCALE, 0.5 * (this._scale || 1)); + const miniScale = 0.5 * this._scale; const miniWidth = CHAT_PET_DISPLAY_SIZE * miniScale; const overlayBounds = this._overlay.getBoundingClientRect(); const { left, top } = this._getSubagentLanding(miniWidth); @@ -3335,6 +3335,15 @@ export class ChatPetWidget extends Disposable { private _setScale(scale: number): void { this._stopJumpGame('restore'); this._scale = scale; + for (const pet of this._subagentPets.values()) { + const previousScale = Number.parseFloat(pet.element.style.getPropertyValue('--chat-pet-subagent-scale')); + const miniScale = scale * 0.5; + pet.element.style.top = `${Number.parseFloat(pet.element.style.top) + CHAT_PET_DISPLAY_SIZE * (previousScale - miniScale)}px`; + pet.element.style.setProperty('--chat-pet-subagent-scale', String(miniScale)); + } + if (this._subagentPets.size && !this._subagentResizeScheduler.isScheduled()) { + this._subagentResizeScheduler.schedule(); + } const displaySize = this._getDisplaySize(); this._button.element.style.width = `${displaySize}px`; this._button.element.style.height = `${displaySize}px`; diff --git a/src/vs/workbench/contrib/chat/test/browser/widget/chatPetWidget.test.ts b/src/vs/workbench/contrib/chat/test/browser/widget/chatPetWidget.test.ts index 739efe1fe4ac29..e4abd7a3f9a308 100644 --- a/src/vs/workbench/contrib/chat/test/browser/widget/chatPetWidget.test.ts +++ b/src/vs/workbench/contrib/chat/test/browser/widget/chatPetWidget.test.ts @@ -3326,6 +3326,11 @@ suite('ChatPetWidget', () => { widget.setHost({ ...firstHost, model: constObservable(createSubagentTestModel([tool])) }); const pet = overlay.querySelector('.chat-pet-subagent')!; pet.classList.remove('arriving'); + for (const scale of [1.6, 0.4, 1]) { + service.setScale(scale); + assert.strictEqual(Number.parseFloat(pet.style.getPropertyValue('--chat-pet-subagent-scale')), scale * 0.5); + assert.ok(Math.abs(pet.getBoundingClientRect().width - button.getBoundingClientRect().width / 2) < 0.1); + } const body = pet.querySelector('img')!; await whenSpriteLoaded(body); setReducedMotion(true); From a9a31cd11930a22e2b84a30b59e16ea8782cda3b Mon Sep 17 00:00:00 2001 From: Lisa Rosenberg Date: Thu, 12 Nov 2026 22:07:58 +0100 Subject: [PATCH 29/66] chore: cleanup code --- .../contrib/chat/browser/widget/chatPetWidget.ts | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/vs/workbench/contrib/chat/browser/widget/chatPetWidget.ts b/src/vs/workbench/contrib/chat/browser/widget/chatPetWidget.ts index b7ee793d91cabf..355a9bd80cc7c2 100644 --- a/src/vs/workbench/contrib/chat/browser/widget/chatPetWidget.ts +++ b/src/vs/workbench/contrib/chat/browser/widget/chatPetWidget.ts @@ -3243,7 +3243,7 @@ export class ChatPetWidget extends Disposable { const platform = getChatPetFallTarget(input.left + input.width / 2, movement.top - 1, 0, 0, this._getPlatforms(), input.top).platform; const { left, right } = this._getSubagentHorizontalBounds(overlay, input, movement, platform); const bottom = Math.min(platform?.top ?? input.top, input.top, movement.bottom) - overlay.top; - const height = Math.min(CHAT_PET_SUBAGENT_MAX_HEIGHT, bottom - (movement.top - overlay.top)); + const height = bottom - (movement.top - overlay.top); const width = right - left; if (width < CHAT_PET_DISPLAY_SIZE * CHAT_PET_MIN_SUBAGENT_SCALE || height < CHAT_PET_DISPLAY_SIZE * CHAT_PET_MIN_SUBAGENT_SCALE) { return; @@ -3280,12 +3280,11 @@ export class ChatPetWidget extends Disposable { // The input's top edge is the floor; the movement bounds also include the input itself. const maximumBottom = Math.min(platform?.top ?? input.top, input.top, movement.bottom) - overlay.top; const width = maximumRight - minimumLeft; - const height = Math.min(CHAT_PET_SUBAGENT_MAX_HEIGHT, maximumBottom - minimumTop); + const height = maximumBottom - minimumTop; if (width < CHAT_PET_DISPLAY_SIZE * CHAT_PET_MIN_SUBAGENT_SCALE || height < CHAT_PET_DISPLAY_SIZE * CHAT_PET_MIN_SUBAGENT_SCALE) { return; } const pets = activePets.map(pet => ({ - element: pet.element, left: Number.parseFloat(pet.element.style.left), top: Number.parseFloat(pet.element.style.top), size: CHAT_PET_DISPLAY_SIZE * Number.parseFloat(pet.element.style.getPropertyValue('--chat-pet-subagent-scale')), @@ -3297,7 +3296,6 @@ export class ChatPetWidget extends Disposable { if (!this._subagentResizeScheduler.isScheduled()) { this._subagentResizeScheduler.schedule(); } - return; } } @@ -3335,9 +3333,9 @@ export class ChatPetWidget extends Disposable { private _setScale(scale: number): void { this._stopJumpGame('restore'); this._scale = scale; + const miniScale = scale * 0.5; for (const pet of this._subagentPets.values()) { const previousScale = Number.parseFloat(pet.element.style.getPropertyValue('--chat-pet-subagent-scale')); - const miniScale = scale * 0.5; pet.element.style.top = `${Number.parseFloat(pet.element.style.top) + CHAT_PET_DISPLAY_SIZE * (previousScale - miniScale)}px`; pet.element.style.setProperty('--chat-pet-subagent-scale', String(miniScale)); } From f88b99f5778e952e8421ce75eab6afe4f660abf3 Mon Sep 17 00:00:00 2001 From: Lisa Rosenberg Date: Thu, 12 Nov 2026 22:34:05 +0100 Subject: [PATCH 30/66] chore: optimize code --- .../chat/browser/widget/chatPetWidget.ts | 26 ++++++++++--------- 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/src/vs/workbench/contrib/chat/browser/widget/chatPetWidget.ts b/src/vs/workbench/contrib/chat/browser/widget/chatPetWidget.ts index 355a9bd80cc7c2..845c565c7e93c2 100644 --- a/src/vs/workbench/contrib/chat/browser/widget/chatPetWidget.ts +++ b/src/vs/workbench/contrib/chat/browser/widget/chatPetWidget.ts @@ -3013,6 +3013,7 @@ export class ChatPetWidget extends Disposable { private _updateSubagentPets(subagents: ReadonlySet): void { let removed = false; + let added = false; for (const [id, pet] of this._subagentPets) { if (!subagents.has(id)) { removed = true; @@ -3024,6 +3025,7 @@ export class ChatPetWidget extends Disposable { if (this._subagentPets.has(id)) { continue; } + added = true; const element = dom.append(this._subagentLayer, dom.$('.chat-pet-subagent', { 'aria-hidden': 'true' })); const miniScale = 0.5 * this._scale; const miniWidth = CHAT_PET_DISPLAY_SIZE * miniScale; @@ -3196,7 +3198,9 @@ export class ChatPetWidget extends Disposable { setState('idle'); this._subagentPets.set(id, { element, canvas, image, get accessoryImage() { return accessoryImage; }, eyes, disposables, updateBlink, updateAppearance, fallTo, isRespawning: () => respawnPhase !== 'none' }); } - this._constrainSubagentPets(); + if (added || removed) { + this._constrainSubagentPets(); + } if (removed) { this._settleSubagentPets(); } @@ -3284,17 +3288,15 @@ export class ChatPetWidget extends Disposable { if (width < CHAT_PET_DISPLAY_SIZE * CHAT_PET_MIN_SUBAGENT_SCALE || height < CHAT_PET_DISPLAY_SIZE * CHAT_PET_MIN_SUBAGENT_SCALE) { return; } - const pets = activePets.map(pet => ({ - left: Number.parseFloat(pet.element.style.left), - top: Number.parseFloat(pet.element.style.top), - size: CHAT_PET_DISPLAY_SIZE * Number.parseFloat(pet.element.style.getPropertyValue('--chat-pet-subagent-scale')), - })); - const left = Math.min(...pets.map(pet => pet.left)); - const right = Math.max(...pets.map(pet => pet.left + pet.size)); - const bottom = Math.max(...pets.map(pet => pet.top + pet.size)); - if (left < minimumLeft - CHAT_PET_SUBAGENT_BOUNDARY_EPSILON || right > maximumRight + CHAT_PET_SUBAGENT_BOUNDARY_EPSILON || bottom > maximumBottom + CHAT_PET_SUBAGENT_BOUNDARY_EPSILON) { - if (!this._subagentResizeScheduler.isScheduled()) { - this._subagentResizeScheduler.schedule(); + for (const pet of activePets) { + const left = Number.parseFloat(pet.element.style.left); + const top = Number.parseFloat(pet.element.style.top); + const size = CHAT_PET_DISPLAY_SIZE * Number.parseFloat(pet.element.style.getPropertyValue('--chat-pet-subagent-scale')); + if (left < minimumLeft - CHAT_PET_SUBAGENT_BOUNDARY_EPSILON || left + size > maximumRight + CHAT_PET_SUBAGENT_BOUNDARY_EPSILON || top + size > maximumBottom + CHAT_PET_SUBAGENT_BOUNDARY_EPSILON) { + if (!this._subagentResizeScheduler.isScheduled()) { + this._subagentResizeScheduler.schedule(); + } + break; } } } From 3def78e2463ed6479991929ec75b1b057d612dea Mon Sep 17 00:00:00 2001 From: Lisa Rosenberg Date: Thu, 12 Nov 2026 22:49:01 +0100 Subject: [PATCH 31/66] feat: remove unneeded code --- .../contrib/chat/browser/widget/chatPetWidget.ts | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/src/vs/workbench/contrib/chat/browser/widget/chatPetWidget.ts b/src/vs/workbench/contrib/chat/browser/widget/chatPetWidget.ts index 845c565c7e93c2..f604166bcc01a0 100644 --- a/src/vs/workbench/contrib/chat/browser/widget/chatPetWidget.ts +++ b/src/vs/workbench/contrib/chat/browser/widget/chatPetWidget.ts @@ -159,7 +159,6 @@ const CHAT_PET_DIZZY_SOURCE_HEIGHT = 128; const CHAT_PET_MAX_VERTICAL_OFFSET = 10; const CHAT_PET_DEFAULT_RIGHT_INSET = 32; const CHAT_PET_MIN_SCALE = 0.4; -const CHAT_PET_MIN_SUBAGENT_SCALE = CHAT_PET_MIN_SCALE * 0.5; const CHAT_PET_SCALE_STEP = 0.2; const CHAT_PET_SPEECH_BUBBLE_RIGHT_OVERHANG = 20; const CHAT_PET_SLEEP_RIGHT_OVERHANG = (CHAT_PET_SLEEP_SOURCE_WIDTH - CHAT_PET_SOURCE_SIZE) / 2; @@ -3247,11 +3246,6 @@ export class ChatPetWidget extends Disposable { const platform = getChatPetFallTarget(input.left + input.width / 2, movement.top - 1, 0, 0, this._getPlatforms(), input.top).platform; const { left, right } = this._getSubagentHorizontalBounds(overlay, input, movement, platform); const bottom = Math.min(platform?.top ?? input.top, input.top, movement.bottom) - overlay.top; - const height = bottom - (movement.top - overlay.top); - const width = right - left; - if (width < CHAT_PET_DISPLAY_SIZE * CHAT_PET_MIN_SUBAGENT_SCALE || height < CHAT_PET_DISPLAY_SIZE * CHAT_PET_MIN_SUBAGENT_SCALE) { - return; - } let displaced = false; for (const pet of pets) { const petLeft = Number.parseFloat(pet.element.style.left); @@ -3280,14 +3274,8 @@ export class ChatPetWidget extends Disposable { const bounds = this._getSubagentHorizontalBounds(overlay, input, movement, platform); const minimumLeft = bounds.left; const maximumRight = bounds.right; - const minimumTop = movement.top - overlay.top; // The input's top edge is the floor; the movement bounds also include the input itself. const maximumBottom = Math.min(platform?.top ?? input.top, input.top, movement.bottom) - overlay.top; - const width = maximumRight - minimumLeft; - const height = maximumBottom - minimumTop; - if (width < CHAT_PET_DISPLAY_SIZE * CHAT_PET_MIN_SUBAGENT_SCALE || height < CHAT_PET_DISPLAY_SIZE * CHAT_PET_MIN_SUBAGENT_SCALE) { - return; - } for (const pet of activePets) { const left = Number.parseFloat(pet.element.style.left); const top = Number.parseFloat(pet.element.style.top); From 49427926b11957365e6789a2a3615f6a3ea15085 Mon Sep 17 00:00:00 2001 From: Lisa Rosenberg Date: Thu, 12 Nov 2026 23:01:30 +0100 Subject: [PATCH 32/66] docs: add docstrings --- .../chat/browser/widget/chatPetWidget.ts | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/vs/workbench/contrib/chat/browser/widget/chatPetWidget.ts b/src/vs/workbench/contrib/chat/browser/widget/chatPetWidget.ts index f604166bcc01a0..01976f6f6f455f 100644 --- a/src/vs/workbench/contrib/chat/browser/widget/chatPetWidget.ts +++ b/src/vs/workbench/contrib/chat/browser/widget/chatPetWidget.ts @@ -145,8 +145,11 @@ const MOUSE_BOUNCE_HORIZONTAL_TRANSFER = 0.35; const MOUSE_BOUNCE_EDGE_KICK = 320; const MOUSE_BOUNCE_MAX_HORIZONTAL_VELOCITY = 1_800; const CHAT_PET_DISPLAY_SIZE = 48; +/** Maximum stacking height before mini pets share space. */ const CHAT_PET_SUBAGENT_MAX_HEIGHT = 96; +/** Tolerance for fractional pixels when checking mini-pet bounds. */ const CHAT_PET_SUBAGENT_BOUNDARY_EPSILON = 0.01; +/** Distance kept between mini pets and the edges of their platform. */ const CHAT_PET_SUBAGENT_EDGE_INSET = 12; const CHAT_PET_SOURCE_SIZE = 96; const CHAT_PET_SLEEP_SOURCE_WIDTH = 120; @@ -218,16 +221,27 @@ interface ChatPetSpriteElement { redrawFrame?: () => void; } +/** Visual state and lifecycle controls for one active subagent pet. */ interface ChatPetSubagent { + /** Container positioned on the chat overlay. */ readonly element: HTMLElement; + /** Canvas used to draw the pet and its accessory. */ readonly canvas: HTMLCanvasElement; + /** Image containing the current body sprite. */ readonly image: HTMLImageElement; + /** Image containing the current accessory, if any. */ readonly accessoryImage: HTMLImageElement | undefined; + /** Eye elements used for tracking and blinking. */ readonly eyes: HTMLElement; + /** Resources owned by this pet. */ readonly disposables: DisposableStore; + /** Updates whether blinking is enabled. */ readonly updateBlink: () => void; + /** Synchronizes appearance and motion with the main pet. */ readonly updateAppearance: (motionChanged: boolean, variantChanged: boolean, accessoryChanged: boolean) => void; + /** Starts a fall to an overlay-relative position, optionally followed by respawning. */ readonly fallTo: (top: number, respawn?: boolean) => void; + /** Reports whether a fall-and-respawn sequence is in progress. */ readonly isRespawning: () => boolean; } @@ -1265,10 +1279,15 @@ export class ChatPetHopController extends Disposable { export class ChatPetWidget extends Disposable { + /** Active pets keyed by request and tool call identity. */ private readonly _subagentPets = new Map(); + /** Chat model currently supplying active subagents. */ private _subagentModel: IChatModel | undefined; + /** Resources for active pets and their disappearance effects. */ private readonly _subagentEffects = this._register(new DisposableStore()); + /** Coalesces bounds checks while the chat is resizing. */ private readonly _subagentResizeScheduler = this._register(new RunOnceScheduler(() => this._reconcileSubagentResize(), 16)); + /** Overlay layer containing mini pets. */ private readonly _subagentLayer: HTMLElement; private parent: HTMLElement; private dragBounds: HTMLElement; @@ -2957,6 +2976,7 @@ export class ChatPetWidget extends Disposable { return this._button.element.offsetLeft; } + /** Returns the visible, inset horizontal bounds for mini-pet placement. */ private _getSubagentHorizontalBounds(overlay: DOMRect, input: DOMRect, movement: DOMRect, platform: IChatPetPlatform | undefined): { left: number; right: number } { const left = Math.max(0, input.left, movement.left, platform?.left ?? input.left); const right = Math.min(dom.getWindow(this._overlay).innerWidth, input.right, movement.right, platform?.right ?? input.right); @@ -3010,6 +3030,7 @@ export class ChatPetWidget extends Disposable { return { ...best!, top: Math.max(best!.top, minimumTop) }; } + /** Creates and removes pets to match the active subagent identities. */ private _updateSubagentPets(subagents: ReadonlySet): void { let removed = false; let added = false; @@ -3289,6 +3310,7 @@ export class ChatPetWidget extends Disposable { } } + /** Removes an active pet after playing its disappearance effect. */ private _despawnSubagentPet(pet: ChatPetSubagent): void { this._subagentEffects.delete(pet.disposables); pet.image.remove(); From 4595826689bd463b3c398dc05b9341af0279e3ae Mon Sep 17 00:00:00 2001 From: Lisa Rosenberg Date: Fri, 13 Nov 2026 17:16:23 +0100 Subject: [PATCH 33/66] feat: remove variables and animate the fall the same way the main pet does --- .../chat/browser/widget/chatPetWidget.ts | 53 +++++++++---------- .../chat/browser/widget/media/chatPet.css | 14 ----- .../test/browser/widget/chatPetWidget.test.ts | 44 +++++++-------- 3 files changed, 48 insertions(+), 63 deletions(-) diff --git a/src/vs/workbench/contrib/chat/browser/widget/chatPetWidget.ts b/src/vs/workbench/contrib/chat/browser/widget/chatPetWidget.ts index 01976f6f6f455f..ecaec26d42f353 100644 --- a/src/vs/workbench/contrib/chat/browser/widget/chatPetWidget.ts +++ b/src/vs/workbench/contrib/chat/browser/widget/chatPetWidget.ts @@ -3014,7 +3014,7 @@ export class ChatPetWidget extends Disposable { continue; } const otherLeft = Number.parseFloat(other.element.style.left); - const otherWidth = CHAT_PET_DISPLAY_SIZE * Number.parseFloat(other.element.style.getPropertyValue('--chat-pet-subagent-scale')); + const otherWidth = CHAT_PET_DISPLAY_SIZE * 0.5 * this._scale; if (left < otherLeft + otherWidth && left + size > otherLeft) { top = Math.min(top, Number.parseFloat(other.element.style.top) - size); } @@ -3053,13 +3053,8 @@ export class ChatPetWidget extends Disposable { const { left, top } = this._getSubagentLanding(miniWidth); element.style.left = `${left}px`; element.style.top = `${top}px`; - element.style.setProperty('--chat-pet-subagent-scale', String(miniScale)); + element.style.transform = `scale(${miniScale})`; const distance = Math.max(0, overlayBounds.top + top + miniWidth); - element.style.setProperty('--chat-pet-subagent-fall-distance', `${distance}px`); - element.style.setProperty('--chat-pet-subagent-fall-duration', `${getChatPetFallDuration(distance)}ms`); - if (!this._motionReduced) { - element.classList.add('arriving'); - } const canvas = dom.append(element, dom.$('canvas.chat-pet-subagent-canvas')) as HTMLCanvasElement; canvas.width = CHAT_PET_SOURCE_SIZE; canvas.height = CHAT_PET_SOURCE_SIZE; @@ -3152,17 +3147,23 @@ export class ChatPetWidget extends Disposable { } }); })); - disposables.add(dom.addDisposableListener(element, 'animationend', event => { - if (event.target === element && (event as AnimationEvent).animationName === 'chat-pet-subagent-fall') { - element.classList.remove('arriving'); + const fallAnimation = disposables.add(new MutableDisposable()); + const animateFall = (from: number, to: number) => { + const fall = element.animate([{ top: `${from}px` }, { top: `${to}px` }], { + duration: getChatPetFallDuration(to - from), + easing: 'cubic-bezier(0.42, 0, 1, 1)', + }); + fallAnimation.value = toDisposable(() => fall.cancel()); + fall.onfinish = () => { + fallAnimation.clear(); if (respawnPhase === 'falling') { respawnPhase = 'despawning'; setState('idle'); } else if (!this._motionReduced) { setState('splat'); } - } - })); + }; + }; const updateAppearance = (motionChanged: boolean, variantChanged: boolean, accessoryChanged: boolean) => { sprite.color = this._color; eyes.style.color = getChatPetEyeColor(this._color); @@ -3171,7 +3172,7 @@ export class ChatPetWidget extends Disposable { } if (motionChanged || variantChanged) { if (this._motionReduced) { - element.classList.remove('arriving'); + fallAnimation.clear(); if (respawnPhase === 'falling') { respawnPhase = 'despawning'; } @@ -3184,16 +3185,11 @@ export class ChatPetWidget extends Disposable { const fallTo = (top: number, respawn = false) => { const previousTop = element.getBoundingClientRect().top - this._overlay.getBoundingClientRect().top; respawnPhase = respawn ? 'falling' : 'none'; - element.classList.remove('arriving'); + fallAnimation.clear(); element.style.top = `${top}px`; setState('idle'); if (!this._motionReduced && top > previousTop) { - const distance = top - previousTop; - element.style.setProperty('--chat-pet-subagent-fall-distance', `${distance}px`); - element.style.setProperty('--chat-pet-subagent-fall-duration', `${getChatPetFallDuration(distance)}ms`); - // Restart the existing fall animation, including when another support disappears mid-fall. - void element.offsetWidth; - element.classList.add('arriving'); + animateFall(previousTop, top); } else if (respawn) { respawnPhase = 'despawning'; setState('idle'); @@ -3202,7 +3198,7 @@ export class ChatPetWidget extends Disposable { const advanceRespawn = () => { const overlay = this._overlay.getBoundingClientRect(); const input = this.dragBounds.getBoundingClientRect(); - const size = CHAT_PET_DISPLAY_SIZE * Number.parseFloat(element.style.getPropertyValue('--chat-pet-subagent-scale')); + const size = CHAT_PET_DISPLAY_SIZE * 0.5 * this._scale; if (respawnPhase === 'despawning') { respawnPhase = 'respawning'; element.style.left = `${Math.max(input.left - overlay.left, Math.min(Number.parseFloat(element.style.left), input.right - overlay.left - size))}px`; @@ -3216,6 +3212,9 @@ export class ChatPetWidget extends Disposable { } }; setState('idle'); + if (!this._motionReduced && distance > 0) { + animateFall(top - distance, top); + } this._subagentPets.set(id, { element, canvas, image, get accessoryImage() { return accessoryImage; }, eyes, disposables, updateBlink, updateAppearance, fallTo, isRespawning: () => respawnPhase !== 'none' }); } if (added || removed) { @@ -3235,7 +3234,7 @@ export class ChatPetWidget extends Disposable { pet, left: Number.parseFloat(pet.element.style.left), top: Number.parseFloat(pet.element.style.top), - size: CHAT_PET_DISPLAY_SIZE * Number.parseFloat(pet.element.style.getPropertyValue('--chat-pet-subagent-scale')), + size: CHAT_PET_DISPLAY_SIZE * 0.5 * this._scale, })).sort((a, b) => b.top - a.top); for (const [index, pet] of pets.entries()) { const landing = getChatPetFallTarget(overlay.left + pet.left, overlay.top + pet.top - POSITION_EPSILON, pet.size, pet.size, platforms, floor); @@ -3271,7 +3270,7 @@ export class ChatPetWidget extends Disposable { for (const pet of pets) { const petLeft = Number.parseFloat(pet.element.style.left); const petTop = Number.parseFloat(pet.element.style.top); - const size = CHAT_PET_DISPLAY_SIZE * Number.parseFloat(pet.element.style.getPropertyValue('--chat-pet-subagent-scale')); + const size = CHAT_PET_DISPLAY_SIZE * 0.5 * this._scale; if (petLeft < left - CHAT_PET_SUBAGENT_BOUNDARY_EPSILON || petLeft + size > right + CHAT_PET_SUBAGENT_BOUNDARY_EPSILON || petTop < movement.top - overlay.top - CHAT_PET_SUBAGENT_BOUNDARY_EPSILON || petTop + size > bottom + CHAT_PET_SUBAGENT_BOUNDARY_EPSILON) { displaced = true; pet.fallTo(movement.bottom - overlay.top - size, true); @@ -3300,7 +3299,7 @@ export class ChatPetWidget extends Disposable { for (const pet of activePets) { const left = Number.parseFloat(pet.element.style.left); const top = Number.parseFloat(pet.element.style.top); - const size = CHAT_PET_DISPLAY_SIZE * Number.parseFloat(pet.element.style.getPropertyValue('--chat-pet-subagent-scale')); + const size = CHAT_PET_DISPLAY_SIZE * 0.5 * this._scale; if (left < minimumLeft - CHAT_PET_SUBAGENT_BOUNDARY_EPSILON || left + size > maximumRight + CHAT_PET_SUBAGENT_BOUNDARY_EPSILON || top + size > maximumBottom + CHAT_PET_SUBAGENT_BOUNDARY_EPSILON) { if (!this._subagentResizeScheduler.isScheduled()) { this._subagentResizeScheduler.schedule(); @@ -3315,7 +3314,7 @@ export class ChatPetWidget extends Disposable { this._subagentEffects.delete(pet.disposables); pet.image.remove(); pet.accessoryImage?.remove(); - pet.element.classList.remove('chat-pet-subagent', 'arriving'); + pet.element.classList.remove('chat-pet-subagent'); pet.element.classList.add('chat-pet-subagent-despawning'); pet.eyes.remove(); const effects = this._subagentEffects.add(new DisposableStore()); @@ -3344,12 +3343,12 @@ export class ChatPetWidget extends Disposable { private _setScale(scale: number): void { this._stopJumpGame('restore'); + const previousScale = this._scale * 0.5; this._scale = scale; const miniScale = scale * 0.5; for (const pet of this._subagentPets.values()) { - const previousScale = Number.parseFloat(pet.element.style.getPropertyValue('--chat-pet-subagent-scale')); pet.element.style.top = `${Number.parseFloat(pet.element.style.top) + CHAT_PET_DISPLAY_SIZE * (previousScale - miniScale)}px`; - pet.element.style.setProperty('--chat-pet-subagent-scale', String(miniScale)); + pet.element.style.transform = `scale(${miniScale})`; } if (this._subagentPets.size && !this._subagentResizeScheduler.isScheduled()) { this._subagentResizeScheduler.schedule(); diff --git a/src/vs/workbench/contrib/chat/browser/widget/media/chatPet.css b/src/vs/workbench/contrib/chat/browser/widget/media/chatPet.css index 87d305c3635836..51342a872bfa3f 100644 --- a/src/vs/workbench/contrib/chat/browser/widget/media/chatPet.css +++ b/src/vs/workbench/contrib/chat/browser/widget/media/chatPet.css @@ -185,24 +185,10 @@ position: absolute; width: 48px; height: 48px; - transform: scale(var(--chat-pet-subagent-scale)); transform-origin: top left; pointer-events: none; } -.chat-pet-subagent.arriving { - animation: chat-pet-subagent-fall var(--chat-pet-subagent-fall-duration) cubic-bezier(0.42, 0, 1, 1) both; -} - -@keyframes chat-pet-subagent-fall { - from { transform: translateY(calc(-1 * var(--chat-pet-subagent-fall-distance))) scale(var(--chat-pet-subagent-scale)); } - to { transform: translateY(0) scale(var(--chat-pet-subagent-scale)); } -} - -.monaco-workbench.monaco-reduce-motion .chat-pet-subagent.arriving { - animation: none; -} - .chat-pet-subagent-canvas { width: 48px; height: 48px; diff --git a/src/vs/workbench/contrib/chat/test/browser/widget/chatPetWidget.test.ts b/src/vs/workbench/contrib/chat/test/browser/widget/chatPetWidget.test.ts index e4abd7a3f9a308..26cef688f4e59c 100644 --- a/src/vs/workbench/contrib/chat/test/browser/widget/chatPetWidget.test.ts +++ b/src/vs/workbench/contrib/chat/test/browser/widget/chatPetWidget.test.ts @@ -2855,7 +2855,7 @@ suite('ChatPetWidget', () => { assert.deepStrictEqual([...firstMini.querySelectorAll('.chat-pet-pupil')].map(pupil => pupil.style.transform), ['', '']); assert.deepStrictEqual([...mainPupils].map(pupil => pupil.style.transform), ['translate(2px, -2px)', 'translate(2px, -2px)']); assert.ok(firstMini.offsetLeft >= button.offsetLeft + button.offsetWidth); - const miniSize = 48 * Number.parseFloat(firstMini.style.getPropertyValue('--chat-pet-subagent-scale')); + const miniSize = 48 * 0.5; assert.strictEqual(Number.parseFloat(firstMini.style.top) + miniSize, 0); const [bodyImage, accessoryImage] = firstMini.querySelectorAll('img'); assert.ok(accessoryImage?.src.includes('/accessories/')); @@ -2884,7 +2884,7 @@ suite('ChatPetWidget', () => { assert.ok(minis[1].offsetLeft + miniSize <= button.offsetLeft || minis[1].offsetLeft >= button.offsetLeft + button.offsetWidth); assert.strictEqual(Number.parseFloat(minis[1].style.top) + miniSize, -60); assert.strictEqual(overlay.querySelectorAll('.chat-pet-subagent').length, 2); - assert.strictEqual(overlay.querySelectorAll('.chat-pet-subagent.arriving').length, 2); + assert.strictEqual([...overlay.querySelectorAll('.chat-pet-subagent')].filter(pet => pet.getAnimations().length > 0).length, 2); assert.strictEqual(button.querySelectorAll('.chat-pet-subagent').length, 0); assert.ok(overlay.querySelector('.chat-pet-subagent img')?.getAttribute('src')?.includes('buddy-')); const mini = overlay.querySelector('.chat-pet-subagent')!; @@ -2923,7 +2923,7 @@ suite('ChatPetWidget', () => { service.setHorizontalPosition(0.8); }, model); const pet = overlay.querySelector('.chat-pet-subagent')!; - assert.strictEqual(Number.parseFloat(pet.style.getPropertyValue('--chat-pet-subagent-scale')), 1); + assert.strictEqual(Number.parseFloat(pet.style.transform.slice(6)), 1); assert.ok(pet.offsetLeft + 48 <= button.offsetLeft || pet.offsetLeft >= button.offsetLeft + button.offsetWidth); }); @@ -3013,9 +3013,9 @@ suite('ChatPetWidget', () => { }); widget.setHost({ ...firstHost, model: constObservable(createSubagentTestModel(tools)) }); const pets = [...overlay.querySelectorAll('.chat-pet-subagent')]; - const scales = pets.map(pet => pet.style.getPropertyValue('--chat-pet-subagent-scale')); + const scales = pets.map(pet => pet.style.transform); for (const [index, pet] of pets.entries()) { - pet.classList.remove('arriving'); + pet.getAnimations().forEach(animation => animation.cancel()); pet.style.left = `${[20, 80, 90, 220][index]}px`; pet.style.top = `${index === 1 ? -48 : -24}px`; } @@ -3030,8 +3030,8 @@ suite('ChatPetWidget', () => { stays: [pets[0].style.left, pets[0].style.top], upper: [pets[1].style.left, pets[1].style.top], }, { stays: ['20px', '-24px'], upper: ['80px', '-24px'] }); - await waitForPetAnimation(() => pets.every(pet => !pet.classList.contains('arriving') && pet.querySelector('img')?.getAttribute('src')?.includes('buddy-idle-') === true)); - assert.deepStrictEqual(pets.map(pet => pet.style.getPropertyValue('--chat-pet-subagent-scale')), scales); + await waitForPetAnimation(() => pets.every(pet => pet.getAnimations().length === 0 && pet.querySelector('img')?.getAttribute('src')?.includes('buddy-idle-') === true)); + assert.deepStrictEqual(pets.map(pet => pet.style.transform), scales); const input = firstParent.getBoundingClientRect(); const rects = pets.map(pet => pet.getBoundingClientRect()); assert.ok(rects.every(rect => rect.left >= input.left - 0.1 && rect.right <= input.right + 0.1 && rect.bottom <= input.top + 0.1)); @@ -3209,7 +3209,7 @@ suite('ChatPetWidget', () => { const pets = [...overlay.querySelectorAll('.chat-pet-subagent')]; // A three-high stack on the input platform and an independent neighbor on the ground. pets.forEach((pet, index) => { - pet.classList.remove('arriving'); + pet.getAnimations().forEach(animation => animation.cancel()); pet.style.left = index === 3 ? '96px' : '48px'; pet.style.top = `${index === 3 ? -24 : -(index + 1) * 24}px`; }); @@ -3219,7 +3219,7 @@ suite('ChatPetWidget', () => { assert.deepStrictEqual({ remaining: [...overlay.querySelectorAll('.chat-pet-subagent')], tops: pets.filter((_, index) => index !== removedIndex).map(pet => pet.style.top), - falling: pets[2].classList.contains('arriving'), + falling: pets[2].getAnimations().length > 0, neighbor: pets[3].getBoundingClientRect().toJSON(), }, { remaining: pets.filter((_, index) => index !== removedIndex), tops: ['-24px', '-48px', '-24px'], falling: !reducedMotion, neighbor: neighborPosition }); // Removing the next support mid-fall must continue from the currently rendered position. @@ -3231,11 +3231,11 @@ suite('ChatPetWidget', () => { changed.fire({ reason: 'other' }); assert.strictEqual(pets[2].style.top, '-24px'); if (!reducedMotion) { - assert.ok(Math.abs(Number.parseFloat(pets[2].style.getPropertyValue('--chat-pet-subagent-fall-distance')) - (-24 - previousTop)) < 0.1); + assert.ok(Math.abs(Number.parseFloat((pets[2].getAnimations()[0].effect as KeyframeEffect).getKeyframes()[0].top as string) - previousTop) < 0.1); setReducedMotion(true); } assert.deepStrictEqual({ - falling: pets[2].classList.contains('arriving'), + falling: pets[2].getAnimations().length > 0, bottom: pets[2].getBoundingClientRect().bottom, }, { falling: false, bottom: overlay.getBoundingClientRect().top }); }); @@ -3286,14 +3286,14 @@ suite('ChatPetWidget', () => { platformChanged.fire(); assert.ok(pets.every(pet => Math.abs(Number.parseFloat(pet.style.top) + 24 + overlay.getBoundingClientRect().top - root.getBoundingClientRect().bottom) < 0.1)); await waitForPetAnimation(() => pets.every(pet => pet.querySelector('img')?.getAttribute('src')?.includes('buddy-respawn-') === true)); - await waitForPetAnimation(() => pets.every(pet => !pet.classList.contains('arriving') && pet.querySelector('img')?.getAttribute('src')?.includes('buddy-idle-') === true)); + await waitForPetAnimation(() => pets.every(pet => pet.getAnimations().length === 0 && pet.querySelector('img')?.getAttribute('src')?.includes('buddy-idle-') === true)); assert.deepStrictEqual({ identity: [...overlay.querySelectorAll('.chat-pet-subagent')], onPrompt: pets.every(pet => pet.getBoundingClientRect().bottom <= firstParent.getBoundingClientRect().top - 60 + 0.1), }, { identity: pets, onPrompt: true }); promptVisible = false; platformChanged.fire(); - await waitForPetAnimation(() => pets.every(pet => !pet.classList.contains('arriving'))); + await waitForPetAnimation(() => pets.every(pet => pet.getAnimations().length === 0)); assert.ok(pets.every(pet => pet.getBoundingClientRect().bottom <= firstParent.getBoundingClientRect().top + 0.1)); }); } @@ -3325,10 +3325,10 @@ suite('ChatPetWidget', () => { tool.toolSpecificData = { kind: 'subagent', isActive: true }; widget.setHost({ ...firstHost, model: constObservable(createSubagentTestModel([tool])) }); const pet = overlay.querySelector('.chat-pet-subagent')!; - pet.classList.remove('arriving'); + pet.getAnimations().forEach(animation => animation.cancel()); for (const scale of [1.6, 0.4, 1]) { service.setScale(scale); - assert.strictEqual(Number.parseFloat(pet.style.getPropertyValue('--chat-pet-subagent-scale')), scale * 0.5); + assert.strictEqual(Number.parseFloat(pet.style.transform.slice(6)), scale * 0.5); assert.ok(Math.abs(pet.getBoundingClientRect().width - button.getBoundingClientRect().width / 2) < 0.1); } const body = pet.querySelector('img')!; @@ -3361,7 +3361,7 @@ suite('ChatPetWidget', () => { const pet = overlay.querySelector('.chat-pet-subagent')!; const image = pet.querySelector('img')!; await whenSpriteLoaded(image); - pet.dispatchEvent(new mainWindow.AnimationEvent('animationend', { animationName: 'chat-pet-subagent-fall' })); + pet.getAnimations()[0]?.dispatchEvent(new mainWindow.Event('finish')); await whenSpriteLoaded(image); assert.ok(image.getAttribute('src')?.includes('buddy-splat-')); setReducedMotion(true); @@ -3393,12 +3393,12 @@ suite('ChatPetWidget', () => { const eyes = first.querySelector('.chat-pet-eyes')!; await Promise.all([whenSpriteLoaded(image), whenSpriteLoaded(secondImage)]); const idleSource = image.getAttribute('src'); - const land = (pet: HTMLElement) => pet.dispatchEvent(new mainWindow.AnimationEvent('animationend', { animationName: 'chat-pet-subagent-fall' })); + const land = (pet: HTMLElement) => pet.getAnimations()[0]?.dispatchEvent(new mainWindow.Event('finish')); land(first); await whenSpriteLoaded(image); assert.deepStrictEqual({ squishing: image.getAttribute('src')?.includes('buddy-splat-'), - arriving: first.classList.contains('arriving'), + arriving: first.getAnimations().length > 0, idleEyes: eyes.classList.contains('tracking'), otherSource: secondImage.getAttribute('src'), }, { squishing: true, arriving: false, idleEyes: false, otherSource: idleSource }); @@ -3420,11 +3420,11 @@ suite('ChatPetWidget', () => { const tool = new ChatToolInvocation(undefined, { id: 'subagent', displayName: 'Subagent', modelDescription: 'Subagent', source: ToolDataSource.Internal }, 'subagent', undefined, {}); tool.toolSpecificData = { kind: 'subagent', isActive: true }; widget.setHost({ ...firstHost, model: constObservable(createSubagentTestModel([tool], changed.event)) }); - assert.ok(overlay.querySelector('.chat-pet-subagent:not(.arriving)')); + assert.ok(overlay.querySelector('.chat-pet-subagent')); const pet = overlay.querySelector('.chat-pet-subagent')!; const image = pet.querySelector('img')!; const idleSource = image.getAttribute('src'); - pet.dispatchEvent(new mainWindow.AnimationEvent('animationend', { animationName: 'chat-pet-subagent-fall' })); + pet.getAnimations()[0]?.dispatchEvent(new mainWindow.Event('finish')); assert.strictEqual(image.getAttribute('src'), idleSource); tool.toolSpecificData = { kind: 'subagent', isActive: false }; changed.fire({ reason: 'other' }); @@ -3440,8 +3440,8 @@ suite('ChatPetWidget', () => { tool.toolSpecificData = { kind: 'subagent', isActive: true }; widget.setHost({ ...firstHost, model: constObservable(createSubagentTestModel([tool])) }); const pet = overlay.querySelector('.chat-pet-subagent')!; - // Exercise idle frames independently of the CSS arrival and landing animation. - pet.classList.remove('arriving'); + // Exercise idle frames independently of the arrival and landing animation. + pet.getAnimations().forEach(animation => animation.cancel()); const eyes = pet.querySelector('.chat-pet-eyes')!; const pupil = pet.querySelector('.chat-pet-pupil')!; await whenSpriteLoaded(pet.querySelector('img')!); From 806816a5c7036fea5f6f698632ef26b4edf4d42c Mon Sep 17 00:00:00 2001 From: Lisa Rosenberg Date: Fri, 13 Nov 2026 17:21:54 +0100 Subject: [PATCH 34/66] feat: don't rescan whole chat history --- .../chat/browser/widget/chatPetWidget.ts | 36 +++++++++++++------ .../test/browser/widget/chatPetWidget.test.ts | 35 ++++++++++++++++++ 2 files changed, 61 insertions(+), 10 deletions(-) diff --git a/src/vs/workbench/contrib/chat/browser/widget/chatPetWidget.ts b/src/vs/workbench/contrib/chat/browser/widget/chatPetWidget.ts index ecaec26d42f353..7018fdd913f5b9 100644 --- a/src/vs/workbench/contrib/chat/browser/widget/chatPetWidget.ts +++ b/src/vs/workbench/contrib/chat/browser/widget/chatPetWidget.ts @@ -1913,24 +1913,40 @@ export class ChatPetWidget extends Disposable { } observableSignalFromEvent(this, model.onDidChange).read(reader); const subagents = new Set(); + let initializing = true; for (const request of model.getRequests()) { const response = request.response; if (!response) { continue; } - observableSignalFromEvent(this, response.onDidChange).read(reader); - for (const part of response.response.value) { - if (part.kind !== 'toolInvocation') { - continue; + let previous = new Set(); + reader.store.add(autorun(reader => { + observableSignalFromEvent(this, response.onDidChange).read(reader); + const current = new Set(); + for (const part of response.response.value) { + if (part.kind !== 'toolInvocation') { + continue; + } + part.toolSpecificDataKind.read(reader); + part.state.read(reader); + const data = part.toolSpecificData; + if (data?.kind === 'subagent' && data.presentation !== 'phase' && data.hasStarted !== false && (getSubagentIsActive(data) ?? !IChatToolInvocation.isComplete(part, reader))) { + current.add(JSON.stringify([request.id, part.toolCallId])); + } } - part.toolSpecificDataKind.read(reader); - part.state.read(reader); - const data = part.toolSpecificData; - if (data?.kind === 'subagent' && data.presentation !== 'phase' && data.hasStarted !== false && (getSubagentIsActive(data) ?? !IChatToolInvocation.isComplete(part, reader))) { - subagents.add(JSON.stringify([request.id, part.toolCallId])); + for (const id of previous) { + subagents.delete(id); } - } + for (const id of current) { + subagents.add(id); + } + previous = current; + if (!initializing) { + this._updateSubagentPets(subagents); + } + })); } + initializing = false; this._updateSubagentPets(subagents); })); diff --git a/src/vs/workbench/contrib/chat/test/browser/widget/chatPetWidget.test.ts b/src/vs/workbench/contrib/chat/test/browser/widget/chatPetWidget.test.ts index 26cef688f4e59c..516891f1667b97 100644 --- a/src/vs/workbench/contrib/chat/test/browser/widget/chatPetWidget.test.ts +++ b/src/vs/workbench/contrib/chat/test/browser/widget/chatPetWidget.test.ts @@ -2829,6 +2829,41 @@ suite('ChatPetWidget', () => { }(); } + test('mini pets update only the changed response while tracking older subagents', () => { + const { widget, firstHost, overlay } = createHostTransitionHarness(true); + const changes = [disposables.add(new Emitter()), disposables.add(new Emitter())]; + const tools = ['older', 'current'].map(id => { + const tool = new ChatToolInvocation(undefined, { id, displayName: id, modelDescription: 'Subagent', source: ToolDataSource.Internal }, id, undefined, {}); + tool.toolSpecificData = { kind: 'subagent', isActive: true }; + return tool; + }); + const reads = [0, 0]; + const requests = tools.map((tool, index) => { + const response = new class extends mock() { + override readonly onDidChange = changes[index].event; + override readonly isPendingConfirmation = constObservable(undefined); + override readonly response = new class extends mock() { + override get value(): IChatProgressResponseContent[] { reads[index]++; return [tool]; } + }(); + }(); + return new class extends mock() { override readonly id = `request-${index}`; override readonly response = response; }(); + }); + const model = new class extends mock() { + override readonly onDidChange = Event.None; + override readonly hasActiveRequest = constObservable(true); + override readonly lastRequestObs = constObservable(requests[1]); + override getRequests(): IChatRequestModel[] { return requests; } + }(); + widget.setHost({ ...firstHost, model: constObservable(model) }); + assert.strictEqual(overlay.querySelectorAll('.chat-pet-subagent').length, 2); + reads[0] = 0; + changes[1].fire({ reason: 'other' }); + assert.strictEqual(reads[0], 0); + tools[0].toolSpecificData = { kind: 'subagent', isActive: false }; + changes[0].fire({ reason: 'other' }); + assert.strictEqual(overlay.querySelectorAll('.chat-pet-subagent').length, 1); + }); + test('shows one mini pet per active subagent and removes it when it stops', async () => { const { widget, firstHost, button, overlay, service } = createHostTransitionHarness(); const responseChanged = disposables.add(new Emitter()); From c20b2ffa3939183617a3f33791737013f7038ece Mon Sep 17 00:00:00 2001 From: Lisa Rosenberg Date: Fri, 13 Nov 2026 17:23:41 +0100 Subject: [PATCH 35/66] feat: only update platform position for subagent pets if there are any --- src/vs/workbench/contrib/chat/browser/widget/chatPetWidget.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/vs/workbench/contrib/chat/browser/widget/chatPetWidget.ts b/src/vs/workbench/contrib/chat/browser/widget/chatPetWidget.ts index 7018fdd913f5b9..6acdb323632402 100644 --- a/src/vs/workbench/contrib/chat/browser/widget/chatPetWidget.ts +++ b/src/vs/workbench/contrib/chat/browser/widget/chatPetWidget.ts @@ -2363,7 +2363,7 @@ export class ChatPetWidget extends Disposable { } private _updatePlatformPosition(): void { - if (this._enabled) { + if (this._enabled && this._subagentPets.size) { this._settleSubagentPets(true); } if (this._jumpGame.value) { From 95143a30d955dd513ed8f4393faa4eb53494dd49 Mon Sep 17 00:00:00 2001 From: Lisa Rosenberg Date: Fri, 13 Nov 2026 17:26:54 +0100 Subject: [PATCH 36/66] feat: optimize pet position and size storing --- .../chat/browser/widget/chatPetWidget.ts | 37 +++++++++++-------- .../test/browser/widget/chatPetWidget.test.ts | 18 ++++++--- 2 files changed, 34 insertions(+), 21 deletions(-) diff --git a/src/vs/workbench/contrib/chat/browser/widget/chatPetWidget.ts b/src/vs/workbench/contrib/chat/browser/widget/chatPetWidget.ts index 6acdb323632402..950aedd95876b9 100644 --- a/src/vs/workbench/contrib/chat/browser/widget/chatPetWidget.ts +++ b/src/vs/workbench/contrib/chat/browser/widget/chatPetWidget.ts @@ -225,6 +225,9 @@ interface ChatPetSpriteElement { interface ChatPetSubagent { /** Container positioned on the chat overlay. */ readonly element: HTMLElement; + /** Landing position relative to the overlay. */ + left: number; + top: number; /** Canvas used to draw the pet and its accessory. */ readonly canvas: HTMLCanvasElement; /** Image containing the current body sprite. */ @@ -3029,10 +3032,8 @@ export class ChatPetWidget extends Disposable { if (other.isRespawning()) { continue; } - const otherLeft = Number.parseFloat(other.element.style.left); - const otherWidth = CHAT_PET_DISPLAY_SIZE * 0.5 * this._scale; - if (left < otherLeft + otherWidth && left + size > otherLeft) { - top = Math.min(top, Number.parseFloat(other.element.style.top) - size); + if (left < other.left + size && left + size > other.left) { + top = Math.min(top, other.top - size); } } if (top >= minimumTop - CHAT_PET_SUBAGENT_BOUNDARY_EPSILON) { @@ -3202,6 +3203,7 @@ export class ChatPetWidget extends Disposable { const previousTop = element.getBoundingClientRect().top - this._overlay.getBoundingClientRect().top; respawnPhase = respawn ? 'falling' : 'none'; fallAnimation.clear(); + pet.top = top; element.style.top = `${top}px`; setState('idle'); if (!this._motionReduced && top > previousTop) { @@ -3217,21 +3219,25 @@ export class ChatPetWidget extends Disposable { const size = CHAT_PET_DISPLAY_SIZE * 0.5 * this._scale; if (respawnPhase === 'despawning') { respawnPhase = 'respawning'; - element.style.left = `${Math.max(input.left - overlay.left, Math.min(Number.parseFloat(element.style.left), input.right - overlay.left - size))}px`; - element.style.top = `${this.movementBounds.getBoundingClientRect().top - overlay.top}px`; + pet.left = Math.max(input.left - overlay.left, Math.min(pet.left, input.right - overlay.left - size)); + pet.top = this.movementBounds.getBoundingClientRect().top - overlay.top; + element.style.left = `${pet.left}px`; + element.style.top = `${pet.top}px`; setState('idle'); } else if (respawnPhase === 'respawning') { const landing = this._getSubagentLanding(size); - element.style.left = `${landing.left}px`; + pet.left = landing.left; + element.style.left = `${pet.left}px`; fallTo(landing.top); this._constrainSubagentPets(); } }; + const pet: ChatPetSubagent = { element, left, top, canvas, image, get accessoryImage() { return accessoryImage; }, eyes, disposables, updateBlink, updateAppearance, fallTo, isRespawning: () => respawnPhase !== 'none' }; setState('idle'); if (!this._motionReduced && distance > 0) { animateFall(top - distance, top); } - this._subagentPets.set(id, { element, canvas, image, get accessoryImage() { return accessoryImage; }, eyes, disposables, updateBlink, updateAppearance, fallTo, isRespawning: () => respawnPhase !== 'none' }); + this._subagentPets.set(id, pet); } if (added || removed) { this._constrainSubagentPets(); @@ -3248,8 +3254,8 @@ export class ChatPetWidget extends Disposable { const floor = platformChanged ? this.movementBounds.getBoundingClientRect().bottom : Math.min(this.dragBounds.getBoundingClientRect().top, this.movementBounds.getBoundingClientRect().bottom); const pets = [...this._subagentPets.values()].filter(pet => !pet.isRespawning()).map(pet => ({ pet, - left: Number.parseFloat(pet.element.style.left), - top: Number.parseFloat(pet.element.style.top), + left: pet.left, + top: pet.top, size: CHAT_PET_DISPLAY_SIZE * 0.5 * this._scale, })).sort((a, b) => b.top - a.top); for (const [index, pet] of pets.entries()) { @@ -3284,8 +3290,8 @@ export class ChatPetWidget extends Disposable { const bottom = Math.min(platform?.top ?? input.top, input.top, movement.bottom) - overlay.top; let displaced = false; for (const pet of pets) { - const petLeft = Number.parseFloat(pet.element.style.left); - const petTop = Number.parseFloat(pet.element.style.top); + const petLeft = pet.left; + const petTop = pet.top; const size = CHAT_PET_DISPLAY_SIZE * 0.5 * this._scale; if (petLeft < left - CHAT_PET_SUBAGENT_BOUNDARY_EPSILON || petLeft + size > right + CHAT_PET_SUBAGENT_BOUNDARY_EPSILON || petTop < movement.top - overlay.top - CHAT_PET_SUBAGENT_BOUNDARY_EPSILON || petTop + size > bottom + CHAT_PET_SUBAGENT_BOUNDARY_EPSILON) { displaced = true; @@ -3313,8 +3319,8 @@ export class ChatPetWidget extends Disposable { // The input's top edge is the floor; the movement bounds also include the input itself. const maximumBottom = Math.min(platform?.top ?? input.top, input.top, movement.bottom) - overlay.top; for (const pet of activePets) { - const left = Number.parseFloat(pet.element.style.left); - const top = Number.parseFloat(pet.element.style.top); + const left = pet.left; + const top = pet.top; const size = CHAT_PET_DISPLAY_SIZE * 0.5 * this._scale; if (left < minimumLeft - CHAT_PET_SUBAGENT_BOUNDARY_EPSILON || left + size > maximumRight + CHAT_PET_SUBAGENT_BOUNDARY_EPSILON || top + size > maximumBottom + CHAT_PET_SUBAGENT_BOUNDARY_EPSILON) { if (!this._subagentResizeScheduler.isScheduled()) { @@ -3363,7 +3369,8 @@ export class ChatPetWidget extends Disposable { this._scale = scale; const miniScale = scale * 0.5; for (const pet of this._subagentPets.values()) { - pet.element.style.top = `${Number.parseFloat(pet.element.style.top) + CHAT_PET_DISPLAY_SIZE * (previousScale - miniScale)}px`; + pet.top += CHAT_PET_DISPLAY_SIZE * (previousScale - miniScale); + pet.element.style.top = `${pet.top}px`; pet.element.style.transform = `scale(${miniScale})`; } if (this._subagentPets.size && !this._subagentResizeScheduler.isScheduled()) { diff --git a/src/vs/workbench/contrib/chat/test/browser/widget/chatPetWidget.test.ts b/src/vs/workbench/contrib/chat/test/browser/widget/chatPetWidget.test.ts index 516891f1667b97..c3458cd27d265c 100644 --- a/src/vs/workbench/contrib/chat/test/browser/widget/chatPetWidget.test.ts +++ b/src/vs/workbench/contrib/chat/test/browser/widget/chatPetWidget.test.ts @@ -2829,6 +2829,15 @@ suite('ChatPetWidget', () => { }(); } + function setMiniPetPosition(widget: ChatPetWidget, element: HTMLElement, left: number, top: number): void { + // eslint-disable-next-line local/code-no-bracket-notation-for-identifiers -- Set up positions without exposing a test-only API. + const pet = [...widget['_subagentPets'].values()].find(pet => pet.element === element)!; + pet.left = left; + pet.top = top; + element.style.left = `${left}px`; + element.style.top = `${top}px`; + } + test('mini pets update only the changed response while tracking older subagents', () => { const { widget, firstHost, overlay } = createHostTransitionHarness(true); const changes = [disposables.add(new Emitter()), disposables.add(new Emitter())]; @@ -3051,8 +3060,7 @@ suite('ChatPetWidget', () => { const scales = pets.map(pet => pet.style.transform); for (const [index, pet] of pets.entries()) { pet.getAnimations().forEach(animation => animation.cancel()); - pet.style.left = `${[20, 80, 90, 220][index]}px`; - pet.style.top = `${index === 1 ? -48 : -24}px`; + setMiniPetPosition(widget, pet, [20, 80, 90, 220][index], index === 1 ? -48 : -24); } firstParent.style.width = '120px'; layout(); @@ -3083,8 +3091,7 @@ suite('ChatPetWidget', () => { tool.toolSpecificData = { kind: 'subagent', isActive: true }; widget.setHost({ ...firstHost, model: constObservable(createSubagentTestModel([tool])) }); const pet = overlay.querySelector('.chat-pet-subagent')!; - pet.style.left = '98px'; - pet.style.top = '-24px'; + setMiniPetPosition(widget, pet, 98, -24); firstParent.style.width = '120px'; layout(); clock.tick(8); @@ -3245,8 +3252,7 @@ suite('ChatPetWidget', () => { // A three-high stack on the input platform and an independent neighbor on the ground. pets.forEach((pet, index) => { pet.getAnimations().forEach(animation => animation.cancel()); - pet.style.left = index === 3 ? '96px' : '48px'; - pet.style.top = `${index === 3 ? -24 : -(index + 1) * 24}px`; + setMiniPetPosition(widget, pet, index === 3 ? 96 : 48, index === 3 ? -24 : -(index + 1) * 24); }); const neighborPosition = pets[3].getBoundingClientRect().toJSON(); tools[removedIndex].toolSpecificData = { kind: 'subagent', isActive: false }; From ce55c495844e24e2120843244db2a980fdff2038 Mon Sep 17 00:00:00 2001 From: Lisa Rosenberg Date: Fri, 13 Nov 2026 17:29:30 +0100 Subject: [PATCH 37/66] feat: remove duplicated bounds logic --- .../chat/browser/widget/chatPetWidget.ts | 76 ++++++------------- 1 file changed, 23 insertions(+), 53 deletions(-) diff --git a/src/vs/workbench/contrib/chat/browser/widget/chatPetWidget.ts b/src/vs/workbench/contrib/chat/browser/widget/chatPetWidget.ts index 950aedd95876b9..2be855fc402bd0 100644 --- a/src/vs/workbench/contrib/chat/browser/widget/chatPetWidget.ts +++ b/src/vs/workbench/contrib/chat/browser/widget/chatPetWidget.ts @@ -2334,9 +2334,7 @@ export class ChatPetWidget extends Disposable { } private _handleHostLayoutChange(): void { - if (this._subagentPets.size && !this._subagentResizeScheduler.isScheduled()) { - this._subagentResizeScheduler.schedule(); - } + this._scheduleSubagentResize(); if (this._jumpGame.value) { this._jumpGame.value.layout(); return; @@ -2995,22 +2993,24 @@ export class ChatPetWidget extends Disposable { return this._button.element.offsetLeft; } - /** Returns the visible, inset horizontal bounds for mini-pet placement. */ - private _getSubagentHorizontalBounds(overlay: DOMRect, input: DOMRect, movement: DOMRect, platform: IChatPetPlatform | undefined): { left: number; right: number } { + /** Returns the visible bounds and platforms for mini-pet placement. */ + private _getSubagentBounds(): { overlay: DOMRect; movement: DOMRect; platforms: readonly IChatPetPlatform[]; left: number; right: number; bottom: number; floor: number } { + const overlay = this._overlay.getBoundingClientRect(); + const input = this.dragBounds.getBoundingClientRect(); + const movement = this.movementBounds.getBoundingClientRect(); + const platforms = this._getPlatforms(); + const platform = getChatPetFallTarget(input.left + input.width / 2, movement.top - 1, 0, 0, platforms, input.top).platform; const left = Math.max(0, input.left, movement.left, platform?.left ?? input.left); const right = Math.min(dom.getWindow(this._overlay).innerWidth, input.right, movement.right, platform?.right ?? input.right); const inset = Math.min(CHAT_PET_SUBAGENT_EDGE_INSET, Math.max(0, (right - left) / 4)); - return { left: left + inset - overlay.left, right: right - inset - overlay.left }; + const floor = Math.min(input.top, movement.bottom); + return { overlay, movement, platforms, left: left + inset - overlay.left, right: right - inset - overlay.left, bottom: Math.min(platform?.top ?? input.top, floor) - overlay.top, floor }; } /** Choose a random landing point, accounting for mini pets already on the platform. */ private _getSubagentLanding(size: number): { left: number; top: number } { - const overlay = this._overlay.getBoundingClientRect(); - const input = this.dragBounds.getBoundingClientRect(); - const movement = this.movementBounds.getBoundingClientRect(); - const platforms = this._getPlatforms(); - const platform = getChatPetFallTarget(input.left + input.width / 2, movement.top - 1, 0, 0, platforms, input.top).platform; - const bounds = this._getSubagentHorizontalBounds(overlay, input, movement, platform); + const bounds = this._getSubagentBounds(); + const { overlay, movement, platforms, floor } = bounds; const minimumLeft = bounds.left; const maximumLeft = Math.max(minimumLeft, bounds.right - size); const petLeft = this._button.element.offsetLeft; @@ -3018,8 +3018,7 @@ export class ChatPetWidget extends Disposable { const afterPetStart = Math.max(minimumLeft, petLeft + this._getDisplaySize()); const afterPet = Math.max(0, maximumLeft - afterPetStart); const available = beforePet + afterPet; - const floor = Math.min(input.top, movement.bottom); - const minimumTop = Math.max(movement.top, Math.min(platform?.top ?? input.top, floor) - CHAT_PET_SUBAGENT_MAX_HEIGHT) - overlay.top; + const minimumTop = Math.max(movement.top - overlay.top, bounds.bottom - CHAT_PET_SUBAGENT_MAX_HEIGHT); const attempts = Math.max(1, Math.ceil(available / Math.max(1, size / 2))); const start = Math.random() * available; let best: { left: number; top: number } | undefined; @@ -3229,7 +3228,7 @@ export class ChatPetWidget extends Disposable { pet.left = landing.left; element.style.left = `${pet.left}px`; fallTo(landing.top); - this._constrainSubagentPets(); + this._scheduleSubagentResize(); } }; const pet: ChatPetSubagent = { element, left, top, canvas, image, get accessoryImage() { return accessoryImage; }, eyes, disposables, updateBlink, updateAppearance, fallTo, isRespawning: () => respawnPhase !== 'none' }; @@ -3240,7 +3239,7 @@ export class ChatPetWidget extends Disposable { this._subagentPets.set(id, pet); } if (added || removed) { - this._constrainSubagentPets(); + this._scheduleSubagentResize(); } if (removed) { this._settleSubagentPets(); @@ -3276,18 +3275,19 @@ export class ChatPetWidget extends Disposable { } } + private _scheduleSubagentResize(): void { + if (this._subagentPets.size && !this._subagentResizeScheduler.isScheduled()) { + this._subagentResizeScheduler.schedule(); + } + } + /** Relocate only mini pets that no longer fit after resizing has settled. */ private _reconcileSubagentResize(): void { const pets = [...this._subagentPets.values()].filter(pet => !pet.isRespawning()); if (!pets.length) { return; } - const overlay = this._overlay.getBoundingClientRect(); - const input = this.dragBounds.getBoundingClientRect(); - const movement = this.movementBounds.getBoundingClientRect(); - const platform = getChatPetFallTarget(input.left + input.width / 2, movement.top - 1, 0, 0, this._getPlatforms(), input.top).platform; - const { left, right } = this._getSubagentHorizontalBounds(overlay, input, movement, platform); - const bottom = Math.min(platform?.top ?? input.top, input.top, movement.bottom) - overlay.top; + const { overlay, movement, left, right, bottom } = this._getSubagentBounds(); let displaced = false; for (const pet of pets) { const petLeft = pet.left; @@ -3303,34 +3303,6 @@ export class ChatPetWidget extends Disposable { } } - /** Check whether pets need to fall after their bounds change. */ - private _constrainSubagentPets(): void { - const activePets = [...this._subagentPets.values()].filter(pet => !pet.isRespawning()); - if (!activePets.length) { - return; - } - const overlay = this._overlay.getBoundingClientRect(); - const input = this.dragBounds.getBoundingClientRect(); - const movement = this.movementBounds.getBoundingClientRect(); - const platform = getChatPetFallTarget(input.left + input.width / 2, movement.top - 1, 0, 0, this._getPlatforms(), input.top).platform; - const bounds = this._getSubagentHorizontalBounds(overlay, input, movement, platform); - const minimumLeft = bounds.left; - const maximumRight = bounds.right; - // The input's top edge is the floor; the movement bounds also include the input itself. - const maximumBottom = Math.min(platform?.top ?? input.top, input.top, movement.bottom) - overlay.top; - for (const pet of activePets) { - const left = pet.left; - const top = pet.top; - const size = CHAT_PET_DISPLAY_SIZE * 0.5 * this._scale; - if (left < minimumLeft - CHAT_PET_SUBAGENT_BOUNDARY_EPSILON || left + size > maximumRight + CHAT_PET_SUBAGENT_BOUNDARY_EPSILON || top + size > maximumBottom + CHAT_PET_SUBAGENT_BOUNDARY_EPSILON) { - if (!this._subagentResizeScheduler.isScheduled()) { - this._subagentResizeScheduler.schedule(); - } - break; - } - } - } - /** Removes an active pet after playing its disappearance effect. */ private _despawnSubagentPet(pet: ChatPetSubagent): void { this._subagentEffects.delete(pet.disposables); @@ -3373,9 +3345,7 @@ export class ChatPetWidget extends Disposable { pet.element.style.top = `${pet.top}px`; pet.element.style.transform = `scale(${miniScale})`; } - if (this._subagentPets.size && !this._subagentResizeScheduler.isScheduled()) { - this._subagentResizeScheduler.schedule(); - } + this._scheduleSubagentResize(); const displaySize = this._getDisplaySize(); this._button.element.style.width = `${displaySize}px`; this._button.element.style.height = `${displaySize}px`; From 3f2c0205185aaa13173990b78182b9f930d43127 Mon Sep 17 00:00:00 2001 From: Lisa Rosenberg Date: Fri, 13 Nov 2026 17:48:40 +0100 Subject: [PATCH 38/66] feat: let the composite be the only draw for mini pets --- .../contrib/chat/browser/widget/chatPetWidget.ts | 15 ++++++++------- .../test/browser/widget/chatPetWidget.test.ts | 1 + 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src/vs/workbench/contrib/chat/browser/widget/chatPetWidget.ts b/src/vs/workbench/contrib/chat/browser/widget/chatPetWidget.ts index 2be855fc402bd0..2ba78113756869 100644 --- a/src/vs/workbench/contrib/chat/browser/widget/chatPetWidget.ts +++ b/src/vs/workbench/contrib/chat/browser/widget/chatPetWidget.ts @@ -3155,12 +3155,12 @@ export class ChatPetWidget extends Disposable { eyes.classList.toggle('tracking', state === 'idle'); this._startSpriteAnimation(source, sprite, animation, state === 'splat' ? () => setState('idle') : undefined, false, frameIndex => { eyes.classList.toggle('bobbed', state === 'idle' && !this._motionReduced && (source.accessoryRigFrame ?? frameIndex) >= 20); + }, undefined, undefined, (context, frameIndex) => { if (accessoryImage?.complete && accessoryImage.naturalWidth > 0 && accessory) { - const context = canvas.getContext('2d'); - if (context) { - drawChatPetComposite(context, image, accessoryImage, frameIndex, source.accessoryRigFrame ?? frameIndex, source.frameWidth, source.frameHeight ?? CHAT_PET_SOURCE_SIZE, 'right', state, source.fixedOrientationDecorations, true, accessory.eyeAccessoryMirrorsWithFacing !== false, accessory.coversAntennae === true, sprite.color); - } + drawChatPetComposite(context, image, accessoryImage, frameIndex, source.accessoryRigFrame ?? frameIndex, source.frameWidth, source.frameHeight ?? CHAT_PET_SOURCE_SIZE, 'right', state, source.fixedOrientationDecorations, true, accessory.eyeAccessoryMirrorsWithFacing !== false, accessory.coversAntennae === true, sprite.color); + return true; } + return false; }); })); const fallAnimation = disposables.add(new MutableDisposable()); @@ -4323,7 +4323,7 @@ export class ChatPetWidget extends Disposable { } } - private _startSpriteAnimation(source: ChatPetSpriteSource, sprite: ChatPetSpriteElement, animationDisposable: MutableDisposable, onComplete?: () => void, reverse = false, onFrame?: (frameIndex: number) => void, state?: ChatPetState, initialFrame?: number): void { + private _startSpriteAnimation(source: ChatPetSpriteSource, sprite: ChatPetSpriteElement, animationDisposable: MutableDisposable, onComplete?: () => void, reverse = false, onFrame?: (frameIndex: number) => void, state?: ChatPetState, initialFrame?: number, renderFrame?: (context: CanvasRenderingContext2D, frameIndex: number) => boolean): void { sprite.color = this._color; const { frameDurations } = source; const { image, canvas } = sprite; @@ -4347,7 +4347,8 @@ export class ChatPetWidget extends Disposable { const drawFrame = (animationFrameIndex: number) => { renderedFrameIndex = animationFrameIndex; const frameIndex = source.frameIndices?.[animationFrameIndex] ?? animationFrameIndex; - if (state) { + const rendered = renderFrame?.(context, frameIndex); + if (!rendered && state) { const activeAccessory = sprite.activeAccessory ? getChatPetAccessory(sprite.activeAccessory) : undefined; drawChatPetComposite( context, @@ -4368,7 +4369,7 @@ export class ChatPetWidget extends Disposable { ); this._drawPropeller(sprite.activeAccessory, sprite.activeAccessoryImage, source, state, source.accessoryRigFrame ?? frameIndex); this._drawEyeAccessory(sprite.activeAccessory, sprite.activeAccessoryImage, source, state, source.accessoryRigFrame ?? frameIndex); - } else { + } else if (!rendered) { context.clearRect(0, 0, source.frameWidth, frameHeight); context.drawImage(getChatPetColoredSprite(image, sprite.color), frameIndex * source.frameWidth, 0, source.frameWidth, frameHeight, 0, 0, source.frameWidth, frameHeight); } diff --git a/src/vs/workbench/contrib/chat/test/browser/widget/chatPetWidget.test.ts b/src/vs/workbench/contrib/chat/test/browser/widget/chatPetWidget.test.ts index c3458cd27d265c..b2aaa2b26b99be 100644 --- a/src/vs/workbench/contrib/chat/test/browser/widget/chatPetWidget.test.ts +++ b/src/vs/workbench/contrib/chat/test/browser/widget/chatPetWidget.test.ts @@ -2908,6 +2908,7 @@ suite('ChatPetWidget', () => { const draws = sinon.spy(miniCanvas.getContext('2d')!, 'drawImage'); bodyImage.dispatchEvent(new mainWindow.Event('load')); assert.ok(draws.calledWith(accessoryImage)); + assert.strictEqual(draws.getCalls().filter(call => call.args[0] !== accessoryImage).length, 1); draws.restore(); button.dataset.state = 'idle'; const miniPupil = firstMini.querySelector('.chat-pet-pupil')!; From 61c3599ad92fda48814b9dbbffee31346d035ba0 Mon Sep 17 00:00:00 2001 From: Lisa Rosenberg Date: Fri, 13 Nov 2026 17:58:05 +0100 Subject: [PATCH 39/66] refactor: unify names --- .../chat/browser/widget/chatPetWidget.ts | 222 ++++++------ .../chat/browser/widget/media/chatPet.css | 16 +- .../test/browser/widget/chatPetWidget.test.ts | 326 +++++++++--------- 3 files changed, 282 insertions(+), 282 deletions(-) diff --git a/src/vs/workbench/contrib/chat/browser/widget/chatPetWidget.ts b/src/vs/workbench/contrib/chat/browser/widget/chatPetWidget.ts index 2ba78113756869..e587ff4500ddde 100644 --- a/src/vs/workbench/contrib/chat/browser/widget/chatPetWidget.ts +++ b/src/vs/workbench/contrib/chat/browser/widget/chatPetWidget.ts @@ -145,12 +145,12 @@ const MOUSE_BOUNCE_HORIZONTAL_TRANSFER = 0.35; const MOUSE_BOUNCE_EDGE_KICK = 320; const MOUSE_BOUNCE_MAX_HORIZONTAL_VELOCITY = 1_800; const CHAT_PET_DISPLAY_SIZE = 48; -/** Maximum stacking height before mini pets share space. */ -const CHAT_PET_SUBAGENT_MAX_HEIGHT = 96; -/** Tolerance for fractional pixels when checking mini-pet bounds. */ -const CHAT_PET_SUBAGENT_BOUNDARY_EPSILON = 0.01; -/** Distance kept between mini pets and the edges of their platform. */ -const CHAT_PET_SUBAGENT_EDGE_INSET = 12; +/** Maximum stacking height before subagent pets share space. */ +const SUBAGENT_PET_MAX_HEIGHT = 96; +/** Tolerance for fractional pixels when checking subagent pet bounds. */ +const SUBAGENT_PET_BOUNDARY_EPSILON = 0.01; +/** Distance kept between subagent pets and the edges of their platform. */ +const SUBAGENT_PET_EDGE_INSET = 12; const CHAT_PET_SOURCE_SIZE = 96; const CHAT_PET_SLEEP_SOURCE_WIDTH = 120; const CHAT_PET_TYPING_SOURCE_WIDTH = 168; @@ -222,7 +222,7 @@ interface ChatPetSpriteElement { } /** Visual state and lifecycle controls for one active subagent pet. */ -interface ChatPetSubagent { +interface SubagentPet { /** Container positioned on the chat overlay. */ readonly element: HTMLElement; /** Landing position relative to the overlay. */ @@ -1282,16 +1282,16 @@ export class ChatPetHopController extends Disposable { export class ChatPetWidget extends Disposable { - /** Active pets keyed by request and tool call identity. */ - private readonly _subagentPets = new Map(); + /** Active subagent pets keyed by request and tool call identity. */ + private readonly _subagentPets = new Map(); /** Chat model currently supplying active subagents. */ - private _subagentModel: IChatModel | undefined; - /** Resources for active pets and their disappearance effects. */ - private readonly _subagentEffects = this._register(new DisposableStore()); + private _subagentPetModel: IChatModel | undefined; + /** Resources for active subagent pets and their disappearance effects. */ + private readonly _subagentPetEffects = this._register(new DisposableStore()); /** Coalesces bounds checks while the chat is resizing. */ - private readonly _subagentResizeScheduler = this._register(new RunOnceScheduler(() => this._reconcileSubagentResize(), 16)); - /** Overlay layer containing mini pets. */ - private readonly _subagentLayer: HTMLElement; + private readonly _subagentPetResizeScheduler = this._register(new RunOnceScheduler(() => this._reconcileSubagentPetResize(), 16)); + /** Overlay layer containing subagent pets. */ + private readonly _subagentPetLayer: HTMLElement; private parent: HTMLElement; private dragBounds: HTMLElement; private movementBounds: HTMLElement; @@ -1457,7 +1457,7 @@ export class ChatPetWidget extends Disposable { this.parent.classList.add('chat-pet-host'); this._overlay = dom.$(`.${CHAT_PET_OVERLAY_CLASS}`); this.parent.prepend(this._overlay); - this._subagentLayer = dom.append(this._overlay, dom.$('.chat-pet-subagent-layer')); + this._subagentPetLayer = dom.append(this._overlay, dom.$('.chat-subagent-pet-layer')); this._register(toDisposable(() => { this.parent.classList.remove('chat-pet-host'); this._overlay.remove(); @@ -1752,7 +1752,7 @@ export class ChatPetWidget extends Disposable { this._setScale(scale); } const enabled = isChatPetVisible(serviceEnabled, isWindowActive); - this._subagentLayer.classList.toggle('hidden', !enabled); + this._subagentPetLayer.classList.toggle('hidden', !enabled); const color = this.chatPetService.color.read(reader); const colorChanged = color !== this._color; this._color = color; @@ -1830,20 +1830,20 @@ export class ChatPetWidget extends Disposable { this._finishDisable(); } } - for (const pet of this._subagentPets.values()) { - pet.updateBlink(); + for (const subagentPet of this._subagentPets.values()) { + subagentPet.updateBlink(); if (enabled && (wasMotionReduced !== this._motionReduced || colorChanged || accessoryChanged)) { - pet.updateAppearance(wasMotionReduced !== this._motionReduced, variantChanged, accessoryChanged); + subagentPet.updateAppearance(wasMotionReduced !== this._motionReduced, variantChanged, accessoryChanged); } } if (!enabled) { - this._subagentResizeScheduler.cancel(); - for (const pet of this._subagentPets.values()) { - pet.element.remove(); + this._subagentPetResizeScheduler.cancel(); + for (const subagentPet of this._subagentPets.values()) { + subagentPet.element.remove(); } this._subagentPets.clear(); - this._subagentEffects.clear(); + this._subagentPetEffects.clear(); this._hopController.cancel(); this._idleScheduler.cancel(); this._transientScheduler.cancel(); @@ -1907,9 +1907,9 @@ export class ChatPetWidget extends Disposable { this._register(autorun(reader => { const enabled = isChatPetVisible(this.chatPetService.enabled.read(reader), windowActive.read(reader)); const model = this._host.read(reader).model.read(reader); - if (model !== this._subagentModel) { + if (model !== this._subagentPetModel) { this._updateSubagentPets(new Set()); - this._subagentModel = model; + this._subagentPetModel = model; } if (!enabled || !model) { return; @@ -2334,7 +2334,7 @@ export class ChatPetWidget extends Disposable { } private _handleHostLayoutChange(): void { - this._scheduleSubagentResize(); + this._scheduleSubagentPetResize(); if (this._jumpGame.value) { this._jumpGame.value.layout(); return; @@ -2993,8 +2993,8 @@ export class ChatPetWidget extends Disposable { return this._button.element.offsetLeft; } - /** Returns the visible bounds and platforms for mini-pet placement. */ - private _getSubagentBounds(): { overlay: DOMRect; movement: DOMRect; platforms: readonly IChatPetPlatform[]; left: number; right: number; bottom: number; floor: number } { + /** Returns the visible bounds and platforms for subagent pet placement. */ + private _getSubagentPetBounds(): { overlay: DOMRect; movement: DOMRect; platforms: readonly IChatPetPlatform[]; left: number; right: number; bottom: number; floor: number } { const overlay = this._overlay.getBoundingClientRect(); const input = this.dragBounds.getBoundingClientRect(); const movement = this.movementBounds.getBoundingClientRect(); @@ -3002,14 +3002,14 @@ export class ChatPetWidget extends Disposable { const platform = getChatPetFallTarget(input.left + input.width / 2, movement.top - 1, 0, 0, platforms, input.top).platform; const left = Math.max(0, input.left, movement.left, platform?.left ?? input.left); const right = Math.min(dom.getWindow(this._overlay).innerWidth, input.right, movement.right, platform?.right ?? input.right); - const inset = Math.min(CHAT_PET_SUBAGENT_EDGE_INSET, Math.max(0, (right - left) / 4)); + const inset = Math.min(SUBAGENT_PET_EDGE_INSET, Math.max(0, (right - left) / 4)); const floor = Math.min(input.top, movement.bottom); return { overlay, movement, platforms, left: left + inset - overlay.left, right: right - inset - overlay.left, bottom: Math.min(platform?.top ?? input.top, floor) - overlay.top, floor }; } - /** Choose a random landing point, accounting for mini pets already on the platform. */ - private _getSubagentLanding(size: number): { left: number; top: number } { - const bounds = this._getSubagentBounds(); + /** Choose a random landing point, accounting for subagent pets already on the platform. */ + private _getSubagentPetLanding(size: number): { left: number; top: number } { + const bounds = this._getSubagentPetBounds(); const { overlay, movement, platforms, floor } = bounds; const minimumLeft = bounds.left; const maximumLeft = Math.max(minimumLeft, bounds.right - size); @@ -3018,7 +3018,7 @@ export class ChatPetWidget extends Disposable { const afterPetStart = Math.max(minimumLeft, petLeft + this._getDisplaySize()); const afterPet = Math.max(0, maximumLeft - afterPetStart); const available = beforePet + afterPet; - const minimumTop = Math.max(movement.top - overlay.top, bounds.bottom - CHAT_PET_SUBAGENT_MAX_HEIGHT); + const minimumTop = Math.max(movement.top - overlay.top, bounds.bottom - SUBAGENT_PET_MAX_HEIGHT); const attempts = Math.max(1, Math.ceil(available / Math.max(1, size / 2))); const start = Math.random() * available; let best: { left: number; top: number } | undefined; @@ -3027,34 +3027,34 @@ export class ChatPetWidget extends Disposable { const left = available > 0 ? (offset < beforePet ? minimumLeft + offset : afterPetStart + offset - beforePet) : minimumLeft; const landing = getChatPetFallTarget(overlay.left + left, -size, size, size, platforms, floor); let top = landing.top - overlay.top; - for (const other of this._subagentPets.values()) { - if (other.isRespawning()) { + for (const otherSubagentPet of this._subagentPets.values()) { + if (otherSubagentPet.isRespawning()) { continue; } - if (left < other.left + size && left + size > other.left) { - top = Math.min(top, other.top - size); + if (left < otherSubagentPet.left + size && left + size > otherSubagentPet.left) { + top = Math.min(top, otherSubagentPet.top - size); } } - if (top >= minimumTop - CHAT_PET_SUBAGENT_BOUNDARY_EPSILON) { + if (top >= minimumTop - SUBAGENT_PET_BOUNDARY_EPSILON) { return { left, top }; } if (!best || top > best.top) { best = { left, top }; } } - // If the area is full, allow overlap instead of shrinking the pets. + // If the area is full, allow overlap instead of shrinking the subagent pets. return { ...best!, top: Math.max(best!.top, minimumTop) }; } - /** Creates and removes pets to match the active subagent identities. */ + /** Creates and removes subagent pets to match the active subagent identities. */ private _updateSubagentPets(subagents: ReadonlySet): void { let removed = false; let added = false; - for (const [id, pet] of this._subagentPets) { + for (const [id, subagentPet] of this._subagentPets) { if (!subagents.has(id)) { removed = true; this._subagentPets.delete(id); - this._despawnSubagentPet(pet); + this._despawnSubagentPet(subagentPet); } } for (const id of subagents) { @@ -3062,16 +3062,16 @@ export class ChatPetWidget extends Disposable { continue; } added = true; - const element = dom.append(this._subagentLayer, dom.$('.chat-pet-subagent', { 'aria-hidden': 'true' })); - const miniScale = 0.5 * this._scale; - const miniWidth = CHAT_PET_DISPLAY_SIZE * miniScale; + const element = dom.append(this._subagentPetLayer, dom.$('.chat-subagent-pet', { 'aria-hidden': 'true' })); + const subagentPetScale = 0.5 * this._scale; + const subagentPetWidth = CHAT_PET_DISPLAY_SIZE * subagentPetScale; const overlayBounds = this._overlay.getBoundingClientRect(); - const { left, top } = this._getSubagentLanding(miniWidth); + const { left, top } = this._getSubagentPetLanding(subagentPetWidth); element.style.left = `${left}px`; element.style.top = `${top}px`; - element.style.transform = `scale(${miniScale})`; - const distance = Math.max(0, overlayBounds.top + top + miniWidth); - const canvas = dom.append(element, dom.$('canvas.chat-pet-subagent-canvas')) as HTMLCanvasElement; + element.style.transform = `scale(${subagentPetScale})`; + const distance = Math.max(0, overlayBounds.top + top + subagentPetWidth); + const canvas = dom.append(element, dom.$('canvas.chat-subagent-pet-canvas')) as HTMLCanvasElement; canvas.width = CHAT_PET_SOURCE_SIZE; canvas.height = CHAT_PET_SOURCE_SIZE; const eyes = element.appendChild(this._eyes.cloneNode(true)) as HTMLElement; @@ -3080,7 +3080,7 @@ export class ChatPetWidget extends Disposable { for (const eye of eyes.children) { (eye.firstElementChild as HTMLElement | null)?.style.removeProperty('transform'); } - const disposables = this._subagentEffects.add(new DisposableStore()); + const disposables = this._subagentPetEffects.add(new DisposableStore()); let state: 'idle' | 'splat' = 'idle'; let respawnPhase: 'none' | 'falling' | 'despawning' | 'respawning' = 'none'; const respawnTimer = disposables.add(new RunOnceScheduler(() => advanceRespawn(), RESPAWN_EFFECT_REDUCED_MOTION_DURATION)); @@ -3202,7 +3202,7 @@ export class ChatPetWidget extends Disposable { const previousTop = element.getBoundingClientRect().top - this._overlay.getBoundingClientRect().top; respawnPhase = respawn ? 'falling' : 'none'; fallAnimation.clear(); - pet.top = top; + subagentPet.top = top; element.style.top = `${top}px`; setState('idle'); if (!this._motionReduced && top > previousTop) { @@ -3218,84 +3218,84 @@ export class ChatPetWidget extends Disposable { const size = CHAT_PET_DISPLAY_SIZE * 0.5 * this._scale; if (respawnPhase === 'despawning') { respawnPhase = 'respawning'; - pet.left = Math.max(input.left - overlay.left, Math.min(pet.left, input.right - overlay.left - size)); - pet.top = this.movementBounds.getBoundingClientRect().top - overlay.top; - element.style.left = `${pet.left}px`; - element.style.top = `${pet.top}px`; + subagentPet.left = Math.max(input.left - overlay.left, Math.min(subagentPet.left, input.right - overlay.left - size)); + subagentPet.top = this.movementBounds.getBoundingClientRect().top - overlay.top; + element.style.left = `${subagentPet.left}px`; + element.style.top = `${subagentPet.top}px`; setState('idle'); } else if (respawnPhase === 'respawning') { - const landing = this._getSubagentLanding(size); - pet.left = landing.left; - element.style.left = `${pet.left}px`; + const landing = this._getSubagentPetLanding(size); + subagentPet.left = landing.left; + element.style.left = `${subagentPet.left}px`; fallTo(landing.top); - this._scheduleSubagentResize(); + this._scheduleSubagentPetResize(); } }; - const pet: ChatPetSubagent = { element, left, top, canvas, image, get accessoryImage() { return accessoryImage; }, eyes, disposables, updateBlink, updateAppearance, fallTo, isRespawning: () => respawnPhase !== 'none' }; + const subagentPet: SubagentPet = { element, left, top, canvas, image, get accessoryImage() { return accessoryImage; }, eyes, disposables, updateBlink, updateAppearance, fallTo, isRespawning: () => respawnPhase !== 'none' }; setState('idle'); if (!this._motionReduced && distance > 0) { animateFall(top - distance, top); } - this._subagentPets.set(id, pet); + this._subagentPets.set(id, subagentPet); } if (added || removed) { - this._scheduleSubagentResize(); + this._scheduleSubagentPetResize(); } if (removed) { this._settleSubagentPets(); } } - /** Settle each column from the bottom up so remaining mini pets can support those above them. */ + /** Settle each column from the bottom up so remaining subagent pets can support those above them. */ private _settleSubagentPets(platformChanged = false): void { const overlay = this._overlay.getBoundingClientRect(); const platforms = this._getPlatforms(); const floor = platformChanged ? this.movementBounds.getBoundingClientRect().bottom : Math.min(this.dragBounds.getBoundingClientRect().top, this.movementBounds.getBoundingClientRect().bottom); - const pets = [...this._subagentPets.values()].filter(pet => !pet.isRespawning()).map(pet => ({ - pet, - left: pet.left, - top: pet.top, + const subagentPets = [...this._subagentPets.values()].filter(subagentPet => !subagentPet.isRespawning()).map(subagentPet => ({ + subagentPet, + left: subagentPet.left, + top: subagentPet.top, size: CHAT_PET_DISPLAY_SIZE * 0.5 * this._scale, })).sort((a, b) => b.top - a.top); - for (const [index, pet] of pets.entries()) { - const landing = getChatPetFallTarget(overlay.left + pet.left, overlay.top + pet.top - POSITION_EPSILON, pet.size, pet.size, platforms, floor); - let top = Math.max(pet.top, landing.top - overlay.top); + for (const [index, entry] of subagentPets.entries()) { + const landing = getChatPetFallTarget(overlay.left + entry.left, overlay.top + entry.top - POSITION_EPSILON, entry.size, entry.size, platforms, floor); + let top = Math.max(entry.top, landing.top - overlay.top); let supported = !!landing.platform; for (let below = 0; below < index; below++) { - const support = pets[below]; - if (!support.pet.isRespawning() && pet.left < support.left + support.size && pet.left + pet.size > support.left && support.top >= pet.top + pet.size - POSITION_EPSILON && support.top - pet.size <= top) { - top = Math.min(top, support.top - pet.size); + const support = subagentPets[below]; + if (!support.subagentPet.isRespawning() && entry.left < support.left + support.size && entry.left + entry.size > support.left && support.top >= entry.top + entry.size - POSITION_EPSILON && support.top - entry.size <= top) { + top = Math.min(top, support.top - entry.size); supported = true; } } - if (top > pet.top + POSITION_EPSILON) { - pet.pet.fallTo(top, platformChanged && !supported); - pet.top = top; + if (top > entry.top + POSITION_EPSILON) { + entry.subagentPet.fallTo(top, platformChanged && !supported); + entry.top = top; } } } - private _scheduleSubagentResize(): void { - if (this._subagentPets.size && !this._subagentResizeScheduler.isScheduled()) { - this._subagentResizeScheduler.schedule(); + private _scheduleSubagentPetResize(): void { + if (this._subagentPets.size && !this._subagentPetResizeScheduler.isScheduled()) { + this._subagentPetResizeScheduler.schedule(); } } - /** Relocate only mini pets that no longer fit after resizing has settled. */ - private _reconcileSubagentResize(): void { - const pets = [...this._subagentPets.values()].filter(pet => !pet.isRespawning()); - if (!pets.length) { + /** Relocate only subagent pets that no longer fit after resizing has settled. */ + private _reconcileSubagentPetResize(): void { + const subagentPets = [...this._subagentPets.values()].filter(subagentPet => !subagentPet.isRespawning()); + if (!subagentPets.length) { return; } - const { overlay, movement, left, right, bottom } = this._getSubagentBounds(); + const { overlay, movement, left, right, bottom } = this._getSubagentPetBounds(); let displaced = false; - for (const pet of pets) { - const petLeft = pet.left; - const petTop = pet.top; + for (const subagentPet of subagentPets) { + const subagentPetLeft = subagentPet.left; + const subagentPetTop = subagentPet.top; const size = CHAT_PET_DISPLAY_SIZE * 0.5 * this._scale; - if (petLeft < left - CHAT_PET_SUBAGENT_BOUNDARY_EPSILON || petLeft + size > right + CHAT_PET_SUBAGENT_BOUNDARY_EPSILON || petTop < movement.top - overlay.top - CHAT_PET_SUBAGENT_BOUNDARY_EPSILON || petTop + size > bottom + CHAT_PET_SUBAGENT_BOUNDARY_EPSILON) { + if (subagentPetLeft < left - SUBAGENT_PET_BOUNDARY_EPSILON || subagentPetLeft + size > right + SUBAGENT_PET_BOUNDARY_EPSILON || subagentPetTop < movement.top - overlay.top - SUBAGENT_PET_BOUNDARY_EPSILON || subagentPetTop + size > bottom + SUBAGENT_PET_BOUNDARY_EPSILON) { displaced = true; - pet.fallTo(movement.bottom - overlay.top - size, true); + subagentPet.fallTo(movement.bottom - overlay.top - size, true); } } if (displaced) { @@ -3303,29 +3303,29 @@ export class ChatPetWidget extends Disposable { } } - /** Removes an active pet after playing its disappearance effect. */ - private _despawnSubagentPet(pet: ChatPetSubagent): void { - this._subagentEffects.delete(pet.disposables); - pet.image.remove(); - pet.accessoryImage?.remove(); - pet.element.classList.remove('chat-pet-subagent'); - pet.element.classList.add('chat-pet-subagent-despawning'); - pet.eyes.remove(); - const effects = this._subagentEffects.add(new DisposableStore()); - const image = dom.append(pet.element, dom.$('img.chat-pet-spritesheet')) as HTMLImageElement; + /** Removes an active subagent pet after playing its disappearance effect. */ + private _despawnSubagentPet(subagentPet: SubagentPet): void { + this._subagentPetEffects.delete(subagentPet.disposables); + subagentPet.image.remove(); + subagentPet.accessoryImage?.remove(); + subagentPet.element.classList.remove('chat-subagent-pet'); + subagentPet.element.classList.add('chat-subagent-pet-despawning'); + subagentPet.eyes.remove(); + const effects = this._subagentPetEffects.add(new DisposableStore()); + const image = dom.append(subagentPet.element, dom.$('img.chat-pet-spritesheet')) as HTMLImageElement; image.alt = ''; const sources = getRespawnSpriteSources(this._variant); const source = this._motionReduced ? sources.reducedMotion : sources.animated; const animation = effects.add(new MutableDisposable()); - const sprite: ChatPetSpriteElement = { container: pet.element, canvas: pet.canvas, image, color: this._color }; + const sprite: ChatPetSpriteElement = { container: subagentPet.element, canvas: subagentPet.canvas, image, color: this._color }; const finish = () => { - pet.element.remove(); - this._subagentEffects.delete(effects); + subagentPet.element.remove(); + this._subagentPetEffects.delete(effects); }; - effects.add(toDisposable(() => pet.element.remove())); + effects.add(toDisposable(() => subagentPet.element.remove())); effects.add(dom.addDisposableListener(image, 'load', () => this._startSpriteAnimation(source, sprite, animation, finish, true))); effects.add(dom.addDisposableListener(image, 'error', finish)); - const targetWindow = dom.getWindow(pet.element); + const targetWindow = dom.getWindow(subagentPet.element); const timer = targetWindow.setTimeout(finish, this._motionReduced ? RESPAWN_EFFECT_REDUCED_MOTION_DURATION : RESPAWN_EFFECT_DURATION); effects.add(toDisposable(() => targetWindow.clearTimeout(timer))); setChatPetImageSource(image, source.url); @@ -3339,13 +3339,13 @@ export class ChatPetWidget extends Disposable { this._stopJumpGame('restore'); const previousScale = this._scale * 0.5; this._scale = scale; - const miniScale = scale * 0.5; - for (const pet of this._subagentPets.values()) { - pet.top += CHAT_PET_DISPLAY_SIZE * (previousScale - miniScale); - pet.element.style.top = `${pet.top}px`; - pet.element.style.transform = `scale(${miniScale})`; + const subagentPetScale = scale * 0.5; + for (const subagentPet of this._subagentPets.values()) { + subagentPet.top += CHAT_PET_DISPLAY_SIZE * (previousScale - subagentPetScale); + subagentPet.element.style.top = `${subagentPet.top}px`; + subagentPet.element.style.transform = `scale(${subagentPetScale})`; } - this._scheduleSubagentResize(); + this._scheduleSubagentPetResize(); const displaySize = this._getDisplaySize(); this._button.element.style.width = `${displaySize}px`; this._button.element.style.height = `${displaySize}px`; diff --git a/src/vs/workbench/contrib/chat/browser/widget/media/chatPet.css b/src/vs/workbench/contrib/chat/browser/widget/media/chatPet.css index 51342a872bfa3f..ebb07b429cdaf1 100644 --- a/src/vs/workbench/contrib/chat/browser/widget/media/chatPet.css +++ b/src/vs/workbench/contrib/chat/browser/widget/media/chatPet.css @@ -170,18 +170,18 @@ pointer-events: none; } -.chat-pet-subagent-layer { +.chat-subagent-pet-layer { position: absolute; inset: 0; pointer-events: none; } -.chat-pet-subagent-layer.hidden { +.chat-subagent-pet-layer.hidden { display: none; } -.chat-pet-subagent, -.chat-pet-subagent-despawning { +.chat-subagent-pet, +.chat-subagent-pet-despawning { position: absolute; width: 48px; height: 48px; @@ -189,17 +189,17 @@ pointer-events: none; } -.chat-pet-subagent-canvas { +.chat-subagent-pet-canvas { width: 48px; height: 48px; image-rendering: pixelated; } -.chat-pet-subagent .chat-pet-eye { +.chat-subagent-pet .chat-pet-eye { height: 12px; } -.chat-pet-subagent .chat-pet-pupil { +.chat-subagent-pet .chat-pet-pupil { height: 8px; } @@ -496,7 +496,7 @@ .chat-pet-button[data-state='painting'] .chat-pet-eyes.blink .chat-pet-pupil, .chat-pet-button[data-state='buttonPress'] .chat-pet-eyes.blink .chat-pet-pupil, .chat-pet-button[data-state='love'] .chat-pet-eyes.blink .chat-pet-pupil, -.chat-pet-subagent .chat-pet-eyes.blink .chat-pet-pupil { +.chat-subagent-pet .chat-pet-eyes.blink .chat-pet-pupil { animation-name: chat-pet-tall-eye-blink; } diff --git a/src/vs/workbench/contrib/chat/test/browser/widget/chatPetWidget.test.ts b/src/vs/workbench/contrib/chat/test/browser/widget/chatPetWidget.test.ts index b2aaa2b26b99be..6529930af39506 100644 --- a/src/vs/workbench/contrib/chat/test/browser/widget/chatPetWidget.test.ts +++ b/src/vs/workbench/contrib/chat/test/browser/widget/chatPetWidget.test.ts @@ -2829,16 +2829,16 @@ suite('ChatPetWidget', () => { }(); } - function setMiniPetPosition(widget: ChatPetWidget, element: HTMLElement, left: number, top: number): void { + function setSubagentPetPosition(widget: ChatPetWidget, element: HTMLElement, left: number, top: number): void { // eslint-disable-next-line local/code-no-bracket-notation-for-identifiers -- Set up positions without exposing a test-only API. - const pet = [...widget['_subagentPets'].values()].find(pet => pet.element === element)!; - pet.left = left; - pet.top = top; + const subagentPet = [...widget['_subagentPets'].values()].find(subagentPet => subagentPet.element === element)!; + subagentPet.left = left; + subagentPet.top = top; element.style.left = `${left}px`; element.style.top = `${top}px`; } - test('mini pets update only the changed response while tracking older subagents', () => { + test('subagent pets update only the changed response while tracking older subagents', () => { const { widget, firstHost, overlay } = createHostTransitionHarness(true); const changes = [disposables.add(new Emitter()), disposables.add(new Emitter())]; const tools = ['older', 'current'].map(id => { @@ -2864,16 +2864,16 @@ suite('ChatPetWidget', () => { override getRequests(): IChatRequestModel[] { return requests; } }(); widget.setHost({ ...firstHost, model: constObservable(model) }); - assert.strictEqual(overlay.querySelectorAll('.chat-pet-subagent').length, 2); + assert.strictEqual(overlay.querySelectorAll('.chat-subagent-pet').length, 2); reads[0] = 0; changes[1].fire({ reason: 'other' }); assert.strictEqual(reads[0], 0); tools[0].toolSpecificData = { kind: 'subagent', isActive: false }; changes[0].fire({ reason: 'other' }); - assert.strictEqual(overlay.querySelectorAll('.chat-pet-subagent').length, 1); + assert.strictEqual(overlay.querySelectorAll('.chat-subagent-pet').length, 1); }); - test('shows one mini pet per active subagent and removes it when it stops', async () => { + test('shows one subagent pet per active subagent and removes it when it stops', async () => { const { widget, firstHost, button, overlay, service } = createHostTransitionHarness(); const responseChanged = disposables.add(new Emitter()); const parts: IChatProgressResponseContent[] = []; @@ -2895,26 +2895,26 @@ suite('ChatPetWidget', () => { pupil.style.transform = 'translate(2px, -2px)'; } const first = createSubagent('first'); - const firstMini = overlay.querySelector('.chat-pet-subagent')!; - assert.deepStrictEqual([...firstMini.querySelectorAll('.chat-pet-pupil')].map(pupil => pupil.style.transform), ['', '']); + const firstSubagentPet = overlay.querySelector('.chat-subagent-pet')!; + assert.deepStrictEqual([...firstSubagentPet.querySelectorAll('.chat-pet-pupil')].map(pupil => pupil.style.transform), ['', '']); assert.deepStrictEqual([...mainPupils].map(pupil => pupil.style.transform), ['translate(2px, -2px)', 'translate(2px, -2px)']); - assert.ok(firstMini.offsetLeft >= button.offsetLeft + button.offsetWidth); - const miniSize = 48 * 0.5; - assert.strictEqual(Number.parseFloat(firstMini.style.top) + miniSize, 0); - const [bodyImage, accessoryImage] = firstMini.querySelectorAll('img'); + assert.ok(firstSubagentPet.offsetLeft >= button.offsetLeft + button.offsetWidth); + const subagentPetSize = 48 * 0.5; + assert.strictEqual(Number.parseFloat(firstSubagentPet.style.top) + subagentPetSize, 0); + const [bodyImage, accessoryImage] = firstSubagentPet.querySelectorAll('img'); assert.ok(accessoryImage?.src.includes('/accessories/')); await Promise.all([bodyImage.decode(), accessoryImage.decode()]); - const miniCanvas = firstMini.querySelector('canvas')!; - const draws = sinon.spy(miniCanvas.getContext('2d')!, 'drawImage'); + const subagentPetCanvas = firstSubagentPet.querySelector('canvas')!; + const draws = sinon.spy(subagentPetCanvas.getContext('2d')!, 'drawImage'); bodyImage.dispatchEvent(new mainWindow.Event('load')); assert.ok(draws.calledWith(accessoryImage)); assert.strictEqual(draws.getCalls().filter(call => call.args[0] !== accessoryImage).length, 1); draws.restore(); button.dataset.state = 'idle'; - const miniPupil = firstMini.querySelector('.chat-pet-pupil')!; + const subagentPetPupil = firstSubagentPet.querySelector('.chat-pet-pupil')!; const mainPupil = button.querySelector('.chat-pet-pupil')!; - assert.strictEqual(mainWindow.getComputedStyle(miniPupil).height, mainWindow.getComputedStyle(mainPupil).height); - assert.strictEqual(mainWindow.getComputedStyle(miniPupil).height, '8px'); + assert.strictEqual(mainWindow.getComputedStyle(subagentPetPupil).height, mainWindow.getComputedStyle(mainPupil).height); + assert.strictEqual(mainWindow.getComputedStyle(subagentPetPupil).height, '8px'); widget.setHost({ ...firstHost, transition: undefined, model: modelValue, getPlatforms: () => { const bounds = overlay.getBoundingClientRect(); return [ @@ -2925,41 +2925,41 @@ suite('ChatPetWidget', () => { button.style.left = '300px'; button.style.top = '-140px'; createSubagent('second'); - const minis = overlay.querySelectorAll('.chat-pet-subagent'); - assert.ok(minis[1].offsetLeft + miniSize <= button.offsetLeft || minis[1].offsetLeft >= button.offsetLeft + button.offsetWidth); - assert.strictEqual(Number.parseFloat(minis[1].style.top) + miniSize, -60); - assert.strictEqual(overlay.querySelectorAll('.chat-pet-subagent').length, 2); - assert.strictEqual([...overlay.querySelectorAll('.chat-pet-subagent')].filter(pet => pet.getAnimations().length > 0).length, 2); - assert.strictEqual(button.querySelectorAll('.chat-pet-subagent').length, 0); - assert.ok(overlay.querySelector('.chat-pet-subagent img')?.getAttribute('src')?.includes('buddy-')); - const mini = overlay.querySelector('.chat-pet-subagent')!; - const position = mini.style.left; + const subagentPets = overlay.querySelectorAll('.chat-subagent-pet'); + assert.ok(subagentPets[1].offsetLeft + subagentPetSize <= button.offsetLeft || subagentPets[1].offsetLeft >= button.offsetLeft + button.offsetWidth); + assert.strictEqual(Number.parseFloat(subagentPets[1].style.top) + subagentPetSize, -60); + assert.strictEqual(overlay.querySelectorAll('.chat-subagent-pet').length, 2); + assert.strictEqual([...overlay.querySelectorAll('.chat-subagent-pet')].filter(subagentPet => subagentPet.getAnimations().length > 0).length, 2); + assert.strictEqual(button.querySelectorAll('.chat-subagent-pet').length, 0); + assert.ok(overlay.querySelector('.chat-subagent-pet img')?.getAttribute('src')?.includes('buddy-')); + const subagentPet = overlay.querySelector('.chat-subagent-pet')!; + const position = subagentPet.style.left; button.style.left = '300px'; button.style.transform = 'rotate(45deg)'; - assert.strictEqual(mini.style.left, position); + assert.strictEqual(subagentPet.style.left, position); first.toolSpecificData = { kind: 'subagent', isActive: false }; responseChanged.fire({ reason: 'other' }); - assert.strictEqual(overlay.querySelectorAll('.chat-pet-subagent').length, 1); - assert.ok(firstMini.classList.contains('chat-pet-subagent-despawning')); - assert.strictEqual(overlay.querySelector('.chat-pet-subagent'), minis[1]); + assert.strictEqual(overlay.querySelectorAll('.chat-subagent-pet').length, 1); + assert.ok(firstSubagentPet.classList.contains('chat-subagent-pet-despawning')); + assert.strictEqual(overlay.querySelector('.chat-subagent-pet'), subagentPets[1]); const third = createSubagent('third'); - const thirdMini = overlay.querySelectorAll('.chat-pet-subagent')[1]; + const thirdSubagentPet = overlay.querySelectorAll('.chat-subagent-pet')[1]; parts.splice(parts.indexOf(third), 1); const replacement = new ChatToolInvocation(undefined, { id: 'replacement', displayName: 'Replacement', modelDescription: 'Subagent', source: ToolDataSource.Internal }, 'replacement', undefined, {}); replacement.toolSpecificData = { kind: 'subagent', isActive: true }; parts.push(replacement); responseChanged.fire({ reason: 'other' }); - assert.ok(thirdMini.classList.contains('chat-pet-subagent-despawning')); - assert.strictEqual(overlay.querySelector('.chat-pet-subagent'), minis[1]); - assert.strictEqual(overlay.querySelectorAll('.chat-pet-subagent').length, 2); - assert.ok(overlay.querySelector('.chat-pet-subagent-despawning img')?.getAttribute('src')?.includes('buddy-respawn-')); + assert.ok(thirdSubagentPet.classList.contains('chat-subagent-pet-despawning')); + assert.strictEqual(overlay.querySelector('.chat-subagent-pet'), subagentPets[1]); + assert.strictEqual(overlay.querySelectorAll('.chat-subagent-pet').length, 2); + assert.ok(overlay.querySelector('.chat-subagent-pet-despawning img')?.getAttribute('src')?.includes('buddy-respawn-')); modelValue.set(undefined, undefined); - assert.strictEqual(overlay.querySelectorAll('.chat-pet-subagent').length, 0); + assert.strictEqual(overlay.querySelectorAll('.chat-subagent-pet').length, 0); await timeout(900); - assert.strictEqual(overlay.querySelectorAll('.chat-pet-subagent-despawning').length, 0); + assert.strictEqual(overlay.querySelectorAll('.chat-subagent-pet-despawning').length, 0); }); - test('mini pets use restored geometry when the initial model already has a subagent', () => { + test('subagent pets use restored geometry when the initial model already has a subagent', () => { const tool = new ChatToolInvocation(undefined, { id: 'subagent', displayName: 'Subagent', modelDescription: 'Subagent', source: ToolDataSource.Internal }, 'subagent', undefined, {}); tool.toolSpecificData = { kind: 'subagent', isActive: true }; const model = createSubagentTestModel([tool]); @@ -2967,12 +2967,12 @@ suite('ChatPetWidget', () => { service.setScale(2); service.setHorizontalPosition(0.8); }, model); - const pet = overlay.querySelector('.chat-pet-subagent')!; - assert.strictEqual(Number.parseFloat(pet.style.transform.slice(6)), 1); - assert.ok(pet.offsetLeft + 48 <= button.offsetLeft || pet.offsetLeft >= button.offsetLeft + button.offsetWidth); + const subagentPet = overlay.querySelector('.chat-subagent-pet')!; + assert.strictEqual(Number.parseFloat(subagentPet.style.transform.slice(6)), 1); + assert.ok(subagentPet.offsetLeft + 48 <= button.offsetLeft || subagentPet.offsetLeft >= button.offsetLeft + button.offsetWidth); }); - test('mini pets stop when disabled and return for active subagents when re-enabled', async () => { + test('subagent pets stop when disabled and return for active subagents when re-enabled', async () => { const { widget, firstHost, overlay, service } = createHostTransitionHarness(); const changed = disposables.add(new Emitter()); const parts: IChatProgressResponseContent[] = []; @@ -2981,7 +2981,7 @@ suite('ChatPetWidget', () => { tool.toolSpecificData = { kind: 'subagent', isActive: true }; parts.push(tool); changed.fire({ reason: 'other' }); - const first = overlay.querySelector('.chat-pet-subagent')!; + const first = overlay.querySelector('.chat-subagent-pet')!; await whenSpriteLoaded(first.querySelector('img')!); service.toggle(); assert.strictEqual(first.isConnected, false); @@ -2989,12 +2989,12 @@ suite('ChatPetWidget', () => { second.toolSpecificData = { kind: 'subagent', isActive: true }; parts.push(second); changed.fire({ reason: 'other' }); - assert.strictEqual(overlay.querySelectorAll('.chat-pet-subagent').length, 0); + assert.strictEqual(overlay.querySelectorAll('.chat-subagent-pet').length, 0); service.toggle(); - assert.strictEqual(overlay.querySelectorAll('.chat-pet-subagent').length, 2); + assert.strictEqual(overlay.querySelectorAll('.chat-subagent-pet').length, 2); }); - test('mini pets avoid existing positions when the main pet moves between subagents', () => { + test('subagent pets avoid existing positions when the main pet moves between subagents', () => { const { widget, firstHost, button, overlay } = createHostTransitionHarness(true); const changed = disposables.add(new Emitter()); const parts: IChatProgressResponseContent[] = []; @@ -3009,12 +3009,12 @@ suite('ChatPetWidget', () => { add('first'); button.style.left = '324px'; add('second'); - const [first, second] = overlay.querySelectorAll('.chat-pet-subagent'); + const [first, second] = overlay.querySelectorAll('.chat-subagent-pet'); assert.ok(second.offsetLeft + 24 <= first.offsetLeft || first.offsetLeft + 24 <= second.offsetLeft || Number.parseFloat(second.style.top) + 24 <= Number.parseFloat(first.style.top) || Number.parseFloat(first.style.top) + 24 <= Number.parseFloat(second.style.top)); }); - test('mini pets spawn across the platform and stack where their paths overlap', async () => { + test('subagent pets spawn across the platform and stack where their paths overlap', async () => { const { widget, firstHost, button, overlay, firstParent, layout } = createHostTransitionHarness(true); const changed = disposables.add(new Emitter()); const parts: IChatProgressResponseContent[] = []; @@ -3031,25 +3031,25 @@ suite('ChatPetWidget', () => { add('left', 0.1); add('right', 0.9); add('above', 0.1); - const [left, right, above] = [...overlay.querySelectorAll('.chat-pet-subagent')]; + const [left, right, above] = [...overlay.querySelectorAll('.chat-subagent-pet')]; assert.ok(right.offsetLeft - left.offsetLeft > 200); assert.strictEqual(above.style.left, left.style.left); assert.strictEqual(Number.parseFloat(above.style.top) + 24, Number.parseFloat(left.style.top)); firstParent.style.width = '120px'; layout(); const bounds = firstParent.getBoundingClientRect(); - await waitForPetAnimation(() => [left, right, above].every(pet => { - const rect = pet.getBoundingClientRect(); - return rect.left >= bounds.left - 0.1 && rect.right <= bounds.right + 0.1 && rect.bottom <= bounds.top + 0.1 && pet.querySelector('img')?.getAttribute('src')?.includes('buddy-idle-'); + await waitForPetAnimation(() => [left, right, above].every(subagentPet => { + const rect = subagentPet.getBoundingClientRect(); + return rect.left >= bounds.left - 0.1 && rect.right <= bounds.right + 0.1 && rect.bottom <= bounds.top + 0.1 && subagentPet.querySelector('img')?.getAttribute('src')?.includes('buddy-idle-'); })); - const rects = [left, right, above].map(pet => pet.getBoundingClientRect()); + const rects = [left, right, above].map(subagentPet => subagentPet.getBoundingClientRect()); assert.ok(rects.every(rect => rect.left >= bounds.left - 0.1 && rect.right <= bounds.right + 0.1 && rect.bottom <= bounds.top + 0.1)); assert.ok(rects.every((rect, index) => rects.slice(index + 1).every(other => rect.right <= other.left + 0.1 || other.right <= rect.left + 0.1 || rect.bottom <= other.top + 0.1 || other.bottom <= rect.top + 0.1))); }); for (const reducedMotion of [false, true]) { - test(`mini pets keep their size and only displaced pets respawn (${reducedMotion ? 'reduced motion' : 'animated'})`, async () => { + test(`subagent pets keep their size and only displaced pets respawn (${reducedMotion ? 'reduced motion' : 'animated'})`, async () => { const { widget, firstHost, overlay, firstParent, layout } = createHostTransitionHarness(reducedMotion); const tools = ['stays', 'upper', 'support', 'outside'].map(id => { const tool = new ChatToolInvocation(undefined, { id, displayName: id, modelDescription: 'Subagent', source: ToolDataSource.Internal }, id, undefined, {}); @@ -3057,52 +3057,52 @@ suite('ChatPetWidget', () => { return tool; }); widget.setHost({ ...firstHost, model: constObservable(createSubagentTestModel(tools)) }); - const pets = [...overlay.querySelectorAll('.chat-pet-subagent')]; - const scales = pets.map(pet => pet.style.transform); - for (const [index, pet] of pets.entries()) { - pet.getAnimations().forEach(animation => animation.cancel()); - setMiniPetPosition(widget, pet, [20, 80, 90, 220][index], index === 1 ? -48 : -24); + const subagentPets = [...overlay.querySelectorAll('.chat-subagent-pet')]; + const scales = subagentPets.map(subagentPet => subagentPet.style.transform); + for (const [index, subagentPet] of subagentPets.entries()) { + subagentPet.getAnimations().forEach(animation => animation.cancel()); + setSubagentPetPosition(widget, subagentPet, [20, 80, 90, 220][index], index === 1 ? -48 : -24); } firstParent.style.width = '120px'; layout(); layout(); layout(); - assert.deepStrictEqual(pets.map(pet => pet.style.left), ['20px', '80px', '90px', '220px']); - await waitForPetAnimation(() => pets[2].querySelector('img')?.getAttribute('src')?.includes('buddy-respawn-') === true - && pets[3].querySelector('img')?.getAttribute('src')?.includes('buddy-respawn-') === true); + assert.deepStrictEqual(subagentPets.map(subagentPet => subagentPet.style.left), ['20px', '80px', '90px', '220px']); + await waitForPetAnimation(() => subagentPets[2].querySelector('img')?.getAttribute('src')?.includes('buddy-respawn-') === true + && subagentPets[3].querySelector('img')?.getAttribute('src')?.includes('buddy-respawn-') === true); assert.deepStrictEqual({ - stays: [pets[0].style.left, pets[0].style.top], - upper: [pets[1].style.left, pets[1].style.top], + stays: [subagentPets[0].style.left, subagentPets[0].style.top], + upper: [subagentPets[1].style.left, subagentPets[1].style.top], }, { stays: ['20px', '-24px'], upper: ['80px', '-24px'] }); - await waitForPetAnimation(() => pets.every(pet => pet.getAnimations().length === 0 && pet.querySelector('img')?.getAttribute('src')?.includes('buddy-idle-') === true)); - assert.deepStrictEqual(pets.map(pet => pet.style.transform), scales); + await waitForPetAnimation(() => subagentPets.every(subagentPet => subagentPet.getAnimations().length === 0 && subagentPet.querySelector('img')?.getAttribute('src')?.includes('buddy-idle-') === true)); + assert.deepStrictEqual(subagentPets.map(subagentPet => subagentPet.style.transform), scales); const input = firstParent.getBoundingClientRect(); - const rects = pets.map(pet => pet.getBoundingClientRect()); + const rects = subagentPets.map(subagentPet => subagentPet.getBoundingClientRect()); assert.ok(rects.every(rect => rect.left >= input.left - 0.1 && rect.right <= input.right + 0.1 && rect.bottom <= input.top + 0.1)); assert.ok(rects.every((rect, index) => rects.slice(index + 1).every(other => rect.right <= other.left + 0.1 || other.right <= rect.left + 0.1 || rect.bottom <= other.top + 0.1 || other.bottom <= rect.top + 0.1))); }); } - test('mini pets start falling near the edge while resizing continues', () => { + test('subagent pets start falling near the edge while resizing continues', () => { const clock = sinon.useFakeTimers({ toFake: ['setTimeout', 'clearTimeout'] }); disposables.add(toDisposable(() => clock.restore())); const { widget, firstHost, firstParent, overlay, layout } = createHostTransitionHarness(true); const tool = new ChatToolInvocation(undefined, { id: 'edge', displayName: 'Edge', modelDescription: 'Subagent', source: ToolDataSource.Internal }, 'edge', undefined, {}); tool.toolSpecificData = { kind: 'subagent', isActive: true }; widget.setHost({ ...firstHost, model: constObservable(createSubagentTestModel([tool])) }); - const pet = overlay.querySelector('.chat-pet-subagent')!; - setMiniPetPosition(widget, pet, 98, -24); + const subagentPet = overlay.querySelector('.chat-subagent-pet')!; + setSubagentPetPosition(widget, subagentPet, 98, -24); firstParent.style.width = '120px'; layout(); clock.tick(8); layout(); - assert.ok(pet.querySelector('img')?.getAttribute('src')?.includes('buddy-idle-')); + assert.ok(subagentPet.querySelector('img')?.getAttribute('src')?.includes('buddy-idle-')); clock.tick(8); - assert.ok(pet.querySelector('img')?.getAttribute('src')?.includes('buddy-respawn-')); + assert.ok(subagentPet.querySelector('img')?.getAttribute('src')?.includes('buddy-respawn-')); }); - test('mini pets spawn inside the visible window when their platform extends beyond it', () => { + test('subagent pets spawn inside the visible window when their platform extends beyond it', () => { const { widget, firstHost, root, firstParent, button, overlay } = createHostTransitionHarness(true); root.style.width = `${mainWindow.innerWidth + 240}px`; firstParent.style.left = `${mainWindow.innerWidth - 80}px`; @@ -3116,13 +3116,13 @@ suite('ChatPetWidget', () => { tool.toolSpecificData = { kind: 'subagent', isActive: true }; tools.push(tool); changed.fire({ reason: 'other' }); - const rect = overlay.querySelector('.chat-pet-subagent')!.getBoundingClientRect(); + const rect = overlay.querySelector('.chat-subagent-pet')!.getBoundingClientRect(); assert.ok(rect.right <= mainWindow.innerWidth - 12 + 0.1); }); for (const petLeft of [0, 192]) { for (const staggered of [false, true]) { - test(`mini pets land above the input without a resize (main pet at ${petLeft}, ${staggered ? 'staggered' : 'together'})`, () => { + test(`subagent pets land above the input without a resize (main pet at ${petLeft}, ${staggered ? 'staggered' : 'together'})`, () => { const { widget, firstHost, button, overlay, firstParent } = createHostTransitionHarness(true); firstParent.style.width = '240px'; button.style.left = `${petLeft}px`; @@ -3131,11 +3131,11 @@ suite('ChatPetWidget', () => { widget.setHost({ ...firstHost, transition: undefined, model: constObservable(createSubagentTestModel(tools, changed.event)) }); const checkLanding = (count: number) => { const input = firstParent.getBoundingClientRect(); - const pets = [...overlay.querySelectorAll('.chat-pet-subagent')].map(pet => pet.getBoundingClientRect()); + const subagentPets = [...overlay.querySelectorAll('.chat-subagent-pet')].map(subagentPet => subagentPet.getBoundingClientRect()); assert.deepStrictEqual({ - count: pets.length, - aboveInput: pets.every(pet => pet.bottom <= input.top + 0.1), - withinWidth: pets.every(pet => pet.left >= input.left - 0.1 && pet.right <= input.right + 0.1), + count: subagentPets.length, + aboveInput: subagentPets.every(subagentPet => subagentPet.bottom <= input.top + 0.1), + withinWidth: subagentPets.every(subagentPet => subagentPet.left >= input.left - 0.1 && subagentPet.right <= input.right + 0.1), }, { count, aboveInput: true, withinWidth: true }); }; for (let index = 0; index < 10; index++) { @@ -3157,7 +3157,7 @@ suite('ChatPetWidget', () => { } } - test('mini pets keep their initial size when crowded and resized', async () => { + test('subagent pets keep their initial size when crowded and resized', async () => { const { widget, firstHost, overlay, firstParent, root, layout } = createHostTransitionHarness(true); const changed = disposables.add(new Emitter()); const tools = Array.from({ length: 100 }, (_, index) => { @@ -3167,22 +3167,22 @@ suite('ChatPetWidget', () => { return tool; }); widget.setHost({ ...firstHost, transition: undefined, model: constObservable(createSubagentTestModel(tools, changed.event)) }); - const pets = [...overlay.querySelectorAll('.chat-pet-subagent')]; - const initialSize = pets[0].getBoundingClientRect().width; + const subagentPets = [...overlay.querySelectorAll('.chat-subagent-pet')]; + const initialSize = subagentPets[0].getBoundingClientRect().width; assert.ok(Math.abs(initialSize - 24) < 0.1); - assert.ok(pets.every(pet => Math.abs(pet.getBoundingClientRect().width - initialSize) < 0.1)); + assert.ok(subagentPets.every(subagentPet => Math.abs(subagentPet.getBoundingClientRect().width - initialSize) < 0.1)); for (const width of [120, 80, 120]) { firstParent.style.width = `${width}px`; root.style.height = '64px'; firstParent.style.top = '32px'; layout(); await timeout(50); - assert.ok(pets.every(pet => Math.abs(pet.getBoundingClientRect().width - initialSize) < 0.1)); + assert.ok(subagentPets.every(subagentPet => Math.abs(subagentPet.getBoundingClientRect().width - initialSize) < 0.1)); } }); for (const petLeft of [0, 300]) { - test(`mini pets stay in a bounded area with many subagents (main pet at ${petLeft})`, async () => { + test(`subagent pets stay in a bounded area with many subagents (main pet at ${petLeft})`, async () => { const { widget, firstHost, button, overlay, firstParent, root, layout } = createHostTransitionHarness(true); const changed = disposables.add(new Emitter()); const tools = Array.from({ length: 100 }, (_, index) => { @@ -3193,9 +3193,9 @@ suite('ChatPetWidget', () => { }); button.style.left = `${petLeft}px`; widget.setHost({ ...firstHost, transition: undefined, model: constObservable(createSubagentTestModel(tools, changed.event)) }); - const pets = [...overlay.querySelectorAll('.chat-pet-subagent')]; + const subagentPets = [...overlay.querySelectorAll('.chat-subagent-pet')]; const checkBounds = (count: number) => { - const rects = [...overlay.querySelectorAll('.chat-pet-subagent')].map(pet => pet.getBoundingClientRect()); + const rects = [...overlay.querySelectorAll('.chat-subagent-pet')].map(subagentPet => subagentPet.getBoundingClientRect()); const input = firstParent.getBoundingClientRect(); const movement = root.getBoundingClientRect(); const left = Math.min(...rects.map(rect => rect.left)); @@ -3213,25 +3213,25 @@ suite('ChatPetWidget', () => { checkBounds(100); firstParent.style.width = '120px'; layout(); - await waitForPetAnimation(() => pets.every(pet => { - const rect = pet.getBoundingClientRect(); + await waitForPetAnimation(() => subagentPets.every(subagentPet => { + const rect = subagentPet.getBoundingClientRect(); const input = firstParent.getBoundingClientRect(); - return rect.left >= input.left - 0.1 && rect.right <= input.right + 0.1 && rect.bottom <= input.top + 0.1 && pet.querySelector('img')?.getAttribute('src')?.includes('buddy-idle-'); + return rect.left >= input.left - 0.1 && rect.right <= input.right + 0.1 && rect.bottom <= input.top + 0.1 && subagentPet.querySelector('img')?.getAttribute('src')?.includes('buddy-idle-'); })); checkBounds(100); root.style.height = '64px'; firstParent.style.top = '32px'; layout(); - await waitForPetAnimation(() => pets.every(pet => { - const rect = pet.getBoundingClientRect(); + await waitForPetAnimation(() => subagentPets.every(subagentPet => { + const rect = subagentPet.getBoundingClientRect(); const input = firstParent.getBoundingClientRect(); - return rect.left >= input.left - 0.1 && rect.right <= input.right + 0.1 && rect.top >= root.getBoundingClientRect().top - 0.1 && rect.bottom <= input.top + 0.1 && pet.querySelector('img')?.getAttribute('src')?.includes('buddy-idle-'); + return rect.left >= input.left - 0.1 && rect.right <= input.right + 0.1 && rect.top >= root.getBoundingClientRect().top - 0.1 && rect.bottom <= input.top + 0.1 && subagentPet.querySelector('img')?.getAttribute('src')?.includes('buddy-idle-'); })); checkBounds(100); tools[0].toolSpecificData = { kind: 'subagent', isActive: false }; changed.fire({ reason: 'other' }); checkBounds(99); - assert.deepStrictEqual([...overlay.querySelectorAll('.chat-pet-subagent')], pets.slice(1)); + assert.deepStrictEqual([...overlay.querySelectorAll('.chat-subagent-pet')], subagentPets.slice(1)); tools[0].toolSpecificData = { kind: 'subagent', isActive: true }; changed.fire({ reason: 'other' }); checkBounds(100); @@ -3240,7 +3240,7 @@ suite('ChatPetWidget', () => { for (const reducedMotion of [false, true]) { for (const removedIndex of [0, 1]) { - test(`mini pets fall when their ${removedIndex === 0 ? 'bottom' : 'middle'} support finishes (${reducedMotion ? 'reduced motion' : 'animated'})`, () => { + test(`subagent pets fall when their ${removedIndex === 0 ? 'bottom' : 'middle'} support finishes (${reducedMotion ? 'reduced motion' : 'animated'})`, () => { const { widget, firstHost, overlay, setReducedMotion } = createHostTransitionHarness(reducedMotion); const changed = disposables.add(new Emitter()); const tools = ['bottom', 'middle', 'top', 'neighbor'].map(id => { @@ -3249,42 +3249,42 @@ suite('ChatPetWidget', () => { return tool; }); widget.setHost({ ...firstHost, model: constObservable(createSubagentTestModel(tools, changed.event)) }); - const pets = [...overlay.querySelectorAll('.chat-pet-subagent')]; + const subagentPets = [...overlay.querySelectorAll('.chat-subagent-pet')]; // A three-high stack on the input platform and an independent neighbor on the ground. - pets.forEach((pet, index) => { - pet.getAnimations().forEach(animation => animation.cancel()); - setMiniPetPosition(widget, pet, index === 3 ? 96 : 48, index === 3 ? -24 : -(index + 1) * 24); + subagentPets.forEach((subagentPet, index) => { + subagentPet.getAnimations().forEach(animation => animation.cancel()); + setSubagentPetPosition(widget, subagentPet, index === 3 ? 96 : 48, index === 3 ? -24 : -(index + 1) * 24); }); - const neighborPosition = pets[3].getBoundingClientRect().toJSON(); + const neighborPosition = subagentPets[3].getBoundingClientRect().toJSON(); tools[removedIndex].toolSpecificData = { kind: 'subagent', isActive: false }; changed.fire({ reason: 'other' }); assert.deepStrictEqual({ - remaining: [...overlay.querySelectorAll('.chat-pet-subagent')], - tops: pets.filter((_, index) => index !== removedIndex).map(pet => pet.style.top), - falling: pets[2].getAnimations().length > 0, - neighbor: pets[3].getBoundingClientRect().toJSON(), - }, { remaining: pets.filter((_, index) => index !== removedIndex), tops: ['-24px', '-48px', '-24px'], falling: !reducedMotion, neighbor: neighborPosition }); + remaining: [...overlay.querySelectorAll('.chat-subagent-pet')], + tops: subagentPets.filter((_, index) => index !== removedIndex).map(subagentPet => subagentPet.style.top), + falling: subagentPets[2].getAnimations().length > 0, + neighbor: subagentPets[3].getBoundingClientRect().toJSON(), + }, { remaining: subagentPets.filter((_, index) => index !== removedIndex), tops: ['-24px', '-48px', '-24px'], falling: !reducedMotion, neighbor: neighborPosition }); // Removing the next support mid-fall must continue from the currently rendered position. - for (const animation of pets[2].getAnimations()) { + for (const animation of subagentPets[2].getAnimations()) { animation.pause(); } - const previousTop = pets[2].getBoundingClientRect().top - overlay.getBoundingClientRect().top; + const previousTop = subagentPets[2].getBoundingClientRect().top - overlay.getBoundingClientRect().top; tools[1 - removedIndex].toolSpecificData = { kind: 'subagent', isActive: false }; changed.fire({ reason: 'other' }); - assert.strictEqual(pets[2].style.top, '-24px'); + assert.strictEqual(subagentPets[2].style.top, '-24px'); if (!reducedMotion) { - assert.ok(Math.abs(Number.parseFloat((pets[2].getAnimations()[0].effect as KeyframeEffect).getKeyframes()[0].top as string) - previousTop) < 0.1); + assert.ok(Math.abs(Number.parseFloat((subagentPets[2].getAnimations()[0].effect as KeyframeEffect).getKeyframes()[0].top as string) - previousTop) < 0.1); setReducedMotion(true); } assert.deepStrictEqual({ - falling: pets[2].getAnimations().length > 0, - bottom: pets[2].getBoundingClientRect().bottom, + falling: subagentPets[2].getAnimations().length > 0, + bottom: subagentPets[2].getBoundingClientRect().bottom, }, { falling: false, bottom: overlay.getBoundingClientRect().top }); }); } } - test('mini pets keep a large initial group on the approval prompt', () => { + test('subagent pets keep a large initial group on the approval prompt', () => { const { widget, firstHost, overlay, firstParent, button } = createHostTransitionHarness(true); firstParent.style.width = '240px'; button.style.left = '192px'; @@ -3299,18 +3299,18 @@ suite('ChatPetWidget', () => { return [{ left: bounds.left + 20, right: bounds.right - 20, top: bounds.top - 60, isDefault: true }]; } }); const bounds = firstParent.getBoundingClientRect(); - const pets = [...overlay.querySelectorAll('.chat-pet-subagent')]; + const subagentPets = [...overlay.querySelectorAll('.chat-subagent-pet')]; assert.deepStrictEqual({ - count: pets.length, - onPrompt: pets.every(pet => { - const rect = pet.getBoundingClientRect(); + count: subagentPets.length, + onPrompt: subagentPets.every(subagentPet => { + const rect = subagentPet.getBoundingClientRect(); return rect.bottom <= bounds.top - 60 + 0.1 && rect.left >= bounds.left + 20 - 0.1 && rect.right <= bounds.right - 20 + 0.1; }), }, { count: 20, onPrompt: true }); }); for (const reducedMotion of [false, true]) { - test(`mini pets fall and respawn when a prompt replaces their support (${reducedMotion ? 'reduced motion' : 'animated'})`, async () => { + test(`subagent pets fall and respawn when a prompt replaces their support (${reducedMotion ? 'reduced motion' : 'animated'})`, async () => { const { widget, firstHost, overlay, firstParent, root, platformChanged } = createHostTransitionHarness(reducedMotion); let promptVisible = false; const tools = ['first', 'second'].map(id => { @@ -3323,24 +3323,24 @@ suite('ChatPetWidget', () => { return [{ left: bounds.left, right: bounds.right, top: bounds.top - (promptVisible ? 60 : 0), isDefault: true }]; } }); await timeout(1_300); - const pets = [...overlay.querySelectorAll('.chat-pet-subagent')]; + const subagentPets = [...overlay.querySelectorAll('.chat-subagent-pet')]; promptVisible = true; platformChanged.fire(); - assert.ok(pets.every(pet => Math.abs(Number.parseFloat(pet.style.top) + 24 + overlay.getBoundingClientRect().top - root.getBoundingClientRect().bottom) < 0.1)); - await waitForPetAnimation(() => pets.every(pet => pet.querySelector('img')?.getAttribute('src')?.includes('buddy-respawn-') === true)); - await waitForPetAnimation(() => pets.every(pet => pet.getAnimations().length === 0 && pet.querySelector('img')?.getAttribute('src')?.includes('buddy-idle-') === true)); + assert.ok(subagentPets.every(subagentPet => Math.abs(Number.parseFloat(subagentPet.style.top) + 24 + overlay.getBoundingClientRect().top - root.getBoundingClientRect().bottom) < 0.1)); + await waitForPetAnimation(() => subagentPets.every(subagentPet => subagentPet.querySelector('img')?.getAttribute('src')?.includes('buddy-respawn-') === true)); + await waitForPetAnimation(() => subagentPets.every(subagentPet => subagentPet.getAnimations().length === 0 && subagentPet.querySelector('img')?.getAttribute('src')?.includes('buddy-idle-') === true)); assert.deepStrictEqual({ - identity: [...overlay.querySelectorAll('.chat-pet-subagent')], - onPrompt: pets.every(pet => pet.getBoundingClientRect().bottom <= firstParent.getBoundingClientRect().top - 60 + 0.1), - }, { identity: pets, onPrompt: true }); + identity: [...overlay.querySelectorAll('.chat-subagent-pet')], + onPrompt: subagentPets.every(subagentPet => subagentPet.getBoundingClientRect().bottom <= firstParent.getBoundingClientRect().top - 60 + 0.1), + }, { identity: subagentPets, onPrompt: true }); promptVisible = false; platformChanged.fire(); - await waitForPetAnimation(() => pets.every(pet => pet.getAnimations().length === 0)); - assert.ok(pets.every(pet => pet.getBoundingClientRect().bottom <= firstParent.getBoundingClientRect().top + 0.1)); + await waitForPetAnimation(() => subagentPets.every(subagentPet => subagentPet.getAnimations().length === 0)); + assert.ok(subagentPets.every(subagentPet => subagentPet.getBoundingClientRect().bottom <= firstParent.getBoundingClientRect().top + 0.1)); }); } - test('mini pets cancel a pending prompt respawn when their subagent finishes', async () => { + test('subagent pets cancel a pending prompt respawn when their subagent finishes', async () => { const { widget, firstHost, overlay, firstParent, platformChanged } = createHostTransitionHarness(true); const changed = disposables.add(new Emitter()); let promptVisible = false; @@ -3352,28 +3352,28 @@ suite('ChatPetWidget', () => { } }); promptVisible = true; platformChanged.fire(); - const image = overlay.querySelector('.chat-pet-subagent img')!; + const image = overlay.querySelector('.chat-subagent-pet img')!; await whenSpriteLoaded(image); assert.ok(image.getAttribute('src')?.includes('buddy-respawn-')); tool.toolSpecificData = { kind: 'subagent', isActive: false }; changed.fire({ reason: 'other' }); await timeout(1_000); - assert.strictEqual(overlay.querySelectorAll('.chat-pet-subagent, .chat-pet-subagent-despawning').length, 0); + assert.strictEqual(overlay.querySelectorAll('.chat-subagent-pet, .chat-subagent-pet-despawning').length, 0); }); - test('mini pets update appearance and motion settings while active', async () => { + test('subagent pets update appearance and motion settings while active', async () => { const { widget, firstHost, button, overlay, service, setReducedMotion } = createHostTransitionHarness(); const tool = new ChatToolInvocation(undefined, { id: 'subagent', displayName: 'Subagent', modelDescription: 'Subagent', source: ToolDataSource.Internal }, 'subagent', undefined, {}); tool.toolSpecificData = { kind: 'subagent', isActive: true }; widget.setHost({ ...firstHost, model: constObservable(createSubagentTestModel([tool])) }); - const pet = overlay.querySelector('.chat-pet-subagent')!; - pet.getAnimations().forEach(animation => animation.cancel()); + const subagentPet = overlay.querySelector('.chat-subagent-pet')!; + subagentPet.getAnimations().forEach(animation => animation.cancel()); for (const scale of [1.6, 0.4, 1]) { service.setScale(scale); - assert.strictEqual(Number.parseFloat(pet.style.transform.slice(6)), scale * 0.5); - assert.ok(Math.abs(pet.getBoundingClientRect().width - button.getBoundingClientRect().width / 2) < 0.1); + assert.strictEqual(Number.parseFloat(subagentPet.style.transform.slice(6)), scale * 0.5); + assert.ok(Math.abs(subagentPet.getBoundingClientRect().width - button.getBoundingClientRect().width / 2) < 0.1); } - const body = pet.querySelector('img')!; + const body = subagentPet.querySelector('img')!; await whenSpriteLoaded(body); setReducedMotion(true); await whenSpriteLoaded(body); @@ -3386,34 +3386,34 @@ suite('ChatPetWidget', () => { await whenSpriteLoaded(body); assert.ok(body.getAttribute('src')?.includes('buddy-idle-stable')); service.setColor('#12abcd'); - assert.strictEqual(pet.querySelector('.chat-pet-eyes')!.style.color, button.querySelector('.chat-pet-eyes')!.style.color); + assert.strictEqual(subagentPet.querySelector('.chat-pet-eyes')!.style.color, button.querySelector('.chat-pet-eyes')!.style.color); service.unlockAchievement(getChatPetAchievementForAccessory(ChatPetAccessoryIds.CowboyHat).id); service.setAccessory(ChatPetAccessoryIds.CowboyHat); - const hat = pet.querySelectorAll('img')[1]; + const hat = subagentPet.querySelectorAll('img')[1]; assert.ok(hat?.src.includes('/accessories/')); service.setAccessory(undefined); - assert.strictEqual(pet.querySelectorAll('img').length, 1); + assert.strictEqual(subagentPet.querySelectorAll('img').length, 1); }); - test('mini pets stop squishing when reduced motion is enabled during landing', async () => { + test('subagent pets stop squishing when reduced motion is enabled during landing', async () => { const { widget, firstHost, overlay, setReducedMotion } = createHostTransitionHarness(); const tool = new ChatToolInvocation(undefined, { id: 'subagent', displayName: 'Subagent', modelDescription: 'Subagent', source: ToolDataSource.Internal }, 'subagent', undefined, {}); tool.toolSpecificData = { kind: 'subagent', isActive: true }; widget.setHost({ ...firstHost, model: constObservable(createSubagentTestModel([tool])) }); - const pet = overlay.querySelector('.chat-pet-subagent')!; - const image = pet.querySelector('img')!; + const subagentPet = overlay.querySelector('.chat-subagent-pet')!; + const image = subagentPet.querySelector('img')!; await whenSpriteLoaded(image); - pet.getAnimations()[0]?.dispatchEvent(new mainWindow.Event('finish')); + subagentPet.getAnimations()[0]?.dispatchEvent(new mainWindow.Event('finish')); await whenSpriteLoaded(image); assert.ok(image.getAttribute('src')?.includes('buddy-splat-')); setReducedMotion(true); await whenSpriteLoaded(image); assert.ok(image.getAttribute('src')?.includes('buddy-idle-')); assert.ok(image.getAttribute('src')?.endsWith('-96.png')); - assert.ok(pet.querySelector('.chat-pet-eyes.tracking')); + assert.ok(subagentPet.querySelector('.chat-pet-eyes.tracking')); }); - test('mini pets squish on landing and return to their own idle animation', async () => { + test('subagent pets squish on landing and return to their own idle animation', async () => { const clock = sinon.useFakeTimers({ toFake: ['setTimeout', 'clearTimeout', 'performance'] }); disposables.add(toDisposable(() => clock.restore())); const { widget, firstHost, overlay } = createHostTransitionHarness(); @@ -3424,9 +3424,9 @@ suite('ChatPetWidget', () => { return tool; }); widget.setHost({ ...firstHost, model: constObservable(createSubagentTestModel(tools, changed.event)) }); - const [first, second] = overlay.querySelectorAll('.chat-pet-subagent'); - for (const pet of [first, second]) { - for (const animation of pet.getAnimations()) { + const [first, second] = overlay.querySelectorAll('.chat-subagent-pet'); + for (const subagentPet of [first, second]) { + for (const animation of subagentPet.getAnimations()) { animation.pause(); } } @@ -3435,7 +3435,7 @@ suite('ChatPetWidget', () => { const eyes = first.querySelector('.chat-pet-eyes')!; await Promise.all([whenSpriteLoaded(image), whenSpriteLoaded(secondImage)]); const idleSource = image.getAttribute('src'); - const land = (pet: HTMLElement) => pet.getAnimations()[0]?.dispatchEvent(new mainWindow.Event('finish')); + const land = (subagentPet: HTMLElement) => subagentPet.getAnimations()[0]?.dispatchEvent(new mainWindow.Event('finish')); land(first); await whenSpriteLoaded(image); assert.deepStrictEqual({ @@ -3453,27 +3453,27 @@ suite('ChatPetWidget', () => { changed.fire({ reason: 'other' }); land(second); clock.tick(900); - assert.deepStrictEqual({ active: [...overlay.querySelectorAll('.chat-pet-subagent')], removed: !second.isConnected }, { active: [first], removed: true }); + assert.deepStrictEqual({ active: [...overlay.querySelectorAll('.chat-subagent-pet')], removed: !second.isConnected }, { active: [first], removed: true }); }); - test('mini pets use the reduced-motion disappearance sprite', () => { + test('subagent pets use the reduced-motion disappearance sprite', () => { const { widget, firstHost, overlay } = createHostTransitionHarness(true); const changed = disposables.add(new Emitter()); const tool = new ChatToolInvocation(undefined, { id: 'subagent', displayName: 'Subagent', modelDescription: 'Subagent', source: ToolDataSource.Internal }, 'subagent', undefined, {}); tool.toolSpecificData = { kind: 'subagent', isActive: true }; widget.setHost({ ...firstHost, model: constObservable(createSubagentTestModel([tool], changed.event)) }); - assert.ok(overlay.querySelector('.chat-pet-subagent')); - const pet = overlay.querySelector('.chat-pet-subagent')!; - const image = pet.querySelector('img')!; + assert.ok(overlay.querySelector('.chat-subagent-pet')); + const subagentPet = overlay.querySelector('.chat-subagent-pet')!; + const image = subagentPet.querySelector('img')!; const idleSource = image.getAttribute('src'); - pet.getAnimations()[0]?.dispatchEvent(new mainWindow.Event('finish')); + subagentPet.getAnimations()[0]?.dispatchEvent(new mainWindow.Event('finish')); assert.strictEqual(image.getAttribute('src'), idleSource); tool.toolSpecificData = { kind: 'subagent', isActive: false }; changed.fire({ reason: 'other' }); - assert.ok(overlay.querySelector('.chat-pet-subagent-despawning img')?.getAttribute('src')?.endsWith('-96.png')); + assert.ok(overlay.querySelector('.chat-subagent-pet-despawning img')?.getAttribute('src')?.endsWith('-96.png')); }); - test('mini pets blink and move their eyes with their own idle frames', async () => { + test('subagent pets blink and move their eyes with their own idle frames', async () => { const clock = sinon.useFakeTimers({ toFake: ['setTimeout', 'clearTimeout', 'performance'] }); disposables.add(toDisposable(() => clock.restore())); sinon.stub(Math, 'random').returns(0); @@ -3481,12 +3481,12 @@ suite('ChatPetWidget', () => { const tool = new ChatToolInvocation(undefined, { id: 'subagent', displayName: 'Subagent', modelDescription: 'Subagent', source: ToolDataSource.Internal }, 'subagent', undefined, {}); tool.toolSpecificData = { kind: 'subagent', isActive: true }; widget.setHost({ ...firstHost, model: constObservable(createSubagentTestModel([tool])) }); - const pet = overlay.querySelector('.chat-pet-subagent')!; + const subagentPet = overlay.querySelector('.chat-subagent-pet')!; // Exercise idle frames independently of the arrival and landing animation. - pet.getAnimations().forEach(animation => animation.cancel()); - const eyes = pet.querySelector('.chat-pet-eyes')!; - const pupil = pet.querySelector('.chat-pet-pupil')!; - await whenSpriteLoaded(pet.querySelector('img')!); + subagentPet.getAnimations().forEach(animation => animation.cancel()); + const eyes = subagentPet.querySelector('.chat-pet-eyes')!; + const pupil = subagentPet.querySelector('.chat-pet-pupil')!; + await whenSpriteLoaded(subagentPet.querySelector('img')!); assert.ok(!eyes.classList.contains('bobbed')); clock.tick(800); assert.ok(eyes.classList.contains('bobbed')); From 8d73cad3d883b404ee63baf9bea463a5d066777b Mon Sep 17 00:00:00 2001 From: Lisa Rosenberg Date: Fri, 13 Nov 2026 18:29:31 +0100 Subject: [PATCH 40/66] feat: use class --- .../chat/browser/widget/chatPetWidget.ts | 483 ++++++++++-------- 1 file changed, 257 insertions(+), 226 deletions(-) diff --git a/src/vs/workbench/contrib/chat/browser/widget/chatPetWidget.ts b/src/vs/workbench/contrib/chat/browser/widget/chatPetWidget.ts index e587ff4500ddde..40a5ab08f36aa5 100644 --- a/src/vs/workbench/contrib/chat/browser/widget/chatPetWidget.ts +++ b/src/vs/workbench/contrib/chat/browser/widget/chatPetWidget.ts @@ -221,31 +221,23 @@ interface ChatPetSpriteElement { redrawFrame?: () => void; } -/** Visual state and lifecycle controls for one active subagent pet. */ -interface SubagentPet { - /** Container positioned on the chat overlay. */ - readonly element: HTMLElement; - /** Landing position relative to the overlay. */ - left: number; - top: number; - /** Canvas used to draw the pet and its accessory. */ - readonly canvas: HTMLCanvasElement; - /** Image containing the current body sprite. */ - readonly image: HTMLImageElement; - /** Image containing the current accessory, if any. */ - readonly accessoryImage: HTMLImageElement | undefined; - /** Eye elements used for tracking and blinking. */ +interface SubagentPetHost { + readonly layer: HTMLElement; + readonly overlay: HTMLElement; readonly eyes: HTMLElement; - /** Resources owned by this pet. */ - readonly disposables: DisposableStore; - /** Updates whether blinking is enabled. */ - readonly updateBlink: () => void; - /** Synchronizes appearance and motion with the main pet. */ - readonly updateAppearance: (motionChanged: boolean, variantChanged: boolean, accessoryChanged: boolean) => void; - /** Starts a fall to an overlay-relative position, optionally followed by respawning. */ - readonly fallTo: (top: number, respawn?: boolean) => void; - /** Reports whether a fall-and-respawn sequence is in progress. */ - readonly isRespawning: () => boolean; + readonly onDidChangeAnimationVisibility: Event; + readonly enabled: boolean; + readonly motionReduced: boolean; + readonly variant: ChatPetVariant; + readonly color: ChatPetColor; + readonly accessory: ChatPetAccessoryId | undefined; + readonly scale: number; + isAnimationVisible(element: HTMLElement): boolean; + getDragBounds(): DOMRect; + getMovementBounds(): DOMRect; + getLanding(size: number): { left: number; top: number }; + scheduleResize(): void; + startAnimation(source: ChatPetSpriteSource, sprite: ChatPetSpriteElement, animation: MutableDisposable, onComplete?: () => void, reverse?: boolean, onFrame?: (frameIndex: number) => void, renderFrame?: (context: CanvasRenderingContext2D, frameIndex: number) => boolean): void; } interface ChatPetPendingRender { @@ -1280,6 +1272,226 @@ export class ChatPetHopController extends Disposable { } } +/** Owns the appearance, animation and lifecycle of one subagent pet. */ +class SubagentPet extends Disposable { + readonly element: HTMLElement; + private readonly canvas: HTMLCanvasElement; + private readonly image: HTMLImageElement; + private readonly eyes: HTMLElement; + private readonly _sprite: ChatPetSpriteElement; + private readonly _activity = this._register(new DisposableStore()); + private readonly _animation = this._activity.add(new MutableDisposable()); + private readonly _fallAnimation = this._activity.add(new MutableDisposable()); + private readonly _accessoryListener = this._activity.add(new MutableDisposable()); + private readonly _respawnTimer = this._activity.add(new RunOnceScheduler(() => this._advanceRespawn(), RESPAWN_EFFECT_REDUCED_MOTION_DURATION)); + private readonly _blink: ChatPetBlinkController; + private _state: 'idle' | 'splat' = 'idle'; + private _respawnPhase: 'none' | 'falling' | 'despawning' | 'respawning' = 'none'; + private _accessory: ReturnType | undefined; + private _accessoryImage: HTMLImageElement | undefined; + + constructor(private readonly _host: SubagentPetHost, public left: number, public top: number) { + super(); + const scale = 0.5 * _host.scale; + const size = CHAT_PET_DISPLAY_SIZE * scale; + this.element = dom.append(_host.layer, dom.$('.chat-subagent-pet', { 'aria-hidden': 'true' })); + this.element.style.left = `${left}px`; + this.element.style.top = `${top}px`; + this.element.style.transform = `scale(${scale})`; + const distance = Math.max(0, _host.overlay.getBoundingClientRect().top + top + size); + this.canvas = dom.append(this.element, dom.$('canvas.chat-subagent-pet-canvas')) as HTMLCanvasElement; + this.canvas.width = CHAT_PET_SOURCE_SIZE; + this.canvas.height = CHAT_PET_SOURCE_SIZE; + this.eyes = this.element.appendChild(_host.eyes.cloneNode(true)) as HTMLElement; + this.eyes.classList.remove('blink', 'blinking', 'bobbed'); + this.eyes.classList.add('tracking'); + for (const eye of this.eyes.children) { + (eye.firstElementChild as HTMLElement | null)?.style.removeProperty('transform'); + } + this._blink = this._activity.add(new ChatPetBlinkController(blinking => this.eyes.classList.toggle('blink', blinking))); + this._activity.add(_host.onDidChangeAnimationVisibility(() => this.updateBlink())); + const firstPupil = this.eyes.firstElementChild?.firstElementChild; + if (firstPupil) { + this._activity.add(dom.addDisposableListener(firstPupil, 'animationend', event => { + if ((event as AnimationEvent).animationName === 'chat-pet-tall-eye-blink') { + this._blink.onAnimationComplete(); + } + })); + } + this.updateBlink(); + this.image = dom.append(this.element, dom.$('img.chat-pet-spritesheet')) as HTMLImageElement; + this.image.alt = ''; + this._sprite = { container: this.element, canvas: this.canvas, image: this.image, color: _host.color }; + this._updateAccessory(); + this._activity.add(dom.addDisposableListener(this.image, 'load', () => this._onImageLoad())); + this._setState('idle'); + if (!_host.motionReduced && distance > 0) { + this._animateFall(top - distance, top); + } + } + + isRespawning(): boolean { return this._respawnPhase !== 'none'; } + + updateBlink(): void { + this._blink.setEnabled(this._respawnPhase === 'none' && this._state === 'idle' && this._host.enabled && !this._host.motionReduced && this._host.isAnimationVisible(this.element)); + } + + updateAppearance(motionChanged: boolean, variantChanged: boolean, accessoryChanged: boolean): void { + this._sprite.color = this._host.color; + this.eyes.style.color = getChatPetEyeColor(this._host.color); + if (accessoryChanged) { + this._updateAccessory(); + } + if (motionChanged || variantChanged) { + if (this._host.motionReduced) { + this._fallAnimation.clear(); + if (this._respawnPhase === 'falling') { + this._respawnPhase = 'despawning'; + } + } + this._setState(this._host.motionReduced ? 'idle' : this._state); + } else { + this._sprite.redrawFrame?.(); + } + } + + fallTo(top: number, respawn = false): void { + const previousTop = this.element.getBoundingClientRect().top - this._host.overlay.getBoundingClientRect().top; + this._respawnPhase = respawn ? 'falling' : 'none'; + this._fallAnimation.clear(); + this.top = top; + this.element.style.top = `${top}px`; + this._setState('idle'); + if (!this._host.motionReduced && top > previousTop) { + this._animateFall(previousTop, top); + } else if (respawn) { + this._respawnPhase = 'despawning'; + this._setState('idle'); + } + } + + /** Plays the disappearance effect and releases the pet when it completes. */ + despawn(onComplete: () => void): void { + this._activity.clear(); + this.image.remove(); + this._accessoryImage?.remove(); + this.element.classList.remove('chat-subagent-pet'); + this.element.classList.add('chat-subagent-pet-despawning'); + this.eyes.remove(); + const image = dom.append(this.element, dom.$('img.chat-pet-spritesheet')) as HTMLImageElement; + image.alt = ''; + const sources = getRespawnSpriteSources(this._host.variant); + const source = this._host.motionReduced ? sources.reducedMotion : sources.animated; + const animation = this._activity.add(new MutableDisposable()); + const sprite: ChatPetSpriteElement = { container: this.element, canvas: this.canvas, image, color: this._host.color }; + const finish = () => { + this.element.remove(); + onComplete(); + }; + this._activity.add(toDisposable(() => this.element.remove())); + this._activity.add(dom.addDisposableListener(image, 'load', () => this._host.startAnimation(source, sprite, animation, finish, true))); + this._activity.add(dom.addDisposableListener(image, 'error', finish)); + const targetWindow = dom.getWindow(this.element); + const timer = targetWindow.setTimeout(finish, this._host.motionReduced ? RESPAWN_EFFECT_REDUCED_MOTION_DURATION : RESPAWN_EFFECT_DURATION); + this._activity.add(toDisposable(() => targetWindow.clearTimeout(timer))); + setChatPetImageSource(image, source.url); + } + + private _getSource(): ChatPetSpriteSource { + const sources = this._respawnPhase === 'despawning' || this._respawnPhase === 'respawning' + ? getRespawnSpriteSources(this._host.variant) : getChatPetSpriteSources(this._host.variant)[this._state]; + return this._host.motionReduced ? sources.reducedMotion : sources.animated; + } + + private _setState(state: 'idle' | 'splat'): void { + this._respawnTimer.cancel(); + this._animation.clear(); + this._state = state; + this.updateBlink(); + if (this._host.motionReduced) { + this.eyes.classList.remove('bobbed'); + } + setChatPetImageSource(this.image, this._getSource().url); + } + + private _updateAccessory(): void { + this._accessory = this._host.accessory ? getChatPetAccessory(this._host.accessory) : undefined; + if (!this._accessory) { + this._accessoryListener.clear(); + this._accessoryImage?.remove(); + this._accessoryImage = undefined; + } else { + if (!this._accessoryImage) { + this._accessoryImage = dom.append(this.element, dom.$('img.chat-pet-spritesheet')) as HTMLImageElement; + this._accessoryImage.alt = ''; + this._accessoryListener.value = dom.addDisposableListener(this._accessoryImage, 'load', () => this._sprite.redrawFrame?.()); + } + setChatPetImageSource(this._accessoryImage, getChatPetAccessoryImageSource(this._accessory).url); + } + this._sprite.redrawFrame?.(); + } + + private _onImageLoad(): void { + if (this._respawnPhase === 'despawning' || this._respawnPhase === 'respawning') { + this.eyes.classList.remove('tracking', 'bobbed'); + this._host.startAnimation(this._getSource(), this._sprite, this._animation, () => this._advanceRespawn(), this._respawnPhase === 'despawning'); + if (this._host.motionReduced) { + this._respawnTimer.schedule(); + } + return; + } + if (this._state === 'splat' && this._host.motionReduced) { + this._setState('idle'); + return; + } + const source = this._getSource(); + this.eyes.classList.toggle('tracking', this._state === 'idle'); + this._host.startAnimation(source, this._sprite, this._animation, this._state === 'splat' ? () => this._setState('idle') : undefined, false, frameIndex => { + this.eyes.classList.toggle('bobbed', this._state === 'idle' && !this._host.motionReduced && (source.accessoryRigFrame ?? frameIndex) >= 20); + }, (context, frameIndex) => { + if (this._accessoryImage?.complete && this._accessoryImage.naturalWidth > 0 && this._accessory) { + drawChatPetComposite(context, this.image, this._accessoryImage, frameIndex, source.accessoryRigFrame ?? frameIndex, source.frameWidth, source.frameHeight ?? CHAT_PET_SOURCE_SIZE, 'right', this._state, source.fixedOrientationDecorations, true, this._accessory.eyeAccessoryMirrorsWithFacing !== false, this._accessory.coversAntennae === true, this._sprite.color); + return true; + } + return false; + }); + } + + private _animateFall(from: number, to: number): void { + const fall = this.element.animate([{ top: `${from}px` }, { top: `${to}px` }], { duration: getChatPetFallDuration(to - from), easing: 'cubic-bezier(0.42, 0, 1, 1)' }); + this._fallAnimation.value = toDisposable(() => fall.cancel()); + fall.onfinish = () => { + this._fallAnimation.clear(); + if (this._respawnPhase === 'falling') { + this._respawnPhase = 'despawning'; + this._setState('idle'); + } else if (!this._host.motionReduced) { + this._setState('splat'); + } + }; + } + + private _advanceRespawn(): void { + const overlay = this._host.overlay.getBoundingClientRect(); + const input = this._host.getDragBounds(); + const size = CHAT_PET_DISPLAY_SIZE * 0.5 * this._host.scale; + if (this._respawnPhase === 'despawning') { + this._respawnPhase = 'respawning'; + this.left = Math.max(input.left - overlay.left, Math.min(this.left, input.right - overlay.left - size)); + this.top = this._host.getMovementBounds().top - overlay.top; + this.element.style.left = `${this.left}px`; + this.element.style.top = `${this.top}px`; + this._setState('idle'); + } else if (this._respawnPhase === 'respawning') { + const landing = this._host.getLanding(size); + this.left = landing.left; + this.element.style.left = `${this.left}px`; + this.fallTo(landing.top); + this._host.scheduleResize(); + } + } +} + export class ChatPetWidget extends Disposable { /** Active subagent pets keyed by request and tool call identity. */ @@ -3054,7 +3266,7 @@ export class ChatPetWidget extends Disposable { if (!subagents.has(id)) { removed = true; this._subagentPets.delete(id); - this._despawnSubagentPet(subagentPet); + subagentPet.despawn(() => this._subagentPetEffects.delete(subagentPet)); } } for (const id of subagents) { @@ -3062,180 +3274,27 @@ export class ChatPetWidget extends Disposable { continue; } added = true; - const element = dom.append(this._subagentPetLayer, dom.$('.chat-subagent-pet', { 'aria-hidden': 'true' })); - const subagentPetScale = 0.5 * this._scale; - const subagentPetWidth = CHAT_PET_DISPLAY_SIZE * subagentPetScale; - const overlayBounds = this._overlay.getBoundingClientRect(); - const { left, top } = this._getSubagentPetLanding(subagentPetWidth); - element.style.left = `${left}px`; - element.style.top = `${top}px`; - element.style.transform = `scale(${subagentPetScale})`; - const distance = Math.max(0, overlayBounds.top + top + subagentPetWidth); - const canvas = dom.append(element, dom.$('canvas.chat-subagent-pet-canvas')) as HTMLCanvasElement; - canvas.width = CHAT_PET_SOURCE_SIZE; - canvas.height = CHAT_PET_SOURCE_SIZE; - const eyes = element.appendChild(this._eyes.cloneNode(true)) as HTMLElement; - eyes.classList.remove('blink', 'blinking', 'bobbed'); - eyes.classList.add('tracking'); - for (const eye of eyes.children) { - (eye.firstElementChild as HTMLElement | null)?.style.removeProperty('transform'); - } - const disposables = this._subagentPetEffects.add(new DisposableStore()); - let state: 'idle' | 'splat' = 'idle'; - let respawnPhase: 'none' | 'falling' | 'despawning' | 'respawning' = 'none'; - const respawnTimer = disposables.add(new RunOnceScheduler(() => advanceRespawn(), RESPAWN_EFFECT_REDUCED_MOTION_DURATION)); - const blink = disposables.add(new ChatPetBlinkController(blinking => eyes.classList.toggle('blink', blinking))); - const updateBlink = () => blink.setEnabled(respawnPhase === 'none' && state === 'idle' && this._enabled && !this._motionReduced && this._isAnimationVisible(this._visual) && this._isAnimationVisible(element)); - disposables.add(this._onDidChangeAnimationVisibility.event(updateBlink)); - const firstPupil = eyes.firstElementChild?.firstElementChild; - if (firstPupil) { - disposables.add(dom.addDisposableListener(firstPupil, 'animationend', event => { - if ((event as AnimationEvent).animationName === 'chat-pet-tall-eye-blink') { - blink.onAnimationComplete(); - } - })); - } - updateBlink(); - const animation = disposables.add(new MutableDisposable()); - const image = dom.append(element, dom.$('img.chat-pet-spritesheet')) as HTMLImageElement; - image.alt = ''; - const getSource = (): ChatPetSpriteSource => { - if (respawnPhase === 'despawning' || respawnPhase === 'respawning') { - const sources = getRespawnSpriteSources(this._variant); - return this._motionReduced ? sources.reducedMotion : sources.animated; - } - const sources = getChatPetSpriteSources(this._variant)[state]; - return this._motionReduced ? sources.reducedMotion : sources.animated; - }; - const setState = (nextState: 'idle' | 'splat') => { - respawnTimer.cancel(); - animation.clear(); - state = nextState; - updateBlink(); - if (this._motionReduced) { - eyes.classList.remove('bobbed'); - } - setChatPetImageSource(image, getSource().url); - }; - const sprite: ChatPetSpriteElement = { container: element, canvas, image, color: this._color }; - let accessory = this._selectedAccessory ? getChatPetAccessory(this._selectedAccessory) : undefined; - let accessoryImage: HTMLImageElement | undefined; - const accessoryListener = disposables.add(new MutableDisposable()); - const updateAccessory = () => { - accessory = this._selectedAccessory ? getChatPetAccessory(this._selectedAccessory) : undefined; - if (!accessory) { - accessoryListener.clear(); - accessoryImage?.remove(); - accessoryImage = undefined; - } else { - if (!accessoryImage) { - accessoryImage = dom.append(element, dom.$('img.chat-pet-spritesheet')) as HTMLImageElement; - accessoryImage.alt = ''; - accessoryListener.value = dom.addDisposableListener(accessoryImage, 'load', () => sprite.redrawFrame?.()); - } - setChatPetImageSource(accessoryImage, getChatPetAccessoryImageSource(accessory).url); - } - sprite.redrawFrame?.(); - }; - updateAccessory(); - disposables.add(dom.addDisposableListener(image, 'load', () => { - if (respawnPhase === 'despawning' || respawnPhase === 'respawning') { - eyes.classList.remove('tracking', 'bobbed'); - this._startSpriteAnimation(getSource(), sprite, animation, advanceRespawn, respawnPhase === 'despawning'); - if (this._motionReduced) { - respawnTimer.schedule(); - } - return; - } - if (state === 'splat' && this._motionReduced) { - setState('idle'); - return; - } - const source = getSource(); - eyes.classList.toggle('tracking', state === 'idle'); - this._startSpriteAnimation(source, sprite, animation, state === 'splat' ? () => setState('idle') : undefined, false, frameIndex => { - eyes.classList.toggle('bobbed', state === 'idle' && !this._motionReduced && (source.accessoryRigFrame ?? frameIndex) >= 20); - }, undefined, undefined, (context, frameIndex) => { - if (accessoryImage?.complete && accessoryImage.naturalWidth > 0 && accessory) { - drawChatPetComposite(context, image, accessoryImage, frameIndex, source.accessoryRigFrame ?? frameIndex, source.frameWidth, source.frameHeight ?? CHAT_PET_SOURCE_SIZE, 'right', state, source.fixedOrientationDecorations, true, accessory.eyeAccessoryMirrorsWithFacing !== false, accessory.coversAntennae === true, sprite.color); - return true; - } - return false; - }); - })); - const fallAnimation = disposables.add(new MutableDisposable()); - const animateFall = (from: number, to: number) => { - const fall = element.animate([{ top: `${from}px` }, { top: `${to}px` }], { - duration: getChatPetFallDuration(to - from), - easing: 'cubic-bezier(0.42, 0, 1, 1)', - }); - fallAnimation.value = toDisposable(() => fall.cancel()); - fall.onfinish = () => { - fallAnimation.clear(); - if (respawnPhase === 'falling') { - respawnPhase = 'despawning'; - setState('idle'); - } else if (!this._motionReduced) { - setState('splat'); - } - }; - }; - const updateAppearance = (motionChanged: boolean, variantChanged: boolean, accessoryChanged: boolean) => { - sprite.color = this._color; - eyes.style.color = getChatPetEyeColor(this._color); - if (accessoryChanged) { - updateAccessory(); - } - if (motionChanged || variantChanged) { - if (this._motionReduced) { - fallAnimation.clear(); - if (respawnPhase === 'falling') { - respawnPhase = 'despawning'; - } - } - setState(this._motionReduced ? 'idle' : state); - } else { - sprite.redrawFrame?.(); - } + const widget = this; + const host: SubagentPetHost = { + layer: this._subagentPetLayer, + overlay: this._overlay, + eyes: this._eyes, + onDidChangeAnimationVisibility: this._onDidChangeAnimationVisibility.event, + get enabled() { return widget._enabled; }, + get motionReduced() { return widget._motionReduced; }, + get variant() { return widget._variant; }, + get color() { return widget._color; }, + get accessory() { return widget._selectedAccessory; }, + get scale() { return widget._scale; }, + isAnimationVisible: element => this._isAnimationVisible(this._visual) && this._isAnimationVisible(element), + getDragBounds: () => this.dragBounds.getBoundingClientRect(), + getMovementBounds: () => this.movementBounds.getBoundingClientRect(), + getLanding: size => this._getSubagentPetLanding(size), + scheduleResize: () => this._scheduleSubagentPetResize(), + startAnimation: (source, sprite, animation, onComplete, reverse, onFrame, renderFrame) => this._startSpriteAnimation(source, sprite, animation, onComplete, reverse, onFrame, undefined, undefined, renderFrame), }; - const fallTo = (top: number, respawn = false) => { - const previousTop = element.getBoundingClientRect().top - this._overlay.getBoundingClientRect().top; - respawnPhase = respawn ? 'falling' : 'none'; - fallAnimation.clear(); - subagentPet.top = top; - element.style.top = `${top}px`; - setState('idle'); - if (!this._motionReduced && top > previousTop) { - animateFall(previousTop, top); - } else if (respawn) { - respawnPhase = 'despawning'; - setState('idle'); - } - }; - const advanceRespawn = () => { - const overlay = this._overlay.getBoundingClientRect(); - const input = this.dragBounds.getBoundingClientRect(); - const size = CHAT_PET_DISPLAY_SIZE * 0.5 * this._scale; - if (respawnPhase === 'despawning') { - respawnPhase = 'respawning'; - subagentPet.left = Math.max(input.left - overlay.left, Math.min(subagentPet.left, input.right - overlay.left - size)); - subagentPet.top = this.movementBounds.getBoundingClientRect().top - overlay.top; - element.style.left = `${subagentPet.left}px`; - element.style.top = `${subagentPet.top}px`; - setState('idle'); - } else if (respawnPhase === 'respawning') { - const landing = this._getSubagentPetLanding(size); - subagentPet.left = landing.left; - element.style.left = `${subagentPet.left}px`; - fallTo(landing.top); - this._scheduleSubagentPetResize(); - } - }; - const subagentPet: SubagentPet = { element, left, top, canvas, image, get accessoryImage() { return accessoryImage; }, eyes, disposables, updateBlink, updateAppearance, fallTo, isRespawning: () => respawnPhase !== 'none' }; - setState('idle'); - if (!this._motionReduced && distance > 0) { - animateFall(top - distance, top); - } + const { left, top } = this._getSubagentPetLanding(CHAT_PET_DISPLAY_SIZE * 0.5 * this._scale); + const subagentPet = this._subagentPetEffects.add(new SubagentPet(host, left, top)); this._subagentPets.set(id, subagentPet); } if (added || removed) { @@ -3303,34 +3362,6 @@ export class ChatPetWidget extends Disposable { } } - /** Removes an active subagent pet after playing its disappearance effect. */ - private _despawnSubagentPet(subagentPet: SubagentPet): void { - this._subagentPetEffects.delete(subagentPet.disposables); - subagentPet.image.remove(); - subagentPet.accessoryImage?.remove(); - subagentPet.element.classList.remove('chat-subagent-pet'); - subagentPet.element.classList.add('chat-subagent-pet-despawning'); - subagentPet.eyes.remove(); - const effects = this._subagentPetEffects.add(new DisposableStore()); - const image = dom.append(subagentPet.element, dom.$('img.chat-pet-spritesheet')) as HTMLImageElement; - image.alt = ''; - const sources = getRespawnSpriteSources(this._variant); - const source = this._motionReduced ? sources.reducedMotion : sources.animated; - const animation = effects.add(new MutableDisposable()); - const sprite: ChatPetSpriteElement = { container: subagentPet.element, canvas: subagentPet.canvas, image, color: this._color }; - const finish = () => { - subagentPet.element.remove(); - this._subagentPetEffects.delete(effects); - }; - effects.add(toDisposable(() => subagentPet.element.remove())); - effects.add(dom.addDisposableListener(image, 'load', () => this._startSpriteAnimation(source, sprite, animation, finish, true))); - effects.add(dom.addDisposableListener(image, 'error', finish)); - const targetWindow = dom.getWindow(subagentPet.element); - const timer = targetWindow.setTimeout(finish, this._motionReduced ? RESPAWN_EFFECT_REDUCED_MOTION_DURATION : RESPAWN_EFFECT_DURATION); - effects.add(toDisposable(() => targetWindow.clearTimeout(timer))); - setChatPetImageSource(image, source.url); - } - private _getDisplaySize(): number { return CHAT_PET_SOURCE_SIZE / 2 * this._scale; } From 49d4924b28af5a50494dc951104d5ce1b15b4085 Mon Sep 17 00:00:00 2001 From: Lisa Rosenberg Date: Fri, 13 Nov 2026 18:35:50 +0100 Subject: [PATCH 41/66] feat: add optional random --- .../chat/browser/widget/chatPetWidget.ts | 9 +++++++-- .../test/browser/widget/chatPetWidget.test.ts | 20 ++++++++++--------- 2 files changed, 18 insertions(+), 11 deletions(-) diff --git a/src/vs/workbench/contrib/chat/browser/widget/chatPetWidget.ts b/src/vs/workbench/contrib/chat/browser/widget/chatPetWidget.ts index 40a5ab08f36aa5..dc323f6a60193b 100644 --- a/src/vs/workbench/contrib/chat/browser/widget/chatPetWidget.ts +++ b/src/vs/workbench/contrib/chat/browser/widget/chatPetWidget.ts @@ -232,6 +232,7 @@ interface SubagentPetHost { readonly color: ChatPetColor; readonly accessory: ChatPetAccessoryId | undefined; readonly scale: number; + readonly random: () => number; isAnimationVisible(element: HTMLElement): boolean; getDragBounds(): DOMRect; getMovementBounds(): DOMRect; @@ -1308,7 +1309,7 @@ class SubagentPet extends Disposable { for (const eye of this.eyes.children) { (eye.firstElementChild as HTMLElement | null)?.style.removeProperty('transform'); } - this._blink = this._activity.add(new ChatPetBlinkController(blinking => this.eyes.classList.toggle('blink', blinking))); + this._blink = this._activity.add(new ChatPetBlinkController(blinking => this.eyes.classList.toggle('blink', blinking), _host.random)); this._activity.add(_host.onDidChangeAnimationVisibility(() => this.updateBlink())); const firstPupil = this.eyes.firstElementChild?.firstElementChild; if (firstPupil) { @@ -1641,12 +1642,14 @@ export class ChatPetWidget extends Disposable { private _color: ChatPetColor; private _selectedAccessory: ChatPetAccessoryId | undefined; private _scale = 1; + private readonly _random: () => number; constructor( host: IChatPetWidgetHost, options: { readonly resizeObserverCtor?: typeof ResizeObserver; readonly intersectionObserverCtor?: typeof IntersectionObserver; + readonly random?: () => number; } | undefined, @IChatPetService private readonly chatPetService: IChatPetService, @IAccessibilityService private readonly accessibilityService: IAccessibilityService, @@ -1657,6 +1660,7 @@ export class ChatPetWidget extends Disposable { @IInstantiationService private readonly instantiationService: IInstantiationService, ) { super(); + this._random = options?.random ?? Math.random; this.parent = host.parent; this.dragBounds = host.dragBounds; @@ -3232,7 +3236,7 @@ export class ChatPetWidget extends Disposable { const available = beforePet + afterPet; const minimumTop = Math.max(movement.top - overlay.top, bounds.bottom - SUBAGENT_PET_MAX_HEIGHT); const attempts = Math.max(1, Math.ceil(available / Math.max(1, size / 2))); - const start = Math.random() * available; + const start = this._random() * available; let best: { left: number; top: number } | undefined; for (let index = 0; index < attempts; index++) { const offset = available > 0 ? (start + index * available / attempts) % available : 0; @@ -3286,6 +3290,7 @@ export class ChatPetWidget extends Disposable { get color() { return widget._color; }, get accessory() { return widget._selectedAccessory; }, get scale() { return widget._scale; }, + random: this._random, isAnimationVisible: element => this._isAnimationVisible(this._visual) && this._isAnimationVisible(element), getDragBounds: () => this.dragBounds.getBoundingClientRect(), getMovementBounds: () => this.movementBounds.getBoundingClientRect(), diff --git a/src/vs/workbench/contrib/chat/test/browser/widget/chatPetWidget.test.ts b/src/vs/workbench/contrib/chat/test/browser/widget/chatPetWidget.test.ts index 6529930af39506..19336c05a80e91 100644 --- a/src/vs/workbench/contrib/chat/test/browser/widget/chatPetWidget.test.ts +++ b/src/vs/workbench/contrib/chat/test/browser/widget/chatPetWidget.test.ts @@ -114,7 +114,7 @@ suite('ChatPetWidget', () => { } } - function createHostTransitionHarness(motionReduced = false, initialTransition: IChatPetWidgetHost['transition'] = 'teleport', color?: ChatPetColor, intersectionObserverCtor?: typeof IntersectionObserver, setPlatformOccupation?: IChatPetWidgetHost['setPlatformOccupation'], supportsJumpGame = false, initializeService?: (service: ChatPetService) => void, initialModel?: IChatModel) { + function createHostTransitionHarness(motionReduced = false, initialTransition: IChatPetWidgetHost['transition'] = 'teleport', color?: ChatPetColor, intersectionObserverCtor?: typeof IntersectionObserver, setPlatformOccupation?: IChatPetWidgetHost['setPlatformOccupation'], supportsJumpGame = false, initializeService?: (service: ChatPetService) => void, initialModel?: IChatModel, random?: () => number) { const root = mainWindow.document.createElement('div'); root.style.cssText = 'position:fixed;left:0;top:0;width:800px;height:640px'; if (supportsJumpGame) { @@ -179,7 +179,7 @@ suite('ChatPetWidget', () => { } initializeService?.(service); const widget = disposables.add(new ChatPetWidget( - firstHost, { resizeObserverCtor: TestResizeObserver, intersectionObserverCtor }, service, accessibilityService, + firstHost, { resizeObserverCtor: TestResizeObserver, intersectionObserverCtor, random }, service, accessibilityService, new class extends mock() { override showContextMenu(delegate: IContextMenuDelegate): void { contextMenu = delegate; } }(), @@ -208,6 +208,10 @@ suite('ChatPetWidget', () => { }; } + function createSubagentPetTestHarness(random: () => number, motionReduced = false) { + return createHostTransitionHarness(motionReduced, undefined, undefined, undefined, undefined, false, undefined, undefined, random); + } + /** * Resolves once `condition` holds. Pet transitions advance through sprite loads, CSS transitions, * animation frames and timers, and every step that a test waits for changes the DOM, so the @@ -3015,14 +3019,14 @@ suite('ChatPetWidget', () => { }); test('subagent pets spawn across the platform and stack where their paths overlap', async () => { - const { widget, firstHost, button, overlay, firstParent, layout } = createHostTransitionHarness(true); + let randomValue = 0; + const { widget, firstHost, button, overlay, firstParent, layout } = createSubagentPetTestHarness(() => randomValue, true); const changed = disposables.add(new Emitter()); const parts: IChatProgressResponseContent[] = []; widget.setHost({ ...firstHost, model: constObservable(createSubagentTestModel(parts, changed.event)) }); button.style.left = '300px'; - const random = sinon.stub(Math, 'random'); const add = (id: string, position: number) => { - random.returns(position); + randomValue = position; const tool = new ChatToolInvocation(undefined, { id, displayName: id, modelDescription: 'Subagent', source: ToolDataSource.Internal }, id, undefined, {}); tool.toolSpecificData = { kind: 'subagent', isActive: true }; parts.push(tool); @@ -3103,7 +3107,7 @@ suite('ChatPetWidget', () => { }); test('subagent pets spawn inside the visible window when their platform extends beyond it', () => { - const { widget, firstHost, root, firstParent, button, overlay } = createHostTransitionHarness(true); + const { widget, firstHost, root, firstParent, button, overlay } = createSubagentPetTestHarness(() => 0.99, true); root.style.width = `${mainWindow.innerWidth + 240}px`; firstParent.style.left = `${mainWindow.innerWidth - 80}px`; firstParent.style.width = '240px'; @@ -3111,7 +3115,6 @@ suite('ChatPetWidget', () => { const tools: ChatToolInvocation[] = []; widget.setHost({ ...firstHost, model: constObservable(createSubagentTestModel(tools, changed.event)) }); button.style.left = '0px'; - sinon.stub(Math, 'random').returns(0.99); const tool = new ChatToolInvocation(undefined, { id: 'edge', displayName: 'Edge', modelDescription: 'Subagent', source: ToolDataSource.Internal }, 'edge', undefined, {}); tool.toolSpecificData = { kind: 'subagent', isActive: true }; tools.push(tool); @@ -3476,8 +3479,7 @@ suite('ChatPetWidget', () => { test('subagent pets blink and move their eyes with their own idle frames', async () => { const clock = sinon.useFakeTimers({ toFake: ['setTimeout', 'clearTimeout', 'performance'] }); disposables.add(toDisposable(() => clock.restore())); - sinon.stub(Math, 'random').returns(0); - const { widget, firstHost, overlay, setReducedMotion } = createHostTransitionHarness(); + const { widget, firstHost, overlay, setReducedMotion } = createSubagentPetTestHarness(() => 0); const tool = new ChatToolInvocation(undefined, { id: 'subagent', displayName: 'Subagent', modelDescription: 'Subagent', source: ToolDataSource.Internal }, 'subagent', undefined, {}); tool.toolSpecificData = { kind: 'subagent', isActive: true }; widget.setHost({ ...firstHost, model: constObservable(createSubagentTestModel([tool])) }); From 52f5a78f53e9bd0e499178a71c0b1e5c24025119 Mon Sep 17 00:00:00 2001 From: Lisa Rosenberg Date: Fri, 13 Nov 2026 18:38:03 +0100 Subject: [PATCH 42/66] feat: remove redundant layer toggle --- src/vs/workbench/contrib/chat/browser/widget/chatPetWidget.ts | 1 - .../workbench/contrib/chat/browser/widget/media/chatPet.css | 4 ---- 2 files changed, 5 deletions(-) diff --git a/src/vs/workbench/contrib/chat/browser/widget/chatPetWidget.ts b/src/vs/workbench/contrib/chat/browser/widget/chatPetWidget.ts index dc323f6a60193b..6e1fb29ac072e9 100644 --- a/src/vs/workbench/contrib/chat/browser/widget/chatPetWidget.ts +++ b/src/vs/workbench/contrib/chat/browser/widget/chatPetWidget.ts @@ -1968,7 +1968,6 @@ export class ChatPetWidget extends Disposable { this._setScale(scale); } const enabled = isChatPetVisible(serviceEnabled, isWindowActive); - this._subagentPetLayer.classList.toggle('hidden', !enabled); const color = this.chatPetService.color.read(reader); const colorChanged = color !== this._color; this._color = color; diff --git a/src/vs/workbench/contrib/chat/browser/widget/media/chatPet.css b/src/vs/workbench/contrib/chat/browser/widget/media/chatPet.css index ebb07b429cdaf1..2e9603d9b29538 100644 --- a/src/vs/workbench/contrib/chat/browser/widget/media/chatPet.css +++ b/src/vs/workbench/contrib/chat/browser/widget/media/chatPet.css @@ -176,10 +176,6 @@ pointer-events: none; } -.chat-subagent-pet-layer.hidden { - display: none; -} - .chat-subagent-pet, .chat-subagent-pet-despawning { position: absolute; From d73d881d4a92e50e9b2fa4039d56e9e02798ff1a Mon Sep 17 00:00:00 2001 From: Lisa Rosenberg Date: Fri, 13 Nov 2026 18:46:22 +0100 Subject: [PATCH 43/66] feat: add max. subagent pets --- .../chat/browser/widget/chatPetWidget.ts | 17 ++++++++- .../test/browser/widget/chatPetWidget.test.ts | 38 ++++++++++++++++--- 2 files changed, 48 insertions(+), 7 deletions(-) diff --git a/src/vs/workbench/contrib/chat/browser/widget/chatPetWidget.ts b/src/vs/workbench/contrib/chat/browser/widget/chatPetWidget.ts index 6e1fb29ac072e9..32468f44f7047e 100644 --- a/src/vs/workbench/contrib/chat/browser/widget/chatPetWidget.ts +++ b/src/vs/workbench/contrib/chat/browser/widget/chatPetWidget.ts @@ -145,6 +145,8 @@ const MOUSE_BOUNCE_HORIZONTAL_TRANSFER = 0.35; const MOUSE_BOUNCE_EDGE_KICK = 320; const MOUSE_BOUNCE_MAX_HORIZONTAL_VELOCITY = 1_800; const CHAT_PET_DISPLAY_SIZE = 48; +/** Maximum number of subagent pets shown at once. */ +const SUBAGENT_PET_MAX_COUNT = 10; /** Maximum stacking height before subagent pets share space. */ const SUBAGENT_PET_MAX_HEIGHT = 96; /** Tolerance for fractional pixels when checking subagent pet bounds. */ @@ -1497,6 +1499,8 @@ export class ChatPetWidget extends Disposable { /** Active subagent pets keyed by request and tool call identity. */ private readonly _subagentPets = new Map(); + private _activeSubagents: ReadonlySet = new Set(); + private _despawningSubagentPetCount = 0; /** Chat model currently supplying active subagents. */ private _subagentPetModel: IChatModel | undefined; /** Resources for active subagent pets and their disappearance effects. */ @@ -2054,6 +2058,8 @@ export class ChatPetWidget extends Disposable { if (!enabled) { this._subagentPetResizeScheduler.cancel(); + this._activeSubagents = new Set(); + this._despawningSubagentPetCount = 0; for (const subagentPet of this._subagentPets.values()) { subagentPet.element.remove(); } @@ -3263,16 +3269,25 @@ export class ChatPetWidget extends Disposable { /** Creates and removes subagent pets to match the active subagent identities. */ private _updateSubagentPets(subagents: ReadonlySet): void { + this._activeSubagents = new Set(subagents); let removed = false; let added = false; for (const [id, subagentPet] of this._subagentPets) { if (!subagents.has(id)) { removed = true; this._subagentPets.delete(id); - subagentPet.despawn(() => this._subagentPetEffects.delete(subagentPet)); + this._despawningSubagentPetCount++; + subagentPet.despawn(() => { + this._subagentPetEffects.delete(subagentPet); + this._despawningSubagentPetCount--; + this._updateSubagentPets(this._activeSubagents); + }); } } for (const id of subagents) { + if (this._subagentPets.size + this._despawningSubagentPetCount >= SUBAGENT_PET_MAX_COUNT) { + break; + } if (this._subagentPets.has(id)) { continue; } diff --git a/src/vs/workbench/contrib/chat/test/browser/widget/chatPetWidget.test.ts b/src/vs/workbench/contrib/chat/test/browser/widget/chatPetWidget.test.ts index 19336c05a80e91..5654db663709b6 100644 --- a/src/vs/workbench/contrib/chat/test/browser/widget/chatPetWidget.test.ts +++ b/src/vs/workbench/contrib/chat/test/browser/widget/chatPetWidget.test.ts @@ -2877,6 +2877,31 @@ suite('ChatPetWidget', () => { assert.strictEqual(overlay.querySelectorAll('.chat-subagent-pet').length, 1); }); + test('subagent pets fill available slots without replacing active pets', async () => { + const { widget, firstHost, overlay } = createHostTransitionHarness(true); + const changed = disposables.add(new Emitter()); + const tools = Array.from({ length: 12 }, (_, index) => { + const id = `subagent-${index}`; + const tool = new ChatToolInvocation(undefined, { id, displayName: id, modelDescription: 'Subagent', source: ToolDataSource.Internal }, id, undefined, {}); + tool.toolSpecificData = { kind: 'subagent', isActive: true }; + return tool; + }); + widget.setHost({ ...firstHost, model: constObservable(createSubagentTestModel(tools, changed.event)) }); + const initial = [...overlay.querySelectorAll('.chat-subagent-pet')]; + assert.strictEqual(initial.length, 10); + tools[10].toolSpecificData = { kind: 'subagent', isActive: false }; + changed.fire({ reason: 'other' }); + assert.deepStrictEqual([...overlay.querySelectorAll('.chat-subagent-pet')], initial); + tools[0].toolSpecificData = { kind: 'subagent', isActive: false }; + changed.fire({ reason: 'other' }); + assert.strictEqual(overlay.querySelectorAll('.chat-subagent-pet, .chat-subagent-pet-despawning').length, 10); + await waitForPetAnimation(() => overlay.querySelectorAll('.chat-subagent-pet').length === 10); + const after = [...overlay.querySelectorAll('.chat-subagent-pet')]; + assert.deepStrictEqual(after.slice(0, 9), initial.slice(1)); + assert.ok(!initial.includes(after[9])); + assert.strictEqual(overlay.querySelectorAll('.chat-subagent-pet-despawning').length, 0); + }); + test('shows one subagent pet per active subagent and removes it when it stops', async () => { const { widget, firstHost, button, overlay, service } = createHostTransitionHarness(); const responseChanged = disposables.add(new Emitter()); @@ -3213,7 +3238,7 @@ suite('ChatPetWidget', () => { largeEnough: rects.every(rect => rect.width >= 9.5 && rect.height >= 9.5), }, { count, withinChat: true, bounded: true, largeEnough: true }, JSON.stringify({ left, right, top, bottom, input: input.toJSON(), movement: movement.toJSON() })); }; - checkBounds(100); + checkBounds(10); firstParent.style.width = '120px'; layout(); await waitForPetAnimation(() => subagentPets.every(subagentPet => { @@ -3221,7 +3246,7 @@ suite('ChatPetWidget', () => { const input = firstParent.getBoundingClientRect(); return rect.left >= input.left - 0.1 && rect.right <= input.right + 0.1 && rect.bottom <= input.top + 0.1 && subagentPet.querySelector('img')?.getAttribute('src')?.includes('buddy-idle-'); })); - checkBounds(100); + checkBounds(10); root.style.height = '64px'; firstParent.style.top = '32px'; layout(); @@ -3230,14 +3255,15 @@ suite('ChatPetWidget', () => { const input = firstParent.getBoundingClientRect(); return rect.left >= input.left - 0.1 && rect.right <= input.right + 0.1 && rect.top >= root.getBoundingClientRect().top - 0.1 && rect.bottom <= input.top + 0.1 && subagentPet.querySelector('img')?.getAttribute('src')?.includes('buddy-idle-'); })); - checkBounds(100); + checkBounds(10); tools[0].toolSpecificData = { kind: 'subagent', isActive: false }; changed.fire({ reason: 'other' }); - checkBounds(99); + checkBounds(9); assert.deepStrictEqual([...overlay.querySelectorAll('.chat-subagent-pet')], subagentPets.slice(1)); + await waitForPetAnimation(() => overlay.querySelectorAll('.chat-subagent-pet').length === 10); tools[0].toolSpecificData = { kind: 'subagent', isActive: true }; changed.fire({ reason: 'other' }); - checkBounds(100); + checkBounds(10); }); } @@ -3309,7 +3335,7 @@ suite('ChatPetWidget', () => { const rect = subagentPet.getBoundingClientRect(); return rect.bottom <= bounds.top - 60 + 0.1 && rect.left >= bounds.left + 20 - 0.1 && rect.right <= bounds.right - 20 + 0.1; }), - }, { count: 20, onPrompt: true }); + }, { count: 10, onPrompt: true }); }); for (const reducedMotion of [false, true]) { From 91083a913fc5c8b3ebdbbbf273d5599c96d2a658 Mon Sep 17 00:00:00 2001 From: Lisa Rosenberg Date: Fri, 13 Nov 2026 18:48:23 +0100 Subject: [PATCH 44/66] refactor: rename constant --- .../workbench/contrib/chat/browser/widget/chatPetWidget.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/vs/workbench/contrib/chat/browser/widget/chatPetWidget.ts b/src/vs/workbench/contrib/chat/browser/widget/chatPetWidget.ts index 32468f44f7047e..9754ec2a992d9b 100644 --- a/src/vs/workbench/contrib/chat/browser/widget/chatPetWidget.ts +++ b/src/vs/workbench/contrib/chat/browser/widget/chatPetWidget.ts @@ -147,8 +147,8 @@ const MOUSE_BOUNCE_MAX_HORIZONTAL_VELOCITY = 1_800; const CHAT_PET_DISPLAY_SIZE = 48; /** Maximum number of subagent pets shown at once. */ const SUBAGENT_PET_MAX_COUNT = 10; -/** Maximum stacking height before subagent pets share space. */ -const SUBAGENT_PET_MAX_HEIGHT = 96; +/** Maximum stacking height (CSS pixels) before subagent pets share space. */ +const SUBAGENT_PET_MAX_STACKING_HEIGHT = 96; /** Tolerance for fractional pixels when checking subagent pet bounds. */ const SUBAGENT_PET_BOUNDARY_EPSILON = 0.01; /** Distance kept between subagent pets and the edges of their platform. */ @@ -3239,7 +3239,7 @@ export class ChatPetWidget extends Disposable { const afterPetStart = Math.max(minimumLeft, petLeft + this._getDisplaySize()); const afterPet = Math.max(0, maximumLeft - afterPetStart); const available = beforePet + afterPet; - const minimumTop = Math.max(movement.top - overlay.top, bounds.bottom - SUBAGENT_PET_MAX_HEIGHT); + const minimumTop = Math.max(movement.top - overlay.top, bounds.bottom - SUBAGENT_PET_MAX_STACKING_HEIGHT); const attempts = Math.max(1, Math.ceil(available / Math.max(1, size / 2))); const start = this._random() * available; let best: { left: number; top: number } | undefined; From 3acc53b34bf0344e57e6d060d4dda56cb95f86d8 Mon Sep 17 00:00:00 2001 From: Lisa Rosenberg Date: Fri, 13 Nov 2026 18:52:32 +0100 Subject: [PATCH 45/66] docs: add docstrings where needed and update some names --- .../chat/browser/widget/chatPetWidget.ts | 85 +++++++++++-------- 1 file changed, 49 insertions(+), 36 deletions(-) diff --git a/src/vs/workbench/contrib/chat/browser/widget/chatPetWidget.ts b/src/vs/workbench/contrib/chat/browser/widget/chatPetWidget.ts index 9754ec2a992d9b..89a0bac753e15d 100644 --- a/src/vs/workbench/contrib/chat/browser/widget/chatPetWidget.ts +++ b/src/vs/workbench/contrib/chat/browser/widget/chatPetWidget.ts @@ -223,6 +223,7 @@ interface ChatPetSpriteElement { redrawFrame?: () => void; } +/** Supplies shared appearance, geometry, and animation services to a subagent pet. */ interface SubagentPetHost { readonly layer: HTMLElement; readonly overlay: HTMLElement; @@ -1277,22 +1278,26 @@ export class ChatPetHopController extends Disposable { /** Owns the appearance, animation and lifecycle of one subagent pet. */ class SubagentPet extends Disposable { + /** Overlay element positioned at the pet's landing coordinates. */ readonly element: HTMLElement; private readonly canvas: HTMLCanvasElement; private readonly image: HTMLImageElement; private readonly eyes: HTMLElement; private readonly _sprite: ChatPetSpriteElement; + /** Resources for the active pet or its disappearance effect. */ private readonly _activity = this._register(new DisposableStore()); - private readonly _animation = this._activity.add(new MutableDisposable()); + private readonly _spriteAnimation = this._activity.add(new MutableDisposable()); private readonly _fallAnimation = this._activity.add(new MutableDisposable()); private readonly _accessoryListener = this._activity.add(new MutableDisposable()); private readonly _respawnTimer = this._activity.add(new RunOnceScheduler(() => this._advanceRespawn(), RESPAWN_EFFECT_REDUCED_MOTION_DURATION)); - private readonly _blink: ChatPetBlinkController; + private readonly _blinkController: ChatPetBlinkController; private _state: 'idle' | 'splat' = 'idle'; + /** Tracks relocation after the pet loses its supporting platform. */ private _respawnPhase: 'none' | 'falling' | 'despawning' | 'respawning' = 'none'; private _accessory: ReturnType | undefined; private _accessoryImage: HTMLImageElement | undefined; + /** Creates a pet at the given overlay-relative landing position. */ constructor(private readonly _host: SubagentPetHost, public left: number, public top: number) { super(); const scale = 0.5 * _host.scale; @@ -1311,13 +1316,13 @@ class SubagentPet extends Disposable { for (const eye of this.eyes.children) { (eye.firstElementChild as HTMLElement | null)?.style.removeProperty('transform'); } - this._blink = this._activity.add(new ChatPetBlinkController(blinking => this.eyes.classList.toggle('blink', blinking), _host.random)); + this._blinkController = this._activity.add(new ChatPetBlinkController(blinking => this.eyes.classList.toggle('blink', blinking), _host.random)); this._activity.add(_host.onDidChangeAnimationVisibility(() => this.updateBlink())); const firstPupil = this.eyes.firstElementChild?.firstElementChild; if (firstPupil) { this._activity.add(dom.addDisposableListener(firstPupil, 'animationend', event => { if ((event as AnimationEvent).animationName === 'chat-pet-tall-eye-blink') { - this._blink.onAnimationComplete(); + this._blinkController.onAnimationComplete(); } })); } @@ -1333,12 +1338,15 @@ class SubagentPet extends Disposable { } } + /** Returns whether the pet is being relocated. */ isRespawning(): boolean { return this._respawnPhase !== 'none'; } + /** Enables blinking only while the idle pet is visible. */ updateBlink(): void { - this._blink.setEnabled(this._respawnPhase === 'none' && this._state === 'idle' && this._host.enabled && !this._host.motionReduced && this._host.isAnimationVisible(this.element)); + this._blinkController.setEnabled(this._respawnPhase === 'none' && this._state === 'idle' && this._host.enabled && !this._host.motionReduced && this._host.isAnimationVisible(this.element)); } + /** Applies changes to the shared color, motion, variant, and accessory. */ updateAppearance(motionChanged: boolean, variantChanged: boolean, accessoryChanged: boolean): void { this._sprite.color = this._host.color; this.eyes.style.color = getChatPetEyeColor(this._host.color); @@ -1358,6 +1366,7 @@ class SubagentPet extends Disposable { } } + /** Falls to an overlay-relative position, optionally starting relocation on landing. */ fallTo(top: number, respawn = false): void { const previousTop = this.element.getBoundingClientRect().top - this._host.overlay.getBoundingClientRect().top; this._respawnPhase = respawn ? 'falling' : 'none'; @@ -1400,7 +1409,7 @@ class SubagentPet extends Disposable { setChatPetImageSource(image, source.url); } - private _getSource(): ChatPetSpriteSource { + private _getSpriteSource(): ChatPetSpriteSource { const sources = this._respawnPhase === 'despawning' || this._respawnPhase === 'respawning' ? getRespawnSpriteSources(this._host.variant) : getChatPetSpriteSources(this._host.variant)[this._state]; return this._host.motionReduced ? sources.reducedMotion : sources.animated; @@ -1408,13 +1417,13 @@ class SubagentPet extends Disposable { private _setState(state: 'idle' | 'splat'): void { this._respawnTimer.cancel(); - this._animation.clear(); + this._spriteAnimation.clear(); this._state = state; this.updateBlink(); if (this._host.motionReduced) { this.eyes.classList.remove('bobbed'); } - setChatPetImageSource(this.image, this._getSource().url); + setChatPetImageSource(this.image, this._getSpriteSource().url); } private _updateAccessory(): void { @@ -1437,7 +1446,7 @@ class SubagentPet extends Disposable { private _onImageLoad(): void { if (this._respawnPhase === 'despawning' || this._respawnPhase === 'respawning') { this.eyes.classList.remove('tracking', 'bobbed'); - this._host.startAnimation(this._getSource(), this._sprite, this._animation, () => this._advanceRespawn(), this._respawnPhase === 'despawning'); + this._host.startAnimation(this._getSpriteSource(), this._sprite, this._spriteAnimation, () => this._advanceRespawn(), this._respawnPhase === 'despawning'); if (this._host.motionReduced) { this._respawnTimer.schedule(); } @@ -1447,9 +1456,9 @@ class SubagentPet extends Disposable { this._setState('idle'); return; } - const source = this._getSource(); + const source = this._getSpriteSource(); this.eyes.classList.toggle('tracking', this._state === 'idle'); - this._host.startAnimation(source, this._sprite, this._animation, this._state === 'splat' ? () => this._setState('idle') : undefined, false, frameIndex => { + this._host.startAnimation(source, this._sprite, this._spriteAnimation, this._state === 'splat' ? () => this._setState('idle') : undefined, false, frameIndex => { this.eyes.classList.toggle('bobbed', this._state === 'idle' && !this._host.motionReduced && (source.accessoryRigFrame ?? frameIndex) >= 20); }, (context, frameIndex) => { if (this._accessoryImage?.complete && this._accessoryImage.naturalWidth > 0 && this._accessory) { @@ -1474,6 +1483,7 @@ class SubagentPet extends Disposable { }; } + /** Advances relocation from disappearance to reappearance and landing. */ private _advanceRespawn(): void { const overlay = this._host.overlay.getBoundingClientRect(); const input = this._host.getDragBounds(); @@ -1499,7 +1509,9 @@ export class ChatPetWidget extends Disposable { /** Active subagent pets keyed by request and tool call identity. */ private readonly _subagentPets = new Map(); - private _activeSubagents: ReadonlySet = new Set(); + /** Active subagent identities, including those waiting for an available pet slot. */ + private _activeSubagentIds: ReadonlySet = new Set(); + /** Disappearing pets still occupy a slot until their effect finishes. */ private _despawningSubagentPetCount = 0; /** Chat model currently supplying active subagents. */ private _subagentPetModel: IChatModel | undefined; @@ -2058,7 +2070,7 @@ export class ChatPetWidget extends Disposable { if (!enabled) { this._subagentPetResizeScheduler.cancel(); - this._activeSubagents = new Set(); + this._activeSubagentIds = new Set(); this._despawningSubagentPetCount = 0; for (const subagentPet of this._subagentPets.values()) { subagentPet.element.remove(); @@ -2136,17 +2148,17 @@ export class ChatPetWidget extends Disposable { return; } observableSignalFromEvent(this, model.onDidChange).read(reader); - const subagents = new Set(); + const activeSubagentIds = new Set(); let initializing = true; for (const request of model.getRequests()) { const response = request.response; if (!response) { continue; } - let previous = new Set(); + let previousResponseSubagentIds = new Set(); reader.store.add(autorun(reader => { observableSignalFromEvent(this, response.onDidChange).read(reader); - const current = new Set(); + const responseSubagentIds = new Set(); for (const part of response.response.value) { if (part.kind !== 'toolInvocation') { continue; @@ -2155,23 +2167,23 @@ export class ChatPetWidget extends Disposable { part.state.read(reader); const data = part.toolSpecificData; if (data?.kind === 'subagent' && data.presentation !== 'phase' && data.hasStarted !== false && (getSubagentIsActive(data) ?? !IChatToolInvocation.isComplete(part, reader))) { - current.add(JSON.stringify([request.id, part.toolCallId])); + responseSubagentIds.add(JSON.stringify([request.id, part.toolCallId])); } } - for (const id of previous) { - subagents.delete(id); + for (const id of previousResponseSubagentIds) { + activeSubagentIds.delete(id); } - for (const id of current) { - subagents.add(id); + for (const id of responseSubagentIds) { + activeSubagentIds.add(id); } - previous = current; + previousResponseSubagentIds = responseSubagentIds; if (!initializing) { - this._updateSubagentPets(subagents); + this._updateSubagentPets(activeSubagentIds); } })); } initializing = false; - this._updateSubagentPets(subagents); + this._updateSubagentPets(activeSubagentIds); })); this._register(autorun(reader => { @@ -3234,18 +3246,18 @@ export class ChatPetWidget extends Disposable { const { overlay, movement, platforms, floor } = bounds; const minimumLeft = bounds.left; const maximumLeft = Math.max(minimumLeft, bounds.right - size); - const petLeft = this._button.element.offsetLeft; - const beforePet = Math.max(0, Math.min(maximumLeft, petLeft - size) - minimumLeft); - const afterPetStart = Math.max(minimumLeft, petLeft + this._getDisplaySize()); - const afterPet = Math.max(0, maximumLeft - afterPetStart); - const available = beforePet + afterPet; + const mainPetLeft = this._button.element.offsetLeft; + const beforeMainPet = Math.max(0, Math.min(maximumLeft, mainPetLeft - size) - minimumLeft); + const afterMainPetStart = Math.max(minimumLeft, mainPetLeft + this._getDisplaySize()); + const afterMainPet = Math.max(0, maximumLeft - afterMainPetStart); + const available = beforeMainPet + afterMainPet; const minimumTop = Math.max(movement.top - overlay.top, bounds.bottom - SUBAGENT_PET_MAX_STACKING_HEIGHT); const attempts = Math.max(1, Math.ceil(available / Math.max(1, size / 2))); const start = this._random() * available; let best: { left: number; top: number } | undefined; for (let index = 0; index < attempts; index++) { const offset = available > 0 ? (start + index * available / attempts) % available : 0; - const left = available > 0 ? (offset < beforePet ? minimumLeft + offset : afterPetStart + offset - beforePet) : minimumLeft; + const left = available > 0 ? (offset < beforeMainPet ? minimumLeft + offset : afterMainPetStart + offset - beforeMainPet) : minimumLeft; const landing = getChatPetFallTarget(overlay.left + left, -size, size, size, platforms, floor); let top = landing.top - overlay.top; for (const otherSubagentPet of this._subagentPets.values()) { @@ -3267,24 +3279,24 @@ export class ChatPetWidget extends Disposable { return { ...best!, top: Math.max(best!.top, minimumTop) }; } - /** Creates and removes subagent pets to match the active subagent identities. */ - private _updateSubagentPets(subagents: ReadonlySet): void { - this._activeSubagents = new Set(subagents); + /** Keeps existing pets for active subagents and fills available slots up to the limit. */ + private _updateSubagentPets(activeSubagentIds: ReadonlySet): void { + this._activeSubagentIds = new Set(activeSubagentIds); let removed = false; let added = false; for (const [id, subagentPet] of this._subagentPets) { - if (!subagents.has(id)) { + if (!activeSubagentIds.has(id)) { removed = true; this._subagentPets.delete(id); this._despawningSubagentPetCount++; subagentPet.despawn(() => { this._subagentPetEffects.delete(subagentPet); this._despawningSubagentPetCount--; - this._updateSubagentPets(this._activeSubagents); + this._updateSubagentPets(this._activeSubagentIds); }); } } - for (const id of subagents) { + for (const id of activeSubagentIds) { if (this._subagentPets.size + this._despawningSubagentPetCount >= SUBAGENT_PET_MAX_COUNT) { break; } @@ -3353,6 +3365,7 @@ export class ChatPetWidget extends Disposable { } } + /** Schedules one bounds check for the current group of subagent pets. */ private _scheduleSubagentPetResize(): void { if (this._subagentPets.size && !this._subagentPetResizeScheduler.isScheduled()) { this._subagentPetResizeScheduler.schedule(); From c77a57c29e42c74ee6c44be663d1ff3875e5e8eb Mon Sep 17 00:00:00 2001 From: Lisa Rosenberg Date: Fri, 13 Nov 2026 20:26:31 +0100 Subject: [PATCH 46/66] feat: rename reader --- .../contrib/chat/browser/widget/chatPetWidget.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/vs/workbench/contrib/chat/browser/widget/chatPetWidget.ts b/src/vs/workbench/contrib/chat/browser/widget/chatPetWidget.ts index 89a0bac753e15d..89a7f5aee23265 100644 --- a/src/vs/workbench/contrib/chat/browser/widget/chatPetWidget.ts +++ b/src/vs/workbench/contrib/chat/browser/widget/chatPetWidget.ts @@ -2156,17 +2156,17 @@ export class ChatPetWidget extends Disposable { continue; } let previousResponseSubagentIds = new Set(); - reader.store.add(autorun(reader => { - observableSignalFromEvent(this, response.onDidChange).read(reader); + reader.store.add(autorun(responseReader => { + observableSignalFromEvent(this, response.onDidChange).read(responseReader); const responseSubagentIds = new Set(); for (const part of response.response.value) { if (part.kind !== 'toolInvocation') { continue; } - part.toolSpecificDataKind.read(reader); - part.state.read(reader); + part.toolSpecificDataKind.read(responseReader); + part.state.read(responseReader); const data = part.toolSpecificData; - if (data?.kind === 'subagent' && data.presentation !== 'phase' && data.hasStarted !== false && (getSubagentIsActive(data) ?? !IChatToolInvocation.isComplete(part, reader))) { + if (data?.kind === 'subagent' && data.presentation !== 'phase' && data.hasStarted !== false && (getSubagentIsActive(data) ?? !IChatToolInvocation.isComplete(part, responseReader))) { responseSubagentIds.add(JSON.stringify([request.id, part.toolCallId])); } } From d221165dc552e6af01c74a504985e28446e550ca Mon Sep 17 00:00:00 2001 From: Lisa Rosenberg Date: Fri, 13 Nov 2026 20:36:24 +0100 Subject: [PATCH 47/66] feat: use shared host which is initialized with first subagent pet --- .../chat/browser/widget/chatPetWidget.ts | 29 ++++++++++++------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/src/vs/workbench/contrib/chat/browser/widget/chatPetWidget.ts b/src/vs/workbench/contrib/chat/browser/widget/chatPetWidget.ts index 89a7f5aee23265..a54cd36a091d0d 100644 --- a/src/vs/workbench/contrib/chat/browser/widget/chatPetWidget.ts +++ b/src/vs/workbench/contrib/chat/browser/widget/chatPetWidget.ts @@ -1521,6 +1521,8 @@ export class ChatPetWidget extends Disposable { private readonly _subagentPetResizeScheduler = this._register(new RunOnceScheduler(() => this._reconcileSubagentPetResize(), 16)); /** Overlay layer containing subagent pets. */ private readonly _subagentPetLayer: HTMLElement; + /** Shared widget services, initialized when the first subagent pet appears. */ + private _subagentPetHost: SubagentPetHost | undefined; private parent: HTMLElement; private dragBounds: HTMLElement; private movementBounds: HTMLElement; @@ -3304,8 +3306,23 @@ export class ChatPetWidget extends Disposable { continue; } added = true; + const { left, top } = this._getSubagentPetLanding(CHAT_PET_DISPLAY_SIZE * 0.5 * this._scale); + const subagentPet = this._subagentPetEffects.add(new SubagentPet(this._getSubagentPetHost(), left, top)); + this._subagentPets.set(id, subagentPet); + } + if (added || removed) { + this._scheduleSubagentPetResize(); + } + if (removed) { + this._settleSubagentPets(); + } + } + + /** Creates the shared subagent pet host on first use. */ + private _getSubagentPetHost(): SubagentPetHost { + if (!this._subagentPetHost) { const widget = this; - const host: SubagentPetHost = { + this._subagentPetHost = { layer: this._subagentPetLayer, overlay: this._overlay, eyes: this._eyes, @@ -3324,16 +3341,8 @@ export class ChatPetWidget extends Disposable { scheduleResize: () => this._scheduleSubagentPetResize(), startAnimation: (source, sprite, animation, onComplete, reverse, onFrame, renderFrame) => this._startSpriteAnimation(source, sprite, animation, onComplete, reverse, onFrame, undefined, undefined, renderFrame), }; - const { left, top } = this._getSubagentPetLanding(CHAT_PET_DISPLAY_SIZE * 0.5 * this._scale); - const subagentPet = this._subagentPetEffects.add(new SubagentPet(host, left, top)); - this._subagentPets.set(id, subagentPet); - } - if (added || removed) { - this._scheduleSubagentPetResize(); - } - if (removed) { - this._settleSubagentPets(); } + return this._subagentPetHost; } /** Settle each column from the bottom up so remaining subagent pets can support those above them. */ From 19e762a394047c381e3d222a8299e8f2a341a27e Mon Sep 17 00:00:00 2001 From: Lisa Rosenberg Date: Fri, 13 Nov 2026 20:46:29 +0100 Subject: [PATCH 48/66] feat: move element cleanup into class --- .../chat/browser/widget/chatPetWidget.ts | 53 ++++++++++--------- .../test/browser/widget/chatPetWidget.test.ts | 6 ++- 2 files changed, 31 insertions(+), 28 deletions(-) diff --git a/src/vs/workbench/contrib/chat/browser/widget/chatPetWidget.ts b/src/vs/workbench/contrib/chat/browser/widget/chatPetWidget.ts index a54cd36a091d0d..da0b56b0efe299 100644 --- a/src/vs/workbench/contrib/chat/browser/widget/chatPetWidget.ts +++ b/src/vs/workbench/contrib/chat/browser/widget/chatPetWidget.ts @@ -1298,15 +1298,16 @@ class SubagentPet extends Disposable { private _accessoryImage: HTMLImageElement | undefined; /** Creates a pet at the given overlay-relative landing position. */ - constructor(private readonly _host: SubagentPetHost, public left: number, public top: number) { + constructor(private readonly _host: SubagentPetHost, private _left: number, private _top: number) { super(); const scale = 0.5 * _host.scale; const size = CHAT_PET_DISPLAY_SIZE * scale; this.element = dom.append(_host.layer, dom.$('.chat-subagent-pet', { 'aria-hidden': 'true' })); - this.element.style.left = `${left}px`; - this.element.style.top = `${top}px`; + this._register(toDisposable(() => this.element.remove())); + this.element.style.left = `${this._left}px`; + this.element.style.top = `${this._top}px`; this.element.style.transform = `scale(${scale})`; - const distance = Math.max(0, _host.overlay.getBoundingClientRect().top + top + size); + const distance = Math.max(0, _host.overlay.getBoundingClientRect().top + this._top + size); this.canvas = dom.append(this.element, dom.$('canvas.chat-subagent-pet-canvas')) as HTMLCanvasElement; this.canvas.width = CHAT_PET_SOURCE_SIZE; this.canvas.height = CHAT_PET_SOURCE_SIZE; @@ -1334,10 +1335,20 @@ class SubagentPet extends Disposable { this._activity.add(dom.addDisposableListener(this.image, 'load', () => this._onImageLoad())); this._setState('idle'); if (!_host.motionReduced && distance > 0) { - this._animateFall(top - distance, top); + this._animateFall(this._top - distance, this._top); } } + get left(): number { return this._left; } + get top(): number { return this._top; } + + /** Updates the scale while keeping the pet's bottom edge in place. */ + setScale(previousScale: number, scale: number): void { + this._top += CHAT_PET_DISPLAY_SIZE * (previousScale - scale); + this.element.style.top = `${this._top}px`; + this.element.style.transform = `scale(${scale})`; + } + /** Returns whether the pet is being relocated. */ isRespawning(): boolean { return this._respawnPhase !== 'none'; } @@ -1371,7 +1382,7 @@ class SubagentPet extends Disposable { const previousTop = this.element.getBoundingClientRect().top - this._host.overlay.getBoundingClientRect().top; this._respawnPhase = respawn ? 'falling' : 'none'; this._fallAnimation.clear(); - this.top = top; + this._top = top; this.element.style.top = `${top}px`; this._setState('idle'); if (!this._host.motionReduced && top > previousTop) { @@ -1396,15 +1407,10 @@ class SubagentPet extends Disposable { const source = this._host.motionReduced ? sources.reducedMotion : sources.animated; const animation = this._activity.add(new MutableDisposable()); const sprite: ChatPetSpriteElement = { container: this.element, canvas: this.canvas, image, color: this._host.color }; - const finish = () => { - this.element.remove(); - onComplete(); - }; - this._activity.add(toDisposable(() => this.element.remove())); - this._activity.add(dom.addDisposableListener(image, 'load', () => this._host.startAnimation(source, sprite, animation, finish, true))); - this._activity.add(dom.addDisposableListener(image, 'error', finish)); + this._activity.add(dom.addDisposableListener(image, 'load', () => this._host.startAnimation(source, sprite, animation, onComplete, true))); + this._activity.add(dom.addDisposableListener(image, 'error', onComplete)); const targetWindow = dom.getWindow(this.element); - const timer = targetWindow.setTimeout(finish, this._host.motionReduced ? RESPAWN_EFFECT_REDUCED_MOTION_DURATION : RESPAWN_EFFECT_DURATION); + const timer = targetWindow.setTimeout(onComplete, this._host.motionReduced ? RESPAWN_EFFECT_REDUCED_MOTION_DURATION : RESPAWN_EFFECT_DURATION); this._activity.add(toDisposable(() => targetWindow.clearTimeout(timer))); setChatPetImageSource(image, source.url); } @@ -1490,15 +1496,15 @@ class SubagentPet extends Disposable { const size = CHAT_PET_DISPLAY_SIZE * 0.5 * this._host.scale; if (this._respawnPhase === 'despawning') { this._respawnPhase = 'respawning'; - this.left = Math.max(input.left - overlay.left, Math.min(this.left, input.right - overlay.left - size)); - this.top = this._host.getMovementBounds().top - overlay.top; - this.element.style.left = `${this.left}px`; - this.element.style.top = `${this.top}px`; + this._left = Math.max(input.left - overlay.left, Math.min(this._left, input.right - overlay.left - size)); + this._top = this._host.getMovementBounds().top - overlay.top; + this.element.style.left = `${this._left}px`; + this.element.style.top = `${this._top}px`; this._setState('idle'); } else if (this._respawnPhase === 'respawning') { const landing = this._host.getLanding(size); - this.left = landing.left; - this.element.style.left = `${this.left}px`; + this._left = landing.left; + this.element.style.left = `${this._left}px`; this.fallTo(landing.top); this._host.scheduleResize(); } @@ -2074,9 +2080,6 @@ export class ChatPetWidget extends Disposable { this._subagentPetResizeScheduler.cancel(); this._activeSubagentIds = new Set(); this._despawningSubagentPetCount = 0; - for (const subagentPet of this._subagentPets.values()) { - subagentPet.element.remove(); - } this._subagentPets.clear(); this._subagentPetEffects.clear(); this._hopController.cancel(); @@ -3413,9 +3416,7 @@ export class ChatPetWidget extends Disposable { this._scale = scale; const subagentPetScale = scale * 0.5; for (const subagentPet of this._subagentPets.values()) { - subagentPet.top += CHAT_PET_DISPLAY_SIZE * (previousScale - subagentPetScale); - subagentPet.element.style.top = `${subagentPet.top}px`; - subagentPet.element.style.transform = `scale(${subagentPetScale})`; + subagentPet.setScale(previousScale, subagentPetScale); } this._scheduleSubagentPetResize(); const displaySize = this._getDisplaySize(); diff --git a/src/vs/workbench/contrib/chat/test/browser/widget/chatPetWidget.test.ts b/src/vs/workbench/contrib/chat/test/browser/widget/chatPetWidget.test.ts index 5654db663709b6..b6575b9193a0d3 100644 --- a/src/vs/workbench/contrib/chat/test/browser/widget/chatPetWidget.test.ts +++ b/src/vs/workbench/contrib/chat/test/browser/widget/chatPetWidget.test.ts @@ -2836,8 +2836,10 @@ suite('ChatPetWidget', () => { function setSubagentPetPosition(widget: ChatPetWidget, element: HTMLElement, left: number, top: number): void { // eslint-disable-next-line local/code-no-bracket-notation-for-identifiers -- Set up positions without exposing a test-only API. const subagentPet = [...widget['_subagentPets'].values()].find(subagentPet => subagentPet.element === element)!; - subagentPet.left = left; - subagentPet.top = top; + // eslint-disable-next-line local/code-no-bracket-notation-for-identifiers -- Set up the private position for layout tests. + subagentPet['_left'] = left; + // eslint-disable-next-line local/code-no-bracket-notation-for-identifiers -- Set up the private position for layout tests. + subagentPet['_top'] = top; element.style.left = `${left}px`; element.style.top = `${top}px`; } From e140bd8d3e348eeb9c8bea93d738274b6f7bde40 Mon Sep 17 00:00:00 2001 From: Lisa Rosenberg Date: Fri, 13 Nov 2026 20:56:27 +0100 Subject: [PATCH 49/66] refactor: move code and add missing docstring --- .../chat/browser/widget/chatPetWidget.ts | 40 +++++++++++-------- 1 file changed, 24 insertions(+), 16 deletions(-) diff --git a/src/vs/workbench/contrib/chat/browser/widget/chatPetWidget.ts b/src/vs/workbench/contrib/chat/browser/widget/chatPetWidget.ts index da0b56b0efe299..c01548dc953171 100644 --- a/src/vs/workbench/contrib/chat/browser/widget/chatPetWidget.ts +++ b/src/vs/workbench/contrib/chat/browser/widget/chatPetWidget.ts @@ -145,14 +145,6 @@ const MOUSE_BOUNCE_HORIZONTAL_TRANSFER = 0.35; const MOUSE_BOUNCE_EDGE_KICK = 320; const MOUSE_BOUNCE_MAX_HORIZONTAL_VELOCITY = 1_800; const CHAT_PET_DISPLAY_SIZE = 48; -/** Maximum number of subagent pets shown at once. */ -const SUBAGENT_PET_MAX_COUNT = 10; -/** Maximum stacking height (CSS pixels) before subagent pets share space. */ -const SUBAGENT_PET_MAX_STACKING_HEIGHT = 96; -/** Tolerance for fractional pixels when checking subagent pet bounds. */ -const SUBAGENT_PET_BOUNDARY_EPSILON = 0.01; -/** Distance kept between subagent pets and the edges of their platform. */ -const SUBAGENT_PET_EDGE_INSET = 12; const CHAT_PET_SOURCE_SIZE = 96; const CHAT_PET_SLEEP_SOURCE_WIDTH = 120; const CHAT_PET_TYPING_SOURCE_WIDTH = 168; @@ -194,6 +186,17 @@ const SPEECHLESS_FRAME_DURATIONS = [400, 120, 1_000, 120, 1_080]; const WORRY_FRAME_DURATIONS = [600, 600]; const DIZZY_FRAME_DURATIONS = Array.from({ length: 8 }, () => 120); +/** Scaling factor for calculating the size of the subagent pets. */ +const SUBAGENT_PET_SCALE = 0.5; +/** Maximum number of subagent pets shown at once. */ +const SUBAGENT_PET_MAX_COUNT = 10; +/** Maximum stacking height (CSS pixels) before subagent pets share space. */ +const SUBAGENT_PET_MAX_STACKING_HEIGHT = 96; +/** Tolerance for fractional pixels when checking subagent pet bounds. */ +const SUBAGENT_PET_BOUNDARY_EPSILON = 0.01; +/** Distance kept between subagent pets and the edges of their platform. */ +const SUBAGENT_PET_EDGE_INSET = 12; + interface ChatPetSpriteSource { readonly url: string; readonly frameWidth: number; @@ -1276,6 +1279,11 @@ export class ChatPetHopController extends Disposable { } } +/** Returns the displayed size of a subagent pet at the given main pet scale. */ +function getSubagentPetSize(scale: number): number { + return CHAT_PET_DISPLAY_SIZE * SUBAGENT_PET_SCALE * scale; +} + /** Owns the appearance, animation and lifecycle of one subagent pet. */ class SubagentPet extends Disposable { /** Overlay element positioned at the pet's landing coordinates. */ @@ -1300,8 +1308,8 @@ class SubagentPet extends Disposable { /** Creates a pet at the given overlay-relative landing position. */ constructor(private readonly _host: SubagentPetHost, private _left: number, private _top: number) { super(); - const scale = 0.5 * _host.scale; - const size = CHAT_PET_DISPLAY_SIZE * scale; + const scale = SUBAGENT_PET_SCALE * _host.scale; + const size = getSubagentPetSize(_host.scale); this.element = dom.append(_host.layer, dom.$('.chat-subagent-pet', { 'aria-hidden': 'true' })); this._register(toDisposable(() => this.element.remove())); this.element.style.left = `${this._left}px`; @@ -1493,7 +1501,7 @@ class SubagentPet extends Disposable { private _advanceRespawn(): void { const overlay = this._host.overlay.getBoundingClientRect(); const input = this._host.getDragBounds(); - const size = CHAT_PET_DISPLAY_SIZE * 0.5 * this._host.scale; + const size = getSubagentPetSize(this._host.scale); if (this._respawnPhase === 'despawning') { this._respawnPhase = 'respawning'; this._left = Math.max(input.left - overlay.left, Math.min(this._left, input.right - overlay.left - size)); @@ -3309,7 +3317,7 @@ export class ChatPetWidget extends Disposable { continue; } added = true; - const { left, top } = this._getSubagentPetLanding(CHAT_PET_DISPLAY_SIZE * 0.5 * this._scale); + const { left, top } = this._getSubagentPetLanding(getSubagentPetSize(this._scale)); const subagentPet = this._subagentPetEffects.add(new SubagentPet(this._getSubagentPetHost(), left, top)); this._subagentPets.set(id, subagentPet); } @@ -3357,7 +3365,7 @@ export class ChatPetWidget extends Disposable { subagentPet, left: subagentPet.left, top: subagentPet.top, - size: CHAT_PET_DISPLAY_SIZE * 0.5 * this._scale, + size: getSubagentPetSize(this._scale), })).sort((a, b) => b.top - a.top); for (const [index, entry] of subagentPets.entries()) { const landing = getChatPetFallTarget(overlay.left + entry.left, overlay.top + entry.top - POSITION_EPSILON, entry.size, entry.size, platforms, floor); @@ -3391,11 +3399,11 @@ export class ChatPetWidget extends Disposable { return; } const { overlay, movement, left, right, bottom } = this._getSubagentPetBounds(); + const size = getSubagentPetSize(this._scale); let displaced = false; for (const subagentPet of subagentPets) { const subagentPetLeft = subagentPet.left; const subagentPetTop = subagentPet.top; - const size = CHAT_PET_DISPLAY_SIZE * 0.5 * this._scale; if (subagentPetLeft < left - SUBAGENT_PET_BOUNDARY_EPSILON || subagentPetLeft + size > right + SUBAGENT_PET_BOUNDARY_EPSILON || subagentPetTop < movement.top - overlay.top - SUBAGENT_PET_BOUNDARY_EPSILON || subagentPetTop + size > bottom + SUBAGENT_PET_BOUNDARY_EPSILON) { displaced = true; subagentPet.fallTo(movement.bottom - overlay.top - size, true); @@ -3412,9 +3420,9 @@ export class ChatPetWidget extends Disposable { private _setScale(scale: number): void { this._stopJumpGame('restore'); - const previousScale = this._scale * 0.5; + const previousScale = this._scale * SUBAGENT_PET_SCALE; this._scale = scale; - const subagentPetScale = scale * 0.5; + const subagentPetScale = scale * SUBAGENT_PET_SCALE; for (const subagentPet of this._subagentPets.values()) { subagentPet.setScale(previousScale, subagentPetScale); } From 34178bb4e1e81c4c585f61e46e4d8dd9b25eb273 Mon Sep 17 00:00:00 2001 From: Lisa Rosenberg Date: Fri, 13 Nov 2026 20:59:42 +0100 Subject: [PATCH 50/66] refactor: add missing leading underscores for private fields --- .../chat/browser/widget/chatPetWidget.ts | 52 +++++++++---------- 1 file changed, 26 insertions(+), 26 deletions(-) diff --git a/src/vs/workbench/contrib/chat/browser/widget/chatPetWidget.ts b/src/vs/workbench/contrib/chat/browser/widget/chatPetWidget.ts index c01548dc953171..f3500d4c61ed27 100644 --- a/src/vs/workbench/contrib/chat/browser/widget/chatPetWidget.ts +++ b/src/vs/workbench/contrib/chat/browser/widget/chatPetWidget.ts @@ -1288,9 +1288,9 @@ function getSubagentPetSize(scale: number): number { class SubagentPet extends Disposable { /** Overlay element positioned at the pet's landing coordinates. */ readonly element: HTMLElement; - private readonly canvas: HTMLCanvasElement; - private readonly image: HTMLImageElement; - private readonly eyes: HTMLElement; + private readonly _canvas: HTMLCanvasElement; + private readonly _image: HTMLImageElement; + private readonly _eyes: HTMLElement; private readonly _sprite: ChatPetSpriteElement; /** Resources for the active pet or its disappearance effect. */ private readonly _activity = this._register(new DisposableStore()); @@ -1316,18 +1316,18 @@ class SubagentPet extends Disposable { this.element.style.top = `${this._top}px`; this.element.style.transform = `scale(${scale})`; const distance = Math.max(0, _host.overlay.getBoundingClientRect().top + this._top + size); - this.canvas = dom.append(this.element, dom.$('canvas.chat-subagent-pet-canvas')) as HTMLCanvasElement; - this.canvas.width = CHAT_PET_SOURCE_SIZE; - this.canvas.height = CHAT_PET_SOURCE_SIZE; - this.eyes = this.element.appendChild(_host.eyes.cloneNode(true)) as HTMLElement; - this.eyes.classList.remove('blink', 'blinking', 'bobbed'); - this.eyes.classList.add('tracking'); - for (const eye of this.eyes.children) { + this._canvas = dom.append(this.element, dom.$('canvas.chat-subagent-pet-canvas')) as HTMLCanvasElement; + this._canvas.width = CHAT_PET_SOURCE_SIZE; + this._canvas.height = CHAT_PET_SOURCE_SIZE; + this._eyes = this.element.appendChild(_host.eyes.cloneNode(true)) as HTMLElement; + this._eyes.classList.remove('blink', 'blinking', 'bobbed'); + this._eyes.classList.add('tracking'); + for (const eye of this._eyes.children) { (eye.firstElementChild as HTMLElement | null)?.style.removeProperty('transform'); } - this._blinkController = this._activity.add(new ChatPetBlinkController(blinking => this.eyes.classList.toggle('blink', blinking), _host.random)); + this._blinkController = this._activity.add(new ChatPetBlinkController(blinking => this._eyes.classList.toggle('blink', blinking), _host.random)); this._activity.add(_host.onDidChangeAnimationVisibility(() => this.updateBlink())); - const firstPupil = this.eyes.firstElementChild?.firstElementChild; + const firstPupil = this._eyes.firstElementChild?.firstElementChild; if (firstPupil) { this._activity.add(dom.addDisposableListener(firstPupil, 'animationend', event => { if ((event as AnimationEvent).animationName === 'chat-pet-tall-eye-blink') { @@ -1336,11 +1336,11 @@ class SubagentPet extends Disposable { })); } this.updateBlink(); - this.image = dom.append(this.element, dom.$('img.chat-pet-spritesheet')) as HTMLImageElement; - this.image.alt = ''; - this._sprite = { container: this.element, canvas: this.canvas, image: this.image, color: _host.color }; + this._image = dom.append(this.element, dom.$('img.chat-pet-spritesheet')) as HTMLImageElement; + this._image.alt = ''; + this._sprite = { container: this.element, canvas: this._canvas, image: this._image, color: _host.color }; this._updateAccessory(); - this._activity.add(dom.addDisposableListener(this.image, 'load', () => this._onImageLoad())); + this._activity.add(dom.addDisposableListener(this._image, 'load', () => this._onImageLoad())); this._setState('idle'); if (!_host.motionReduced && distance > 0) { this._animateFall(this._top - distance, this._top); @@ -1368,7 +1368,7 @@ class SubagentPet extends Disposable { /** Applies changes to the shared color, motion, variant, and accessory. */ updateAppearance(motionChanged: boolean, variantChanged: boolean, accessoryChanged: boolean): void { this._sprite.color = this._host.color; - this.eyes.style.color = getChatPetEyeColor(this._host.color); + this._eyes.style.color = getChatPetEyeColor(this._host.color); if (accessoryChanged) { this._updateAccessory(); } @@ -1404,17 +1404,17 @@ class SubagentPet extends Disposable { /** Plays the disappearance effect and releases the pet when it completes. */ despawn(onComplete: () => void): void { this._activity.clear(); - this.image.remove(); + this._image.remove(); this._accessoryImage?.remove(); this.element.classList.remove('chat-subagent-pet'); this.element.classList.add('chat-subagent-pet-despawning'); - this.eyes.remove(); + this._eyes.remove(); const image = dom.append(this.element, dom.$('img.chat-pet-spritesheet')) as HTMLImageElement; image.alt = ''; const sources = getRespawnSpriteSources(this._host.variant); const source = this._host.motionReduced ? sources.reducedMotion : sources.animated; const animation = this._activity.add(new MutableDisposable()); - const sprite: ChatPetSpriteElement = { container: this.element, canvas: this.canvas, image, color: this._host.color }; + const sprite: ChatPetSpriteElement = { container: this.element, canvas: this._canvas, image, color: this._host.color }; this._activity.add(dom.addDisposableListener(image, 'load', () => this._host.startAnimation(source, sprite, animation, onComplete, true))); this._activity.add(dom.addDisposableListener(image, 'error', onComplete)); const targetWindow = dom.getWindow(this.element); @@ -1435,9 +1435,9 @@ class SubagentPet extends Disposable { this._state = state; this.updateBlink(); if (this._host.motionReduced) { - this.eyes.classList.remove('bobbed'); + this._eyes.classList.remove('bobbed'); } - setChatPetImageSource(this.image, this._getSpriteSource().url); + setChatPetImageSource(this._image, this._getSpriteSource().url); } private _updateAccessory(): void { @@ -1459,7 +1459,7 @@ class SubagentPet extends Disposable { private _onImageLoad(): void { if (this._respawnPhase === 'despawning' || this._respawnPhase === 'respawning') { - this.eyes.classList.remove('tracking', 'bobbed'); + this._eyes.classList.remove('tracking', 'bobbed'); this._host.startAnimation(this._getSpriteSource(), this._sprite, this._spriteAnimation, () => this._advanceRespawn(), this._respawnPhase === 'despawning'); if (this._host.motionReduced) { this._respawnTimer.schedule(); @@ -1471,12 +1471,12 @@ class SubagentPet extends Disposable { return; } const source = this._getSpriteSource(); - this.eyes.classList.toggle('tracking', this._state === 'idle'); + this._eyes.classList.toggle('tracking', this._state === 'idle'); this._host.startAnimation(source, this._sprite, this._spriteAnimation, this._state === 'splat' ? () => this._setState('idle') : undefined, false, frameIndex => { - this.eyes.classList.toggle('bobbed', this._state === 'idle' && !this._host.motionReduced && (source.accessoryRigFrame ?? frameIndex) >= 20); + this._eyes.classList.toggle('bobbed', this._state === 'idle' && !this._host.motionReduced && (source.accessoryRigFrame ?? frameIndex) >= 20); }, (context, frameIndex) => { if (this._accessoryImage?.complete && this._accessoryImage.naturalWidth > 0 && this._accessory) { - drawChatPetComposite(context, this.image, this._accessoryImage, frameIndex, source.accessoryRigFrame ?? frameIndex, source.frameWidth, source.frameHeight ?? CHAT_PET_SOURCE_SIZE, 'right', this._state, source.fixedOrientationDecorations, true, this._accessory.eyeAccessoryMirrorsWithFacing !== false, this._accessory.coversAntennae === true, this._sprite.color); + drawChatPetComposite(context, this._image, this._accessoryImage, frameIndex, source.accessoryRigFrame ?? frameIndex, source.frameWidth, source.frameHeight ?? CHAT_PET_SOURCE_SIZE, 'right', this._state, source.fixedOrientationDecorations, true, this._accessory.eyeAccessoryMirrorsWithFacing !== false, this._accessory.coversAntennae === true, this._sprite.color); return true; } return false; From c095bda0c88f96f6336400c7dd7bd9d363f74558 Mon Sep 17 00:00:00 2001 From: Lisa Rosenberg Date: Fri, 13 Nov 2026 21:19:40 +0100 Subject: [PATCH 51/66] feat: add further performance optimizations --- .../chat/browser/widget/chatPetWidget.ts | 27 +++++++++++++++---- .../test/browser/widget/chatPetWidget.test.ts | 16 +++++++++++ 2 files changed, 38 insertions(+), 5 deletions(-) diff --git a/src/vs/workbench/contrib/chat/browser/widget/chatPetWidget.ts b/src/vs/workbench/contrib/chat/browser/widget/chatPetWidget.ts index f3500d4c61ed27..882af6e6b2a416 100644 --- a/src/vs/workbench/contrib/chat/browser/widget/chatPetWidget.ts +++ b/src/vs/workbench/contrib/chat/browser/widget/chatPetWidget.ts @@ -1499,10 +1499,10 @@ class SubagentPet extends Disposable { /** Advances relocation from disappearance to reappearance and landing. */ private _advanceRespawn(): void { - const overlay = this._host.overlay.getBoundingClientRect(); - const input = this._host.getDragBounds(); const size = getSubagentPetSize(this._host.scale); if (this._respawnPhase === 'despawning') { + const overlay = this._host.overlay.getBoundingClientRect(); + const input = this._host.getDragBounds(); this._respawnPhase = 'respawning'; this._left = Math.max(input.left - overlay.left, Math.min(this._left, input.right - overlay.left - size)); this._top = this._host.getMovementBounds().top - overlay.top; @@ -2177,12 +2177,28 @@ export class ChatPetWidget extends Disposable { continue; } part.toolSpecificDataKind.read(responseReader); - part.state.read(responseReader); const data = part.toolSpecificData; + if (data?.kind === 'subagent') { + // Metadata updates also notify through the tool state. + part.state.read(responseReader); + } if (data?.kind === 'subagent' && data.presentation !== 'phase' && data.hasStarted !== false && (getSubagentIsActive(data) ?? !IChatToolInvocation.isComplete(part, responseReader))) { responseSubagentIds.add(JSON.stringify([request.id, part.toolCallId])); } } + // Skip pet updates when a streamed response leaves the active subagents unchanged. + let changed = responseSubagentIds.size !== previousResponseSubagentIds.size; + if (!changed) { + for (const id of responseSubagentIds) { + if (!previousResponseSubagentIds.has(id)) { + changed = true; + break; + } + } + } + if (!changed) { + return; + } for (const id of previousResponseSubagentIds) { activeSubagentIds.delete(id); } @@ -3324,7 +3340,7 @@ export class ChatPetWidget extends Disposable { if (added || removed) { this._scheduleSubagentPetResize(); } - if (removed) { + if (removed && this._subagentPets.size) { this._settleSubagentPets(); } } @@ -3361,11 +3377,12 @@ export class ChatPetWidget extends Disposable { const overlay = this._overlay.getBoundingClientRect(); const platforms = this._getPlatforms(); const floor = platformChanged ? this.movementBounds.getBoundingClientRect().bottom : Math.min(this.dragBounds.getBoundingClientRect().top, this.movementBounds.getBoundingClientRect().bottom); + const size = getSubagentPetSize(this._scale); const subagentPets = [...this._subagentPets.values()].filter(subagentPet => !subagentPet.isRespawning()).map(subagentPet => ({ subagentPet, left: subagentPet.left, top: subagentPet.top, - size: getSubagentPetSize(this._scale), + size, })).sort((a, b) => b.top - a.top); for (const [index, entry] of subagentPets.entries()) { const landing = getChatPetFallTarget(overlay.left + entry.left, overlay.top + entry.top - POSITION_EPSILON, entry.size, entry.size, platforms, floor); diff --git a/src/vs/workbench/contrib/chat/test/browser/widget/chatPetWidget.test.ts b/src/vs/workbench/contrib/chat/test/browser/widget/chatPetWidget.test.ts index b6575b9193a0d3..a43fde8926bceb 100644 --- a/src/vs/workbench/contrib/chat/test/browser/widget/chatPetWidget.test.ts +++ b/src/vs/workbench/contrib/chat/test/browser/widget/chatPetWidget.test.ts @@ -2871,14 +2871,30 @@ suite('ChatPetWidget', () => { }(); widget.setHost({ ...firstHost, model: constObservable(model) }); assert.strictEqual(overlay.querySelectorAll('.chat-subagent-pet').length, 2); + // eslint-disable-next-line local/code-no-bracket-notation-for-identifiers -- Verify streamed updates do not reconcile unchanged pets. + const updateSubagentPets = sinon.spy(widget['_updateSubagentPets']); + // eslint-disable-next-line local/code-no-bracket-notation-for-identifiers -- Observe reconciliation without exposing a test-only API. + widget['_updateSubagentPets'] = updateSubagentPets; reads[0] = 0; changes[1].fire({ reason: 'other' }); assert.strictEqual(reads[0], 0); + assert.ok(updateSubagentPets.notCalled); tools[0].toolSpecificData = { kind: 'subagent', isActive: false }; changes[0].fire({ reason: 'other' }); assert.strictEqual(overlay.querySelectorAll('.chat-subagent-pet').length, 1); }); + test('subagent pets react to tool metadata notifications without a response event', () => { + const { widget, firstHost, overlay } = createHostTransitionHarness(true); + const tool = new ChatToolInvocation(undefined, { id: 'subagent', displayName: 'Subagent', modelDescription: 'Subagent', source: ToolDataSource.Internal }, 'subagent', undefined, {}); + tool.toolSpecificData = { kind: 'subagent', isActive: true }; + widget.setHost({ ...firstHost, model: constObservable(createSubagentTestModel([tool])) }); + assert.strictEqual(overlay.querySelectorAll('.chat-subagent-pet').length, 1); + tool.toolSpecificData = { kind: 'subagent', isActive: false }; + tool.notifyToolSpecificDataChanged(); + assert.strictEqual(overlay.querySelectorAll('.chat-subagent-pet').length, 0); + }); + test('subagent pets fill available slots without replacing active pets', async () => { const { widget, firstHost, overlay } = createHostTransitionHarness(true); const changed = disposables.add(new Emitter()); From 7e49e911c9aea86d707426a577271e8fac56d7f0 Mon Sep 17 00:00:00 2001 From: Lisa Rosenberg Date: Fri, 13 Nov 2026 21:36:26 +0100 Subject: [PATCH 52/66] feat: remove two instances of duplicate work --- .../contrib/chat/browser/widget/chatPetWidget.ts | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/src/vs/workbench/contrib/chat/browser/widget/chatPetWidget.ts b/src/vs/workbench/contrib/chat/browser/widget/chatPetWidget.ts index 882af6e6b2a416..b431f4bdc934e8 100644 --- a/src/vs/workbench/contrib/chat/browser/widget/chatPetWidget.ts +++ b/src/vs/workbench/contrib/chat/browser/widget/chatPetWidget.ts @@ -1388,16 +1388,14 @@ class SubagentPet extends Disposable { /** Falls to an overlay-relative position, optionally starting relocation on landing. */ fallTo(top: number, respawn = false): void { const previousTop = this.element.getBoundingClientRect().top - this._host.overlay.getBoundingClientRect().top; - this._respawnPhase = respawn ? 'falling' : 'none'; + const animateFall = !this._host.motionReduced && top > previousTop; + this._respawnPhase = respawn ? (animateFall ? 'falling' : 'despawning') : 'none'; this._fallAnimation.clear(); this._top = top; this.element.style.top = `${top}px`; this._setState('idle'); - if (!this._host.motionReduced && top > previousTop) { + if (animateFall) { this._animateFall(previousTop, top); - } else if (respawn) { - this._respawnPhase = 'despawning'; - this._setState('idle'); } } @@ -1454,7 +1452,6 @@ class SubagentPet extends Disposable { } setChatPetImageSource(this._accessoryImage, getChatPetAccessoryImageSource(this._accessory).url); } - this._sprite.redrawFrame?.(); } private _onImageLoad(): void { From 532183b17188571b32055b57119beb611505cb1d Mon Sep 17 00:00:00 2001 From: Lisa Rosenberg Date: Fri, 13 Nov 2026 21:42:14 +0100 Subject: [PATCH 53/66] feat: optimize settling loop --- .../chat/browser/widget/chatPetWidget.ts | 22 +++++++------------ 1 file changed, 8 insertions(+), 14 deletions(-) diff --git a/src/vs/workbench/contrib/chat/browser/widget/chatPetWidget.ts b/src/vs/workbench/contrib/chat/browser/widget/chatPetWidget.ts index b431f4bdc934e8..563b9c3c353a3f 100644 --- a/src/vs/workbench/contrib/chat/browser/widget/chatPetWidget.ts +++ b/src/vs/workbench/contrib/chat/browser/widget/chatPetWidget.ts @@ -3375,26 +3375,20 @@ export class ChatPetWidget extends Disposable { const platforms = this._getPlatforms(); const floor = platformChanged ? this.movementBounds.getBoundingClientRect().bottom : Math.min(this.dragBounds.getBoundingClientRect().top, this.movementBounds.getBoundingClientRect().bottom); const size = getSubagentPetSize(this._scale); - const subagentPets = [...this._subagentPets.values()].filter(subagentPet => !subagentPet.isRespawning()).map(subagentPet => ({ - subagentPet, - left: subagentPet.left, - top: subagentPet.top, - size, - })).sort((a, b) => b.top - a.top); - for (const [index, entry] of subagentPets.entries()) { - const landing = getChatPetFallTarget(overlay.left + entry.left, overlay.top + entry.top - POSITION_EPSILON, entry.size, entry.size, platforms, floor); - let top = Math.max(entry.top, landing.top - overlay.top); + const subagentPets = [...this._subagentPets.values()].filter(subagentPet => !subagentPet.isRespawning()).sort((a, b) => b.top - a.top); + for (const [index, subagentPet] of subagentPets.entries()) { + const landing = getChatPetFallTarget(overlay.left + subagentPet.left, overlay.top + subagentPet.top - POSITION_EPSILON, size, size, platforms, floor); + let top = Math.max(subagentPet.top, landing.top - overlay.top); let supported = !!landing.platform; for (let below = 0; below < index; below++) { const support = subagentPets[below]; - if (!support.subagentPet.isRespawning() && entry.left < support.left + support.size && entry.left + entry.size > support.left && support.top >= entry.top + entry.size - POSITION_EPSILON && support.top - entry.size <= top) { - top = Math.min(top, support.top - entry.size); + if (!support.isRespawning() && subagentPet.left < support.left + size && subagentPet.left + size > support.left && support.top >= subagentPet.top + size - POSITION_EPSILON && support.top - size <= top) { + top = Math.min(top, support.top - size); supported = true; } } - if (top > entry.top + POSITION_EPSILON) { - entry.subagentPet.fallTo(top, platformChanged && !supported); - entry.top = top; + if (top > subagentPet.top + POSITION_EPSILON) { + subagentPet.fallTo(top, platformChanged && !supported); } } } From a0cd9b5483a704f708ddc75bf3efd0bea69b3d39 Mon Sep 17 00:00:00 2001 From: Lisa Rosenberg Date: Fri, 13 Nov 2026 21:52:02 +0100 Subject: [PATCH 54/66] feat: simplify the active ID comparison and update --- .../chat/browser/widget/chatPetWidget.ts | 26 +++++++------- .../test/browser/widget/chatPetWidget.test.ts | 35 +++++++++++++++++++ 2 files changed, 47 insertions(+), 14 deletions(-) diff --git a/src/vs/workbench/contrib/chat/browser/widget/chatPetWidget.ts b/src/vs/workbench/contrib/chat/browser/widget/chatPetWidget.ts index 563b9c3c353a3f..fa9cec10d95d98 100644 --- a/src/vs/workbench/contrib/chat/browser/widget/chatPetWidget.ts +++ b/src/vs/workbench/contrib/chat/browser/widget/chatPetWidget.ts @@ -2183,25 +2183,23 @@ export class ChatPetWidget extends Disposable { responseSubagentIds.add(JSON.stringify([request.id, part.toolCallId])); } } - // Skip pet updates when a streamed response leaves the active subagents unchanged. - let changed = responseSubagentIds.size !== previousResponseSubagentIds.size; - if (!changed) { - for (const id of responseSubagentIds) { - if (!previousResponseSubagentIds.has(id)) { - changed = true; - break; - } + // Keep unchanged IDs in place to preserve waiting order for available pet slots. + let changed = false; + for (const id of previousResponseSubagentIds) { + if (!responseSubagentIds.has(id)) { + activeSubagentIds.delete(id); + changed = true; + } + } + for (const id of responseSubagentIds) { + if (!previousResponseSubagentIds.has(id)) { + activeSubagentIds.add(id); + changed = true; } } if (!changed) { return; } - for (const id of previousResponseSubagentIds) { - activeSubagentIds.delete(id); - } - for (const id of responseSubagentIds) { - activeSubagentIds.add(id); - } previousResponseSubagentIds = responseSubagentIds; if (!initializing) { this._updateSubagentPets(activeSubagentIds); diff --git a/src/vs/workbench/contrib/chat/test/browser/widget/chatPetWidget.test.ts b/src/vs/workbench/contrib/chat/test/browser/widget/chatPetWidget.test.ts index a43fde8926bceb..d5cd31b93f3763 100644 --- a/src/vs/workbench/contrib/chat/test/browser/widget/chatPetWidget.test.ts +++ b/src/vs/workbench/contrib/chat/test/browser/widget/chatPetWidget.test.ts @@ -2920,6 +2920,41 @@ suite('ChatPetWidget', () => { assert.strictEqual(overlay.querySelectorAll('.chat-subagent-pet-despawning').length, 0); }); + test('subagent pets preserve waiting order when an earlier response changes', async () => { + const { widget, firstHost, overlay } = createHostTransitionHarness(true); + const changed = disposables.add(new Emitter()); + const makeTool = (id: string) => { + const tool = new ChatToolInvocation(undefined, { id, displayName: id, modelDescription: 'Subagent', source: ToolDataSource.Internal }, id, undefined, {}); + tool.toolSpecificData = { kind: 'subagent', isActive: true }; + return tool; + }; + const olderTools = Array.from({ length: 11 }, (_, index) => makeTool(`older-${index}`)); + const newerTools = [makeTool('newer')]; + const requests = [olderTools, newerTools].map((parts, index) => { + const response = new class extends mock() { + override readonly onDidChange = index === 0 ? changed.event : Event.None; + override readonly isPendingConfirmation = constObservable(undefined); + override readonly response = new class extends mock() { override readonly value = parts; }(); + }(); + return new class extends mock() { override readonly id = `request-${index}`; override readonly response = response; }(); + }); + const model = new class extends mock() { + override readonly onDidChange = Event.None; + override readonly hasActiveRequest = constObservable(true); + override readonly lastRequestObs = constObservable(requests[1]); + override getRequests(): IChatRequestModel[] { return requests; } + }(); + widget.setHost({ ...firstHost, model: constObservable(model) }); + olderTools.push(makeTool('later')); + changed.fire({ reason: 'other' }); + olderTools[0].toolSpecificData = { kind: 'subagent', isActive: false }; + changed.fire({ reason: 'other' }); + await waitForPetAnimation(() => overlay.querySelectorAll('.chat-subagent-pet').length === 10); + // eslint-disable-next-line local/code-no-bracket-notation-for-identifiers -- Verify which waiting subagent received the slot. + const pets = widget['_subagentPets']; + assert.deepStrictEqual({ older: pets.has(JSON.stringify(['request-0', 'older-10'])), newer: pets.has(JSON.stringify(['request-1', 'newer'])) }, { older: true, newer: false }); + }); + test('shows one subagent pet per active subagent and removes it when it stops', async () => { const { widget, firstHost, button, overlay, service } = createHostTransitionHarness(); const responseChanged = disposables.add(new Emitter()); From 141f0fe4222442e1e97f33726dfe4efc9717b911 Mon Sep 17 00:00:00 2001 From: Lisa Rosenberg Date: Fri, 13 Nov 2026 23:21:53 +0100 Subject: [PATCH 55/66] Revert "feat: simplify the active ID comparison and update" This reverts commit a0cd9b5483a704f708ddc75bf3efd0bea69b3d39. --- .../chat/browser/widget/chatPetWidget.ts | 26 +++++++------- .../test/browser/widget/chatPetWidget.test.ts | 35 ------------------- 2 files changed, 14 insertions(+), 47 deletions(-) diff --git a/src/vs/workbench/contrib/chat/browser/widget/chatPetWidget.ts b/src/vs/workbench/contrib/chat/browser/widget/chatPetWidget.ts index fa9cec10d95d98..563b9c3c353a3f 100644 --- a/src/vs/workbench/contrib/chat/browser/widget/chatPetWidget.ts +++ b/src/vs/workbench/contrib/chat/browser/widget/chatPetWidget.ts @@ -2183,23 +2183,25 @@ export class ChatPetWidget extends Disposable { responseSubagentIds.add(JSON.stringify([request.id, part.toolCallId])); } } - // Keep unchanged IDs in place to preserve waiting order for available pet slots. - let changed = false; - for (const id of previousResponseSubagentIds) { - if (!responseSubagentIds.has(id)) { - activeSubagentIds.delete(id); - changed = true; - } - } - for (const id of responseSubagentIds) { - if (!previousResponseSubagentIds.has(id)) { - activeSubagentIds.add(id); - changed = true; + // Skip pet updates when a streamed response leaves the active subagents unchanged. + let changed = responseSubagentIds.size !== previousResponseSubagentIds.size; + if (!changed) { + for (const id of responseSubagentIds) { + if (!previousResponseSubagentIds.has(id)) { + changed = true; + break; + } } } if (!changed) { return; } + for (const id of previousResponseSubagentIds) { + activeSubagentIds.delete(id); + } + for (const id of responseSubagentIds) { + activeSubagentIds.add(id); + } previousResponseSubagentIds = responseSubagentIds; if (!initializing) { this._updateSubagentPets(activeSubagentIds); diff --git a/src/vs/workbench/contrib/chat/test/browser/widget/chatPetWidget.test.ts b/src/vs/workbench/contrib/chat/test/browser/widget/chatPetWidget.test.ts index d5cd31b93f3763..a43fde8926bceb 100644 --- a/src/vs/workbench/contrib/chat/test/browser/widget/chatPetWidget.test.ts +++ b/src/vs/workbench/contrib/chat/test/browser/widget/chatPetWidget.test.ts @@ -2920,41 +2920,6 @@ suite('ChatPetWidget', () => { assert.strictEqual(overlay.querySelectorAll('.chat-subagent-pet-despawning').length, 0); }); - test('subagent pets preserve waiting order when an earlier response changes', async () => { - const { widget, firstHost, overlay } = createHostTransitionHarness(true); - const changed = disposables.add(new Emitter()); - const makeTool = (id: string) => { - const tool = new ChatToolInvocation(undefined, { id, displayName: id, modelDescription: 'Subagent', source: ToolDataSource.Internal }, id, undefined, {}); - tool.toolSpecificData = { kind: 'subagent', isActive: true }; - return tool; - }; - const olderTools = Array.from({ length: 11 }, (_, index) => makeTool(`older-${index}`)); - const newerTools = [makeTool('newer')]; - const requests = [olderTools, newerTools].map((parts, index) => { - const response = new class extends mock() { - override readonly onDidChange = index === 0 ? changed.event : Event.None; - override readonly isPendingConfirmation = constObservable(undefined); - override readonly response = new class extends mock() { override readonly value = parts; }(); - }(); - return new class extends mock() { override readonly id = `request-${index}`; override readonly response = response; }(); - }); - const model = new class extends mock() { - override readonly onDidChange = Event.None; - override readonly hasActiveRequest = constObservable(true); - override readonly lastRequestObs = constObservable(requests[1]); - override getRequests(): IChatRequestModel[] { return requests; } - }(); - widget.setHost({ ...firstHost, model: constObservable(model) }); - olderTools.push(makeTool('later')); - changed.fire({ reason: 'other' }); - olderTools[0].toolSpecificData = { kind: 'subagent', isActive: false }; - changed.fire({ reason: 'other' }); - await waitForPetAnimation(() => overlay.querySelectorAll('.chat-subagent-pet').length === 10); - // eslint-disable-next-line local/code-no-bracket-notation-for-identifiers -- Verify which waiting subagent received the slot. - const pets = widget['_subagentPets']; - assert.deepStrictEqual({ older: pets.has(JSON.stringify(['request-0', 'older-10'])), newer: pets.has(JSON.stringify(['request-1', 'newer'])) }, { older: true, newer: false }); - }); - test('shows one subagent pet per active subagent and removes it when it stops', async () => { const { widget, firstHost, button, overlay, service } = createHostTransitionHarness(); const responseChanged = disposables.add(new Emitter()); From 46dd9514bc79f98a837b3c7a671e89ca51330cb5 Mon Sep 17 00:00:00 2001 From: Lisa Rosenberg Date: Fri, 13 Nov 2026 23:46:44 +0100 Subject: [PATCH 56/66] feat: fix stacking when resizing and increase max stacking height --- .../chat/browser/widget/chatPetWidget.ts | 25 +++++++++++++------ .../test/browser/widget/chatPetWidget.test.ts | 18 +++++++++++++ 2 files changed, 36 insertions(+), 7 deletions(-) diff --git a/src/vs/workbench/contrib/chat/browser/widget/chatPetWidget.ts b/src/vs/workbench/contrib/chat/browser/widget/chatPetWidget.ts index 563b9c3c353a3f..d1976896d46526 100644 --- a/src/vs/workbench/contrib/chat/browser/widget/chatPetWidget.ts +++ b/src/vs/workbench/contrib/chat/browser/widget/chatPetWidget.ts @@ -191,7 +191,7 @@ const SUBAGENT_PET_SCALE = 0.5; /** Maximum number of subagent pets shown at once. */ const SUBAGENT_PET_MAX_COUNT = 10; /** Maximum stacking height (CSS pixels) before subagent pets share space. */ -const SUBAGENT_PET_MAX_STACKING_HEIGHT = 96; +const SUBAGENT_PET_MAX_STACKING_HEIGHT = 500; /** Tolerance for fractional pixels when checking subagent pet bounds. */ const SUBAGENT_PET_BOUNDARY_EPSILON = 0.01; /** Distance kept between subagent pets and the edges of their platform. */ @@ -1350,9 +1350,9 @@ class SubagentPet extends Disposable { get left(): number { return this._left; } get top(): number { return this._top; } - /** Updates the scale while keeping the pet's bottom edge in place. */ - setScale(previousScale: number, scale: number): void { - this._top += CHAT_PET_DISPLAY_SIZE * (previousScale - scale); + /** Updates the scale and overlay-relative top position. */ + setScale(scale: number, top: number): void { + this._top = top; this.element.style.top = `${this._top}px`; this.element.style.transform = `scale(${scale})`; } @@ -3428,11 +3428,22 @@ export class ChatPetWidget extends Disposable { private _setScale(scale: number): void { this._stopJumpGame('restore'); - const previousScale = this._scale * SUBAGENT_PET_SCALE; + const previousSize = getSubagentPetSize(this._scale); this._scale = scale; const subagentPetScale = scale * SUBAGENT_PET_SCALE; - for (const subagentPet of this._subagentPets.values()) { - subagentPet.setScale(previousScale, subagentPetScale); + const size = getSubagentPetSize(scale); + const subagentPets = [...this._subagentPets.values()].map(subagentPet => ({ subagentPet, left: subagentPet.left, top: subagentPet.top })).sort((a, b) => b.top - a.top); + for (const [index, entry] of subagentPets.entries()) { + let supportTop: number | undefined; + if (!entry.subagentPet.isRespawning()) { + for (let below = 0; below < index; below++) { + const support = subagentPets[below]; + if (!support.subagentPet.isRespawning() && entry.left < support.left + previousSize && entry.left + previousSize > support.left && Math.abs(entry.top + previousSize - support.top) <= SUBAGENT_PET_BOUNDARY_EPSILON) { + supportTop = Math.min(supportTop ?? Infinity, support.subagentPet.top - size); + } + } + } + entry.subagentPet.setScale(subagentPetScale, supportTop ?? entry.top + previousSize - size); } this._scheduleSubagentPetResize(); const displaySize = this._getDisplaySize(); diff --git a/src/vs/workbench/contrib/chat/test/browser/widget/chatPetWidget.test.ts b/src/vs/workbench/contrib/chat/test/browser/widget/chatPetWidget.test.ts index a43fde8926bceb..7f71a139b799cb 100644 --- a/src/vs/workbench/contrib/chat/test/browser/widget/chatPetWidget.test.ts +++ b/src/vs/workbench/contrib/chat/test/browser/widget/chatPetWidget.test.ts @@ -3095,6 +3095,24 @@ suite('ChatPetWidget', () => { rect.right <= other.left + 0.1 || other.right <= rect.left + 0.1 || rect.bottom <= other.top + 0.1 || other.bottom <= rect.top + 0.1))); }); + test('subagent pets remain stacked when their size changes', () => { + const { widget, firstHost, overlay, service } = createHostTransitionHarness(true); + const tools = ['bottom', 'middle', 'top'].map(id => { + const tool = new ChatToolInvocation(undefined, { id, displayName: id, modelDescription: 'Subagent', source: ToolDataSource.Internal }, id, undefined, {}); + tool.toolSpecificData = { kind: 'subagent', isActive: true }; + return tool; + }); + widget.setHost({ ...firstHost, model: constObservable(createSubagentTestModel(tools)) }); + const pets = [...overlay.querySelectorAll('.chat-subagent-pet')]; + pets.forEach((pet, index) => setSubagentPetPosition(widget, pet, 48, -(index + 1) * 24)); + for (const scale of [2, 1]) { + service.setScale(scale); + const rects = pets.map(pet => pet.getBoundingClientRect()); + assert.ok(Math.abs(rects[1].bottom - rects[0].top) < 0.1); + assert.ok(Math.abs(rects[2].bottom - rects[1].top) < 0.1); + } + }); + for (const reducedMotion of [false, true]) { test(`subagent pets keep their size and only displaced pets respawn (${reducedMotion ? 'reduced motion' : 'animated'})`, async () => { const { widget, firstHost, overlay, firstParent, layout } = createHostTransitionHarness(reducedMotion); From 1472904abb2d2c85a5203028594a7d8a14ace067 Mon Sep 17 00:00:00 2001 From: Lisa Rosenberg Date: Fri, 13 Nov 2026 23:47:47 +0100 Subject: [PATCH 57/66] Reapply "feat: simplify the active ID comparison and update" This reverts commit 141f0fe4222442e1e97f33726dfe4efc9717b911. --- .../chat/browser/widget/chatPetWidget.ts | 26 +++++++------- .../test/browser/widget/chatPetWidget.test.ts | 35 +++++++++++++++++++ 2 files changed, 47 insertions(+), 14 deletions(-) diff --git a/src/vs/workbench/contrib/chat/browser/widget/chatPetWidget.ts b/src/vs/workbench/contrib/chat/browser/widget/chatPetWidget.ts index d1976896d46526..587d533d198770 100644 --- a/src/vs/workbench/contrib/chat/browser/widget/chatPetWidget.ts +++ b/src/vs/workbench/contrib/chat/browser/widget/chatPetWidget.ts @@ -2183,25 +2183,23 @@ export class ChatPetWidget extends Disposable { responseSubagentIds.add(JSON.stringify([request.id, part.toolCallId])); } } - // Skip pet updates when a streamed response leaves the active subagents unchanged. - let changed = responseSubagentIds.size !== previousResponseSubagentIds.size; - if (!changed) { - for (const id of responseSubagentIds) { - if (!previousResponseSubagentIds.has(id)) { - changed = true; - break; - } + // Keep unchanged IDs in place to preserve waiting order for available pet slots. + let changed = false; + for (const id of previousResponseSubagentIds) { + if (!responseSubagentIds.has(id)) { + activeSubagentIds.delete(id); + changed = true; + } + } + for (const id of responseSubagentIds) { + if (!previousResponseSubagentIds.has(id)) { + activeSubagentIds.add(id); + changed = true; } } if (!changed) { return; } - for (const id of previousResponseSubagentIds) { - activeSubagentIds.delete(id); - } - for (const id of responseSubagentIds) { - activeSubagentIds.add(id); - } previousResponseSubagentIds = responseSubagentIds; if (!initializing) { this._updateSubagentPets(activeSubagentIds); diff --git a/src/vs/workbench/contrib/chat/test/browser/widget/chatPetWidget.test.ts b/src/vs/workbench/contrib/chat/test/browser/widget/chatPetWidget.test.ts index 7f71a139b799cb..2fa3e408fc4b07 100644 --- a/src/vs/workbench/contrib/chat/test/browser/widget/chatPetWidget.test.ts +++ b/src/vs/workbench/contrib/chat/test/browser/widget/chatPetWidget.test.ts @@ -2920,6 +2920,41 @@ suite('ChatPetWidget', () => { assert.strictEqual(overlay.querySelectorAll('.chat-subagent-pet-despawning').length, 0); }); + test('subagent pets preserve waiting order when an earlier response changes', async () => { + const { widget, firstHost, overlay } = createHostTransitionHarness(true); + const changed = disposables.add(new Emitter()); + const makeTool = (id: string) => { + const tool = new ChatToolInvocation(undefined, { id, displayName: id, modelDescription: 'Subagent', source: ToolDataSource.Internal }, id, undefined, {}); + tool.toolSpecificData = { kind: 'subagent', isActive: true }; + return tool; + }; + const olderTools = Array.from({ length: 11 }, (_, index) => makeTool(`older-${index}`)); + const newerTools = [makeTool('newer')]; + const requests = [olderTools, newerTools].map((parts, index) => { + const response = new class extends mock() { + override readonly onDidChange = index === 0 ? changed.event : Event.None; + override readonly isPendingConfirmation = constObservable(undefined); + override readonly response = new class extends mock() { override readonly value = parts; }(); + }(); + return new class extends mock() { override readonly id = `request-${index}`; override readonly response = response; }(); + }); + const model = new class extends mock() { + override readonly onDidChange = Event.None; + override readonly hasActiveRequest = constObservable(true); + override readonly lastRequestObs = constObservable(requests[1]); + override getRequests(): IChatRequestModel[] { return requests; } + }(); + widget.setHost({ ...firstHost, model: constObservable(model) }); + olderTools.push(makeTool('later')); + changed.fire({ reason: 'other' }); + olderTools[0].toolSpecificData = { kind: 'subagent', isActive: false }; + changed.fire({ reason: 'other' }); + await waitForPetAnimation(() => overlay.querySelectorAll('.chat-subagent-pet').length === 10); + // eslint-disable-next-line local/code-no-bracket-notation-for-identifiers -- Verify which waiting subagent received the slot. + const pets = widget['_subagentPets']; + assert.deepStrictEqual({ older: pets.has(JSON.stringify(['request-0', 'older-10'])), newer: pets.has(JSON.stringify(['request-1', 'newer'])) }, { older: true, newer: false }); + }); + test('shows one subagent pet per active subagent and removes it when it stops', async () => { const { widget, firstHost, button, overlay, service } = createHostTransitionHarness(); const responseChanged = disposables.add(new Emitter()); From 42b3e52e2b6b7aa8e7a2743c168f7f782ed8432e Mon Sep 17 00:00:00 2001 From: Lisa Rosenberg Date: Sat, 14 Nov 2026 00:59:11 +0100 Subject: [PATCH 58/66] feat: add arrival delay --- .../chat/browser/widget/chatPetWidget.ts | 17 +++++- .../test/browser/widget/chatPetWidget.test.ts | 55 ++++++++++++++++++- 2 files changed, 68 insertions(+), 4 deletions(-) diff --git a/src/vs/workbench/contrib/chat/browser/widget/chatPetWidget.ts b/src/vs/workbench/contrib/chat/browser/widget/chatPetWidget.ts index 587d533d198770..f04e7f439a9e8e 100644 --- a/src/vs/workbench/contrib/chat/browser/widget/chatPetWidget.ts +++ b/src/vs/workbench/contrib/chat/browser/widget/chatPetWidget.ts @@ -190,6 +190,8 @@ const DIZZY_FRAME_DURATIONS = Array.from({ length: 8 }, () => 120); const SUBAGENT_PET_SCALE = 0.5; /** Maximum number of subagent pets shown at once. */ const SUBAGENT_PET_MAX_COUNT = 10; +/** Delay between subagent pet arrivals, in milliseconds. */ +const SUBAGENT_PET_ARRIVAL_DELAY = 120; /** Maximum stacking height (CSS pixels) before subagent pets share space. */ const SUBAGENT_PET_MAX_STACKING_HEIGHT = 500; /** Tolerance for fractional pixels when checking subagent pet bounds. */ @@ -1530,6 +1532,8 @@ export class ChatPetWidget extends Disposable { private readonly _subagentPetEffects = this._register(new DisposableStore()); /** Coalesces bounds checks while the chat is resizing. */ private readonly _subagentPetResizeScheduler = this._register(new RunOnceScheduler(() => this._reconcileSubagentPetResize(), 16)); + private readonly _subagentPetArrivalScheduler = this._register(new RunOnceScheduler(() => this._updateSubagentPets(this._activeSubagentIds, true), SUBAGENT_PET_ARRIVAL_DELAY)); + private readonly _subagentPetArrivalDelay: number; /** Overlay layer containing subagent pets. */ private readonly _subagentPetLayer: HTMLElement; /** Shared widget services, initialized when the first subagent pet appears. */ @@ -1679,6 +1683,7 @@ export class ChatPetWidget extends Disposable { readonly resizeObserverCtor?: typeof ResizeObserver; readonly intersectionObserverCtor?: typeof IntersectionObserver; readonly random?: () => number; + readonly subagentPetArrivalDelay?: number; } | undefined, @IChatPetService private readonly chatPetService: IChatPetService, @IAccessibilityService private readonly accessibilityService: IAccessibilityService, @@ -1690,6 +1695,7 @@ export class ChatPetWidget extends Disposable { ) { super(); this._random = options?.random ?? Math.random; + this._subagentPetArrivalDelay = options?.subagentPetArrivalDelay ?? SUBAGENT_PET_ARRIVAL_DELAY; this.parent = host.parent; this.dragBounds = host.dragBounds; @@ -2083,6 +2089,7 @@ export class ChatPetWidget extends Disposable { if (!enabled) { this._subagentPetResizeScheduler.cancel(); + this._subagentPetArrivalScheduler.cancel(); this._activeSubagentIds = new Set(); this._despawningSubagentPetCount = 0; this._subagentPets.clear(); @@ -2151,6 +2158,7 @@ export class ChatPetWidget extends Disposable { const enabled = isChatPetVisible(this.chatPetService.enabled.read(reader), windowActive.read(reader)); const model = this._host.read(reader).model.read(reader); if (model !== this._subagentPetModel) { + this._subagentPetArrivalScheduler.cancel(); this._updateSubagentPets(new Set()); this._subagentPetModel = model; } @@ -3304,7 +3312,7 @@ export class ChatPetWidget extends Disposable { } /** Keeps existing pets for active subagents and fills available slots up to the limit. */ - private _updateSubagentPets(activeSubagentIds: ReadonlySet): void { + private _updateSubagentPets(activeSubagentIds: ReadonlySet, arrivalReady = false): void { this._activeSubagentIds = new Set(activeSubagentIds); let removed = false; let added = false; @@ -3327,10 +3335,17 @@ export class ChatPetWidget extends Disposable { if (this._subagentPets.has(id)) { continue; } + if (this._subagentPetArrivalDelay > 0 && !arrivalReady) { + if (!this._subagentPetArrivalScheduler.isScheduled()) { + this._subagentPetArrivalScheduler.schedule(this._subagentPetArrivalDelay); + } + break; + } added = true; const { left, top } = this._getSubagentPetLanding(getSubagentPetSize(this._scale)); const subagentPet = this._subagentPetEffects.add(new SubagentPet(this._getSubagentPetHost(), left, top)); this._subagentPets.set(id, subagentPet); + arrivalReady = false; } if (added || removed) { this._scheduleSubagentPetResize(); diff --git a/src/vs/workbench/contrib/chat/test/browser/widget/chatPetWidget.test.ts b/src/vs/workbench/contrib/chat/test/browser/widget/chatPetWidget.test.ts index 2fa3e408fc4b07..6bb3291341d913 100644 --- a/src/vs/workbench/contrib/chat/test/browser/widget/chatPetWidget.test.ts +++ b/src/vs/workbench/contrib/chat/test/browser/widget/chatPetWidget.test.ts @@ -114,7 +114,7 @@ suite('ChatPetWidget', () => { } } - function createHostTransitionHarness(motionReduced = false, initialTransition: IChatPetWidgetHost['transition'] = 'teleport', color?: ChatPetColor, intersectionObserverCtor?: typeof IntersectionObserver, setPlatformOccupation?: IChatPetWidgetHost['setPlatformOccupation'], supportsJumpGame = false, initializeService?: (service: ChatPetService) => void, initialModel?: IChatModel, random?: () => number) { + function createHostTransitionHarness(motionReduced = false, initialTransition: IChatPetWidgetHost['transition'] = 'teleport', color?: ChatPetColor, intersectionObserverCtor?: typeof IntersectionObserver, setPlatformOccupation?: IChatPetWidgetHost['setPlatformOccupation'], supportsJumpGame = false, initializeService?: (service: ChatPetService) => void, initialModel?: IChatModel, random?: () => number, subagentPetArrivalDelay = 0) { const root = mainWindow.document.createElement('div'); root.style.cssText = 'position:fixed;left:0;top:0;width:800px;height:640px'; if (supportsJumpGame) { @@ -179,7 +179,7 @@ suite('ChatPetWidget', () => { } initializeService?.(service); const widget = disposables.add(new ChatPetWidget( - firstHost, { resizeObserverCtor: TestResizeObserver, intersectionObserverCtor, random }, service, accessibilityService, + firstHost, { resizeObserverCtor: TestResizeObserver, intersectionObserverCtor, random, subagentPetArrivalDelay }, service, accessibilityService, new class extends mock() { override showContextMenu(delegate: IContextMenuDelegate): void { contextMenu = delegate; } }(), @@ -2895,6 +2895,55 @@ suite('ChatPetWidget', () => { assert.strictEqual(overlay.querySelectorAll('.chat-subagent-pet').length, 0); }); + test('subagent pets arrive in sequence and skip subagents that have finished', () => { + const clock = sinon.useFakeTimers({ toFake: ['setTimeout', 'clearTimeout'] }); + disposables.add(toDisposable(() => clock.restore())); + const { widget, firstHost, overlay } = createHostTransitionHarness(true, undefined, undefined, undefined, undefined, false, undefined, undefined, undefined, 120); + const changed = disposables.add(new Emitter()); + const tools = Array.from({ length: 12 }, (_, index) => { + const id = `subagent-${index}`; + const tool = new ChatToolInvocation(undefined, { id, displayName: id, modelDescription: 'Subagent', source: ToolDataSource.Internal }, id, undefined, {}); + tool.toolSpecificData = { kind: 'subagent', isActive: true }; + return tool; + }); + widget.setHost({ ...firstHost, model: constObservable(createSubagentTestModel(tools, changed.event)) }); + assert.strictEqual(overlay.querySelectorAll('.chat-subagent-pet').length, 0); + tools[1].toolSpecificData = { kind: 'subagent', isActive: false }; + changed.fire({ reason: 'other' }); + clock.tick(119); + assert.strictEqual(overlay.querySelectorAll('.chat-subagent-pet').length, 0); + clock.tick(1); + assert.strictEqual(overlay.querySelectorAll('.chat-subagent-pet').length, 1); + clock.tick(120); + assert.strictEqual(overlay.querySelectorAll('.chat-subagent-pet').length, 2); + // eslint-disable-next-line local/code-no-bracket-notation-for-identifiers -- Check the waiting subagent was skipped. + assert.ok(!widget['_subagentPets'].has(JSON.stringify(['request', 'subagent-1']))); + clock.tick(120 * 12); + assert.strictEqual(overlay.querySelectorAll('.chat-subagent-pet, .chat-subagent-pet-despawning').length, 10); + }); + + test('subagent pet arrivals stop when disabled or the model changes', () => { + const clock = sinon.useFakeTimers({ toFake: ['setTimeout', 'clearTimeout'] }); + disposables.add(toDisposable(() => clock.restore())); + const { widget, firstHost, overlay, service } = createHostTransitionHarness(true, undefined, undefined, undefined, undefined, false, undefined, undefined, undefined, 120); + const tools = ['first', 'second'].map(id => { + const tool = new ChatToolInvocation(undefined, { id, displayName: id, modelDescription: 'Subagent', source: ToolDataSource.Internal }, id, undefined, {}); + tool.toolSpecificData = { kind: 'subagent', isActive: true }; + return tool; + }); + const model = observableValue('model', createSubagentTestModel(tools)); + widget.setHost({ ...firstHost, model }); + clock.tick(120); + assert.strictEqual(overlay.querySelectorAll('.chat-subagent-pet').length, 1); + model.set(undefined, undefined); + clock.tick(120); + assert.strictEqual(overlay.querySelectorAll('.chat-subagent-pet').length, 0); + model.set(createSubagentTestModel(tools), undefined); + service.toggle(); + clock.tick(240); + assert.strictEqual(overlay.querySelectorAll('.chat-subagent-pet, .chat-subagent-pet-despawning').length, 0); + }); + test('subagent pets fill available slots without replacing active pets', async () => { const { widget, firstHost, overlay } = createHostTransitionHarness(true); const changed = disposables.add(new Emitter()); @@ -3305,7 +3354,7 @@ suite('ChatPetWidget', () => { assert.deepStrictEqual({ count: rects.length, withinChat: left >= input.left - 0.1 && right <= input.right + 0.1 && top >= movement.top - 0.1 && bottom <= Math.min(input.top, movement.bottom) + 0.1, - bounded: right - left <= input.width + 0.1 && bottom - top <= 96.1, + bounded: right - left <= input.width + 0.1 && bottom - top <= 500.1, largeEnough: rects.every(rect => rect.width >= 9.5 && rect.height >= 9.5), }, { count, withinChat: true, bounded: true, largeEnough: true }, JSON.stringify({ left, right, top, bottom, input: input.toJSON(), movement: movement.toJSON() })); }; From 1dfe7ab65242e1d8a9dd0d676cac42b47de86184 Mon Sep 17 00:00:00 2001 From: Lisa Rosenberg Date: Thu, 26 Nov 2026 22:03:02 +0100 Subject: [PATCH 59/66] feat: add suggested comment on pausing drawing when hidden --- .../chat/browser/widget/chatPetWidget.ts | 26 ++++++++-- .../test/browser/widget/chatPetWidget.test.ts | 47 ++++++++++++++++++- 2 files changed, 66 insertions(+), 7 deletions(-) diff --git a/src/vs/workbench/contrib/chat/browser/widget/chatPetWidget.ts b/src/vs/workbench/contrib/chat/browser/widget/chatPetWidget.ts index 2c2e749329c234..0c42691b3be956 100644 --- a/src/vs/workbench/contrib/chat/browser/widget/chatPetWidget.ts +++ b/src/vs/workbench/contrib/chat/browser/widget/chatPetWidget.ts @@ -247,6 +247,7 @@ interface SubagentPetHost { readonly scale: number; readonly random: () => number; isAnimationVisible(element: HTMLElement): boolean; + observeAnimationVisibility(element: HTMLElement): IDisposable; getDragBounds(): DOMRect; getMovementBounds(): DOMRect; getLanding(size: number): { left: number; top: number }; @@ -1357,6 +1358,7 @@ class SubagentPet extends Disposable { const size = getSubagentPetSize(_host.scale); this.element = dom.append(_host.layer, dom.$('.chat-subagent-pet', { 'aria-hidden': 'true' })); this._register(toDisposable(() => this.element.remove())); + this._register(_host.observeAnimationVisibility(this.element)); this.element.style.left = `${this._left}px`; this.element.style.top = `${this._top}px`; this.element.style.transform = `scale(${scale})`; @@ -1503,9 +1505,8 @@ class SubagentPet extends Disposable { if (this._respawnPhase === 'despawning' || this._respawnPhase === 'respawning') { this._eyes.classList.remove('tracking', 'bobbed'); this._host.startAnimation(this._getSpriteSource(), this._sprite, this._spriteAnimation, () => this._advanceRespawn(), this._respawnPhase === 'despawning'); - if (this._host.motionReduced) { - this._respawnTimer.schedule(); - } + // Relocation must finish even when its sprite is outside the viewport. + this._respawnTimer.schedule(this._host.motionReduced ? RESPAWN_EFFECT_REDUCED_MOTION_DURATION : RESPAWN_EFFECT_DURATION); return; } if (this._state === 'splat' && this._host.motionReduced) { @@ -1644,6 +1645,7 @@ export class ChatPetWidget extends Disposable { private _dragOrigin: readonly [number, number] | undefined; private _dragPosition: readonly [number, number] | undefined; private readonly _animationVisibility = new Map(); + private readonly _animationObserver: IntersectionObserver | undefined; private readonly _onDidChangeAnimationVisibility = this._register(new Emitter()); private readonly _dragMonitor = this._register(new GlobalPointerMoveMonitor()); private readonly _idleExpired = observableValue(this, false); @@ -1860,16 +1862,19 @@ export class ChatPetWidget extends Disposable { return; } for (const entry of entries) { - this._animationVisibility.set(entry.target, entry.isIntersecting && entry.boundingClientRect.width > 0 && entry.boundingClientRect.height > 0); + if (this._animationVisibility.has(entry.target)) { + this._animationVisibility.set(entry.target, entry.isIntersecting && entry.boundingClientRect.width > 0 && entry.boundingClientRect.height > 0); + } } this._updateAnimationVisibility(); }); + this._animationObserver = observer; this._register(toDisposable(() => { observer.disconnect(); this._animationVisibility.clear(); })); for (const element of [this._visual, ...this._sprites.map(sprite => sprite.container), this._speechBubble.container, this._respawnEffect.container]) { - observer.observe(element); + this._register(this._observeAnimationVisibility(element)); } } this._register(dom.addDisposableListener(dom.getWindow(this._button.element).document, dom.EventType.POINTER_MOVE, (event: PointerEvent) => { @@ -2472,6 +2477,16 @@ export class ChatPetWidget extends Disposable { this._updateAnimationVisibility(); } + /** Tracks sprite visibility until its owning element is disposed. */ + private _observeAnimationVisibility(element: HTMLElement): IDisposable { + this._animationVisibility.set(element, true); + this._animationObserver?.observe(element); + return toDisposable(() => { + this._animationObserver?.unobserve(element); + this._animationVisibility.delete(element); + }); + } + private _isAnimationVisible(element: HTMLElement): boolean { return element.isConnected && !dom.getWindow(element).document.hidden && this._animationVisibility.get(element) !== false; } @@ -3433,6 +3448,7 @@ export class ChatPetWidget extends Disposable { get scale() { return widget._scale; }, random: this._random, isAnimationVisible: element => this._isAnimationVisible(this._visual) && this._isAnimationVisible(element), + observeAnimationVisibility: element => this._observeAnimationVisibility(element), getDragBounds: () => this.dragBounds.getBoundingClientRect(), getMovementBounds: () => this.movementBounds.getBoundingClientRect(), getLanding: size => this._getSubagentPetLanding(size), diff --git a/src/vs/workbench/contrib/chat/test/browser/widget/chatPetWidget.test.ts b/src/vs/workbench/contrib/chat/test/browser/widget/chatPetWidget.test.ts index 66f00c400f6bdc..f7286ebd2a565b 100644 --- a/src/vs/workbench/contrib/chat/test/browser/widget/chatPetWidget.test.ts +++ b/src/vs/workbench/contrib/chat/test/browser/widget/chatPetWidget.test.ts @@ -102,11 +102,11 @@ suite('ChatPetWidget', () => { this.targets.clear(); } - setVisible(visible: boolean): void { + setVisible(visible: boolean, element?: Element): void { if (this.targets.size === 0) { return; } - this.callback([...this.targets].map(target => new class extends mock() { + this.callback([...this.targets].filter(target => !element || target === element).map(target => new class extends mock() { override readonly target = target; override readonly isIntersecting = visible; override readonly boundingClientRect = target.getBoundingClientRect(); @@ -3771,6 +3771,49 @@ suite('ChatPetWidget', () => { assert.ok(overlay.querySelector('.chat-subagent-pet-despawning img')?.getAttribute('src')?.endsWith('-96.png')); }); + test('subagent pets pause invisible sprites, resume independently, and unobserve after despawning', async () => { + const clock = sinon.useFakeTimers({ toFake: ['setTimeout', 'clearTimeout', 'performance'] }); + disposables.add(toDisposable(() => clock.restore())); + let visibilityObserver: TestIntersectionObserver | undefined; + class VisibilityObserver extends TestIntersectionObserver { + constructor(callback: IntersectionObserverCallback) { + super(callback); + visibilityObserver = this; + } + } + const { widget, firstHost, overlay } = createHostTransitionHarness(false, 'teleport', 'stable', VisibilityObserver); + const responseChanged = disposables.add(new Emitter()); + const tool = new ChatToolInvocation(undefined, { id: 'subagent', displayName: 'Subagent', modelDescription: 'Subagent', source: ToolDataSource.Internal }, 'subagent', undefined, {}); + tool.toolSpecificData = { kind: 'subagent', isActive: true }; + widget.setHost({ ...firstHost, model: constObservable(createSubagentTestModel([tool], responseChanged.event)) }); + const pet = overlay.querySelector('.chat-subagent-pet')!; + pet.getAnimations().forEach(animation => animation.cancel()); + await whenSpriteLoaded(pet.querySelector('img')!); + const draws = sinon.spy(pet.querySelector('canvas')!.getContext('2d')!, 'drawImage'); + disposables.add(toDisposable(() => draws.restore())); + assert.ok(visibilityObserver); + const unobserve = sinon.spy(visibilityObserver, 'unobserve'); + const snapshots: number[] = []; + clock.tick(800); + snapshots.push(draws.callCount); + visibilityObserver.setVisible(false); + clock.tick(1_200); + snapshots.push(draws.callCount); + // A subagent pet can be visible while the main pet remains outside the viewport. + visibilityObserver.setVisible(true, pet); + snapshots.push(draws.callCount); + clock.tick(800); + snapshots.push(draws.callCount); + visibilityObserver.setVisible(false, pet); + tool.toolSpecificData = { kind: 'subagent', isActive: false }; + responseChanged.fire({ reason: 'other' }); + const observedWhileDespawning = !unobserve.calledWith(pet); + clock.tick(2_000); + assert.deepStrictEqual({ snapshots, observedWhileDespawning, removed: !pet.isConnected, unobserved: unobserve.calledWith(pet) }, { + snapshots: [1, 1, 2, 3], observedWhileDespawning: true, removed: true, unobserved: true, + }); + }); + test('subagent pets blink and move their eyes with their own idle frames', async () => { const clock = sinon.useFakeTimers({ toFake: ['setTimeout', 'clearTimeout', 'performance'] }); disposables.add(toDisposable(() => clock.restore())); From eac5e11e3b28cf286d456b9fe3f301718e2b0584 Mon Sep 17 00:00:00 2001 From: Lisa Rosenberg Date: Thu, 26 Nov 2026 22:14:22 +0100 Subject: [PATCH 60/66] feat: add suggested comment on checking on overlapping/unsupported subagent pets --- .../chat/browser/widget/chatPetWidget.ts | 19 ++++++++++---- .../test/browser/widget/chatPetWidget.test.ts | 25 +++++++++++++++++++ 2 files changed, 39 insertions(+), 5 deletions(-) diff --git a/src/vs/workbench/contrib/chat/browser/widget/chatPetWidget.ts b/src/vs/workbench/contrib/chat/browser/widget/chatPetWidget.ts index 0c42691b3be956..50e1be05f69189 100644 --- a/src/vs/workbench/contrib/chat/browser/widget/chatPetWidget.ts +++ b/src/vs/workbench/contrib/chat/browser/widget/chatPetWidget.ts @@ -3490,19 +3490,27 @@ export class ChatPetWidget extends Disposable { } } - /** Relocate only subagent pets that no longer fit after resizing has settled. */ - private _reconcileSubagentPetResize(): void { - const subagentPets = [...this._subagentPets.values()].filter(subagentPet => !subagentPet.isRespawning()); + /** Relocates pets outside the bounds, also checking overlaps and support after scaling. */ + private _reconcileSubagentPetResize(checkPlacement = false): void { + const subagentPets = [...this._subagentPets.values()].filter(subagentPet => !subagentPet.isRespawning()).sort((a, b) => b.top - a.top); if (!subagentPets.length) { return; } - const { overlay, movement, left, right, bottom } = this._getSubagentPetBounds(); + const { overlay, movement, platforms, floor, left, right, bottom } = this._getSubagentPetBounds(); const size = getSubagentPetSize(this._scale); let displaced = false; for (const subagentPet of subagentPets) { const subagentPetLeft = subagentPet.left; const subagentPetTop = subagentPet.top; - if (subagentPetLeft < left - SUBAGENT_PET_BOUNDARY_EPSILON || subagentPetLeft + size > right + SUBAGENT_PET_BOUNDARY_EPSILON || subagentPetTop < movement.top - overlay.top - SUBAGENT_PET_BOUNDARY_EPSILON || subagentPetTop + size > bottom + SUBAGENT_PET_BOUNDARY_EPSILON) { + const overlaps = checkPlacement && subagentPets.some(other => other !== subagentPet && !other.isRespawning() + && subagentPetLeft < other.left + size - SUBAGENT_PET_BOUNDARY_EPSILON && subagentPetLeft + size > other.left + SUBAGENT_PET_BOUNDARY_EPSILON + && subagentPetTop < other.top + size - SUBAGENT_PET_BOUNDARY_EPSILON && subagentPetTop + size > other.top + SUBAGENT_PET_BOUNDARY_EPSILON); + const landing = checkPlacement ? getChatPetFallTarget(overlay.left + subagentPetLeft, overlay.top + subagentPetTop - POSITION_EPSILON, size, size, platforms, floor) : undefined; + const supported = !landing || Math.abs(landing.top - overlay.top - subagentPetTop) <= SUBAGENT_PET_BOUNDARY_EPSILON + || subagentPets.some(other => other !== subagentPet && !other.isRespawning() + && subagentPetLeft < other.left + size && subagentPetLeft + size > other.left + && Math.abs(subagentPetTop + size - other.top) <= SUBAGENT_PET_BOUNDARY_EPSILON); + if (overlaps || !supported || subagentPetLeft < left - SUBAGENT_PET_BOUNDARY_EPSILON || subagentPetLeft + size > right + SUBAGENT_PET_BOUNDARY_EPSILON || subagentPetTop < movement.top - overlay.top - SUBAGENT_PET_BOUNDARY_EPSILON || subagentPetTop + size > bottom + SUBAGENT_PET_BOUNDARY_EPSILON) { displaced = true; subagentPet.fallTo(movement.bottom - overlay.top - size, true); } @@ -3535,6 +3543,7 @@ export class ChatPetWidget extends Disposable { } entry.subagentPet.setScale(subagentPetScale, supportTop ?? entry.top + previousSize - size); } + this._reconcileSubagentPetResize(true); this._scheduleSubagentPetResize(); const displaySize = this._getDisplaySize(); this._button.element.style.width = `${displaySize}px`; diff --git a/src/vs/workbench/contrib/chat/test/browser/widget/chatPetWidget.test.ts b/src/vs/workbench/contrib/chat/test/browser/widget/chatPetWidget.test.ts index f7286ebd2a565b..b89e23a8dab1e5 100644 --- a/src/vs/workbench/contrib/chat/test/browser/widget/chatPetWidget.test.ts +++ b/src/vs/workbench/contrib/chat/test/browser/widget/chatPetWidget.test.ts @@ -3347,6 +3347,31 @@ suite('ChatPetWidget', () => { }); for (const reducedMotion of [false, true]) { + for (const enlarge of [true, false]) { + test(`subagent pets relocate only invalid placements when ${enlarge ? 'enlarged' : 'shrunk'} (${reducedMotion ? 'reduced motion' : 'animated'})`, async () => { + const { widget, firstHost, overlay, service } = createHostTransitionHarness(reducedMotion); + service.setScale(enlarge ? 1 : 2); + const tools = ['first', 'second', 'unaffected'].map(id => { + const tool = new ChatToolInvocation(undefined, { id, displayName: id, modelDescription: 'Subagent', source: ToolDataSource.Internal }, id, undefined, {}); + tool.toolSpecificData = { kind: 'subagent', isActive: true }; + return tool; + }); + widget.setHost({ ...firstHost, model: constObservable(createSubagentTestModel(tools)) }); + const pets = [...overlay.querySelectorAll('.chat-subagent-pet')]; + const positions = enlarge ? [[120, -24], [150, -24], [280, -24]] : [[48, -48], [80, -96], [280, -48]]; + pets.forEach((pet, index) => { + pet.getAnimations().forEach(animation => animation.cancel()); + setSubagentPetPosition(widget, pet, positions[index][0], positions[index][1]); + }); + service.setScale(enlarge ? 2 : 1); + assert.deepStrictEqual(pets.map(pet => Number.parseFloat(pet.style.top) > 0), enlarge ? [true, false, false] : [false, true, false]); + await waitForPetAnimation(() => pets.every(pet => pet.getAnimations().length === 0 && pet.querySelector('img')?.getAttribute('src')?.includes('buddy-idle-') === true)); + const rects = pets.map(pet => pet.getBoundingClientRect()); + assert.ok(rects.every((rect, index) => rects.slice(index + 1).every(other => + rect.right <= other.left + 0.1 || other.right <= rect.left + 0.1 || rect.bottom <= other.top + 0.1 || other.bottom <= rect.top + 0.1))); + }); + } + test(`subagent pets keep their size and only displaced pets respawn (${reducedMotion ? 'reduced motion' : 'animated'})`, async () => { const { widget, firstHost, overlay, firstParent, layout } = createHostTransitionHarness(reducedMotion); const tools = ['stays', 'upper', 'support', 'outside'].map(id => { From 7e264136833d22e723a989f80c3cdd21a906fe98 Mon Sep 17 00:00:00 2001 From: Lisa Rosenberg Date: Thu, 26 Nov 2026 22:21:50 +0100 Subject: [PATCH 61/66] feat: optimize tests --- .../test/browser/widget/chatPetWidget.test.ts | 152 +++++------------- 1 file changed, 40 insertions(+), 112 deletions(-) diff --git a/src/vs/workbench/contrib/chat/test/browser/widget/chatPetWidget.test.ts b/src/vs/workbench/contrib/chat/test/browser/widget/chatPetWidget.test.ts index b89e23a8dab1e5..5817420fb82961 100644 --- a/src/vs/workbench/contrib/chat/test/browser/widget/chatPetWidget.test.ts +++ b/src/vs/workbench/contrib/chat/test/browser/widget/chatPetWidget.test.ts @@ -2967,6 +2967,13 @@ suite('ChatPetWidget', () => { ]); }); + /** Creates an active subagent tool invocation for subagent pet tests. */ + function createSubagentTool(id: string, displayName = id): ChatToolInvocation { + const tool = new ChatToolInvocation(undefined, { id, displayName, modelDescription: 'Subagent', source: ToolDataSource.Internal }, id, undefined, {}); + tool.toolSpecificData = { kind: 'subagent', isActive: true }; + return tool; + } + function createSubagentTestModel(parts: IChatProgressResponseContent[], onDidChange: Event = Event.None): IChatModel { const response = new class extends mock() { override readonly onDidChange = onDidChange; @@ -2996,11 +3003,7 @@ suite('ChatPetWidget', () => { test('subagent pets update only the changed response while tracking older subagents', () => { const { widget, firstHost, overlay } = createHostTransitionHarness(true); const changes = [disposables.add(new Emitter()), disposables.add(new Emitter())]; - const tools = ['older', 'current'].map(id => { - const tool = new ChatToolInvocation(undefined, { id, displayName: id, modelDescription: 'Subagent', source: ToolDataSource.Internal }, id, undefined, {}); - tool.toolSpecificData = { kind: 'subagent', isActive: true }; - return tool; - }); + const tools = ['older', 'current'].map(id => createSubagentTool(id)); const reads = [0, 0]; const requests = tools.map((tool, index) => { const response = new class extends mock() { @@ -3035,8 +3038,7 @@ suite('ChatPetWidget', () => { test('subagent pets react to tool metadata notifications without a response event', () => { const { widget, firstHost, overlay } = createHostTransitionHarness(true); - const tool = new ChatToolInvocation(undefined, { id: 'subagent', displayName: 'Subagent', modelDescription: 'Subagent', source: ToolDataSource.Internal }, 'subagent', undefined, {}); - tool.toolSpecificData = { kind: 'subagent', isActive: true }; + const tool = createSubagentTool('subagent', 'Subagent'); widget.setHost({ ...firstHost, model: constObservable(createSubagentTestModel([tool])) }); assert.strictEqual(overlay.querySelectorAll('.chat-subagent-pet').length, 1); tool.toolSpecificData = { kind: 'subagent', isActive: false }; @@ -3049,12 +3051,7 @@ suite('ChatPetWidget', () => { disposables.add(toDisposable(() => clock.restore())); const { widget, firstHost, overlay } = createHostTransitionHarness(true, undefined, undefined, undefined, undefined, false, undefined, undefined, undefined, 120); const changed = disposables.add(new Emitter()); - const tools = Array.from({ length: 12 }, (_, index) => { - const id = `subagent-${index}`; - const tool = new ChatToolInvocation(undefined, { id, displayName: id, modelDescription: 'Subagent', source: ToolDataSource.Internal }, id, undefined, {}); - tool.toolSpecificData = { kind: 'subagent', isActive: true }; - return tool; - }); + const tools = Array.from({ length: 12 }, (_, index) => createSubagentTool(`subagent-${index}`)); widget.setHost({ ...firstHost, model: constObservable(createSubagentTestModel(tools, changed.event)) }); assert.strictEqual(overlay.querySelectorAll('.chat-subagent-pet').length, 0); tools[1].toolSpecificData = { kind: 'subagent', isActive: false }; @@ -3075,11 +3072,7 @@ suite('ChatPetWidget', () => { const clock = sinon.useFakeTimers({ toFake: ['setTimeout', 'clearTimeout'] }); disposables.add(toDisposable(() => clock.restore())); const { widget, firstHost, overlay, service } = createHostTransitionHarness(true, undefined, undefined, undefined, undefined, false, undefined, undefined, undefined, 120); - const tools = ['first', 'second'].map(id => { - const tool = new ChatToolInvocation(undefined, { id, displayName: id, modelDescription: 'Subagent', source: ToolDataSource.Internal }, id, undefined, {}); - tool.toolSpecificData = { kind: 'subagent', isActive: true }; - return tool; - }); + const tools = ['first', 'second'].map(id => createSubagentTool(id)); const model = observableValue('model', createSubagentTestModel(tools)); widget.setHost({ ...firstHost, model }); clock.tick(120); @@ -3096,12 +3089,7 @@ suite('ChatPetWidget', () => { test('subagent pets fill available slots without replacing active pets', async () => { const { widget, firstHost, overlay } = createHostTransitionHarness(true); const changed = disposables.add(new Emitter()); - const tools = Array.from({ length: 12 }, (_, index) => { - const id = `subagent-${index}`; - const tool = new ChatToolInvocation(undefined, { id, displayName: id, modelDescription: 'Subagent', source: ToolDataSource.Internal }, id, undefined, {}); - tool.toolSpecificData = { kind: 'subagent', isActive: true }; - return tool; - }); + const tools = Array.from({ length: 12 }, (_, index) => createSubagentTool(`subagent-${index}`)); widget.setHost({ ...firstHost, model: constObservable(createSubagentTestModel(tools, changed.event)) }); const initial = [...overlay.querySelectorAll('.chat-subagent-pet')]; assert.strictEqual(initial.length, 10); @@ -3121,13 +3109,8 @@ suite('ChatPetWidget', () => { test('subagent pets preserve waiting order when an earlier response changes', async () => { const { widget, firstHost, overlay } = createHostTransitionHarness(true); const changed = disposables.add(new Emitter()); - const makeTool = (id: string) => { - const tool = new ChatToolInvocation(undefined, { id, displayName: id, modelDescription: 'Subagent', source: ToolDataSource.Internal }, id, undefined, {}); - tool.toolSpecificData = { kind: 'subagent', isActive: true }; - return tool; - }; - const olderTools = Array.from({ length: 11 }, (_, index) => makeTool(`older-${index}`)); - const newerTools = [makeTool('newer')]; + const olderTools = Array.from({ length: 11 }, (_, index) => createSubagentTool(`older-${index}`)); + const newerTools = [createSubagentTool('newer')]; const requests = [olderTools, newerTools].map((parts, index) => { const response = new class extends mock() { override readonly onDidChange = index === 0 ? changed.event : Event.None; @@ -3143,7 +3126,7 @@ suite('ChatPetWidget', () => { override getRequests(): IChatRequestModel[] { return requests; } }(); widget.setHost({ ...firstHost, model: constObservable(model) }); - olderTools.push(makeTool('later')); + olderTools.push(createSubagentTool('later')); changed.fire({ reason: 'other' }); olderTools[0].toolSpecificData = { kind: 'subagent', isActive: false }; changed.fire({ reason: 'other' }); @@ -3162,8 +3145,7 @@ suite('ChatPetWidget', () => { service.unlockAchievement(getChatPetAchievementForAccessory(ChatPetAccessoryIds.CowboyHat).id); service.setAccessory(ChatPetAccessoryIds.CowboyHat); const createSubagent = (id: string) => { - const tool = new ChatToolInvocation(undefined, { id, displayName: id, modelDescription: 'Subagent', source: ToolDataSource.Internal }, id, undefined, {}); - tool.toolSpecificData = { kind: 'subagent', isActive: true }; + const tool = createSubagentTool(id); parts.push(tool); responseChanged.fire({ reason: 'other' }); return tool; @@ -3225,8 +3207,7 @@ suite('ChatPetWidget', () => { const third = createSubagent('third'); const thirdSubagentPet = overlay.querySelectorAll('.chat-subagent-pet')[1]; parts.splice(parts.indexOf(third), 1); - const replacement = new ChatToolInvocation(undefined, { id: 'replacement', displayName: 'Replacement', modelDescription: 'Subagent', source: ToolDataSource.Internal }, 'replacement', undefined, {}); - replacement.toolSpecificData = { kind: 'subagent', isActive: true }; + const replacement = createSubagentTool('replacement', 'Replacement'); parts.push(replacement); responseChanged.fire({ reason: 'other' }); assert.ok(thirdSubagentPet.classList.contains('chat-subagent-pet-despawning')); @@ -3240,8 +3221,7 @@ suite('ChatPetWidget', () => { }); test('subagent pets use restored geometry when the initial model already has a subagent', () => { - const tool = new ChatToolInvocation(undefined, { id: 'subagent', displayName: 'Subagent', modelDescription: 'Subagent', source: ToolDataSource.Internal }, 'subagent', undefined, {}); - tool.toolSpecificData = { kind: 'subagent', isActive: true }; + const tool = createSubagentTool('subagent', 'Subagent'); const model = createSubagentTestModel([tool]); const { button, overlay } = createHostTransitionHarness(true, 'teleport', undefined, undefined, undefined, false, service => { service.setScale(2); @@ -3257,16 +3237,14 @@ suite('ChatPetWidget', () => { const changed = disposables.add(new Emitter()); const parts: IChatProgressResponseContent[] = []; widget.setHost({ ...firstHost, model: constObservable(createSubagentTestModel(parts, changed.event)) }); - const tool = new ChatToolInvocation(undefined, { id: 'first', displayName: 'First', modelDescription: 'Subagent', source: ToolDataSource.Internal }, 'first', undefined, {}); - tool.toolSpecificData = { kind: 'subagent', isActive: true }; + const tool = createSubagentTool('first', 'First'); parts.push(tool); changed.fire({ reason: 'other' }); const first = overlay.querySelector('.chat-subagent-pet')!; await whenSpriteLoaded(first.querySelector('img')!); service.toggle(); assert.strictEqual(first.isConnected, false); - const second = new ChatToolInvocation(undefined, { id: 'second', displayName: 'Second', modelDescription: 'Subagent', source: ToolDataSource.Internal }, 'second', undefined, {}); - second.toolSpecificData = { kind: 'subagent', isActive: true }; + const second = createSubagentTool('second', 'Second'); parts.push(second); changed.fire({ reason: 'other' }); assert.strictEqual(overlay.querySelectorAll('.chat-subagent-pet').length, 0); @@ -3280,8 +3258,7 @@ suite('ChatPetWidget', () => { const parts: IChatProgressResponseContent[] = []; widget.setHost({ ...firstHost, model: constObservable(createSubagentTestModel(parts, changed.event)) }); const add = (id: string) => { - const tool = new ChatToolInvocation(undefined, { id, displayName: id, modelDescription: 'Subagent', source: ToolDataSource.Internal }, id, undefined, {}); - tool.toolSpecificData = { kind: 'subagent', isActive: true }; + const tool = createSubagentTool(id); parts.push(tool); changed.fire({ reason: 'other' }); }; @@ -3303,8 +3280,7 @@ suite('ChatPetWidget', () => { button.style.left = '300px'; const add = (id: string, position: number) => { randomValue = position; - const tool = new ChatToolInvocation(undefined, { id, displayName: id, modelDescription: 'Subagent', source: ToolDataSource.Internal }, id, undefined, {}); - tool.toolSpecificData = { kind: 'subagent', isActive: true }; + const tool = createSubagentTool(id); parts.push(tool); changed.fire({ reason: 'other' }); }; @@ -3330,11 +3306,7 @@ suite('ChatPetWidget', () => { test('subagent pets remain stacked when their size changes', () => { const { widget, firstHost, overlay, service } = createHostTransitionHarness(true); - const tools = ['bottom', 'middle', 'top'].map(id => { - const tool = new ChatToolInvocation(undefined, { id, displayName: id, modelDescription: 'Subagent', source: ToolDataSource.Internal }, id, undefined, {}); - tool.toolSpecificData = { kind: 'subagent', isActive: true }; - return tool; - }); + const tools = ['bottom', 'middle', 'top'].map(id => createSubagentTool(id)); widget.setHost({ ...firstHost, model: constObservable(createSubagentTestModel(tools)) }); const pets = [...overlay.querySelectorAll('.chat-subagent-pet')]; pets.forEach((pet, index) => setSubagentPetPosition(widget, pet, 48, -(index + 1) * 24)); @@ -3351,11 +3323,7 @@ suite('ChatPetWidget', () => { test(`subagent pets relocate only invalid placements when ${enlarge ? 'enlarged' : 'shrunk'} (${reducedMotion ? 'reduced motion' : 'animated'})`, async () => { const { widget, firstHost, overlay, service } = createHostTransitionHarness(reducedMotion); service.setScale(enlarge ? 1 : 2); - const tools = ['first', 'second', 'unaffected'].map(id => { - const tool = new ChatToolInvocation(undefined, { id, displayName: id, modelDescription: 'Subagent', source: ToolDataSource.Internal }, id, undefined, {}); - tool.toolSpecificData = { kind: 'subagent', isActive: true }; - return tool; - }); + const tools = ['first', 'second', 'unaffected'].map(id => createSubagentTool(id)); widget.setHost({ ...firstHost, model: constObservable(createSubagentTestModel(tools)) }); const pets = [...overlay.querySelectorAll('.chat-subagent-pet')]; const positions = enlarge ? [[120, -24], [150, -24], [280, -24]] : [[48, -48], [80, -96], [280, -48]]; @@ -3374,11 +3342,7 @@ suite('ChatPetWidget', () => { test(`subagent pets keep their size and only displaced pets respawn (${reducedMotion ? 'reduced motion' : 'animated'})`, async () => { const { widget, firstHost, overlay, firstParent, layout } = createHostTransitionHarness(reducedMotion); - const tools = ['stays', 'upper', 'support', 'outside'].map(id => { - const tool = new ChatToolInvocation(undefined, { id, displayName: id, modelDescription: 'Subagent', source: ToolDataSource.Internal }, id, undefined, {}); - tool.toolSpecificData = { kind: 'subagent', isActive: true }; - return tool; - }); + const tools = ['stays', 'upper', 'support', 'outside'].map(id => createSubagentTool(id)); widget.setHost({ ...firstHost, model: constObservable(createSubagentTestModel(tools)) }); const subagentPets = [...overlay.querySelectorAll('.chat-subagent-pet')]; const scales = subagentPets.map(subagentPet => subagentPet.style.transform); @@ -3411,8 +3375,7 @@ suite('ChatPetWidget', () => { const clock = sinon.useFakeTimers({ toFake: ['setTimeout', 'clearTimeout'] }); disposables.add(toDisposable(() => clock.restore())); const { widget, firstHost, firstParent, overlay, layout } = createHostTransitionHarness(true); - const tool = new ChatToolInvocation(undefined, { id: 'edge', displayName: 'Edge', modelDescription: 'Subagent', source: ToolDataSource.Internal }, 'edge', undefined, {}); - tool.toolSpecificData = { kind: 'subagent', isActive: true }; + const tool = createSubagentTool('edge', 'Edge'); widget.setHost({ ...firstHost, model: constObservable(createSubagentTestModel([tool])) }); const subagentPet = overlay.querySelector('.chat-subagent-pet')!; setSubagentPetPosition(widget, subagentPet, 98, -24); @@ -3434,8 +3397,7 @@ suite('ChatPetWidget', () => { const tools: ChatToolInvocation[] = []; widget.setHost({ ...firstHost, model: constObservable(createSubagentTestModel(tools, changed.event)) }); button.style.left = '0px'; - const tool = new ChatToolInvocation(undefined, { id: 'edge', displayName: 'Edge', modelDescription: 'Subagent', source: ToolDataSource.Internal }, 'edge', undefined, {}); - tool.toolSpecificData = { kind: 'subagent', isActive: true }; + const tool = createSubagentTool('edge', 'Edge'); tools.push(tool); changed.fire({ reason: 'other' }); const rect = overlay.querySelector('.chat-subagent-pet')!.getBoundingClientRect(); @@ -3462,8 +3424,7 @@ suite('ChatPetWidget', () => { }; for (let index = 0; index < 10; index++) { const id = `subagent-${index}`; - const tool = new ChatToolInvocation(undefined, { id, displayName: id, modelDescription: 'Subagent', source: ToolDataSource.Internal }, id, undefined, {}); - tool.toolSpecificData = { kind: 'subagent', isActive: true }; + const tool = createSubagentTool(id); tools.push(tool); if (staggered) { changed.fire({ reason: 'other' }); @@ -3482,12 +3443,7 @@ suite('ChatPetWidget', () => { test('subagent pets keep their initial size when crowded and resized', async () => { const { widget, firstHost, overlay, firstParent, root, layout } = createHostTransitionHarness(true); const changed = disposables.add(new Emitter()); - const tools = Array.from({ length: 100 }, (_, index) => { - const id = `subagent-${index}`; - const tool = new ChatToolInvocation(undefined, { id, displayName: id, modelDescription: 'Subagent', source: ToolDataSource.Internal }, id, undefined, {}); - tool.toolSpecificData = { kind: 'subagent', isActive: true }; - return tool; - }); + const tools = Array.from({ length: 100 }, (_, index) => createSubagentTool(`subagent-${index}`)); widget.setHost({ ...firstHost, transition: undefined, model: constObservable(createSubagentTestModel(tools, changed.event)) }); const subagentPets = [...overlay.querySelectorAll('.chat-subagent-pet')]; const initialSize = subagentPets[0].getBoundingClientRect().width; @@ -3507,12 +3463,7 @@ suite('ChatPetWidget', () => { test(`subagent pets stay in a bounded area with many subagents (main pet at ${petLeft})`, async () => { const { widget, firstHost, button, overlay, firstParent, root, layout } = createHostTransitionHarness(true); const changed = disposables.add(new Emitter()); - const tools = Array.from({ length: 100 }, (_, index) => { - const id = `subagent-${index}`; - const tool = new ChatToolInvocation(undefined, { id, displayName: id, modelDescription: 'Subagent', source: ToolDataSource.Internal }, id, undefined, {}); - tool.toolSpecificData = { kind: 'subagent', isActive: true }; - return tool; - }); + const tools = Array.from({ length: 100 }, (_, index) => createSubagentTool(`subagent-${index}`)); button.style.left = `${petLeft}px`; widget.setHost({ ...firstHost, transition: undefined, model: constObservable(createSubagentTestModel(tools, changed.event)) }); const subagentPets = [...overlay.querySelectorAll('.chat-subagent-pet')]; @@ -3566,11 +3517,7 @@ suite('ChatPetWidget', () => { test(`subagent pets fall when their ${removedIndex === 0 ? 'bottom' : 'middle'} support finishes (${reducedMotion ? 'reduced motion' : 'animated'})`, () => { const { widget, firstHost, overlay, setReducedMotion } = createHostTransitionHarness(reducedMotion); const changed = disposables.add(new Emitter()); - const tools = ['bottom', 'middle', 'top', 'neighbor'].map(id => { - const tool = new ChatToolInvocation(undefined, { id, displayName: id, modelDescription: 'Subagent', source: ToolDataSource.Internal }, id, undefined, {}); - tool.toolSpecificData = { kind: 'subagent', isActive: true }; - return tool; - }); + const tools = ['bottom', 'middle', 'top', 'neighbor'].map(id => createSubagentTool(id)); widget.setHost({ ...firstHost, model: constObservable(createSubagentTestModel(tools, changed.event)) }); const subagentPets = [...overlay.querySelectorAll('.chat-subagent-pet')]; // A three-high stack on the input platform and an independent neighbor on the ground. @@ -3611,12 +3558,7 @@ suite('ChatPetWidget', () => { const { widget, firstHost, overlay, firstParent, button } = createHostTransitionHarness(true); firstParent.style.width = '240px'; button.style.left = '192px'; - const tools = Array.from({ length: 20 }, (_, index) => { - const id = `subagent-${index}`; - const tool = new ChatToolInvocation(undefined, { id, displayName: id, modelDescription: 'Subagent', source: ToolDataSource.Internal }, id, undefined, {}); - tool.toolSpecificData = { kind: 'subagent', isActive: true }; - return tool; - }); + const tools = Array.from({ length: 20 }, (_, index) => createSubagentTool(`subagent-${index}`)); widget.setHost({ ...firstHost, model: constObservable(createSubagentTestModel(tools)), getPlatforms: () => { const bounds = firstParent.getBoundingClientRect(); return [{ left: bounds.left + 20, right: bounds.right - 20, top: bounds.top - 60, isDefault: true }]; @@ -3636,11 +3578,7 @@ suite('ChatPetWidget', () => { test(`subagent pets fall and respawn when a prompt replaces their support (${reducedMotion ? 'reduced motion' : 'animated'})`, async () => { const { widget, firstHost, overlay, firstParent, root, platformChanged } = createHostTransitionHarness(reducedMotion); let promptVisible = false; - const tools = ['first', 'second'].map(id => { - const tool = new ChatToolInvocation(undefined, { id, displayName: id, modelDescription: 'Subagent', source: ToolDataSource.Internal }, id, undefined, {}); - tool.toolSpecificData = { kind: 'subagent', isActive: true }; - return tool; - }); + const tools = ['first', 'second'].map(id => createSubagentTool(id)); widget.setHost({ ...firstHost, model: constObservable(createSubagentTestModel(tools)), getPlatforms: () => { const bounds = firstParent.getBoundingClientRect(); return [{ left: bounds.left, right: bounds.right, top: bounds.top - (promptVisible ? 60 : 0), isDefault: true }]; @@ -3667,8 +3605,7 @@ suite('ChatPetWidget', () => { const { widget, firstHost, overlay, firstParent, platformChanged } = createHostTransitionHarness(true); const changed = disposables.add(new Emitter()); let promptVisible = false; - const tool = new ChatToolInvocation(undefined, { id: 'subagent', displayName: 'Subagent', modelDescription: 'Subagent', source: ToolDataSource.Internal }, 'subagent', undefined, {}); - tool.toolSpecificData = { kind: 'subagent', isActive: true }; + const tool = createSubagentTool('subagent', 'Subagent'); widget.setHost({ ...firstHost, model: constObservable(createSubagentTestModel([tool], changed.event)), getPlatforms: () => { const bounds = firstParent.getBoundingClientRect(); return [{ left: bounds.left, right: bounds.right, top: bounds.top - (promptVisible ? 60 : 0), isDefault: true }]; @@ -3686,8 +3623,7 @@ suite('ChatPetWidget', () => { test('subagent pets update appearance and motion settings while active', async () => { const { widget, firstHost, button, overlay, service, setReducedMotion } = createHostTransitionHarness(); - const tool = new ChatToolInvocation(undefined, { id: 'subagent', displayName: 'Subagent', modelDescription: 'Subagent', source: ToolDataSource.Internal }, 'subagent', undefined, {}); - tool.toolSpecificData = { kind: 'subagent', isActive: true }; + const tool = createSubagentTool('subagent', 'Subagent'); widget.setHost({ ...firstHost, model: constObservable(createSubagentTestModel([tool])) }); const subagentPet = overlay.querySelector('.chat-subagent-pet')!; subagentPet.getAnimations().forEach(animation => animation.cancel()); @@ -3720,8 +3656,7 @@ suite('ChatPetWidget', () => { test('subagent pets stop squishing when reduced motion is enabled during landing', async () => { const { widget, firstHost, overlay, setReducedMotion } = createHostTransitionHarness(); - const tool = new ChatToolInvocation(undefined, { id: 'subagent', displayName: 'Subagent', modelDescription: 'Subagent', source: ToolDataSource.Internal }, 'subagent', undefined, {}); - tool.toolSpecificData = { kind: 'subagent', isActive: true }; + const tool = createSubagentTool('subagent', 'Subagent'); widget.setHost({ ...firstHost, model: constObservable(createSubagentTestModel([tool])) }); const subagentPet = overlay.querySelector('.chat-subagent-pet')!; const image = subagentPet.querySelector('img')!; @@ -3741,11 +3676,7 @@ suite('ChatPetWidget', () => { disposables.add(toDisposable(() => clock.restore())); const { widget, firstHost, overlay } = createHostTransitionHarness(); const changed = disposables.add(new Emitter()); - const tools = ['first', 'second'].map(id => { - const tool = new ChatToolInvocation(undefined, { id, displayName: id, modelDescription: 'Subagent', source: ToolDataSource.Internal }, id, undefined, {}); - tool.toolSpecificData = { kind: 'subagent', isActive: true }; - return tool; - }); + const tools = ['first', 'second'].map(id => createSubagentTool(id)); widget.setHost({ ...firstHost, model: constObservable(createSubagentTestModel(tools, changed.event)) }); const [first, second] = overlay.querySelectorAll('.chat-subagent-pet'); for (const subagentPet of [first, second]) { @@ -3782,8 +3713,7 @@ suite('ChatPetWidget', () => { test('subagent pets use the reduced-motion disappearance sprite', () => { const { widget, firstHost, overlay } = createHostTransitionHarness(true); const changed = disposables.add(new Emitter()); - const tool = new ChatToolInvocation(undefined, { id: 'subagent', displayName: 'Subagent', modelDescription: 'Subagent', source: ToolDataSource.Internal }, 'subagent', undefined, {}); - tool.toolSpecificData = { kind: 'subagent', isActive: true }; + const tool = createSubagentTool('subagent', 'Subagent'); widget.setHost({ ...firstHost, model: constObservable(createSubagentTestModel([tool], changed.event)) }); assert.ok(overlay.querySelector('.chat-subagent-pet')); const subagentPet = overlay.querySelector('.chat-subagent-pet')!; @@ -3808,8 +3738,7 @@ suite('ChatPetWidget', () => { } const { widget, firstHost, overlay } = createHostTransitionHarness(false, 'teleport', 'stable', VisibilityObserver); const responseChanged = disposables.add(new Emitter()); - const tool = new ChatToolInvocation(undefined, { id: 'subagent', displayName: 'Subagent', modelDescription: 'Subagent', source: ToolDataSource.Internal }, 'subagent', undefined, {}); - tool.toolSpecificData = { kind: 'subagent', isActive: true }; + const tool = createSubagentTool('subagent', 'Subagent'); widget.setHost({ ...firstHost, model: constObservable(createSubagentTestModel([tool], responseChanged.event)) }); const pet = overlay.querySelector('.chat-subagent-pet')!; pet.getAnimations().forEach(animation => animation.cancel()); @@ -3843,8 +3772,7 @@ suite('ChatPetWidget', () => { const clock = sinon.useFakeTimers({ toFake: ['setTimeout', 'clearTimeout', 'performance'] }); disposables.add(toDisposable(() => clock.restore())); const { widget, firstHost, overlay, setReducedMotion } = createSubagentPetTestHarness(() => 0); - const tool = new ChatToolInvocation(undefined, { id: 'subagent', displayName: 'Subagent', modelDescription: 'Subagent', source: ToolDataSource.Internal }, 'subagent', undefined, {}); - tool.toolSpecificData = { kind: 'subagent', isActive: true }; + const tool = createSubagentTool('subagent', 'Subagent'); widget.setHost({ ...firstHost, model: constObservable(createSubagentTestModel([tool])) }); const subagentPet = overlay.querySelector('.chat-subagent-pet')!; // Exercise idle frames independently of the arrival and landing animation. From dcac4e2ee1f45ca2fa71e29145e6d82eaa8c4778 Mon Sep 17 00:00:00 2001 From: Lisa Rosenberg Date: Thu, 26 Nov 2026 22:24:53 +0100 Subject: [PATCH 62/66] feat: optimize tests --- .../test/browser/widget/chatPetWidget.test.ts | 28 +++++++++++-------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/src/vs/workbench/contrib/chat/test/browser/widget/chatPetWidget.test.ts b/src/vs/workbench/contrib/chat/test/browser/widget/chatPetWidget.test.ts index 5817420fb82961..92cdda9e0b4419 100644 --- a/src/vs/workbench/contrib/chat/test/browser/widget/chatPetWidget.test.ts +++ b/src/vs/workbench/contrib/chat/test/browser/widget/chatPetWidget.test.ts @@ -114,7 +114,13 @@ suite('ChatPetWidget', () => { } } - function createHostTransitionHarness(motionReduced = false, initialTransition: IChatPetWidgetHost['transition'] = 'teleport', color?: ChatPetColor, intersectionObserverCtor?: typeof IntersectionObserver, setPlatformOccupation?: IChatPetWidgetHost['setPlatformOccupation'], supportsJumpGame = false, initializeService?: (service: ChatPetService) => void, initialModel?: IChatModel, random?: () => number, subagentPetArrivalDelay = 0) { + interface SubagentPetTestOptions { + readonly initialModel?: IChatModel; + readonly random?: () => number; + readonly subagentPetArrivalDelay?: number; + } + + function createHostTransitionHarness(motionReduced = false, initialTransition: IChatPetWidgetHost['transition'] = 'teleport', color?: ChatPetColor, intersectionObserverCtor?: typeof IntersectionObserver, setPlatformOccupation?: IChatPetWidgetHost['setPlatformOccupation'], supportsJumpGame = false, initializeService?: (service: ChatPetService) => void, options: SubagentPetTestOptions = {}) { const root = mainWindow.document.createElement('div'); root.style.cssText = 'position:fixed;left:0;top:0;width:800px;height:640px'; if (supportsJumpGame) { @@ -155,7 +161,7 @@ suite('ChatPetWidget', () => { onDidChangePlatform: platformChanged.event, setPlatformOccupation, }); - const firstHost = { ...createHost(firstParent, initialTransition), model: constObservable(initialModel) }; + const firstHost = { ...createHost(firstParent, initialTransition), model: constObservable(options.initialModel) }; const secondHost: IChatPetWidgetHost = { ...createHost(secondParent, 'fall'), model: constObservable(new class extends mock() { @@ -179,7 +185,7 @@ suite('ChatPetWidget', () => { } initializeService?.(service); const widget = disposables.add(new ChatPetWidget( - firstHost, { resizeObserverCtor: TestResizeObserver, intersectionObserverCtor, random, subagentPetArrivalDelay }, service, accessibilityService, + firstHost, { resizeObserverCtor: TestResizeObserver, intersectionObserverCtor, random: options.random, subagentPetArrivalDelay: options.subagentPetArrivalDelay ?? 0 }, service, accessibilityService, new class extends mock() { override showContextMenu(delegate: IContextMenuDelegate): void { contextMenu = delegate; } }(), @@ -208,8 +214,8 @@ suite('ChatPetWidget', () => { }; } - function createSubagentPetTestHarness(random: () => number, motionReduced = false) { - return createHostTransitionHarness(motionReduced, undefined, undefined, undefined, undefined, false, undefined, undefined, random); + function createSubagentPetTestHarness(options: SubagentPetTestOptions = {}, motionReduced = false) { + return createHostTransitionHarness(motionReduced, undefined, undefined, undefined, undefined, false, undefined, options); } /** @@ -3049,7 +3055,7 @@ suite('ChatPetWidget', () => { test('subagent pets arrive in sequence and skip subagents that have finished', () => { const clock = sinon.useFakeTimers({ toFake: ['setTimeout', 'clearTimeout'] }); disposables.add(toDisposable(() => clock.restore())); - const { widget, firstHost, overlay } = createHostTransitionHarness(true, undefined, undefined, undefined, undefined, false, undefined, undefined, undefined, 120); + const { widget, firstHost, overlay } = createSubagentPetTestHarness({ subagentPetArrivalDelay: 120 }, true); const changed = disposables.add(new Emitter()); const tools = Array.from({ length: 12 }, (_, index) => createSubagentTool(`subagent-${index}`)); widget.setHost({ ...firstHost, model: constObservable(createSubagentTestModel(tools, changed.event)) }); @@ -3071,7 +3077,7 @@ suite('ChatPetWidget', () => { test('subagent pet arrivals stop when disabled or the model changes', () => { const clock = sinon.useFakeTimers({ toFake: ['setTimeout', 'clearTimeout'] }); disposables.add(toDisposable(() => clock.restore())); - const { widget, firstHost, overlay, service } = createHostTransitionHarness(true, undefined, undefined, undefined, undefined, false, undefined, undefined, undefined, 120); + const { widget, firstHost, overlay, service } = createSubagentPetTestHarness({ subagentPetArrivalDelay: 120 }, true); const tools = ['first', 'second'].map(id => createSubagentTool(id)); const model = observableValue('model', createSubagentTestModel(tools)); widget.setHost({ ...firstHost, model }); @@ -3226,7 +3232,7 @@ suite('ChatPetWidget', () => { const { button, overlay } = createHostTransitionHarness(true, 'teleport', undefined, undefined, undefined, false, service => { service.setScale(2); service.setHorizontalPosition(0.8); - }, model); + }, { initialModel: model }); const subagentPet = overlay.querySelector('.chat-subagent-pet')!; assert.strictEqual(Number.parseFloat(subagentPet.style.transform.slice(6)), 1); assert.ok(subagentPet.offsetLeft + 48 <= button.offsetLeft || subagentPet.offsetLeft >= button.offsetLeft + button.offsetWidth); @@ -3273,7 +3279,7 @@ suite('ChatPetWidget', () => { test('subagent pets spawn across the platform and stack where their paths overlap', async () => { let randomValue = 0; - const { widget, firstHost, button, overlay, firstParent, layout } = createSubagentPetTestHarness(() => randomValue, true); + const { widget, firstHost, button, overlay, firstParent, layout } = createSubagentPetTestHarness({ random: () => randomValue }, true); const changed = disposables.add(new Emitter()); const parts: IChatProgressResponseContent[] = []; widget.setHost({ ...firstHost, model: constObservable(createSubagentTestModel(parts, changed.event)) }); @@ -3389,7 +3395,7 @@ suite('ChatPetWidget', () => { }); test('subagent pets spawn inside the visible window when their platform extends beyond it', () => { - const { widget, firstHost, root, firstParent, button, overlay } = createSubagentPetTestHarness(() => 0.99, true); + const { widget, firstHost, root, firstParent, button, overlay } = createSubagentPetTestHarness({ random: () => 0.99 }, true); root.style.width = `${mainWindow.innerWidth + 240}px`; firstParent.style.left = `${mainWindow.innerWidth - 80}px`; firstParent.style.width = '240px'; @@ -3771,7 +3777,7 @@ suite('ChatPetWidget', () => { test('subagent pets blink and move their eyes with their own idle frames', async () => { const clock = sinon.useFakeTimers({ toFake: ['setTimeout', 'clearTimeout', 'performance'] }); disposables.add(toDisposable(() => clock.restore())); - const { widget, firstHost, overlay, setReducedMotion } = createSubagentPetTestHarness(() => 0); + const { widget, firstHost, overlay, setReducedMotion } = createSubagentPetTestHarness({ random: () => 0 }); const tool = createSubagentTool('subagent', 'Subagent'); widget.setHost({ ...firstHost, model: constObservable(createSubagentTestModel([tool])) }); const subagentPet = overlay.querySelector('.chat-subagent-pet')!; From b938f7c9ef703ad2795f23b56537ca6bab8a4b2a Mon Sep 17 00:00:00 2001 From: Lisa Rosenberg Date: Thu, 26 Nov 2026 22:27:20 +0100 Subject: [PATCH 63/66] feat: improve performance --- .../workbench/contrib/chat/browser/widget/chatPetWidget.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/vs/workbench/contrib/chat/browser/widget/chatPetWidget.ts b/src/vs/workbench/contrib/chat/browser/widget/chatPetWidget.ts index 50e1be05f69189..d70afc1ba0c077 100644 --- a/src/vs/workbench/contrib/chat/browser/widget/chatPetWidget.ts +++ b/src/vs/workbench/contrib/chat/browser/widget/chatPetWidget.ts @@ -3492,10 +3492,13 @@ export class ChatPetWidget extends Disposable { /** Relocates pets outside the bounds, also checking overlaps and support after scaling. */ private _reconcileSubagentPetResize(checkPlacement = false): void { - const subagentPets = [...this._subagentPets.values()].filter(subagentPet => !subagentPet.isRespawning()).sort((a, b) => b.top - a.top); + const subagentPets = [...this._subagentPets.values()].filter(subagentPet => !subagentPet.isRespawning()); if (!subagentPets.length) { return; } + if (checkPlacement) { + subagentPets.sort((a, b) => b.top - a.top); + } const { overlay, movement, platforms, floor, left, right, bottom } = this._getSubagentPetBounds(); const size = getSubagentPetSize(this._scale); let displaced = false; From 1450e8611e9318b87b67117222ba07a025a155f2 Mon Sep 17 00:00:00 2001 From: Lisa Rosenberg Date: Thu, 26 Nov 2026 22:35:17 +0100 Subject: [PATCH 64/66] feat: optimize code --- .../chat/browser/widget/chatPetWidget.ts | 26 ++++++++++++------- .../test/browser/widget/chatPetWidget.test.ts | 12 +++++---- 2 files changed, 24 insertions(+), 14 deletions(-) diff --git a/src/vs/workbench/contrib/chat/browser/widget/chatPetWidget.ts b/src/vs/workbench/contrib/chat/browser/widget/chatPetWidget.ts index d70afc1ba0c077..9a29b8edb1b998 100644 --- a/src/vs/workbench/contrib/chat/browser/widget/chatPetWidget.ts +++ b/src/vs/workbench/contrib/chat/browser/widget/chatPetWidget.ts @@ -3505,15 +3505,23 @@ export class ChatPetWidget extends Disposable { for (const subagentPet of subagentPets) { const subagentPetLeft = subagentPet.left; const subagentPetTop = subagentPet.top; - const overlaps = checkPlacement && subagentPets.some(other => other !== subagentPet && !other.isRespawning() - && subagentPetLeft < other.left + size - SUBAGENT_PET_BOUNDARY_EPSILON && subagentPetLeft + size > other.left + SUBAGENT_PET_BOUNDARY_EPSILON - && subagentPetTop < other.top + size - SUBAGENT_PET_BOUNDARY_EPSILON && subagentPetTop + size > other.top + SUBAGENT_PET_BOUNDARY_EPSILON); - const landing = checkPlacement ? getChatPetFallTarget(overlay.left + subagentPetLeft, overlay.top + subagentPetTop - POSITION_EPSILON, size, size, platforms, floor) : undefined; - const supported = !landing || Math.abs(landing.top - overlay.top - subagentPetTop) <= SUBAGENT_PET_BOUNDARY_EPSILON - || subagentPets.some(other => other !== subagentPet && !other.isRespawning() - && subagentPetLeft < other.left + size && subagentPetLeft + size > other.left - && Math.abs(subagentPetTop + size - other.top) <= SUBAGENT_PET_BOUNDARY_EPSILON); - if (overlaps || !supported || subagentPetLeft < left - SUBAGENT_PET_BOUNDARY_EPSILON || subagentPetLeft + size > right + SUBAGENT_PET_BOUNDARY_EPSILON || subagentPetTop < movement.top - overlay.top - SUBAGENT_PET_BOUNDARY_EPSILON || subagentPetTop + size > bottom + SUBAGENT_PET_BOUNDARY_EPSILON) { + const outsideBounds = subagentPetLeft < left - SUBAGENT_PET_BOUNDARY_EPSILON + || subagentPetLeft + size > right + SUBAGENT_PET_BOUNDARY_EPSILON + || subagentPetTop < movement.top - overlay.top - SUBAGENT_PET_BOUNDARY_EPSILON + || subagentPetTop + size > bottom + SUBAGENT_PET_BOUNDARY_EPSILON; + let invalidPlacement = false; + if (checkPlacement) { + const overlaps = subagentPets.some(other => other !== subagentPet && !other.isRespawning() + && subagentPetLeft < other.left + size - SUBAGENT_PET_BOUNDARY_EPSILON && subagentPetLeft + size > other.left + SUBAGENT_PET_BOUNDARY_EPSILON + && subagentPetTop < other.top + size - SUBAGENT_PET_BOUNDARY_EPSILON && subagentPetTop + size > other.top + SUBAGENT_PET_BOUNDARY_EPSILON); + const landing = getChatPetFallTarget(overlay.left + subagentPetLeft, overlay.top + subagentPetTop - POSITION_EPSILON, size, size, platforms, floor); + const supported = Math.abs(landing.top - overlay.top - subagentPetTop) <= SUBAGENT_PET_BOUNDARY_EPSILON + || subagentPets.some(other => other !== subagentPet && !other.isRespawning() + && subagentPetLeft < other.left + size && subagentPetLeft + size > other.left + && Math.abs(subagentPetTop + size - other.top) <= SUBAGENT_PET_BOUNDARY_EPSILON); + invalidPlacement = overlaps || !supported; + } + if (outsideBounds || invalidPlacement) { displaced = true; subagentPet.fallTo(movement.bottom - overlay.top - size, true); } diff --git a/src/vs/workbench/contrib/chat/test/browser/widget/chatPetWidget.test.ts b/src/vs/workbench/contrib/chat/test/browser/widget/chatPetWidget.test.ts index 92cdda9e0b4419..b903cb92e50ae8 100644 --- a/src/vs/workbench/contrib/chat/test/browser/widget/chatPetWidget.test.ts +++ b/src/vs/workbench/contrib/chat/test/browser/widget/chatPetWidget.test.ts @@ -3222,7 +3222,7 @@ suite('ChatPetWidget', () => { assert.ok(overlay.querySelector('.chat-subagent-pet-despawning img')?.getAttribute('src')?.includes('buddy-respawn-')); modelValue.set(undefined, undefined); assert.strictEqual(overlay.querySelectorAll('.chat-subagent-pet').length, 0); - await timeout(900); + await waitForPetAnimation(() => !overlay.querySelector('.chat-subagent-pet-despawning')); assert.strictEqual(overlay.querySelectorAll('.chat-subagent-pet-despawning').length, 0); }); @@ -3446,7 +3446,9 @@ suite('ChatPetWidget', () => { } } - test('subagent pets keep their initial size when crowded and resized', async () => { + test('subagent pets keep their initial size when crowded and resized', () => { + const clock = sinon.useFakeTimers({ toFake: ['setTimeout', 'clearTimeout'] }); + disposables.add(toDisposable(() => clock.restore())); const { widget, firstHost, overlay, firstParent, root, layout } = createHostTransitionHarness(true); const changed = disposables.add(new Emitter()); const tools = Array.from({ length: 100 }, (_, index) => createSubagentTool(`subagent-${index}`)); @@ -3460,7 +3462,7 @@ suite('ChatPetWidget', () => { root.style.height = '64px'; firstParent.style.top = '32px'; layout(); - await timeout(50); + clock.tick(16); assert.ok(subagentPets.every(subagentPet => Math.abs(subagentPet.getBoundingClientRect().width - initialSize) < 0.1)); } }); @@ -3589,8 +3591,8 @@ suite('ChatPetWidget', () => { const bounds = firstParent.getBoundingClientRect(); return [{ left: bounds.left, right: bounds.right, top: bounds.top - (promptVisible ? 60 : 0), isDefault: true }]; } }); - await timeout(1_300); const subagentPets = [...overlay.querySelectorAll('.chat-subagent-pet')]; + await waitForPetAnimation(() => subagentPets.every(subagentPet => subagentPet.getAnimations().length === 0 && subagentPet.querySelector('img')?.getAttribute('src')?.includes('buddy-idle-') === true)); promptVisible = true; platformChanged.fire(); assert.ok(subagentPets.every(subagentPet => Math.abs(Number.parseFloat(subagentPet.style.top) + 24 + overlay.getBoundingClientRect().top - root.getBoundingClientRect().bottom) < 0.1)); @@ -3623,7 +3625,7 @@ suite('ChatPetWidget', () => { assert.ok(image.getAttribute('src')?.includes('buddy-respawn-')); tool.toolSpecificData = { kind: 'subagent', isActive: false }; changed.fire({ reason: 'other' }); - await timeout(1_000); + await waitForPetAnimation(() => !overlay.querySelector('.chat-subagent-pet, .chat-subagent-pet-despawning')); assert.strictEqual(overlay.querySelectorAll('.chat-subagent-pet, .chat-subagent-pet-despawning').length, 0); }); From ad87593bf3bdde0749cbb447047d75e2b88457be Mon Sep 17 00:00:00 2001 From: Lisa Rosenberg Date: Thu, 26 Nov 2026 22:39:31 +0100 Subject: [PATCH 65/66] feat: optimize code --- .../contrib/chat/test/browser/widget/chatPetWidget.test.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/vs/workbench/contrib/chat/test/browser/widget/chatPetWidget.test.ts b/src/vs/workbench/contrib/chat/test/browser/widget/chatPetWidget.test.ts index b903cb92e50ae8..eea11a1c365c31 100644 --- a/src/vs/workbench/contrib/chat/test/browser/widget/chatPetWidget.test.ts +++ b/src/vs/workbench/contrib/chat/test/browser/widget/chatPetWidget.test.ts @@ -3450,9 +3450,8 @@ suite('ChatPetWidget', () => { const clock = sinon.useFakeTimers({ toFake: ['setTimeout', 'clearTimeout'] }); disposables.add(toDisposable(() => clock.restore())); const { widget, firstHost, overlay, firstParent, root, layout } = createHostTransitionHarness(true); - const changed = disposables.add(new Emitter()); const tools = Array.from({ length: 100 }, (_, index) => createSubagentTool(`subagent-${index}`)); - widget.setHost({ ...firstHost, transition: undefined, model: constObservable(createSubagentTestModel(tools, changed.event)) }); + widget.setHost({ ...firstHost, transition: undefined, model: constObservable(createSubagentTestModel(tools)) }); const subagentPets = [...overlay.querySelectorAll('.chat-subagent-pet')]; const initialSize = subagentPets[0].getBoundingClientRect().width; assert.ok(Math.abs(initialSize - 24) < 0.1); From 1ad4812794c687ed1e657bd39b6dc73a6a1cbc89 Mon Sep 17 00:00:00 2001 From: Lisa Rosenberg Date: Thu, 26 Nov 2026 22:40:55 +0100 Subject: [PATCH 66/66] feat: optimize code --- src/vs/workbench/contrib/chat/browser/widget/chatPetWidget.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/vs/workbench/contrib/chat/browser/widget/chatPetWidget.ts b/src/vs/workbench/contrib/chat/browser/widget/chatPetWidget.ts index 9a29b8edb1b998..b0c45f5f37b656 100644 --- a/src/vs/workbench/contrib/chat/browser/widget/chatPetWidget.ts +++ b/src/vs/workbench/contrib/chat/browser/widget/chatPetWidget.ts @@ -3510,7 +3510,7 @@ export class ChatPetWidget extends Disposable { || subagentPetTop < movement.top - overlay.top - SUBAGENT_PET_BOUNDARY_EPSILON || subagentPetTop + size > bottom + SUBAGENT_PET_BOUNDARY_EPSILON; let invalidPlacement = false; - if (checkPlacement) { + if (checkPlacement && !outsideBounds) { const overlaps = subagentPets.some(other => other !== subagentPet && !other.isRespawning() && subagentPetLeft < other.left + size - SUBAGENT_PET_BOUNDARY_EPSILON && subagentPetLeft + size > other.left + SUBAGENT_PET_BOUNDARY_EPSILON && subagentPetTop < other.top + size - SUBAGENT_PET_BOUNDARY_EPSILON && subagentPetTop + size > other.top + SUBAGENT_PET_BOUNDARY_EPSILON);