Skip to content

armgit / avibe

Public Imported from GitHub
0

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.

fix(search): address Codex review round 4 (6 P2)

cyhe340e9bf429e
diff --git a/ui/src/components/workbench/ChatPage.tsx b/ui/src/components/workbench/ChatPage.tsx
index 983d8de9a..acd7f3610 100644
--- a/ui/src/components/workbench/ChatPage.tsx
+++ b/ui/src/components/workbench/ChatPage.tsx
@@ -811,8 +811,24 @@ export const ChatPage: React.FC = () => {
void refreshQueue();
return;
}
- // A turn started — optimistically show the user row (echo dedupes by id).
- if (body && body.id) appendMessage(body as WorkbenchMessage);
+ // A turn started — show the user row. If we're in an around-jump window
+ // (a search jump landed away from the live tail, newerCursor set), the
+ // transcript is a centered historical window with a deliberate gap to the
+ // tail — appendMessage would graft the just-sent prompt disjointly below
+ // that window (same hole the SSE/reconcile guards avoid). Instead exit
+ // around-mode and catch up to the live tail (which already contains the
+ // persisted prompt) via the shared tail-reload, then scroll the sent row
+ // into view. Outside around-mode, append optimistically (echo dedupes).
+ if (body && body.id) {
+ if (newerCursorRef.current) {
+ await jumpToLatest();
+ if (sessionId === sessionIdRef.current) {
+ setJumpTarget((body as WorkbenchMessage).id);
+ }
+ } else {
+ appendMessage(body as WorkbenchMessage);
+ }
+ }
} catch (err: any) {
if (sessionId === sessionIdRef.current) {
setWorking(false);
@@ -823,7 +839,7 @@ export const ChatPage: React.FC = () => {
}
}
},
- [sessionId, appendMessage, refreshQueue, markWorking],
+ [sessionId, appendMessage, refreshQueue, markWorking, jumpToLatest],
);
// @ mention source: all enabled Agents, filtered client-side (the set is small
@@ -1093,7 +1109,14 @@ export const ChatPage: React.FC = () => {
// reconcile update can't cancel the in-flight around-fetch (Codex P2).
cancelled = true;
};
- }, [deepLinkMessageId, sessionId, loading, session, api, startHighlight, setSearchParams]);
+ // Depend on ``session?.id`` (stable), NOT the whole ``session`` object: a
+ // title / native-bind / agent_status update landing while the around-fetch
+ // is in flight would otherwise re-run this effect — running the cleanup
+ // (cancelling the fetch), then exiting via handledJumpRef so the fetched
+ // window is dropped and ``?msg`` stays unhandled (Codex P2). The closure
+ // still reads ``session`` for the ``!session`` / ``session.id !== sessionId``
+ // readiness checks; it only needs to re-run when the id changes.
+ }, [deepLinkMessageId, sessionId, loading, session?.id, api, startHighlight, setSearchParams]);
// Re-arm the jump guard once ``?msg=`` is gone. ``clearParam`` (above) nulls
// the param after handling, so without this re-selecting the SAME search hit
@@ -1121,11 +1144,20 @@ export const ChatPage: React.FC = () => {
// inbox.session.updated lands after a reply — so the Inbox/sidebar never badge
// the chat you're looking at. Reactive to the unread map, so it's race-free
// against the cross-process event ordering.
+ //
+ // EXCEPT while in an around-jump window (newerCursor set): the SSE feed DROPS
+ // live tail rows there (see the message.new guard) so a fresh agent reply is
+ // neither rendered nor at the bottom of the loaded window — marking it read
+ // here would silently swallow it (no badge, no row), and the user would never
+ // know it arrived. Suppress the mark-read until the user catches up to the
+ // live tail (newerCursor clears) — listing ``newerCursor`` in the deps re-runs
+ // this then, so any still-unread reply gets marked read once it's visible.
useEffect(() => {
+ if (newerCursor) return;
if (sessionId && (unreadBySession[sessionId] ?? 0) > 0) {
void markInboxRead(sessionId);
}
- }, [sessionId, unreadBySession, markInboxRead]);
+ }, [sessionId, unreadBySession, markInboxRead, newerCursor]);
// The Workbench canvas creates the session and hands its first message over
// as router state. Replay it once through the compose path so the agent turn
diff --git a/ui/src/components/workbench/SearchPage.tsx b/ui/src/components/workbench/SearchPage.tsx
index b45bf48a0..6cc6a1cd2 100644
--- a/ui/src/components/workbench/SearchPage.tsx
+++ b/ui/src/components/workbench/SearchPage.tsx
@@ -1,9 +1,10 @@
import { useEffect, useRef, useState } from 'react';
import { useTranslation } from 'react-i18next';
-import { useLocation, useNavigate } from 'react-router-dom';
+import { useLocation, useNavigate, useSearchParams } from 'react-router-dom';
import { ChevronLeft, Loader2, Search, X } from 'lucide-react';
import { useMessageSearch } from '../../lib/useMessageSearch';
+import { Button } from '../ui/button';
import { SearchResultGroup } from './search/SearchResultGroup';
// Mobile full-screen message-content search (design.pen K7Bytg "M · Search
@@ -18,10 +19,32 @@ export const SearchPage: React.FC = () => {
const { t } = useTranslation();
const navigate = useNavigate();
const location = useLocation();
- const [query, setQuery] = useState('');
+ // The query lives in the URL (?q=…), not just component state, so navigating
+ // INTO a result (push /chat/…?msg=…) and back (navigate(-1) → /search?q=…)
+ // restores it — otherwise Back would land on a blank search page. Seed the
+ // input from the param on mount and mirror every keystroke back into it.
+ const [searchParams, setSearchParams] = useSearchParams();
+ const [query, setQuery] = useState(() => searchParams.get('q') ?? '');
const { results, loading } = useMessageSearch(query);
const inputRef = useRef<HTMLInputElement | null>(null);
+ // Drive the query (state + URL together). ``replace: true`` so each keystroke
+ // updates ?q= in place instead of pushing a history entry per character (Back
+ // would otherwise step through every intermediate query). Preserve any other
+ // params already on the URL.
+ const updateQuery = (next: string) => {
+ setQuery(next);
+ setSearchParams(
+ (prev) => {
+ const params = new URLSearchParams(prev);
+ if (next) params.set('q', next);
+ else params.delete('q');
+ return params;
+ },
+ { replace: true },
+ );
+ };
+
// Autofocus the field on mount so typing flows straight in (the search page
// exists only to search). iOS sometimes needs the focus deferred a tick past
// the route transition for the soft keyboard to come up.
@@ -42,7 +65,7 @@ export const SearchPage: React.FC = () => {
// already-empty field it doubles as a back affordance.
const onClear = () => {
if (query) {
- setQuery('');
+ updateQuery('');
inputRef.current?.focus();
} else {
goBack();
@@ -62,20 +85,22 @@ export const SearchPage: React.FC = () => {
<div className="fixed inset-0 z-40 flex flex-col bg-background pt-[env(safe-area-inset-top)] md:absolute">
{/* Header — back chevron + active search field (design.pen P6Nsz/KmsNV). */}
<header className="flex shrink-0 items-center gap-2.5 border-b border-border bg-background/92 px-4 py-3 backdrop-blur">
- <button
+ <Button
type="button"
+ variant="ghost"
+ size="icon"
onClick={goBack}
aria-label={t('common.back')}
- className="flex size-9 shrink-0 items-center justify-center rounded-lg border border-border-strong bg-foreground/[0.04] text-foreground transition hover:bg-foreground/[0.08]"
+ className="size-9 shrink-0 rounded-lg border border-border-strong bg-foreground/[0.04] hover:bg-foreground/[0.08]"
>
<ChevronLeft className="size-5" />
- </button>
+ </Button>
<div className="flex min-w-0 flex-1 items-center gap-2.5 rounded-xl border border-border-strong bg-foreground/[0.04] px-3 py-2.5">
<Search className="size-4 shrink-0 text-mint" />
<input
ref={inputRef}
value={query}
- onChange={(e) => setQuery(e.target.value)}
+ onChange={(e) => updateQuery(e.target.value)}
placeholder={t('workbench.search.placeholder')}
aria-label={t('workbench.search.placeholder')}
className="min-w-0 flex-1 bg-transparent text-[15px] text-foreground outline-none placeholder:text-muted"
@@ -85,14 +110,16 @@ export const SearchPage: React.FC = () => {
enterKeyHint="search"
/>
{loading && <Loader2 className="size-4 shrink-0 animate-spin text-muted" />}
- <button
+ <Button
type="button"
+ variant="ghost"
+ size="icon"
onClick={onClear}
aria-label={t('common.clear')}
- className="flex size-5 shrink-0 items-center justify-center rounded-md text-muted transition hover:text-foreground"
+ className="size-5 shrink-0 rounded-md text-muted hover:bg-transparent hover:text-foreground [&_svg]:size-4"
>
<X className="size-4" />
- </button>
+ </Button>
</div>
</header>
diff --git a/ui/src/components/workbench/search/SearchPalette.tsx b/ui/src/components/workbench/search/SearchPalette.tsx
index d12895682..b033273c6 100644
--- a/ui/src/components/workbench/search/SearchPalette.tsx
+++ b/ui/src/components/workbench/search/SearchPalette.tsx
@@ -99,6 +99,11 @@ export const SearchPalette: React.FC<SearchPaletteProps> = ({ open, onClose }) =
e.preventDefault();
moveSelection(-1);
} else if (e.key === 'Enter') {
+ // Result rows are real <Button>s now (focusable via Tab). Only treat Enter
+ // as "open the arrow-selected hit" while the SEARCH INPUT holds focus; when
+ // a row Button is focused, let its native Enter→click fire so the FOCUSED
+ // row activates instead of the (possibly different) arrow-selected one.
+ if (document.activeElement !== inputRef.current) return;
e.preventDefault();
const target = flatMatches.find((m) => m.messageId === selectedId);
if (target) handleSelect(target.sessionId, target.messageId);