The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
revert(desktop): drop the startup-profile changes made for the setup release
alt-glitch364b2ecc364c
diff --git a/apps/desktop/electron/desktop-profile.test.ts b/apps/desktop/electron/desktop-profile.test.tsindex 92d2aaad840..9cb528e61d5 100644--- a/apps/desktop/electron/desktop-profile.test.ts+++ b/apps/desktop/electron/desktop-profile.test.ts@@ -214,57 +214,3 @@ test.each([null, 'local'])(}})--test('a stored profile whose home is gone boots default instead of a missing --profile', () => {- const root = fs.mkdtempSync(path.join(os.tmpdir(), 'desktop-profile-missing-'))- const target = path.join(root, 'active-profile.json')- const profilesRoot = path.join(root, 'profiles')- fs.mkdirSync(path.join(profilesRoot, 'work'), { recursive: true })-- const preferences = createDesktopProfilePreferences(target, {- profileExists: name => fs.existsSync(path.join(profilesRoot, name))- })-- try {- preferences.remember('work')- assert.equal(preferences.readActive(), 'work')-- // Explicitly default, not "no preference": that would let the CLI's active profile choose the home.- preferences.remember('hermes-setup')- assert.equal(preferences.readActive(), 'default')-- preferences.remember(null)- assert.equal(preferences.readActive(), null)-- preferences.remember('default')- assert.equal(preferences.readActive(), 'default')- } finally {- fs.rmSync(root, { recursive: true, force: true })- }-})--test('a local rename moves the saved startup profile after its old home is gone', () => {- const root = fs.mkdtempSync(path.join(os.tmpdir(), 'desktop-profile-rename-'))- const target = path.join(root, 'active-profile.json')- const profilesRoot = path.join(root, 'profiles')- fs.mkdirSync(path.join(profilesRoot, 'work'), { recursive: true })- const profileExists = (name: string) => fs.existsSync(path.join(profilesRoot, name))-- try {- const preferences = createDesktopProfilePreferences(target, { profileExists })- preferences.remember('work')- // The backend has already renamed the home when the response comes back.- fs.renameSync(path.join(profilesRoot, 'work'), path.join(profilesRoot, 'job'))-- preferences.afterProfileRequest(- null,- { method: 'PATCH', path: '/api/profiles/work', body: { new_name: 'job' } },- { ok: true },- 'local'- )-- assert.equal(createDesktopProfilePreferences(target, { profileExists }).readActive(), 'job')- } finally {- fs.rmSync(root, { recursive: true, force: true })- }-})diff --git a/apps/desktop/electron/desktop-profile.ts b/apps/desktop/electron/desktop-profile.tsindex a3b1d1123ba..65c242280da 100644--- a/apps/desktop/electron/desktop-profile.ts+++ b/apps/desktop/electron/desktop-profile.ts@@ -89,7 +89,6 @@ export function createDesktopProfilePreferences(configPath: string,options: {onDefaultChanged?: (route: DesktopProfileRoute | null) => void- profileExists?: (profile: string) => booleanvalidateRoute?: (route: DesktopProfileRoute) => void} = {}) {@@ -122,26 +121,13 @@ export function createDesktopProfilePreferences(}}- function readStored(): null | string {+ function readActive(): null | string {const value = read().profileconst profile = typeof value === 'string' ? value.trim() : ''return DESKTOP_PROFILE_NAME_RE.test(profile) ? profile : null}- function readActive(): null | string {- const profile = readStored()-- // A stored profile whose home is gone boots default, explicitly: `--profile <missing>` would fail the- // backend, and `null` (no preference) would let the CLI's own active profile pick a different home- // than the one the connection is labelled with.- if (profile && profile !== 'default' && options.profileExists?.(profile) === false) {- return 'default'- }-- return profile- }-function remember(name: unknown): null | string {const profile = typeof name === 'string' ? name.trim() : ''@@ -169,8 +155,7 @@ export function createDesktopProfilePreferences(}function profileChanged(connectionId: null | string, oldName: string, newName: null | string, backendMode: string) {- // A finished rename or delete has already removed oldName's home, so match the saved name, not readActive.- if (backendMode === 'local' && readStored() === oldName) {+ if (backendMode === 'local' && readActive() === oldName) {remember(newName || 'default')}diff --git a/apps/desktop/electron/main.ts b/apps/desktop/electron/main.tsindex 55e562f5105..778699aa789 100644--- a/apps/desktop/electron/main.ts+++ b/apps/desktop/electron/main.ts@@ -9175,9 +9175,9 @@ async function saveRegistryConnection(input: any = {}) {return sanitizeRegistryConnection(entry)}-// Last-used profile and app-wide default share one preference file; only an explicit action changes the default.+// Last-used profile and explicit app-wide default share the existing desktop+// preference file, but only the explicit action changes the default route.const desktopProfilePreferences = createDesktopProfilePreferences(DESKTOP_PROFILE_CONFIG_PATH, {- profileExists: name => fs.existsSync(path.join(HERMES_HOME, 'profiles', name)),validateRoute: validateDesktopProfileRoute,onDefaultChanged: route => {for (const win of BrowserWindow.getAllWindows()) {diff --git a/apps/desktop/electron/profile-migration.ts b/apps/desktop/electron/profile-migration.tsindex 0c0b82cb4c8..30bf4193d90 100644--- a/apps/desktop/electron/profile-migration.ts+++ b/apps/desktop/electron/profile-migration.ts@@ -209,15 +209,9 @@ export function decideMigration(return { profile: best, _migrated: true }}-// The setup profile canary/RC builds made. The backend releases it at boot (hermes_cli/onboarding_migrations.py),-// but only from a backend launched elsewhere, and this pick runs before that backend exists: picking it here-// would boot into it every launch and it would never be released. Once released it carries no marker.-const SETUP_PROFILE_MARKER = '.setup-profile.json'-/**- * List named profile directory names under `profilesRoot`, minus the setup profile, which is never a startup- * profile. A directory named `default` is accepted if present (unusual) but production default is not a child- * of this folder — see `withDefaultCandidate`.+ * List named profile directory names under `profilesRoot`. A directory named `default` is accepted if present+ * (unusual) but production default is not a child of this folder — see `withDefaultCandidate`.*/export function listProfileDirs(deps: MigrationDeps): string[] {let entries: Dirent[]@@ -230,7 +224,6 @@ export function listProfileDirs(deps: MigrationDeps): string[] {return entries.filter(e => e.isDirectory() && (e.name === 'default' || deps.isValidProfileName(e.name)))- .filter(e => !deps.existsSync(`${deps.profilesRoot}/${e.name}/${SETUP_PROFILE_MARKER}`)).map(e => e.name)}diff --git a/apps/desktop/src/store/connections.test.ts b/apps/desktop/src/store/connections.test.tsindex 400ed29306c..cb9ec749f5d 100644--- a/apps/desktop/src/store/connections.test.ts+++ b/apps/desktop/src/store/connections.test.ts@@ -11,7 +11,6 @@ const $activeGatewayProfile = atom('default')const $newChatProfile = atom<null | string>(null)const $freshSessionRequest = atom(0)const $showAllProfiles = atom(false)-const $profilesByConnection = atom<ReadonlyMap<string, { name: string }[]>>(new Map())const $connection = atom<null | {connectionId?: string@@ -75,7 +74,6 @@ vi.mock('@/store/profile', () => ({$freshSessionRequest,$newChatProfile,$newChatRoute: atom(null),- $profilesByConnection,$showAllProfiles,captureNewChatSource: vi.fn(),currentNewChatIntent: () => 0,@@ -109,7 +107,7 @@ const registry: DesktopConnectionsRegistry = {}const list = vi.fn(async () => registry)-const api = vi.fn(async (): Promise<{ profiles: { name: string }[] }> => ({ profiles: [] }))+const api = vi.fn(async () => ({ profiles: [] }))const setLastUsed = vi.fn(async (id: string) => ({ ok: true, registry: { ...registry, lastUsed: id } }))beforeEach(() => {@@ -120,7 +118,6 @@ beforeEach(() => {$activeGatewayProfile.set('default')$newChatProfile.set(null)$showAllProfiles.set(false)- $profilesByConnection.set(new Map())ensureGatewayAgent.mockReset()// Mirrors the real door: the commit hook runs right before the activation// publishes, and a declined hook publishes nothing.@@ -374,68 +371,6 @@ describe('selectConnection', () => {expect(ensureGatewayAgent).toHaveBeenCalledWith('local', 'research', expect.anything())})- it('lands on default when the profile last used on a source is gone from its list', async () => {- setConnectionsRegistry(registry)- $connection.set({ connectionId: 'local', mode: 'local', profile: 'hermes-setup', registryScoped: true })- $activeGatewayProfile.set('hermes-setup')- $connection.set({ connectionId: 'homelab', mode: 'remote', registryScoped: true })- $activeGatewayProfile.set('default')- $profilesByConnection.set(new Map([['local', [{ name: 'default' }, { name: 'work' }]]]))- api.mockResolvedValue({ profiles: [{ name: 'default' }, { name: 'work' }] })-- await selectConnection('local')-- expect(ensureGatewayAgent).toHaveBeenCalledWith('local', 'default', expect.anything())- })-- it('keeps the remembered profile when only a stale cached list lacks it', async () => {- setConnectionsRegistry(registry)- $connection.set({ connectionId: 'local', mode: 'local', profile: 'research', registryScoped: true })- $activeGatewayProfile.set('research')- $connection.set({ connectionId: 'homelab', mode: 'remote', registryScoped: true })- $activeGatewayProfile.set('default')- // The list refresh after creating `research` failed, so the cache predates it.- $profilesByConnection.set(new Map([['local', [{ name: 'default' }]]]))- api.mockResolvedValue({ profiles: [{ name: 'default' }, { name: 'research' }] })-- await selectConnection('local')-- expect(ensureGatewayAgent).toHaveBeenCalledWith('local', 'research', expect.anything())- })-- it('keeps the remembered profile when the backend cannot confirm it is gone', async () => {- setConnectionsRegistry(registry)- $connection.set({ connectionId: 'local', mode: 'local', profile: 'research', registryScoped: true })- $activeGatewayProfile.set('research')- $connection.set({ connectionId: 'homelab', mode: 'remote', registryScoped: true })- $activeGatewayProfile.set('default')- $profilesByConnection.set(new Map([['local', [{ name: 'default' }]]]))- api.mockRejectedValue(new Error('backend unreachable'))-- await selectConnection('local')-- expect(ensureGatewayAgent).toHaveBeenCalledWith('local', 'research', expect.anything())- })-- it('a later pick wins over an earlier one still checking its remembered profile', async () => {- setConnectionsRegistry(registry)- $connection.set({ connectionId: 'local', mode: 'local', profile: 'research', registryScoped: true })- $activeGatewayProfile.set('research')- $connection.set({ connectionId: 'homelab', mode: 'remote', registryScoped: true })- $activeGatewayProfile.set('default')- $profilesByConnection.set(new Map([['local', [{ name: 'default' }]]]))- const listing = deferred<{ profiles: { name: string }[] }>()- api.mockReturnValueOnce(listing.promise)-- const earlier = selectConnection('local')- await selectConnection('work-vps')- listing.resolve({ profiles: [{ name: 'default' }, { name: 'research' }] })- await earlier-- expect(ensureGatewayAgent).not.toHaveBeenCalledWith('local', expect.anything(), expect.anything())- expect($activeConnectionId.get()).toBe('work-vps')- })-it('does not remember a migrated v1 routing alias as a backend profile', async () => {setConnectionsRegistry(registry)$connection.set({ connectionId: 'homelab', mode: 'remote' })diff --git a/apps/desktop/src/store/connections.ts b/apps/desktop/src/store/connections.tsindex a2885d49499..b771e5a8a8e 100644--- a/apps/desktop/src/store/connections.ts+++ b/apps/desktop/src/store/connections.ts@@ -24,7 +24,6 @@ import {$freshSessionRequest,$newChatProfile,$newChatRoute,- $profilesByConnection,$showAllProfiles,captureNewChatSource,currentNewChatIntent,@@ -79,9 +78,6 @@ const $lastProfileByConnection = atom<Record<string, string>>(storedStringRecordlet pendingTarget: null | string = nulllet restoreAttempted = falselet switchRevision = 0-// Counts every pick, including ones that never start a switch, so a pick that waited on its source's backend-// can tell a later pick happened while it waited.-let selectRevision = 0export const $pendingConnectionId = atom<null | string>(null)@@ -128,56 +124,12 @@ $activeConnectionProfile.subscribe(({ connectionId, descriptorProfile, profile,$lastProfileByConnection.set({ ...$lastProfileByConnection.get(), [connectionId]: profile })})-const listsProfile = (profiles: readonly { name: string }[], key: string) =>- profiles.some(profile => normalizeProfileKey(profile.name) === key)--// A pick either knows its profile now or waits on the backend; only a wait can be overtaken (null).-type ProfilePick = { kind: 'ready'; profile: string } | { kind: 'pending'; profile: Promise<null | string> }--// The profile last used on a source; default only once that source's backend no longer lists it (deleted-// elsewhere). The cached list can predate the profile (a failed refresh after create), so it only triggers the check.-function rememberedProfile(connectionId: string): ProfilePick {- const key = normalizeProfileKey($lastProfileByConnection.get()[connectionId])- const cached = $profilesByConnection.get().get(connectionId)-- if (!cached || listsProfile(cached, key)) {- return { kind: 'ready', profile: key }- }-- const listed = getProfiles({ connectionId, profile: 'default' }).then(- ({ profiles }) => (listsProfile(profiles, key) ? key : 'default'),- () => key- )-- return { kind: 'pending', profile: listed }-}--// The profile a pick lands on: the one asked for, else the one last used there. Only a remembered profile-// the cache lacks waits on the backend (every other pick stays synchronous); null when a later pick-// arrived during that wait.-function pickedProfile(connectionId: string, explicit: null | string | undefined): ProfilePick {- const asked = String(explicit ?? '').trim()- const remembered: ProfilePick = asked ? { kind: 'ready', profile: asked } : rememberedProfile(connectionId)- const pick = ++selectRevision-- if (remembered.kind === 'ready') {- return { kind: 'ready', profile: normalizeProfileKey(remembered.profile) }- }-- const settled = remembered.profile.then(profile =>- pick === selectRevision && profile !== null ? normalizeProfileKey(profile) : null- )-- return { kind: 'pending', profile: settled }-}-/** @internal Reset module-owned preferences and switch coordination for tests. */export function _resetConnectionsForTests(): void {$lastProfileByConnection.set({})pendingTarget = nullrestoreAttempted = falseswitchRevision = 0- selectRevision = 0$pendingConnectionId.set(null)}@@ -422,15 +374,13 @@ export async function selectConnection(connectionId: string, options: SelectConn// browse-mode preference alone so it survives restart (#93197).const restoreOnBoot = pendingTarget === null && $activeConnectionId.get() === null- const picked = pickedProfile(connectionId, options.profile)- const targetProfile = picked.kind === 'ready' ? picked.profile : await picked.profile-- if (targetProfile === null) {- return- }-const currentConnectionId = $activeConnectionId.get()const currentProfile = normalizeProfileKey($activeGatewayProfile.get())+ const explicitProfile = String(options.profile ?? '').trim()++ const targetProfile = normalizeProfileKey(+ explicitProfile || ($lastProfileByConnection.get()[connectionId] ?? 'default')+ )const targetKey = `${connectionId}::${targetProfile}`