Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ All documentation lives at **[hermes-agent.nousresearch.com/docs](https://hermes
| [Tools & Toolsets](https://hermes-agent.nousresearch.com/docs/user-guide/features/tools) | 40+ tools, toolset system, terminal backends |
| [Skills System](https://hermes-agent.nousresearch.com/docs/user-guide/features/skills) | Procedural memory, Skills Hub, creating skills |
| [Memory](https://hermes-agent.nousresearch.com/docs/user-guide/features/memory) | Persistent memory, user profiles, best practices |
| [Session presence](docs/session-presence.md) | Active-session discovery for shared-device setups |
| [MCP Integration](https://hermes-agent.nousresearch.com/docs/user-guide/features/mcp) | Connect any MCP server for extended capabilities |
| [Cron Scheduling](https://hermes-agent.nousresearch.com/docs/user-guide/features/cron) | Scheduled tasks with platform delivery |
| [Context Files](https://hermes-agent.nousresearch.com/docs/user-guide/features/context-files) | Project context that shapes every conversation |
Expand Down
22 changes: 21 additions & 1 deletion apps/desktop/src/app/chat/sidebar/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -89,13 +89,15 @@ import {
$messagingPlatformTotals,
$messagingSessions,
$messagingTruncated,
$sessionPresence,
$sessionProfilesTruncated,
$sessions,
$sessionsLoading,
sessionPinId,
setCurrentCwd
} from '@/store/session'
import { $focusedStoredSessionId, $workingSessionIds, type SplitDir } from '@/store/session-states'
import type { SessionPresenceRecord } from '@/types/hermes'

import {
type AppView,
Expand Down Expand Up @@ -227,6 +229,7 @@ interface ChatSidebarProps extends React.ComponentProps<typeof Sidebar> {
onLoadMoreSessions: () => Promise<void> | void
onLoadMoreProfileSessions?: (profile: string) => Promise<void> | void
onLoadMoreMessaging?: (platform: string) => Promise<void> | void
onOpenPresenceSession?: (record: SessionPresenceRecord) => void

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

onOpenPresenceSession is never destructured or invoked by ChatSidebar; the presence data only contributes IDs to workingSessionIdSet. A remote-only presence record therefore has no row to click and cannot follow this route. Please render and wire an actionable presence row, or remove the dormant path and narrow the documentation.

onResumeSession: (sessionId: string) => void
onDeleteSession: (sessionId: string) => void
onArchiveSession: (sessionId: string) => void
Expand Down Expand Up @@ -301,6 +304,7 @@ export function ChatSidebar({
const sessionsLoading = useStore($sessionsLoading)
const sessionProfilesTruncated = useStore($sessionProfilesTruncated)
const workingSessionIds = useStore($workingSessionIds)
const sessionPresence = useStore($sessionPresence)
const profiles = useStore($profiles)
const profileScope = useStore($profileScope)
// Only surface the profile switcher when more than one profile exists, so
Expand Down Expand Up @@ -391,7 +395,23 @@ export function ChatSidebar({
[visibleSessions]
)

const workingSessionIdSet = useMemo(() => new Set(workingSessionIds), [workingSessionIds])
// Live sessions discovered via gateway presence (session.presence_list) surface
// as "working" rows in the virtualized list — the same accent dot the active
// turn uses — rather than a separate section, so presence rides the existing
// session rows.
const visibleSessionPresence = useMemo(
() => [...sessionPresence].sort((a, b) => (b.updated_at ?? 0) - (a.updated_at ?? 0)),
[sessionPresence]
)

const workingSessionIdSet = useMemo(
() =>
new Set([
...workingSessionIds,
...visibleSessionPresence.map(record => record.session_key || record.session_id).filter(Boolean)
]),
[visibleSessionPresence, workingSessionIds]
)

// Index sessions by both their live id and their lineage-root id so a pin
// stored as the pre-compression root resolves to the live continuation tip.
Expand Down
1 change: 1 addition & 0 deletions apps/desktop/src/app/contrib/latest-actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ export function latestSidebarActions(actions: SidebarActions): SidebarActions {
onNavigate: (...args) => actions.onNavigate(...args),
onNewSessionInWorkspace: (...args) => actions.onNewSessionInWorkspace(...args),
onNewSessionSplit: (...args) => actions.onNewSessionSplit(...args),
onOpenPresenceSession: latestOptional(() => actions.onOpenPresenceSession),
onResumeSession: (...args) => actions.onResumeSession(...args),
onTriggerCronJob: (...args) => actions.onTriggerCronJob(...args)
}
Expand Down
1 change: 1 addition & 0 deletions apps/desktop/src/app/contrib/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export type SidebarActions = Pick<
| 'onNavigate'
| 'onNewSessionInWorkspace'
| 'onNewSessionSplit'
| 'onOpenPresenceSession'
| 'onResumeSession'
| 'onTriggerCronJob'
>
Expand Down
5 changes: 5 additions & 0 deletions apps/desktop/src/app/contrib/wiring.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ import { usePromptActions } from '../session/hooks/use-prompt-actions'
import { useRouteResume } from '../session/hooks/use-route-resume'
import { useSessionActions } from '../session/hooks/use-session-actions'
import { useSessionListActions } from '../session/hooks/use-session-list-actions'
import { useSessionPresence } from '../session/hooks/use-session-presence'
import { useSessionStateCache } from '../session/hooks/use-session-state-cache'
import { newSessionOpensTab, startWorkspaceSession } from '../session/workspace-session-target'
import { useOverlayRouting } from '../shell/hooks/use-overlay-routing'
Expand Down Expand Up @@ -429,6 +430,7 @@ export function ContribWiring({ children }: { children: ReactNode }) {
branchStoredSession,
createBackendSessionForSend,
openNewSessionTile,
openPresenceSession,
removeSession,
resumeSession,
selectSidebarItem,
Expand All @@ -453,6 +455,8 @@ export function ContribWiring({ children }: { children: ReactNode }) {
updateSessionState
})

useSessionPresence(gatewayState, requestGateway)

// A profile switch/create drops to a fresh new-session draft so the
// previously open session doesn't bleed across contexts. Skip initial value.
const freshSessionRequest = useStore($freshSessionRequest)
Expand Down Expand Up @@ -853,6 +857,7 @@ export function ContribWiring({ children }: { children: ReactNode }) {
onNavigate: selectSidebarItem,
onNewSessionInWorkspace: path => startSessionInWorkspace(path, { openTab: true }),
onNewSessionSplit: dir => void openNewSessionTile(dir),
onOpenPresenceSession: record => void openPresenceSession(record),
onPasteClipboardImage: opts => composer.pasteClipboardImage(opts),
onPickFiles: () => void composer.pickContextPaths('file'),
onPickFolders: () => void composer.pickContextPaths('folder'),
Expand Down
117 changes: 116 additions & 1 deletion apps/desktop/src/app/session/hooks/use-session-actions/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,13 @@ import {
} from '@/store/session-states'
import { broadcastSessionsChanged } from '@/store/session-sync'
import { isWatchWindow } from '@/store/windows'
import type { SessionCreateResponse, SessionMessage, SessionResumeResponse, UsageStats } from '@/types/hermes'
import type {
SessionCreateResponse,
SessionMessage,
SessionPresenceRecord,
SessionResumeResponse,
UsageStats
} from '@/types/hermes'

import { navigateToWorkspacePage, NEW_CHAT_ROUTE, sessionRoute, SETTINGS_ROUTE } from '../../../routes'
import type { ClientSessionState, SidebarNavItem } from '../../../types'
Expand Down Expand Up @@ -195,6 +201,18 @@ function normalizeNewChatWorkspaceTarget(target: NewChatWorkspaceTarget): NewCha
return typeof target === 'string' ? target.trim() || null : target
}

function presenceMetadataString(record: SessionPresenceRecord, key: string): string {
const value = record.metadata?.[key]

return typeof value === 'string' ? value.trim() : ''
}

function presenceRouteProfile(record: SessionPresenceRecord): string | null {
const routed = presenceMetadataString(record, 'route_profile') || record.profile?.trim() || ''

return routed ? normalizeProfileKey(routed) : null
}

export function useSessionActions({
activeSessionId,
activeSessionIdRef,
Expand Down Expand Up @@ -1111,6 +1129,102 @@ export function useSessionActions({
]
)

const openPresenceSession = useCallback(
async (record: SessionPresenceRecord) => {
const runtimeTarget = record.session_id?.trim()
const storedTarget = record.session_key?.trim() || runtimeTarget

if (!runtimeTarget || !storedTarget) {
return
}

const requestId = resumeRequestRef.current + 1
resumeRequestRef.current = requestId
const routeProfile = presenceRouteProfile(record)

const isCurrentOpen = () =>
resumeRequestRef.current === requestId && selectedStoredSessionIdRef.current === storedTarget

try {
await ensureGatewayProfile(routeProfile)

setFreshDraftReady(false)
setActiveSessionId(null)
activeSessionIdRef.current = null
busyRef.current = true
setBusy(true)
setAwaitingResponse(false)
clearNotifications()
setSelectedStoredSessionId(storedTarget)
selectedStoredSessionIdRef.current = storedTarget
setSessionStartedAt(Date.now())
setMessages([])

let opened: SessionResumeResponse

try {
opened = await requestGateway<SessionResumeResponse>('session.activate', {
cols: 96,
session_id: runtimeTarget
})
} catch {
opened = await requestGateway<SessionResumeResponse>('session.resume', {
cols: 96,
session_id: storedTarget
})
}

if (!isCurrentOpen()) {
return
}

const routedSessionId = opened.session_key?.trim() || storedTarget
const openedMessages = toChatMessages(opened.messages || [])
const runtimeInfo = applyRuntimeInfo(opened.info)

runtimeIdByStoredSessionIdRef.current.set(routedSessionId, opened.session_id)
setSelectedStoredSessionId(routedSessionId)
selectedStoredSessionIdRef.current = routedSessionId
setActiveSessionId(opened.session_id)
activeSessionIdRef.current = opened.session_id
setMessages(openedMessages)
patchSessionWorkspace(routedSessionId, runtimeInfo?.cwd)
updateSessionState(
opened.session_id,
state => ({
...state,
...(runtimeInfo ?? {}),
awaitingResponse: false,
busy: false,
messages: openedMessages
}),
routedSessionId
)
navigate(sessionRoute(routedSessionId))
} catch (err) {
if (isCurrentOpen()) {
notifyError(err, copy.resumeFailed)
}
} finally {
if (isCurrentOpen()) {
busyRef.current = false
setBusy(false)
setAwaitingResponse(false)
}
}
},
[
activeSessionIdRef,
busyRef,
copy,
navigate,
requestGateway,
runtimeIdByStoredSessionIdRef,
selectedStoredSessionIdRef,
updateSessionState
]
)

// Shared fork: create a child session seeded with `branchMessages`, linked to
// `parentStoredId` so it nests under its parent, then open it as its own tab
// and switch to it — the parent chat stays put (mirrors openNewSessionTile).
Expand Down Expand Up @@ -1457,6 +1571,7 @@ export function useSessionActions({
createBackendSessionForSend,
openNewSessionTile,
openSettings,
openPresenceSession,
removeSession,
resumeSession,
selectSidebarItem,
Expand Down
42 changes: 42 additions & 0 deletions apps/desktop/src/app/session/hooks/use-session-presence.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { useEffect } from 'react'

import { setSessionPresence } from '@/store/session'
import type { SessionPresenceListResponse } from '@/types/hermes'

const REFRESH_MS = 5_000

type GatewayRequester = <T = unknown>(method: string, params?: Record<string, unknown>) => Promise<T>

export function useSessionPresence(gatewayState: string | undefined, requestGateway: GatewayRequester) {
useEffect(() => {
if (gatewayState !== 'open') {
setSessionPresence([])

return
}

let cancelled = false

const refresh = async () => {
try {
const result = await requestGateway<SessionPresenceListResponse>('session.presence_list')

if (!cancelled) {
setSessionPresence(Array.isArray(result.sessions) ? result.sessions : [])
}
} catch {
if (!cancelled) {
setSessionPresence([])
}
}
}

void refresh()
const timer = window.setInterval(() => void refresh(), REFRESH_MS)

return () => {
cancelled = true
window.clearInterval(timer)
}
}, [gatewayState, requestGateway])
}
4 changes: 3 additions & 1 deletion apps/desktop/src/store/session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import type { ContextSuggestion } from '@/app/types'
import type { HermesConnection } from '@/global'
import type { ChatMessage } from '@/lib/chat-messages'
import { persistBoolean, persistString, storedBoolean, storedString } from '@/lib/storage'
import type { SessionInfo, UsageStats } from '@/types/hermes'
import type { SessionInfo, SessionPresenceRecord, UsageStats } from '@/types/hermes'

type Updater<T> = T | ((current: T) => T)
export type ComposerModelSource = '' | 'default' | 'manual'
Expand Down Expand Up @@ -341,6 +341,7 @@ export const $messagingTruncated = atom<boolean>(false)
// from the row count the query already returned.
export const $sessionProfilesTruncated = atom<Record<string, boolean>>({})
export const $sessionsLoading = atom(true)
export const $sessionPresence = atom<SessionPresenceRecord[]>([])
export const $activeSessionId = atom<string | null>(null)
export const $selectedStoredSessionId = atom<string | null>(null)
export interface ActiveSessionStoredIdRotation {
Expand Down Expand Up @@ -425,6 +426,7 @@ export const setMessagingTruncated = (next: Updater<boolean>) => updateAtom($mes
export const setSessionProfilesTruncated = (next: Updater<Record<string, boolean>>) =>
updateAtom($sessionProfilesTruncated, next)
export const setSessionsLoading = (next: Updater<boolean>) => updateAtom($sessionsLoading, next)
export const setSessionPresence = (next: Updater<SessionPresenceRecord[]>) => updateAtom($sessionPresence, next)
export const setActiveSessionId = (next: Updater<string | null>) => updateAtom($activeSessionId, next)
export const setActiveSessionStoredIdRotation = (next: Updater<ActiveSessionStoredIdRotation | null>) =>
updateAtom($activeSessionStoredIdRotation, next)
Expand Down
24 changes: 24 additions & 0 deletions apps/desktop/src/types/hermes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -501,6 +501,30 @@ export type TimelineDisplayMetadata =
duration_seconds?: number
}

export interface SessionPresenceRecord {
client?: string
cwd?: string
endpoint?: string
expires_at?: number
host?: string
instance_id?: string
metadata?: Record<string, unknown>
model?: string
pid?: number
profile?: string
session_id: string
session_key?: string
source?: string
status?: string
title?: string
updated_at?: number
version?: number
}

export interface SessionPresenceListResponse {
sessions: SessionPresenceRecord[]
}

export interface SessionMessage {
codex_reasoning_items?: unknown
content: unknown
Expand Down
Binary file added docs/evidence/session-presence-live-row.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Loading