The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(desktop): bot chats share core's unread and drop the branch rail
Brooklyn Nicholson67854b50b03a
diff --git a/apps/desktop/src/app/chat/composer/index.tsx b/apps/desktop/src/app/chat/composer/index.tsxindex dff9371f547..f6e562ad358 100644--- a/apps/desktop/src/app/chat/composer/index.tsx+++ b/apps/desktop/src/app/chat/composer/index.tsx@@ -12,6 +12,7 @@ import { PR_COMMENT_URL_RE } from '@/lib/chat-runtime'import { sanitizeComposerInput } from '@/lib/composer-input-sanitize'import { DATA_IMAGE_URL_RE } from '@/lib/embedded-images'import { triggerHaptic } from '@/lib/haptics'+import { useStoreSelector } from '@/lib/use-session-slice'import { cn } from '@/lib/utils'import { interceptsTypedVoiceStop } from '@/lib/voice-stop-word'import { sessionCompacting } from '@/store/compaction'@@ -22,6 +23,7 @@ import { $hudMode } from '@/store/hud'import { sessionBlockingPrompt } from '@/store/prompts'import { toggleReview } from '@/store/review'import { $gatewayState } from '@/store/session'+import { $sessionStates, isBotChatSession } from '@/store/session-states'import { $threadScrolledUp } from '@/store/thread-scroll'import { $autoSpeakReplies } from '@/store/voice-prefs'import { useTheme } from '@/themes'@@ -922,6 +924,10 @@ export function ChatBar({handleInputDrop} = useComposerDrop({ cwd, insertInlineRefs, onAttachDroppedItems, requestMainFocus })+ // A bot chat is a companion conversation, not a working session, so it has no+ // repo to speak of — see the blank repoPath handed to CodingStatusRow below.+ const botChat = useStoreSelector($sessionStates, () => isBotChatSession(sessionId))+// Branch / worktree hand-offs (CodingStatusRow). Owns the worktree open +// branch-off/convert/list/switch actions; draft travels into the new session.const { handleBranchOff, handleConvertBranch, handleListBranches, handleSwitchBranch, openInWorktree } =@@ -1291,7 +1297,10 @@ export function ChatBar({onOpen={() => toggleReview(scope.target === 'main' ? null : (cwd ?? null), scope.target)}onOpenWorktree={openInWorktree}onSwitchBranch={handleSwitchBranch}- repoPath={cwd}+ // Blank in a bot chat: the row hides itself without a repo,+ // and stops probing git / GitHub for a surface that has no+ // branch to show. Cheaper than a second composer.+ repoPath={botChat ? undefined : cwd}/><divclassName={cn(diff --git a/apps/desktop/src/store/session-states.ts b/apps/desktop/src/store/session-states.tsindex 98143ffa8a1..bb4c5e97db0 100644--- a/apps/desktop/src/store/session-states.ts+++ b/apps/desktop/src/store/session-states.ts@@ -1071,7 +1071,50 @@ export function storedSessionIdForRuntimeId(sessionId: string): null | string {return mirrored || null}+const BOT_CHAT_SCOPE_KEY = 'hermes.desktop.botChatSessions.v1'++/** Stored ids last opened as a bot's chat. A tile carries `workspaceMode`, but+ * a bot chat normally lands in MAIN — `in-place` mints no tile when there is+ * none to front — and main has no tile to carry the scope on. Kept here so a+ * surface can still tell a companion chat from a working session, persisted+ * so that survives a relaunch the way tile scope does. */+export const $botChatSessionIds = atom<ReadonlySet<string>>(+ new Set((readJson<unknown>(BOT_CHAT_SCOPE_KEY) as unknown[] | null)?.filter(id => typeof id === 'string') ?? [])+)++function rememberBotChatScope(storedSessionId: string, isBotChat: boolean): void {+ const current = $botChatSessionIds.get()++ if (current.has(storedSessionId) === isBotChat) {+ return+ }++ const next = new Set(current)++ if (isBotChat) {+ next.add(storedSessionId)+ } else {+ next.delete(storedSessionId)+ }++ $botChatSessionIds.set(next)+ writeJson(BOT_CHAT_SCOPE_KEY, next.size ? [...next] : null)+}++/** True while this live session is a bot's chat rather than a working session.+ * Surfaces read it to drop coding chrome that means nothing in a companion+ * conversation — the composer's branch/worktree rail. */+export function isBotChatSession(sessionId: null | string | undefined): boolean {+ const stored = sessionId ? storedSessionIdForRuntimeId(sessionId) : null++ return Boolean(stored && $botChatSessionIds.get().has(stored))+}+export function setSessionTileWorkspaceScope(storedSessionId: string, scope: SessionTileWorkspaceScope): boolean {+ // Before the tile lookup: openSession routes every open through here, and a+ // bot chat usually has no tile to record the scope on.+ rememberBotChatScope(storedSessionId, scope.workspaceMode === 'bots')+const tile = $sessionTiles.get().find(candidate => candidate.storedSessionId === storedSessionId)const workspaceOwnerKey = scope.workspaceMode === 'bots' ? scope.workspaceOwnerKey : undefinedconst ownerRoute = scope.workspaceMode === 'bots' ? scope.ownerRoute : undefineddiff --git a/apps/desktop/src/store/session-unread.ts b/apps/desktop/src/store/session-unread.tsindex c3e12122f55..de0f7ed6049 100644--- a/apps/desktop/src/store/session-unread.ts+++ b/apps/desktop/src/store/session-unread.ts@@ -43,9 +43,11 @@ import { isBrowserWindow, isSecondaryWindow } from './windows'* cross-profile, `$sessions` is too in all-profiles mode). Unscoped keys let* one profile's watermark/marker paint (or silence) another's row. The bucket* is always the ROW's own `profile` (normalizeProfileKey, absent → "default"),- * never the live gateway's — except for the live busy→idle edge with no loaded- * row, which only ever fires for the ACTIVE gateway's runtimes and therefore- * falls back to `$activeGatewayProfile`.+ * never the live gateway's. Only an id with NO loaded row has no profile to+ * read: it uses the caller's `profileHint` when there is one (a permanently+ * hidden session, e.g. a Bot Mode canonical chat, is never listed and can+ * belong to a profile the gateway isn't homed on), else `$activeGatewayProfile`+ * — the only place a live busy→idle edge can come from.** Both records are BOUNDED: markers cap per profile (oldest evicted),* watermarks cap in total (unlisted, unmarked entries dropped first), and@@ -173,11 +175,19 @@ function resolveLoadedRow(storedSessionId: string): SessionInfo | undefined {return matches.find(row => profileKeyForRow(row) === gateway) ?? matches[0]}+/** Bucket for a stored id with NO loaded row. The live gateway's profile is+ * the right answer for anything born of a live turn, but a permanently+ * hidden session (a Bot Mode canonical chat) is never in any list and can+ * belong to a profile the gateway isn't homed on — those callers pass the+ * owning profile they already know. */+const unlistedProfile = (hint?: null | string): string =>+ normalizeProfileKey((hint ?? '').trim() || $activeGatewayProfile.get())+/** Bucket for a bare stored id: its row's profile, else the live gateway's. */const resolveProfile = (storedSessionId: string): string => {const row = resolveLoadedRow(storedSessionId)- return row ? profileKeyForRow(row) : normalizeProfileKey($activeGatewayProfile.get())+ return row ? profileKeyForRow(row) : unlistedProfile()}/** Write a profile's marker bucket, dropping the key when it empties so we@@ -195,12 +205,13 @@ function setMarkerBucket(profile: string, ids: readonly string[]): void {$unreadFinishedMarkers.set(next)}-/** LIVE-EDGE WRITER — called by session-states.ts on a background busy→idle- * transition. Flags the transient atom (immediate paint) AND persists the- * marker so the dot survives a restart. The marker lands in the row's own- * profile; with no loaded row we use the active gateway's profile, which is- * the only place a live edge can come from. */-export function markSessionUnreadFinished(storedSessionId: string): void {+/** UNREAD WRITER — the live busy→idle edge (session-states.ts) and any surface+ * that learns out-of-band that a session produced something the user hasn't+ * seen. Flags the transient atom (immediate paint) AND persists the marker so+ * the dot survives a restart. The marker lands in the row's own profile; with+ * no loaded row it lands in `profileHint`'s, falling back to the active+ * gateway's — the only place a live edge can come from. */+export function markSessionUnreadFinished(storedSessionId: string, profileHint?: null | string): void {const current = $unreadFinishedSessionIds.get()if (!current.includes(storedSessionId)) {@@ -208,7 +219,7 @@ export function markSessionUnreadFinished(storedSessionId: string): void {}const row = resolveLoadedRow(storedSessionId)- const profile = row ? profileKeyForRow(row) : normalizeProfileKey($activeGatewayProfile.get())+ const profile = row ? profileKeyForRow(row) : unlistedProfile(profileHint)const durableId = row ? sessionPinId(row) : storedSessionIdconst bucket = $unreadFinishedMarkers.get()[profile] ?? []@@ -251,10 +262,13 @@ function ackSessionRow(row: SessionInfo): void {/** Clear persisted unread for a stored id even when its row isn't loaded —* the marker alone can be retired; the watermark needs the row's count. With- * no row there is no profile to read, so we retire it from the active- * gateway's bucket (the profile whose sessions you can actually be opening);- * other profiles' identically-named ids stay untouched. */-export function ackStoredSessionId(storedSessionId: null | string): void {+ * no row there is no profile to read, so we retire it from `profileHint`'s+ * bucket, falling back to the active gateway's (the profile whose sessions+ * you can actually be opening); other profiles' identically-named ids stay+ * untouched. Pass the hint whenever the caller knows the owner — a hidden+ * session can be opened without the gateway ever moving onto its profile,+ * which would otherwise ack a bucket that never held the marker. */+export function ackStoredSessionId(storedSessionId: null | string, profileHint?: null | string): void {if (!storedSessionId) {return}@@ -267,7 +281,7 @@ export function ackStoredSessionId(storedSessionId: null | string): void {return}- const profile = normalizeProfileKey($activeGatewayProfile.get())+ const profile = unlistedProfile(profileHint)const markers = $unreadFinishedMarkers.get()[profile]if (!markers) {@@ -561,5 +575,7 @@ if (!isSecondaryWindow() && !isBrowserWindow()) {// Opening a session acks it durably (the transient atom is already cleared// synchronously by setSelectedStoredSessionId — this is the persisted half).- $selectedStoredSessionId.listen(ackStoredSessionId)+ // Unary on purpose: nanostores hands a listener (value, oldValue), and the+ // old selection would otherwise arrive as the profile hint.+ $selectedStoredSessionId.listen(id => ackStoredSessionId(id))}