@@ -433,7 +433,7 @@ import { ThreadDetailsPanel } from "./chat/ThreadDetailsPanel";
433433import { NoActiveThreadState } from "./NoActiveThreadState" ;
434434import {
435435 resolveEffectiveEnvMode ,
436- resolveLocalCheckoutBranchMismatch ,
436+ resolveCheckoutBranchMismatch ,
437437 shouldShowComposerContextStrip ,
438438 shouldShowEnvironmentIndicator ,
439439} from "./BranchToolbar.logic" ;
@@ -3376,26 +3376,6 @@ export default function ChatView(props: ChatViewProps) {
33763376 scheduleComposerFocus ( ) ;
33773377 } ;
33783378 const insertArtifactTemplateStable = useStableCallback ( insertArtifactTemplate ) ;
3379- const sendAppMessage = async ( text : string ) => {
3380- if ( ! isServerThread || activeThreadId === null ) {
3381- throw new Error ( "Messages from apps need a started thread." ) ;
3382- }
3383- const result = await startThreadTurn ( {
3384- environmentId,
3385- input : {
3386- threadId : activeThreadId ,
3387- message : { messageId : newMessageId ( ) , role : "user" , text, attachments : [ ] } ,
3388- runtimeMode,
3389- interactionMode,
3390- dispatchMode : "queue" ,
3391- } ,
3392- } ) ;
3393- if ( result . _tag === "Failure" ) {
3394- const error = squashAtomCommandFailure ( result ) ;
3395- throw error instanceof Error ? error : new Error ( "Could not send the app's message." ) ;
3396- }
3397- } ;
3398- const sendAppMessageStable = useStableCallback ( sendAppMessage ) ;
33993379 const queuedRunsControlRef = useRef < QueuedRunsControlHandle > ( null ) ;
34003380 const addTerminalContextToDraft = ( selection : TerminalContextSelection ) => {
34013381 composerRef . current ?. addTerminalContext ( selection ) ;
@@ -4685,8 +4665,8 @@ export default function ChatView(props: ChatViewProps) {
46854665 requestedEnvMode : envMode ,
46864666 isGitRepo,
46874667 } ) ;
4688- const localCheckoutBranchMismatch = isServerThread
4689- ? resolveLocalCheckoutBranchMismatch ( {
4668+ const checkoutBranchMismatch = isServerThread
4669+ ? resolveCheckoutBranchMismatch ( {
46904670 effectiveEnvMode : envMode ,
46914671 activeWorktreePath,
46924672 activeThreadBranch,
@@ -4966,10 +4946,10 @@ export default function ChatView(props: ChatViewProps) {
49664946 const nowMinute = useNowMinute ( ) ;
49674947 const activeBranchMismatchKey = branchMismatchKey (
49684948 activeThread ?. id ?? null ,
4969- localCheckoutBranchMismatch ,
4949+ checkoutBranchMismatch ,
49704950 ) ;
49714951 const showBranchMismatchBanner = shouldShowBranchMismatchBanner ( {
4972- hasMismatch : localCheckoutBranchMismatch !== null ,
4952+ hasMismatch : checkoutBranchMismatch !== null ,
49734953 isDismissed : isBranchMismatchDismissedForSession ( activeBranchMismatchKey ) ,
49744954 composerHasContent : composerHasDraftContent ,
49754955 wasShownForCurrentMismatch :
@@ -4988,7 +4968,7 @@ export default function ChatView(props: ChatViewProps) {
49884968 if (
49894969 ! activeProjectCwd ||
49904970 ! activeThread ||
4991- ! localCheckoutBranchMismatch ||
4971+ ! checkoutBranchMismatch ?. canRestoreThreadBranch ||
49924972 isRestoringThreadBranch
49934973 ) {
49944974 return ;
@@ -4998,7 +4978,7 @@ export default function ChatView(props: ChatViewProps) {
49984978 environmentId,
49994979 input : {
50004980 cwd : activeProjectCwd ,
5001- refName : localCheckoutBranchMismatch . threadBranch ,
4981+ refName : checkoutBranchMismatch . threadBranch ,
50024982 } ,
50034983 } ) ;
50044984 if ( checkoutResult . _tag === "Failure" ) {
@@ -5019,7 +4999,7 @@ export default function ChatView(props: ChatViewProps) {
50194999 setIsRestoringThreadBranch ( false ) ;
50205000 return ;
50215001 }
5022- const nextBranch = checkoutResult . value . refName ?? localCheckoutBranchMismatch . threadBranch ;
5002+ const nextBranch = checkoutResult . value . refName ?? checkoutBranchMismatch . threadBranch ;
50235003 if ( nextBranch !== activeThread . branch ) {
50245004 const updateResult = await updateThreadMetadata ( {
50255005 environmentId,
@@ -5114,6 +5094,37 @@ export default function ChatView(props: ChatViewProps) {
51145094 } ;
51155095 } ) ( ) as ComposerBannerStackItem | null ;
51165096
5097+ const sendAppMessage = async ( text : string ) => {
5098+ if ( ! isServerThread || activeThreadId === null ) {
5099+ throw new Error ( "Messages from apps need a started thread." ) ;
5100+ }
5101+ const settingsResult = await persistThreadSettingsForNextTurn ( {
5102+ threadId : activeThreadId ,
5103+ createdAt : new Date ( ) . toISOString ( ) ,
5104+ ...( checkoutBranchMismatch ? { branch : checkoutBranchMismatch . currentBranch } : { } ) ,
5105+ runtimeMode,
5106+ interactionMode,
5107+ } ) ;
5108+ const result =
5109+ settingsResult . _tag === "Failure"
5110+ ? settingsResult
5111+ : await startThreadTurn ( {
5112+ environmentId,
5113+ input : {
5114+ threadId : activeThreadId ,
5115+ message : { messageId : newMessageId ( ) , role : "user" , text, attachments : [ ] } ,
5116+ runtimeMode,
5117+ interactionMode,
5118+ dispatchMode : "queue" ,
5119+ } ,
5120+ } ) ;
5121+ if ( result . _tag === "Failure" ) {
5122+ const error = squashAtomCommandFailure ( result ) ;
5123+ throw error instanceof Error ? error : new Error ( "Could not send the app's message." ) ;
5124+ }
5125+ } ;
5126+ const sendAppMessageStable = useStableCallback ( sendAppMessage ) ;
5127+
51175128 const sendStandaloneCommand = async ( text : string , failureMessage : string ) => {
51185129 if ( ! activeThread || ! clientSettingsHydrated || sendInFlightRef . current ) return ;
51195130 const context = composerRef . current ?. getSendContext ( ) ;
@@ -5142,7 +5153,7 @@ export default function ChatView(props: ChatViewProps) {
51425153 const settingsResult = await persistThreadSettingsForNextTurn ( {
51435154 threadId,
51445155 createdAt,
5145- ...( localCheckoutBranchMismatch ? { branch : localCheckoutBranchMismatch . currentBranch } : { } ) ,
5156+ ...( checkoutBranchMismatch ? { branch : checkoutBranchMismatch . currentBranch } : { } ) ,
51465157 runtimeMode,
51475158 interactionMode : context . interactionMode ,
51485159 } ) ;
@@ -5418,7 +5429,7 @@ export default function ChatView(props: ChatViewProps) {
54185429 ] . filter ( ( item ) => item !== null ) ;
54195430 const usageLimitsItems = usageLimitsBanner === null ? [ ] : [ usageLimitsBanner ] ;
54205431 const projectCloneItems = projectCloneBannerItem === null ? [ ] : [ projectCloneBannerItem ] ;
5421- if ( ! localCheckoutBranchMismatch || ! showBranchMismatchBanner || ! activeBranchMismatchKey ) {
5432+ if ( ! checkoutBranchMismatch || ! showBranchMismatchBanner || ! activeBranchMismatchKey ) {
54225433 return [
54235434 ...feedbackBannerItems ,
54245435 ...limitRecoveryItems ,
@@ -5447,18 +5458,18 @@ export default function ChatView(props: ChatViewProps) {
54475458 < TooltipTrigger
54485459 render = {
54495460 < code className = "min-w-0 truncate font-medium text-foreground" >
5450- { localCheckoutBranchMismatch . threadBranch }
5461+ { checkoutBranchMismatch . threadBranch }
54515462 </ code >
54525463 }
54535464 />
54545465 < TooltipPopup side = "top" >
5455- This thread last ran on { localCheckoutBranchMismatch . threadBranch } . Sending will
5456- continue on { localCheckoutBranchMismatch . currentBranch } .
5466+ This thread last ran on { checkoutBranchMismatch . threadBranch } . Sending will continue
5467+ on { checkoutBranchMismatch . currentBranch } .
54575468 </ TooltipPopup >
54585469 </ Tooltip >
54595470 </ span >
54605471 ) ,
5461- actions : (
5472+ actions : checkoutBranchMismatch . canRestoreThreadBranch ? (
54625473 < Button
54635474 size = "xs"
54645475 variant = "ghost"
@@ -5467,7 +5478,7 @@ export default function ChatView(props: ChatViewProps) {
54675478 >
54685479 { isRestoringThreadBranch ? "Restoring..." : "Restore branch" }
54695480 </ Button >
5470- ) ,
5481+ ) : null ,
54715482 dismissLabel : "Dismiss branch change notice" ,
54725483 onDismiss : ( ) => {
54735484 dismissBranchMismatchForSession ( activeBranchMismatchKey ) ;
@@ -5945,9 +5956,7 @@ export default function ChatView(props: ChatViewProps) {
59455956 const settingsResult = await persistThreadSettingsForNextTurn ( {
59465957 threadId,
59475958 createdAt,
5948- ...( localCheckoutBranchMismatch
5949- ? { branch : localCheckoutBranchMismatch . currentBranch }
5950- : { } ) ,
5959+ ...( checkoutBranchMismatch ? { branch : checkoutBranchMismatch . currentBranch } : { } ) ,
59515960 runtimeMode,
59525961 interactionMode,
59535962 } ) ;
@@ -6922,9 +6931,7 @@ export default function ChatView(props: ChatViewProps) {
69226931 const settingsResult = await persistThreadSettingsForNextTurn ( {
69236932 threadId : threadIdForSend ,
69246933 createdAt : messageCreatedAt ,
6925- ...( localCheckoutBranchMismatch
6926- ? { branch : localCheckoutBranchMismatch . currentBranch }
6927- : { } ) ,
6934+ ...( checkoutBranchMismatch ? { branch : checkoutBranchMismatch . currentBranch } : { } ) ,
69286935 runtimeMode,
69296936 interactionMode : sendInteractionMode ,
69306937 } ) ;
@@ -7278,7 +7285,7 @@ export default function ChatView(props: ChatViewProps) {
72787285 const settingsResult = await persistThreadSettingsForNextTurn ( {
72797286 threadId : threadIdForSend ,
72807287 createdAt : messageCreatedAt ,
7281- ...( localCheckoutBranchMismatch ? { branch : localCheckoutBranchMismatch . currentBranch } : { } ) ,
7288+ ...( checkoutBranchMismatch ? { branch : checkoutBranchMismatch . currentBranch } : { } ) ,
72827289 runtimeMode,
72837290 interactionMode : nextInteractionMode ,
72847291 } ) ;
@@ -7398,7 +7405,7 @@ export default function ChatView(props: ChatViewProps) {
73987405 modelSelection : nextThreadModelSelection ,
73997406 runtimeMode : defaultRuntimeMode ,
74007407 interactionMode : "default" ,
7401- branch : activeThreadBranch ,
7408+ branch : checkoutBranchMismatch ?. currentBranch ?? activeThreadBranch ,
74027409 worktreePath : activeThread . worktreePath ,
74037410 createdAt,
74047411 } ,
@@ -8482,7 +8489,7 @@ export default function ChatView(props: ChatViewProps) {
84828489
84838490 < BranchRestoreConfirmHost
84848491 threadKey = { activeThreadKey }
8485- threadBranch = { localCheckoutBranchMismatch ?. threadBranch ?? "" }
8492+ threadBranch = { checkoutBranchMismatch ?. threadBranch ?? "" }
84868493 canWriteSourceControl = { canWriteSourceControl }
84878494 onConfirm = { handleSwitchCheckoutToThreadStable }
84888495 />
0 commit comments