@@ -28,6 +28,7 @@ import {
2828 extractRpcErrorMessage ,
2929 parseReviewTarget ,
3030} from "@threads/utils/threadNormalize" ;
31+ import { clampThreadName } from "@threads/utils/threadNaming" ;
3132import type { ThreadAction , ThreadState } from "./useThreadsReducer" ;
3233import { useReviewPrompt } from "./useReviewPrompt" ;
3334import { formatRelativeTime } from "@utils/time" ;
@@ -91,8 +92,30 @@ type UseThreadMessagingOptions = {
9192 parentId : string ,
9293 childId : string ,
9394 ) => void ;
95+ renameThread ?: ( workspaceId : string , threadId : string , name : string ) => void ;
9496} ;
9597
98+ function buildReviewThreadTitle ( target : ReviewTarget ) : string | null {
99+ if ( target . type === "commit" ) {
100+ const shortSha = target . sha . trim ( ) . slice ( 0 , 7 ) ;
101+ const title = target . title ?. trim ( ) ?? "" ;
102+ if ( shortSha && title ) {
103+ return clampThreadName ( `Review ${ shortSha } : ${ title } ` ) ;
104+ }
105+ if ( shortSha ) {
106+ return clampThreadName ( `Review ${ shortSha } ` ) ;
107+ }
108+ return clampThreadName ( "Review Commit" ) ;
109+ }
110+ if ( target . type === "baseBranch" ) {
111+ return clampThreadName ( `Review ${ target . branch } ` ) ;
112+ }
113+ if ( target . type === "uncommittedChanges" ) {
114+ return "Review Working Tree" ;
115+ }
116+ return null ;
117+ }
118+
96119function isStaleSteerTurnError ( message : string ) : boolean {
97120 const normalized = message . trim ( ) . toLowerCase ( ) ;
98121 if ( ! normalized ) {
@@ -135,6 +158,7 @@ export function useThreadMessaging({
135158 forkThreadForWorkspace,
136159 updateThreadParent,
137160 registerDetachedReviewChild,
161+ renameThread,
138162} : UseThreadMessagingOptions ) {
139163 const sendMessageToThread = useCallback (
140164 async (
@@ -568,6 +592,10 @@ export function useThreadMessaging({
568592 updateThreadParent ( threadId , [ reviewThreadId ] ) ;
569593 if ( reviewDeliveryMode === "detached" ) {
570594 registerDetachedReviewChild ?.( workspaceId , threadId , reviewThreadId ) ;
595+ const reviewTitle = buildReviewThreadTitle ( target ) ;
596+ if ( reviewTitle && ! getCustomName ( workspaceId , reviewThreadId ) ) {
597+ renameThread ?.( workspaceId , reviewThreadId , reviewTitle ) ;
598+ }
571599 }
572600 }
573601 return true ;
@@ -595,6 +623,7 @@ export function useThreadMessaging({
595623 activeWorkspace ,
596624 ensureThreadForActiveWorkspace ,
597625 ensureThreadForWorkspace ,
626+ getCustomName ,
598627 markProcessing ,
599628 markReviewing ,
600629 onDebug ,
@@ -603,6 +632,7 @@ export function useThreadMessaging({
603632 setActiveTurnId ,
604633 reviewDeliveryMode ,
605634 registerDetachedReviewChild ,
635+ renameThread ,
606636 updateThreadParent ,
607637 ] ,
608638 ) ;
0 commit comments