The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
refactor(desktop): move project scope into a dependency-light store module
Hermes Agent953ca9e094e8
diff --git a/apps/desktop/src/app/chat/sidebar/chat-sidebar.integration.test.tsx b/apps/desktop/src/app/chat/sidebar/chat-sidebar.integration.test.tsxindex 978c36f51a8..6a86df027f0 100644--- a/apps/desktop/src/app/chat/sidebar/chat-sidebar.integration.test.tsx+++ b/apps/desktop/src/app/chat/sidebar/chat-sidebar.integration.test.tsx@@ -10,7 +10,8 @@ import { registry } from '@/contrib/registry'import { $connectionsRegistry } from '@/store/connection-registry-state'import { $sidebarMessagingOpenIds, setSidebarAgentsGrouped, setSidebarGrouping } from '@/store/layout'import { $activeGatewayProfile, $profiles, setShowAllProfiles } from '@/store/profile'-import { $projectScope, $projectTree, ALL_PROJECTS } from '@/store/projects'+import { $projectScope, ALL_PROJECTS } from '@/store/project-scope'+import { $projectTree } from '@/store/projects'import {$currentCwd,$messagingSessions,diff --git a/apps/desktop/src/app/chat/sidebar/index.tsx b/apps/desktop/src/app/chat/sidebar/index.tsxindex 1a696bf6b25..ceec2ebc9ef 100644--- a/apps/desktop/src/app/chat/sidebar/index.tsx+++ b/apps/desktop/src/app/chat/sidebar/index.tsx@@ -86,18 +86,16 @@ import {sidebarProfileForScope} from '@/store/profile'import { $profileRailVisible } from '@/store/profile-rail-prefs'+import { $projectScope, ALL_PROJECTS, exitProjectScope } from '@/store/project-scope'import {$activeProjectId,$newProjectDropPlacement,$projectOwnerBySessionId,$projects,- $projectScope,$projectTree,$projectTreeLoading,$reposScanning,- ALL_PROJECTS,enterProject,- exitProjectScope,followEnteredProjectCwd,openProjectCreate,refreshProjects,diff --git a/apps/desktop/src/app/session/hooks/default-new-session.test.tsx b/apps/desktop/src/app/session/hooks/default-new-session.test.tsxindex b96918b0373..34524b10684 100644--- a/apps/desktop/src/app/session/hooks/default-new-session.test.tsx+++ b/apps/desktop/src/app/session/hooks/default-new-session.test.tsx@@ -15,7 +15,7 @@ import {ensureGatewayProfile,resolveNewChatOwnerRoute} from '@/store/profile'-import { $projectScope, ALL_PROJECTS } from '@/store/projects'+import { $projectScope, ALL_PROJECTS } from '@/store/project-scope'import {$activeSessionId,$sessions,diff --git a/apps/desktop/src/app/session/hooks/use-session-actions.test.tsx b/apps/desktop/src/app/session/hooks/use-session-actions.test.tsxindex dba07ccf47c..ce0717c23fd 100644--- a/apps/desktop/src/app/session/hooks/use-session-actions.test.tsx+++ b/apps/desktop/src/app/session/hooks/use-session-actions.test.tsx@@ -33,7 +33,8 @@ import {ensureGatewayAgent,ensureGatewayProfile} from '@/store/profile'-import { $projectScope, $projectTree, ALL_PROJECTS } from '@/store/projects'+import { $projectScope, ALL_PROJECTS } from '@/store/project-scope'+import { $projectTree } from '@/store/projects'import {$activeSessionId,$activeSessionStoredIdRotation,diff --git a/apps/desktop/src/app/session/hooks/use-session-actions/index.ts b/apps/desktop/src/app/session/hooks/use-session-actions/index.tsindex 1aa9bb13af5..ca98a4fcf4b 100644--- a/apps/desktop/src/app/session/hooks/use-session-actions/index.ts+++ b/apps/desktop/src/app/session/hooks/use-session-actions/index.ts@@ -55,7 +55,8 @@ import {normalizeProfileKey,resolveNewChatOwnerRoute} from '@/store/profile'-import { $projectScope, resolveNewSessionCwd } from '@/store/projects'+import { $projectScope } from '@/store/project-scope'+import { resolveNewSessionCwd } from '@/store/projects'import { receiveApprovalRequest, replayPendingApproval } from '@/store/prompts'import { clearStoredTranscriptReadOnly, markStoredTranscriptReadOnly } from '@/store/read-only-transcript'import {diff --git a/apps/desktop/src/app/session/new-session-route.ts b/apps/desktop/src/app/session/new-session-route.tsindex 9a0c77f43f5..f86cab13e94 100644--- a/apps/desktop/src/app/session/new-session-route.ts+++ b/apps/desktop/src/app/session/new-session-route.ts@@ -10,7 +10,7 @@ import {ensureGatewayProfile,pinLegacyNewChatProfile} from '@/store/profile'-import { $projectScope, ALL_PROJECTS } from '@/store/projects'+import { $projectScope, ALL_PROJECTS } from '@/store/project-scope'import {isPeerInstanceWindow,isProfilePinnedWindow,diff --git a/apps/desktop/src/app/session/workspace-session-target.test.ts b/apps/desktop/src/app/session/workspace-session-target.test.tsindex b50f91a61ce..0fc0cd911d6 100644--- a/apps/desktop/src/app/session/workspace-session-target.test.ts+++ b/apps/desktop/src/app/session/workspace-session-target.test.ts@@ -1,7 +1,8 @@import { afterEach, describe, expect, it, vi } from 'vitest'import { $activeGatewayProfile, $newChatProfile } from '@/store/profile'-import { $projectScope, $projectTree, ALL_PROJECTS } from '@/store/projects'+import { $projectScope, ALL_PROJECTS } from '@/store/project-scope'+import { $projectTree } from '@/store/projects'import {$currentBranch,$currentCwd,diff --git a/apps/desktop/src/store/coding-status.ts b/apps/desktop/src/store/coding-status.tsindex 4b40bf257ec..c5819943c37 100644--- a/apps/desktop/src/store/coding-status.ts+++ b/apps/desktop/src/store/coding-status.ts@@ -3,14 +3,8 @@ import { atom, computed, type ReadableAtom } from 'nanostores'import type { HermesGitWorktree, HermesRepoStatus } from '@/global'import { desktopGit } from '@/lib/desktop-git'-import {- $projectScope,- $projectTree,- $worktreeDialog,- $worktreeRefreshToken,- ALL_PROJECTS,- projectRootCwd-} from './projects'+import { $projectScope, ALL_PROJECTS } from './project-scope'+import { $projectTree, $worktreeDialog, $worktreeRefreshToken, projectRootCwd } from './projects'import {$busy,$currentCwd,diff --git a/apps/desktop/src/store/project-scope.ts b/apps/desktop/src/store/project-scope.tsnew file mode 100644index 00000000000..a05bbb9ddcd--- /dev/null+++ b/apps/desktop/src/store/project-scope.ts@@ -0,0 +1,26 @@+import { persistentAtom } from '@/lib/persisted'++// ── Project scope (the "you're inside a project" view, mirroring profile scope)─+// The sidebar's grouped view is a project switcher: ALL_PROJECTS shows the+// project overview (a list you drill into), and a concrete id means you've+// "entered" that project so only its worktrees/branches/sessions show. This is+// pure view state (localStorage), distinct from the durable active-project+// pointer in projects.db — though entering a project also makes it active so new+// chats land there, exactly as selecting a profile does.+//+// Project ids belong to ONE backend's projects.db, so switching profile or+// connection must leave the scope (store/profile, store/gateway-switch). It lives+// in this dependency-light module so those stores can reset it synchronously,+// before the fresh draft resolves its cwd from it.+export const ALL_PROJECTS = '__all_projects__'++const PROJECT_SCOPE_KEY = 'hermes.desktop.projectScope'++export const $projectScope = persistentAtom<string>(PROJECT_SCOPE_KEY, ALL_PROJECTS, {+ decode: raw => raw || ALL_PROJECTS,+ encode: value => value || ALL_PROJECTS+})++export function exitProjectScope(): void {+ $projectScope.set(ALL_PROJECTS)+}diff --git a/apps/desktop/src/store/projects.test.ts b/apps/desktop/src/store/projects.test.tsindex fa3ab16c152..4a7c4a9a3ab 100644--- a/apps/desktop/src/store/projects.test.ts+++ b/apps/desktop/src/store/projects.test.ts@@ -7,18 +7,16 @@ import { $activeGatewayProfile, $profileScope, ALL_PROFILES, setShowAllProfilesimport { $currentCwd, $selectedStoredSessionId, $sessions, applyConfiguredDefaultProjectDir } from '@/store/session'import type { ProjectInfo } from '@/types/hermes'+import { $projectScope, ALL_PROJECTS, exitProjectScope } from './project-scope'import {$activeProjectId,$projects,- $projectScope,$projectsRpcAvailable,$projectTree,addProjectFolder,- ALL_PROJECTS,createProject,deleteProject,enterProject,- exitProjectScope,fetchProjectSessions,openProjectCreate,pickProjectFolder,diff --git a/apps/desktop/src/store/projects.ts b/apps/desktop/src/store/projects.tsindex f7b2eb85418..0ed1cd0d16c 100644--- a/apps/desktop/src/store/projects.ts+++ b/apps/desktop/src/store/projects.ts@@ -15,7 +15,6 @@ import { desktopDefaultCwd, isDesktopFsRemoteMode, selectDesktopPaths, writeDeskimport { desktopGit } from '@/lib/desktop-git'import { isMissingRestEndpoint, isMissingRpcMethod } from '@/lib/gateway-rpc'import { isUnderPath } from '@/lib/path-compare'-import { persistentAtom } from '@/lib/persisted'import { revealFile } from '@/store/file-actions'import { $gateway, activeGateway, ensureActiveGatewayOpen } from '@/store/gateway'import { $sidebarShowAllSessions, setSidebarAgentsGrouped } from '@/store/layout'@@ -27,6 +26,7 @@ import {normalizeProfileKey,requestFreshSession} from '@/store/profile'+import { $projectScope, ALL_PROJECTS } from '@/store/project-scope'import {$currentCwd,$selectedStoredSessionId,@@ -80,22 +80,6 @@ function projectsStaleBackendError(): Error {// True while the disk scan is in flight (drives the "finding repos" hint).export const $reposScanning = atom(false)-// ── Project scope (the "you're inside a project" view, mirroring profile scope)─-// The sidebar's grouped view is a project switcher: ALL_PROJECTS shows the-// project overview (a list you drill into), and a concrete id means you've-// "entered" that project so only its worktrees/branches/sessions show. This is-// pure view state (localStorage), distinct from the durable active-project-// pointer in projects.db — though entering a project also makes it active so new-// chats land there, exactly as selecting a profile does.-export const ALL_PROJECTS = '__all_projects__'--const PROJECT_SCOPE_KEY = 'hermes.desktop.projectScope'--export const $projectScope = persistentAtom<string>(PROJECT_SCOPE_KEY, ALL_PROJECTS, {- decode: raw => raw || ALL_PROJECTS,- encode: value => value || ALL_PROJECTS-})-// Enter a project: scope the sidebar to it and make it the active project// (best-effort — the durable pointer is nice-to-have, the view scope is the// point). Never opens a session.@@ -110,10 +94,6 @@ export function enterProject(id: string): void {}}-export function exitProjectScope(): void {- $projectScope.set(ALL_PROJECTS)-}-// A project's working root: its primary folder, else the first repo that has// one. Empty for the path-less Home bucket. (The sidebar's `projectTreeCwd` is// the same rule over the same tree — this is the store-side copy so the store