Skip to content

The agent that grows with you

fix: retained group panes re-anchor to the latest message on reopen

Tekniume30388e409a9
diff --git a/apps/desktop/src/plugins/hermes-bots/plugin.js b/apps/desktop/src/plugins/hermes-bots/plugin.js
index 19e3ccf8077..d2315d471e0 100644
--- a/apps/desktop/src/plugins/hermes-bots/plugin.js
+++ b/apps/desktop/src/plugins/hermes-bots/plugin.js
@@ -62,7 +62,7 @@ import {
useQuery,
useValue
} from '@hermes/plugin-sdk'
-import { useEffect, useRef, useState } from 'react'
+import { useEffect, useMemo, useRef, useState } from 'react'
import { jsx, jsxs } from 'react/jsx-runtime'
const { McpTab, ToolsetConfigPanel } = sdk
@@ -9268,7 +9268,7 @@ function GroupClarifyCard({ entry, members }) {
})
}
-function GroupChatWorkspace({ group, members, onBack }) {
+function GroupChatWorkspace({ group, members, onBack, visible = true }) {
const rooms = useValue($groupChats)
const allMeta = useValue($botMeta)
const room = rooms[group] || { log: [], running: false }
@@ -9325,6 +9325,22 @@ function GroupChatWorkspace({ group, members, onBack }) {
}
}, [room.log.length, room.running])
+ // Retained-pane reopen (#89835 follow-up): a hot-mounted room pane stays
+ // mounted while another workspace tab is active, so returning to it never
+ // remounts and the mount-time anchor doesn't rerun. Re-anchor on the
+ // hidden → visible edge — an explicit reopen, so it overrides a stale
+ // read-position and mirrors what a fresh open does.
+ const wasVisibleRef = useRef(visible)
+
+ useEffect(() => {
+ if (visible && !wasVisibleRef.current) {
+ stickToBottomRef.current = true
+ bottomSentinelRef.current?.scrollIntoView({ block: 'end' })
+ }
+
+ wasVisibleRef.current = visible
+ }, [visible])
+
const imagesFor = thread => pendingImages[thread ?? 'main'] || []
const addImages = (thread, picked) => {
@@ -10049,15 +10065,25 @@ function closeGroupChatMainTab(group) {
/** Main-window wrapper: seats the member roster reactively (live roster +
* bot meta + the room's stored cross-connection descriptors) so the room
- * keeps working as members change while the tab is open. */
+ * keeps working as members change while the tab is open. Also subscribes to
+ * this pane's visibility (feature-detected host.paneVisibility): retained
+ * panes stay mounted while hidden, so the workspace needs the hidden →
+ * visible edge to re-anchor its log to the bottom (#89835 follow-up). */
function GroupChatMainView({ group }) {
const allMeta = useValue($botMeta)
// Subscribe: membership changes ride bot meta AND the room record.
useValue($groupChats)
const roster = useValue($lastRoster)
const members = groupChatMemberBots(group, roster, allMeta)
+ // Older SDKs have no paneVisibility: fall back to an always-visible atom so
+ // the hook order stays stable and behavior matches the previous build.
+ const $visible = useMemo(
+ () => (typeof host.paneVisibility === 'function' ? host.paneVisibility(`plugin-workspace:${ID}:group:${slugify(group)}`) : atom(true)),
+ [group]
+ )
+ const visible = useValue($visible)
- return jsx(GroupChatWorkspace, { group, members, onBack: () => closeGroupChatMainTab(group) })
+ return jsx(GroupChatWorkspace, { group, members, visible, onBack: () => closeGroupChatMainTab(group) })
}
/** Open a group chat the Discord way: a tab taking over the MAIN chat window
diff --git a/apps/desktop/src/plugins/hermes-bots/tests/group-room-ux.test.mjs b/apps/desktop/src/plugins/hermes-bots/tests/group-room-ux.test.mjs
index 31b31c82066..cc32992b952 100644
--- a/apps/desktop/src/plugins/hermes-bots/tests/group-room-ux.test.mjs
+++ b/apps/desktop/src/plugins/hermes-bots/tests/group-room-ux.test.mjs
@@ -15,10 +15,11 @@ const source = readFileSync(new URL('../plugin.js', import.meta.url), 'utf8')
// until the user's NEXT send (harvest only ran inside the loop).
test('room composer is a textarea with Enter=submit, Shift+Enter=newline (#89884)', () => {
- const component = source.slice(
- source.indexOf('function GroupMentionInput'),
- source.indexOf('function GroupChatWorkspace')
- )
+ // Slice ONLY GroupMentionInput — functions merged between it and
+ // GroupChatWorkspace (e.g. GroupClarifyCard) legitimately use Input.
+ const start = source.indexOf('function GroupMentionInput')
+ const nextFn = source.indexOf('\nfunction ', start + 1)
+ const component = source.slice(start, nextFn)
// The control is the SDK Textarea, not the single-line Input.
assert.match(component, /jsx\(Textarea, \{/)
@@ -44,6 +45,21 @@ test('room log anchors to the bottom with a user-scroll guard (#89835)', () => {
assert.match(workspace, /scrollIntoView/)
})
+test('retained-pane reopen re-anchors to the bottom (#89835 follow-up)', () => {
+ // A hot-mounted room pane never remounts when the user tabs back to it, so
+ // the workspace re-anchors on the hidden → visible edge, fed by the
+ // feature-detected host.paneVisibility authority (always-visible fallback
+ // keeps older SDKs on the previous behavior).
+ const workspace = source.slice(source.indexOf('function GroupChatWorkspace'))
+ assert.match(workspace, /visible = true/)
+ assert.match(workspace, /wasVisibleRef/)
+ assert.match(workspace, /\[visible\]/)
+ const mainView = source.slice(source.indexOf('function GroupChatMainView'), source.indexOf('function openGroupChat'))
+ assert.match(mainView, /typeof host\.paneVisibility === 'function'/)
+ assert.match(mainView, /plugin-workspace:\$\{ID\}:group:\$\{slugify\(group\)\}/)
+ assert.match(mainView, /atom\(true\)/)
+})
+
test('stranded replies get a bounded background harvest after the loop settles (#89545)', () => {
assert.match(source, /function harvestStrandedUntilSettled\(/)
// The loop's finally block kicks it off only when members remain stranded.
diff --git a/apps/desktop/src/plugins/hermes-bots/tests/legacy-sdk-compat.test.mjs b/apps/desktop/src/plugins/hermes-bots/tests/legacy-sdk-compat.test.mjs
index 159c7bf5afd..8add88a4f35 100644
--- a/apps/desktop/src/plugins/hermes-bots/tests/legacy-sdk-compat.test.mjs
+++ b/apps/desktop/src/plugins/hermes-bots/tests/legacy-sdk-compat.test.mjs
@@ -69,7 +69,7 @@ function writeReactStubs(root) {
2
)}\n`
)
- writeFileSync(join(packageRoot, 'index.js'), proxyModule(['useEffect', 'useRef', 'useState']))
+ writeFileSync(join(packageRoot, 'index.js'), proxyModule(['useEffect', 'useMemo', 'useRef', 'useState']))
writeFileSync(join(packageRoot, 'jsx-runtime.js'), proxyModule(['jsx', 'jsxs']))
}