-
Notifications
You must be signed in to change notification settings - Fork 0
feat: add cross-session transcript search #62
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
5c37716
feat: add cross-session transcript search
wolfiesch a865f2a
fix: complete transcript search negotiation
wolfiesch 01d9d11
fix: validate transcript search identifiers
wolfiesch 0becb90
chore: refresh transcript search provenance
wolfiesch e84672d
test: derive current app-wire fixtures
wolfiesch 3a73be1
Merge remote-tracking branch 'origin/main' into codex/cross-session-t…
wolfiesch bf11a0d
Merge remote-tracking branch 'origin/main' into codex/cross-session-t…
wolfiesch File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
211 changes: 211 additions & 0 deletions
211
apps/web/src/features/transcript-search/LiveTranscriptSearch.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,211 @@ | ||
| import { useNavigate } from "@tanstack/react-router"; | ||
| import { useCallback, useEffect, useLayoutEffect, useMemo, useRef, useState } from "react"; | ||
|
|
||
| import { desktopRuntime } from "../../platform/desktop-runtime.ts"; | ||
| import { useShellData } from "../../state/shell-data.ts"; | ||
| import { fixtureTranscriptSearchSource } from "./fixtures.ts"; | ||
| import { LatestTranscriptSearchExecutor } from "./execution.ts"; | ||
| import type { HistoricContextState, TranscriptSearchPhase } from "./TranscriptSearchScreen.tsx"; | ||
| import { TranscriptSearchScreen } from "./TranscriptSearchScreen.tsx"; | ||
| import { | ||
| DEFAULT_TRANSCRIPT_SEARCH_FILTERS, | ||
| type TranscriptSearchFilters, | ||
| type TranscriptSearchResponse, | ||
| type TranscriptSearchResult, | ||
| transcriptSearchCanRun, | ||
| } from "./model.ts"; | ||
| import { | ||
| setTranscriptSearchQuery, | ||
| TranscriptSearchHandoffTracker, | ||
| useTranscriptSearchMemory, | ||
| } from "./search-memory.ts"; | ||
| import { clientTranscriptSearchSource } from "./source.ts"; | ||
| import type { DesktopRuntimeController } from "@t4-code/client"; | ||
| import type { WorkspaceData } from "../../lib/workspace-data.ts"; | ||
|
|
||
| /** Browser-direct has a real controller; only the disconnected showcase uses fixtures. */ | ||
| export function selectTranscriptSearchSource( | ||
| controller: DesktopRuntimeController | null, | ||
| data: WorkspaceData, | ||
| ) { | ||
| return controller === null | ||
| ? fixtureTranscriptSearchSource | ||
| : clientTranscriptSearchSource(controller, data); | ||
| } | ||
|
|
||
| function errorMessage(error: unknown): string { | ||
| if (error instanceof Error && error.message.trim() !== "") return error.message; | ||
| return "The host did not return a usable response."; | ||
| } | ||
|
|
||
| /** Live route adapter: ephemeral UI state in, client-owned host fan-out out. */ | ||
| export function LiveTranscriptSearch() { | ||
| const navigate = useNavigate(); | ||
| const shellData = useShellData(); | ||
| const controller = desktopRuntime(); | ||
| const searchMemory = useTranscriptSearchMemory(); | ||
| const query = searchMemory.query; | ||
| const [filters, setFilters] = useState<TranscriptSearchFilters>( | ||
| DEFAULT_TRANSCRIPT_SEARCH_FILTERS, | ||
| ); | ||
| const [phase, setPhase] = useState<TranscriptSearchPhase>("idle"); | ||
| const [response, setResponse] = useState<TranscriptSearchResponse | null>(null); | ||
| const [error, setError] = useState<string>(); | ||
| const [historicContext, setHistoricContext] = useState<HistoricContextState>(null); | ||
| const [loadingMoreHostId, setLoadingMoreHostId] = useState<string | null>(null); | ||
| const [loadMoreError, setLoadMoreError] = useState<string>(); | ||
| const searchExecutor = useRef(new LatestTranscriptSearchExecutor()).current; | ||
| const contextAbort = useRef<AbortController | null>(null); | ||
| const loadMoreAbort = useRef<AbortController | null>(null); | ||
| const disposeTimer = useRef<number | null>(null); | ||
| const handoffTracker = useRef(new TranscriptSearchHandoffTracker()).current; | ||
|
|
||
| const source = useMemo( | ||
| () => selectTranscriptSearchSource(controller, shellData), | ||
| [controller, shellData], | ||
| ); | ||
| const projects = useMemo( | ||
| () => | ||
| [...shellData.projects] | ||
| .map((project) => ({ id: project.id, label: project.name })) | ||
| .sort((left, right) => left.label.localeCompare(right.label)), | ||
| [shellData.projects], | ||
| ); | ||
|
|
||
| const runSearch = useCallback( | ||
| async ( | ||
| nextFilters: TranscriptSearchFilters = filters, | ||
| nextQuery: string = query, | ||
| ) => { | ||
| if (!transcriptSearchCanRun(nextQuery)) return; | ||
| loadMoreAbort.current?.abort(); | ||
| await searchExecutor.run( | ||
| source, | ||
| { query: nextQuery.trim(), filters: nextFilters }, | ||
| { | ||
| onStart: () => { | ||
| setPhase("searching"); | ||
| setError(undefined); | ||
| setLoadingMoreHostId(null); | ||
| setLoadMoreError(undefined); | ||
| }, | ||
| onSuccess: (next) => { | ||
| setResponse(next); | ||
| setPhase("complete"); | ||
| }, | ||
| onError: (caught) => { | ||
| setResponse(null); | ||
| setError(errorMessage(caught)); | ||
| setPhase("error"); | ||
| }, | ||
| }, | ||
| ); | ||
| }, | ||
| [filters, query, searchExecutor, source], | ||
| ); | ||
|
|
||
| useLayoutEffect(() => { | ||
| const handoff = handoffTracker.take(searchMemory); | ||
| if (handoff === null) return; | ||
| searchExecutor.cancel(); | ||
| contextAbort.current?.abort(); | ||
| loadMoreAbort.current?.abort(); | ||
| setHistoricContext(null); | ||
| setResponse(null); | ||
| setError(undefined); | ||
| setLoadMoreError(undefined); | ||
| setLoadingMoreHostId(null); | ||
| setPhase("idle"); | ||
| if (transcriptSearchCanRun(handoff.query)) { | ||
| void runSearch(filters, handoff.query); | ||
| } | ||
| }, [filters, handoffTracker, runSearch, searchExecutor, searchMemory]); | ||
|
|
||
| useEffect(() => { | ||
| // StrictMode immediately runs setup → cleanup → setup in development. | ||
| // Defer disposal one tick so that probe cannot cancel the palette handoff. | ||
| if (disposeTimer.current !== null) window.clearTimeout(disposeTimer.current); | ||
| return () => { | ||
| disposeTimer.current = window.setTimeout(() => { | ||
| searchExecutor.cancel(); | ||
| contextAbort.current?.abort(); | ||
| loadMoreAbort.current?.abort(); | ||
| }, 0); | ||
| }; | ||
| }, [searchExecutor]); | ||
|
|
||
| const changeFilters = (next: TranscriptSearchFilters) => { | ||
| setFilters(next); | ||
| if (response !== null && transcriptSearchCanRun(query)) void runSearch(next); | ||
| }; | ||
|
|
||
| const openResult = async (result: TranscriptSearchResult) => { | ||
| contextAbort.current?.abort(); | ||
| const abort = new AbortController(); | ||
| contextAbort.current = abort; | ||
| setHistoricContext({ result, phase: "loading" }); | ||
| try { | ||
| const context = await source.context(result, abort.signal); | ||
| if (!abort.signal.aborted) setHistoricContext({ result, phase: "ready", context }); | ||
| } catch (caught) { | ||
| if (!abort.signal.aborted) { | ||
| setHistoricContext({ result, phase: "error", error: errorMessage(caught) }); | ||
| } | ||
| } | ||
| }; | ||
|
|
||
| return ( | ||
| <TranscriptSearchScreen | ||
| error={error} | ||
| filters={filters} | ||
| historicContext={historicContext} | ||
| onCloseHistoricContext={() => { | ||
| contextAbort.current?.abort(); | ||
| setHistoricContext(null); | ||
| }} | ||
| onFiltersChange={changeFilters} | ||
| onOpenLiveTail={(result) => { | ||
| contextAbort.current?.abort(); | ||
| void navigate({ params: { sessionId: result.sessionViewId }, to: "/sessions/$sessionId" }); | ||
| }} | ||
| loadingMoreHostId={loadingMoreHostId} | ||
| loadMoreError={loadMoreError} | ||
| onLoadMoreHost={ | ||
| source.loadMore === undefined | ||
| ? undefined | ||
| : (hostId) => { | ||
| loadMoreAbort.current?.abort(); | ||
| const abort = new AbortController(); | ||
| loadMoreAbort.current = abort; | ||
| setLoadingMoreHostId(hostId); | ||
| setLoadMoreError(undefined); | ||
| void source | ||
| .loadMore?.(hostId, abort.signal) | ||
| .then((next) => { | ||
| if (!abort.signal.aborted) setResponse(next); | ||
| }) | ||
| .catch((caught) => { | ||
| if (!abort.signal.aborted) setLoadMoreError(errorMessage(caught)); | ||
| }) | ||
| .finally(() => { | ||
| if (!abort.signal.aborted) setLoadingMoreHostId(null); | ||
| }); | ||
| } | ||
| } | ||
| onOpenResult={(result) => void openResult(result)} | ||
| onQueryChange={(next) => { | ||
| setTranscriptSearchQuery(next); | ||
| if (phase !== "idle") { | ||
| searchExecutor.cancel(); | ||
| setResponse(null); | ||
| setPhase("idle"); | ||
| } | ||
| }} | ||
| onSubmit={() => void runSearch()} | ||
| phase={phase} | ||
| projects={projects} | ||
| query={query} | ||
| response={response} | ||
| /> | ||
| ); | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.