Make your computer a home for your AI partner. Avibe is the local-first Agent OS: Vibey, its built-in AI partner, works out of the box, and Claude Code, Codex & OpenCode run unchanged beside it — reach them from your browser, phone, or any chat app.
Python agentagent-osaiai-agentsai-partnerchatopsclaudeclaude-codecodexdevtoolsdiscord-botlark-botllmlocal-firstlong-term-memoryopencodeslack-botvibe-codingvibeywechat
feat(ui): reference a session into the open chat from the sidebar menu
cyh047a02971da5
diff --git a/ui/src/App.tsx b/ui/src/App.tsxindex 97b652e7b..3488d9399 100644--- a/ui/src/App.tsx+++ b/ui/src/App.tsx@@ -30,6 +30,7 @@ import { ToastProvider } from './context/ToastContext';import { ThemeProvider } from './context/ThemeContext';import { WorkbenchInboxProvider } from './context/WorkbenchInboxContext';import { WorkbenchProjectsProvider } from './context/WorkbenchProjectsContext';+import { ComposerBridgeProvider } from './context/ComposerBridgeContext';import { AgentationToggle } from './components/AgentationToggle';import { useEffect, useState } from 'react';import type { ReactNode } from 'react';@@ -326,10 +327,12 @@ function App() {<ApiProvider><WorkbenchInboxProvider><WorkbenchProjectsProvider>- <BrowserRouter>- <AppRoutes />- </BrowserRouter>- <AgentationToggle />+ <ComposerBridgeProvider>+ <BrowserRouter>+ <AppRoutes />+ </BrowserRouter>+ <AgentationToggle />+ </ComposerBridgeProvider></WorkbenchProjectsProvider></WorkbenchInboxProvider></ApiProvider>diff --git a/ui/src/components/workbench/ChatPage.tsx b/ui/src/components/workbench/ChatPage.tsxindex b05977e38..00ad1f9f3 100644--- a/ui/src/components/workbench/ChatPage.tsx+++ b/ui/src/components/workbench/ChatPage.tsx@@ -6,6 +6,7 @@ import clsx from 'clsx';import { useApi } from '../../context/ApiContext';import { useWorkbenchInbox } from '../../context/WorkbenchInboxContext';+import { useRegisterComposerTarget, type ComposerInsertTarget } from '../../context/ComposerBridgeContext';import type { VibeAgentBrief, WorkbenchMessage, WorkbenchSession } from '../../context/ApiContext';import { apiFetch } from '../../lib/apiFetch';import { normalizeChatMessageFontSize } from '../../lib/chatDisplay';@@ -107,6 +108,21 @@ export const ChatPage: React.FC = () => {{ disabled: !sessionId },);+ // Publish this chat's composer to the ComposerBridge while it's mounted, so+ // the sidebar's "reference this session" action can insert a #<session>+ // mention into the open chat's input. Null target (no sessionId) = no chat+ // open, which hides that sidebar action.+ const insertSessionReference = useCallback(+ (refSessionId: string, title?: string | null) =>+ composerRef.current?.insertSessionReference(refSessionId, title),+ [],+ );+ const composerTarget = useMemo<ComposerInsertTarget | null>(+ () => (sessionId ? { sessionId, insertSessionReference } : null),+ [sessionId, insertSessionReference],+ );+ useRegisterComposerTarget(composerTarget);+// Back returns to the page the user came from, not a hardcoded inbox.// location.key === 'default' means /chat was the first history entry (deep// link / refresh) with nothing to pop back to — fall back to the inbox then.diff --git a/ui/src/components/workbench/Composer.tsx b/ui/src/components/workbench/Composer.tsxindex d5cdb760f..4f4dc7842 100644--- a/ui/src/components/workbench/Composer.tsx+++ b/ui/src/components/workbench/Composer.tsx@@ -126,6 +126,10 @@ export interface ComposerHandle {/** Stage + upload files from outside the composer — e.g. a chat-page-wide* drag-and-drop that drops onto the transcript rather than the input row. */addFiles: (files: File[]) => void;+ /** Insert a `#<session>` reference chip at the cursor (e.g. "reference this+ * session" from the sidebar). No-op when the mention editor isn't active+ * (the plain-textarea home composer). */+ insertSessionReference: (sessionId: string, title?: string | null) => void;}// The chat-style input row: an auto-growing textarea + a Send/Stop icon button,@@ -334,6 +338,11 @@ export const Composer = forwardRef<ComposerHandle, ComposerProps>(function Compo// deps array → always runs the latest uploadFiles closure for this session.useImperativeHandle(ref, () => ({addFiles: (files: File[]) => void uploadFiles(files),+ insertSessionReference: (refSessionId: string, title?: string | null) => {+ // Same node a typed `#` pick yields: trigger `#`, label = title||id, data+ // carries the stable sessionId → serializes to `#<id>` + a session ref.+ mentionRef.current?.insertMention('#', title?.trim() || refSessionId, { sessionId: refSessionId });+ },}));const startRecording = async () => {diff --git a/ui/src/components/workbench/MentionEditor.tsx b/ui/src/components/workbench/MentionEditor.tsxindex c8c3bc2c2..573c5a747 100644--- a/ui/src/components/workbench/MentionEditor.tsx+++ b/ui/src/components/workbench/MentionEditor.tsx@@ -30,6 +30,7 @@ import {BeautifulMentionsPlugin,BeautifulMentionNode,$isBeautifulMentionNode,+ useBeautifulMentions,type BeautifulMentionsItem,type BeautifulMentionsMenuProps,type BeautifulMentionsMenuItemProps,@@ -55,6 +56,14 @@ export interface MentionEditorHandle {append: (text: string) => void;/** Replace the whole editor with plain text (restore on a failed send). */setText: (text: string) => void;+ /** Insert a mention chip at the current cursor — same node a picker-selected+ * `@`/`#` yields — when triggered from outside the editor (e.g. "reference+ * this session" in the sidebar). */+ insertMention: (+ trigger: string,+ value: string,+ data?: Record<string, string | number | boolean | null>,+ ) => void;}export interface MentionEditorProps {@@ -223,6 +232,7 @@ function BootstrapPlugin({bridgeRef: Ref<MentionEditorHandle>;}) {const [editor] = useLexicalComposerContext();+ const { insertMention: insertBeautifulMention } = useBeautifulMentions();const seeded = useRef(false);useImperativeHandle(@@ -250,8 +260,13 @@ function BootstrapPlugin({root.append(paragraph);if (text) paragraph.selectStart().insertText(text);}),+ // Insert at the live selection (Lexical keeps it across DOM blur), then+ // focus so the user can keep typing. Produces the same node a typed+ // `#`/`@` pick does, so serialization (#<id> + references) is identical.+ insertMention: (trigger, value, data) =>+ insertBeautifulMention({ trigger, value, data: data ?? {}, focus: true }),}),- [editor],+ [editor, insertBeautifulMention],);useEffect(() => {diff --git a/ui/src/components/workbench/WorkbenchSidebar.tsx b/ui/src/components/workbench/WorkbenchSidebar.tsxindex 8e77e41de..299770baa 100644--- a/ui/src/components/workbench/WorkbenchSidebar.tsx+++ b/ui/src/components/workbench/WorkbenchSidebar.tsx@@ -13,6 +13,7 @@ import {Folder,FolderOpen,FolderPlus,+ Hash,Inbox,KeyRound,Loader2,@@ -26,6 +27,7 @@ import type { LucideIcon } from 'lucide-react';import { useWorkbenchInbox } from '../../context/WorkbenchInboxContext';import { useWorkbenchProjectsTree } from '../../context/WorkbenchProjectsContext';+import { useComposerInsertTarget } from '../../context/ComposerBridgeContext';import type { InboxSession, WorkbenchProject, WorkbenchSession } from '../../context/ApiContext';import { formatRelativeTime } from '../../lib/relativeTime';import { Popover, PopoverAnchor, PopoverContent, PopoverTrigger } from '../ui/popover';@@ -200,6 +202,10 @@ const SessionRow: React.FC<{const navigate = useNavigate();const location = useLocation();const active = location.pathname === `/chat/${session.id}`;+ // "Reference this session" shows only when a chat composer is mounted (a chat+ // is open) AND this row isn't that open session — you can't reference yourself.+ const insertTarget = useComposerInsertTarget();+ const canReference = insertTarget != null && insertTarget.sessionId !== session.id;const [menuOpen, setMenuOpen] = useState(false);const [archiveOpen, setArchiveOpen] = useState(false);const [renaming, setRenaming] = useState(false);@@ -303,6 +309,19 @@ const SessionRow: React.FC<{</button></PopoverAnchor><PopoverContent align="start" className="w-[176px] p-1">+ {canReference && (+ <button+ type="button"+ onClick={() => {+ setMenuOpen(false);+ insertTarget?.insertSessionReference(session.id, session.title);+ }}+ className="flex w-full items-center gap-2 rounded px-2 py-1.5 text-left text-[12px] text-foreground transition hover:bg-foreground/[0.04]"+ >+ <Hash className="size-3 text-muted" />+ {t('workbench.sessionReference')}+ </button>+ )}<buttontype="button"onClick={() => {diff --git a/ui/src/context/ComposerBridgeContext.tsx b/ui/src/context/ComposerBridgeContext.tsxnew file mode 100644index 000000000..3191ad89a--- /dev/null+++ b/ui/src/context/ComposerBridgeContext.tsx@@ -0,0 +1,50 @@+import { createContext, useContext, useEffect, useState, type ReactNode } from 'react';++/**+ * Bridges the chat composer (mounted only inside ChatPage) to components that+ * live outside it — e.g. the sidebar's "reference this session" action, which+ * needs to drop a `#<session>` mention into the currently-open chat's input.+ *+ * `target` is the active chat composer, or `null` when no chat is open. That+ * null/non-null state is exactly the "is the user on a Chat page?" gate the+ * sidebar menu item needs — no separate route check required.+ */+export type ComposerInsertTarget = {+ /** The session whose composer is currently mounted (the open chat). */+ sessionId: string;+ /** Insert a `#<session>` reference chip at the composer's cursor. */+ insertSessionReference: (sessionId: string, title?: string | null) => void;+};++type ComposerBridge = {+ target: ComposerInsertTarget | null;+ setTarget: (target: ComposerInsertTarget | null) => void;+};++const ComposerBridgeContext = createContext<ComposerBridge | null>(null);++export const ComposerBridgeProvider = ({ children }: { children: ReactNode }) => {+ const [target, setTarget] = useState<ComposerInsertTarget | null>(null);+ return (+ <ComposerBridgeContext.Provider value={{ target, setTarget }}>{children}</ComposerBridgeContext.Provider>+ );+};++/** Consumer side (sidebar session menu): the active composer target, or null. */+export const useComposerInsertTarget = (): ComposerInsertTarget | null =>+ useContext(ComposerBridgeContext)?.target ?? null;++/**+ * Producer side (ChatPage): publish `target` while this chat is mounted, clear+ * it on unmount / session change. Only one ChatPage is mounted at a time, so a+ * plain set-on-mount / clear-on-unmount is safe. `target` MUST be memoized by+ * the caller (e.g. on sessionId) so the effect doesn't re-run every render.+ */+export const useRegisterComposerTarget = (target: ComposerInsertTarget | null): void => {+ const setTarget = useContext(ComposerBridgeContext)?.setTarget;+ useEffect(() => {+ if (!setTarget) return;+ setTarget(target);+ return () => setTarget(null);+ }, [setTarget, target]);+};diff --git a/ui/src/i18n/en.json b/ui/src/i18n/en.jsonindex d33462f36..3c9ed5cad 100644--- a/ui/src/i18n/en.json+++ b/ui/src/i18n/en.json@@ -582,6 +582,7 @@"projectRenamePlaceholder": "New name","sessionRename": "Rename","sessionRenamePlaceholder": "Session name",+ "sessionReference": "Reference this session","sessionArchive": "Archive session","archiveSession": {"title": "Archive this session permanently?",diff --git a/ui/src/i18n/zh.json b/ui/src/i18n/zh.jsonindex ad2d551c9..eb411d09b 100644--- a/ui/src/i18n/zh.json+++ b/ui/src/i18n/zh.json@@ -582,6 +582,7 @@"projectRenamePlaceholder": "新名字","sessionRename": "重命名","sessionRenamePlaceholder": "会话名称",+ "sessionReference": "引用该会话","sessionArchive": "归档会话","archiveSession": {"title": "永久归档此会话?",