diff --git a/browser_tests/tests/agent/desktopAgentConsent.spec.ts b/browser_tests/tests/agent/desktopAgentConsent.spec.ts index feed45a8c80..a504ee02b59 100644 --- a/browser_tests/tests/agent/desktopAgentConsent.spec.ts +++ b/browser_tests/tests/agent/desktopAgentConsent.spec.ts @@ -16,7 +16,7 @@ test.describe('Desktop Agent consent', { tag: ['@desktop', '@ui'] }, () => { initialLocalStorage: { [AGENT_COACH_SEEN_KEY]: 'true' } }) - test('keeps the panel locked after Skip and asks again only on Send', async ({ + test('remembers Skip, opens the panel for two launches, and asks again only on Send', async ({ comfyPage, agentPanel, agentConsentWrites, @@ -49,7 +49,7 @@ test.describe('Desktop Agent consent', { tag: ['@desktop', '@ui'] }, () => { await expect(agentPanel.consentDialog).toHaveCount(0) }) - await test.step('The next launch keeps the locked panel without repeating the introduction', async () => { + await test.step('The second launch opens the panel again without repeating the introduction', async () => { await agentPanel.openButton.click() await expect(agentPanel.root).toHaveCount(0) await expect(agentPanel.openButton).toHaveAttribute( @@ -62,6 +62,21 @@ test.describe('Desktop Agent consent', { tag: ['@desktop', '@ui'] }, () => { expect(agentConsentWrites).toEqual([]) }) + await test.step('The third launch leaves the closed panel and the card closed', async () => { + await agentPanel.openButton.click() + await expect(agentPanel.root).toHaveCount(0) + await comfyPage.workflow.reloadAndWaitForApp() + await expect(agentPanel.openButton).toHaveAttribute( + 'aria-pressed', + 'false' + ) + await expect(agentPanel.root).toHaveCount(0) + await expect(agentPanel.consentDialog).toHaveCount(0) + await agentPanel.openButton.click() + await expect(agentPanel.root).toBeVisible() + expect(agentConsentWrites).toEqual([]) + }) + await test.step('Send requests consent while preserving the original draft', async () => { await agentPanel.composer.fill('Keep this Desktop draft until consent') await agentPanel.sendButton.click() diff --git a/docs/adr/AGENT-CONSENT-0045-desktop-introduction-response-is-not-consent.md b/docs/adr/AGENT-CONSENT-0045-desktop-introduction-response-is-not-consent.md index dfc40e810f2..6b0114cb782 100644 --- a/docs/adr/AGENT-CONSENT-0045-desktop-introduction-response-is-not-consent.md +++ b/docs/adr/AGENT-CONSENT-0045-desktop-introduction-response-is-not-consent.md @@ -20,19 +20,20 @@ account/workspace consent setting. Only Agree or Skip sets this marker; display and dismissal do not. The marker controls automatic startup offers, never Agent access. It lives in renderer storage, keyed by scope like Cloud's one-shot offer key: `signed-out`, or the account and workspace. Signed-out users can respond, -the response survives restarts, and a scope that has not answered still gets -one card. +the response survives restarts, and a scope that has not answered can still +get a card under the startup rules below. -For eligible, ready Desktop installations, unfinished consent opens the locked -panel on each startup after authentication and onboarding settle, independently -of Cloud's activation visit limit. The response marker suppresses only the -startup introduction for its scope, so signing in or switching to an -unanswered account or workspace queues a card after the screen clears. The Local entry button only -toggles the panel; Send owns the consent request. +For eligible, ready Desktop installations, the panel opens automatically on +startup for Cloud's activation visits, whether or not the user skipped consent or +closed the panel, and then stops. The response marker suppresses only the +startup introduction for its scope. While visits remain, or while the panel is +open, signing in or switching to an unanswered account or workspace queues a +card after the screen clears. The Local entry button only toggles the panel; +Send owns the consent request. Cloud's account-wide explicit-refusal preference remains separate. Desktop Skip does not write that preference, and an existing Cloud refusal does not suppress -the Desktop introduction or recurring locked panel. Neither preference records +the Desktop introduction or the startup panel. Neither preference records audited server consent. `agentPanelStore` selects one onboarding policy for the whole frontend, and no diff --git a/src/extensions/core/agentPanel.test.ts b/src/extensions/core/agentPanel.test.ts index 2c3a667c733..8f6183b36d1 100644 --- a/src/extensions/core/agentPanel.test.ts +++ b/src/extensions/core/agentPanel.test.ts @@ -280,10 +280,27 @@ describe('AgentPanel extension flag gate', () => { ) }) - it('keeps Local introduction and its locked panel independent of Cloud refusal', async () => { + it('does not show the startup card once the agent stops being ready before it mounts', async () => { + currentUser.value = null + let canShow: boolean | undefined + vi.mocked(useAgentConsent().withConsent).mockImplementationOnce( + async (_trigger, _onAccept, hooks) => { + setAgentReady(false) + await nextTick() + canShow = hooks?.canShow?.() + } + ) + + await loadEntryAndSetup() + await flush() + + expect(useAgentConsent().withConsent).toHaveBeenCalledOnce() + expect(canShow).toBe(false) + }) + + it('keeps Local introduction and its startup panel independent of Cloud refusal', async () => { useSettingStore().settingValues[AGENT_CONSENT_OFFER_DECLINED_SETTING_ID] = true - localStorage.setItem(ACTIVATION_VISITS_STORAGE_KEY, '2') await loadEntryAndSetup() await flush() @@ -299,11 +316,10 @@ describe('AgentPanel extension flag gate', () => { visits: '0' }, { - session: 'signed in after discovery', + session: 'signed in on second visit', user: { id: 'account-a' }, - visits: '2' - }, - { session: 'signed out after discovery', user: null, visits: '2' } + visits: '1' + } ])('offers consent on startup when $session', async ({ user, visits }) => { currentUser.value = user localStorage.setItem(ACTIVATION_VISITS_STORAGE_KEY, visits) @@ -322,6 +338,23 @@ describe('AgentPanel extension flag gate', () => { ) }) + it.for([ + { session: 'signed out', user: null }, + { session: 'signed in', user: { id: 'account-a' } } + ])( + 'leaves the panel and card closed when $session after the two activation visits', + async ({ user }) => { + currentUser.value = user + localStorage.setItem(ACTIVATION_VISITS_STORAGE_KEY, '2') + + await loadEntryAndSetup() + await flush() + + expect(agentStore.isVisible).toBe(false) + expect(useAgentConsent().withConsent).not.toHaveBeenCalled() + } + ) + it.for([ { surface: 'dialog', hold: openDialog, release: closeDialog }, { @@ -369,7 +402,7 @@ describe('AgentPanel extension flag gate', () => { await flush() expect(useAgentConsent().withConsent).toHaveBeenCalledOnce() - expect(agentStore.isVisible).toBe(true) + expect(agentStore.isVisible).toBe(false) expect( localStorage.getItem( 'Comfy.AgentConsent.IntroductionResponded.signed-out' @@ -391,7 +424,7 @@ describe('AgentPanel extension flag gate', () => { workspaceId: null } ])( - 'keeps only the locked panel when initial $restore arrives late after an earlier Skip', + 'opens only the startup panel when initial $restore arrives late after an earlier Skip', async ({ user, initialized, workspaceId }) => { currentUser.value = user isAuthInitialized.value = initialized @@ -401,7 +434,7 @@ describe('AgentPanel extension flag gate', () => { 'Comfy.AgentConsent.IntroductionResponded.account-a.workspace-a', 'true' ) - localStorage.setItem(ACTIVATION_VISITS_STORAGE_KEY, '2') + localStorage.setItem(ACTIVATION_VISITS_STORAGE_KEY, '1') await loadEntryAndSetup() await flush() @@ -438,43 +471,40 @@ describe('AgentPanel extension flag gate', () => { }) it.for([ - { session: 'signed out', user: null, scope: 'signed-out' }, - { - session: 'signed in', - user: { id: 'account-a' }, - scope: 'account-a.workspace-a' - } + { session: 'signed out', user: null }, + { session: 'signed in', user: { id: 'account-a' } } ])( - 'opens the locked panel on every $session launch after Skip', - async ({ user, scope }) => { + 'remembers a $session Skip across launches and opens the panel only for the two activation visits', + async ({ user }) => { currentUser.value = user - localStorage.setItem( - `Comfy.AgentConsent.IntroductionResponded.${scope}`, - 'true' + vi.mocked(useAgentConsent().withConsent).mockImplementationOnce( + async (_trigger, _onAccept, hooks) => { + if (hooks?.canShow?.() === false) return + hooks?.onShown?.() + useAgentConsentIntroductionStore().markResponded() + } ) - localStorage.setItem(ACTIVATION_VISITS_STORAGE_KEY, '2') - openDialog() + const relaunch = async (): Promise => { + agentStore.close('close_button') + setupScope.stop() + setupScope = effectScope() + await loadEntryAndSetup() + await flush() + } await loadEntryAndSetup() await flush() - expect(agentStore.isVisible).toBe(false) - - closeDialog() - await flush() + expect(useAgentConsent().withConsent).toHaveBeenCalledOnce() expect(agentStore.isVisible).toBe(true) - expect(useAgentConsent().withConsent).not.toHaveBeenCalled() - - agentStore.close('close_button') - setAgentReady(true) - await flush() - expect(agentStore.isVisible).toBe(false) - setupScope.stop() - setupScope = effectScope() - await loadEntryAndSetup() - await flush() + await relaunch() expect(agentStore.isVisible).toBe(true) expect(localStorage.getItem(ACTIVATION_VISITS_STORAGE_KEY)).toBe('2') + expect(useAgentConsent().withConsent).toHaveBeenCalledOnce() + + await relaunch() + expect(agentStore.isVisible).toBe(false) + expect(useAgentConsent().withConsent).toHaveBeenCalledOnce() } ) @@ -487,7 +517,6 @@ describe('AgentPanel extension flag gate', () => { async ({ agent }) => { currentUser.value = null Object.assign(agentStore, { comfyAgent: agent, flagsSettled: true }) - localStorage.setItem(ACTIVATION_VISITS_STORAGE_KEY, '2') await loadEntryAndSetup() await flush() diff --git a/src/extensions/core/agentPanel.ts b/src/extensions/core/agentPanel.ts index f95f0bc95f3..7286bfb6b76 100644 --- a/src/extensions/core/agentPanel.ts +++ b/src/extensions/core/agentPanel.ts @@ -237,7 +237,6 @@ export function registerAgentPanelExtension(): void { } const consentCardSeenIn = new Set() - let lockedStartupOpened = false let activationOpenedPanel = false whenever( () => dialogStore.isDialogOpen(CONSENT_DIALOG_KEY), @@ -279,22 +278,6 @@ export function registerAgentPanelExtension(): void { ? 'account_unresolved' : 'workspace_unresolved' - function prepareConsentCard( - candidateUserId: string | undefined, - offeredWorkspaceId: string | null - ): boolean { - const held = screenHolder() - if (held) { - holdOffer(held, candidateUserId, offeredWorkspaceId ?? undefined) - return false - } - if (agentPanelStore.onboarding.startup !== 'lockedUntilConsent') - return true - if (!agentPanelStore.enabled) return false - if (!agentPanelStore.isOpen) agentPanelStore.open('automatic_consent') - return true - } - function claimOneShotOffer( candidateUserId: string | undefined, offeredWorkspaceId: string | null @@ -357,7 +340,7 @@ export function registerAgentPanelExtension(): void { const candidateUserId = resolvedUserInfo.value?.id const offeredWorkspaceId = workspaceStore.activeWorkspaceId - const { offerMemory, startup } = agentPanelStore.onboarding + const { offerMemory } = agentPanelStore.onboarding const key = offerMemory === 'shown' ? claimOneShotOffer(candidateUserId, offeredWorkspaceId) @@ -367,15 +350,13 @@ export function registerAgentPanelExtension(): void { const offeredIdentity = consentStore.identity autoShowInFlight = true dropHold() - if (startup === 'activationVisits') - agentPanelStore.suppressRestoredOpen() + agentPanelStore.suppressRestoredOpen() void withConsent( 'first_load', () => { if ( !agentPanelStore.enabled || - (startup === 'activationVisits' && - automaticActivationVisitsComplete()) || + automaticActivationVisitsComplete() || agentPanelStore.isOpen ) return @@ -385,34 +366,21 @@ export function registerAgentPanelExtension(): void { onShown: () => { if (key) writeAutoShown(key, true) }, - canShow: () => - prepareConsentCard(candidateUserId, offeredWorkspaceId) + canShow: () => { + const held = screenHolder() + if (held) + holdOffer( + held, + candidateUserId, + offeredWorkspaceId ?? undefined + ) + return held === null && agentPanelStore.enabled + } } ).finally(() => finishAutomaticOffer(offeredIdentity)) } - function prepareLockedStartup(): boolean { - if ( - !agentPanelStore.enabled || - !isAuthInitialized.value || - consentStore.isChecking || - consentStore.accepted - ) - return false - const held = screenHolder() - if (held) { - holdOffer(held) - return false - } - if (lockedStartupOpened) return true - lockedStartupOpened = true - if (!agentPanelStore.isOpen) agentPanelStore.open('activation') - return true - } - function prepareStartupPanel(): boolean { - if (agentPanelStore.onboarding.startup === 'lockedUntilConsent') - return prepareLockedStartup() if (!automaticActivationVisitsComplete() || agentPanelStore.isOpen) return true reportOfferExit('activation_window_complete', 'startup') @@ -454,12 +422,7 @@ export function registerAgentPanelExtension(): void { let activationPending = false let activationOffered = false const openWhenStartupDecided = (): void => { - if ( - agentPanelStore.onboarding.startup !== 'activationVisits' || - !agentPanelStore.enabled || - activationPending || - activationOffered - ) + if (!agentPanelStore.enabled || activationPending || activationOffered) return activationPending = true whenStartupDecided() diff --git a/src/workbench/extensions/agent/stores/agent/agentPanelStore.ts b/src/workbench/extensions/agent/stores/agent/agentPanelStore.ts index 529242b8658..3196e080b94 100644 --- a/src/workbench/extensions/agent/stores/agent/agentPanelStore.ts +++ b/src/workbench/extensions/agent/stores/agent/agentPanelStore.ts @@ -42,7 +42,6 @@ const OPEN_STORAGE_KEY = 'Comfy.AgentPanel.open' const DISCOVERED_STORAGE_KEY = 'Comfy.AgentPanel.discovered' interface AgentOnboardingPolicy { - startup: 'activationVisits' | 'lockedUntilConsent' offerMemory: 'shown' | 'answered' agentButton: 'requestConsent' | 'togglePanel' persistSkipAsRefusal: boolean @@ -50,7 +49,6 @@ interface AgentOnboardingPolicy { } const DEFAULT_ONBOARDING: AgentOnboardingPolicy = { - startup: 'activationVisits', offerMemory: 'shown', agentButton: 'requestConsent', persistSkipAsRefusal: true, @@ -58,7 +56,6 @@ const DEFAULT_ONBOARDING: AgentOnboardingPolicy = { } const DESKTOP_ONBOARDING: AgentOnboardingPolicy = { - startup: 'lockedUntilConsent', offerMemory: 'answered', agentButton: 'togglePanel', persistSkipAsRefusal: false,