Skip to content

The agent that grows with you

refactor(desktop): read the profile-window marker through store/windows

kshitijk4poor00600e070599
diff --git a/apps/desktop/src/app/session/new-session-route.ts b/apps/desktop/src/app/session/new-session-route.ts
index b9a65e2fda8..2390cea6ef3 100644
--- a/apps/desktop/src/app/session/new-session-route.ts
+++ b/apps/desktop/src/app/session/new-session-route.ts
@@ -11,7 +11,7 @@ import {
pinLegacyNewChatProfile
} from '@/store/profile'
import { $projectScope, ALL_PROJECTS } from '@/store/projects'
-import { isPeerInstanceWindow, windowProfileOverride } from '@/store/windows'
+import { isPeerInstanceWindow, isProfilePinnedWindow, windowConnectionOverride, windowProfileOverride } from '@/store/windows'
/** Only generic New Session actions consult this preference. Explicit profile,
* agent, project and existing-session actions keep their captured owner. */
@@ -22,12 +22,11 @@ export function defaultNewSessionTarget(): { profile: string; route: AgentProfil
return null
}
- const params = new URLSearchParams(window.location.search)
// An ordinary New Window inherits its opener only for boot. Reusing that
// seed here would undo a later device/profile selection. Only an explicit
// "Open profile in new window" makes the peer's launch route a default.
- const profile = !isPeerInstanceWindow() || params.get('profileWindow') === '1' ? windowProfileOverride() : null
- const saved = profile ? { connectionId: params.get('connectionId') || null, profile } : $defaultProfileRoute.get()
+ const profile = !isPeerInstanceWindow() || isProfilePinnedWindow() ? windowProfileOverride() : null
+ const saved = profile ? { connectionId: windowConnectionOverride(), profile } : $defaultProfileRoute.get()
if (!saved) {
return null
diff --git a/apps/desktop/src/store/windows.test.ts b/apps/desktop/src/store/windows.test.ts
index 69402ae14bb..f66d2733933 100644
--- a/apps/desktop/src/store/windows.test.ts
+++ b/apps/desktop/src/store/windows.test.ts
@@ -7,6 +7,7 @@ import {
canOpenNewWindow,
canOpenSessionWindow,
isPeerInstanceWindow,
+ isProfilePinnedWindow,
openBrowserInNewWindow,
openNewWindow,
openSessionInNewWindow
@@ -71,6 +72,15 @@ describe('isPeerInstanceWindow', () => {
})
})
+describe('isProfilePinnedWindow', () => {
+ it('is set only by an explicit profile-window launch, not by an inherited peer route', () => {
+ expect(isProfilePinnedWindow('?peer=1&profile=work&connectionId=&profileWindow=1')).toBe(true)
+ expect(isProfilePinnedWindow('?peer=1&profile=work&connectionId=remote')).toBe(false)
+ expect(isProfilePinnedWindow('?profileWindow=0')).toBe(false)
+ expect(isProfilePinnedWindow('')).toBe(false)
+ })
+})
+
describe('openSessionInNewWindow', () => {
it('no-ops without a session id', async () => {
const open = vi.fn().mockResolvedValue({ ok: true })
diff --git a/apps/desktop/src/store/windows.ts b/apps/desktop/src/store/windows.ts
index c6f2c5b4435..271e28c93cb 100644
--- a/apps/desktop/src/store/windows.ts
+++ b/apps/desktop/src/store/windows.ts
@@ -125,6 +125,18 @@ export function isPeerInstanceWindow(search = typeof window === 'undefined' ? ''
}
}
+// Set by Electron only for an explicit "Open profile in new window". An
+// ordinary ⌘⇧N peer also carries profile/connectionId (its boot seed) but not
+// this marker, so a later device/profile selection stays the New-session
+// default there (#115102).
+export function isProfilePinnedWindow(search = typeof window === 'undefined' ? '' : window.location.search): boolean {
+ try {
+ return new URLSearchParams(search).get('profileWindow') === '1'
+ } catch {
+ return false
+ }
+}
+
// The profile a helper window (the HUD) was asked to boot against, carried in
// the query string by the main process (see hudUrl). The HUD is a full app
// renderer that otherwise adopts the PRIMARY backend's profile — wrong the
@@ -141,6 +153,17 @@ export function windowProfileOverride(): null | string {
}
}
+// The registry connection a peer was launched against, paired with
+// windowProfileOverride(). Electron writes `connectionId=` (empty) for a
+// registry-local route, which reads back as null here.
+export function windowConnectionOverride(): null | string {
+ try {
+ return new URLSearchParams(window.location.search).get('connectionId') || null
+ } catch {
+ return null
+ }
+}
+
// True when running inside the Electron desktop shell (the preload bridge is
// present). The "open in new window" affordance is desktop-only.
export function canOpenSessionWindow(): boolean {