@@ -29,13 +29,15 @@ import {
2929 buildShowcasePendingTasks ,
3030 SHOWCASE_PENDING_TASK_DEFINITIONS ,
3131} from "./showcasePendingTasks" ;
32+ import { buildShowcaseAgentActivity } from "./showcaseAgentActivity" ;
3233import { retryShowcaseOperation } from "./showcaseRetry" ;
3334import {
3435 clearShowcaseRenderSignal ,
3536 getShowcaseRenderSignal ,
3637 isShowcaseNativeContentReady ,
3738 subscribeToShowcaseRenderSignal ,
3839} from "./showcaseRenderSignal" ;
40+ import { stageShowcaseAgentActivity } from "./stageShowcaseAgentActivity" ;
3941
4042const SHOWCASE_ENABLED = process . env . EXPO_PUBLIC_SHOWCASE === "1" ;
4143const SHOWCASE_THREAD_ID = "remote-command-center" ;
@@ -75,7 +77,14 @@ export function ShowcaseCaptureCoordinator(props: { readonly pathname: string })
7577 const [ themeRequestSettled , setThemeRequestSettled ] = useState ( false ) ;
7678 const [ readyScene , setReadyScene ] = useState < ShowcaseScene | null > ( null ) ;
7779 const [ orientationSettled , setOrientationSettled ] = useState ( false ) ;
80+ const [ agentActivityStaged , setAgentActivityStaged ] = useState ( false ) ;
7881 const requestedSceneRef = useRef < ShowcaseScene | null > ( null ) ;
82+ // Staging reads the latest entities without restarting on every shell
83+ // update, which would re-enter a permission prompt that is still open.
84+ const entitiesRef = useRef ( { threads, projects } ) ;
85+ useEffect ( ( ) => {
86+ entitiesRef . current = { threads, projects } ;
87+ } , [ projects , threads ] ) ;
7988 const renderSignal = useSyncExternalStore (
8089 subscribeToShowcaseRenderSignal ,
8190 getShowcaseRenderSignal ,
@@ -109,6 +118,7 @@ export function ShowcaseCaptureCoordinator(props: { readonly pathname: string })
109118 }
110119
111120 let cancelled = false ;
121+ let lastOutcome : string | null = null ;
112122 void retryShowcaseOperation ( async ( ) => applyNativeShowcaseOrientation ( orientation ) , {
113123 isCancelled : ( ) => cancelled ,
114124 } ) . then ( ( applied ) => {
@@ -129,6 +139,7 @@ export function ShowcaseCaptureCoordinator(props: { readonly pathname: string })
129139 // A native draw belongs only to the scene request that produced it. In
130140 // particular, revisiting review must wait for its newly mounted surface.
131141 clearShowcaseRenderSignal ( ) ;
142+ setAgentActivityStaged ( false ) ;
132143 setRequestedScene ( value ) ;
133144 } ;
134145 readRequestedScene ( ) ;
@@ -176,7 +187,11 @@ export function ShowcaseCaptureCoordinator(props: { readonly pathname: string })
176187 } ;
177188 } , [ connectPairingUrl , pairingUrls ] ) ;
178189
179- const scene = sceneFromPathname ( props . pathname ) ;
190+ const routeScene = sceneFromPathname ( props . pathname ) ;
191+ // Agent activity is captured over the thread list: the runner locks the
192+ // simulator or opens the notification shade on top of it.
193+ const scene =
194+ requestedScene === "agent-activity" && routeScene === "threads" ? "agent-activity" : routeScene ;
180195 const hasServerFixture =
181196 workspace . state . hasReadyEnvironment &&
182197 workspace . environments . length >= 3 &&
@@ -228,6 +243,11 @@ export function ShowcaseCaptureCoordinator(props: { readonly pathname: string })
228243 navigation . dispatch ( StackActions . popToTop ( ) ) ;
229244 return ;
230245 }
246+ // Follows the environments scene, whose settings sheet popToTop leaves open.
247+ if ( requestedScene === "agent-activity" ) {
248+ navigation . dispatch ( CommonActions . reset ( { index : 0 , routes : [ { name : "Home" } ] } ) ) ;
249+ return ;
250+ }
231251 const routes : ShowcaseResetRoute [ ] = [ { name : "Home" } ] ;
232252 if ( requestedScene === "environments" ) {
233253 routes . push ( {
@@ -264,6 +284,39 @@ export function ShowcaseCaptureCoordinator(props: { readonly pathname: string })
264284 ) ;
265285 } , [ hasFixture , navigation , requestedScene , scene , showcaseThread ] ) ;
266286
287+ useEffect ( ( ) => {
288+ if ( ! SHOWCASE_ENABLED || scene !== "agent-activity" || ! hasFixture || agentActivityStaged ) {
289+ return ;
290+ }
291+ let cancelled = false ;
292+ let lastOutcome : string | null = null ;
293+ void retryShowcaseOperation (
294+ async ( ) => {
295+ const now = Date . now ( ) ;
296+ const { threads : latestThreads , projects : latestProjects } = entitiesRef . current ;
297+ const activity = buildShowcaseAgentActivity ( latestThreads , latestProjects , now ) ;
298+ const outcome =
299+ activity === null
300+ ? "fixture threads not loaded"
301+ : await stageShowcaseAgentActivity ( activity , now ) ;
302+ if ( outcome === true ) return true ;
303+ // Surfaces in the runner's Metro output when the scene never turns ready.
304+ if ( outcome !== lastOutcome )
305+ console . warn ( `[showcase] agent activity not staged: ${ outcome } ` ) ;
306+ lastOutcome = outcome ;
307+ return false ;
308+ } ,
309+ // The first attempt waits on the notification permission prompt until
310+ // the runner answers it.
311+ { isCancelled : ( ) => cancelled , attemptTimeoutMs : 60_000 } ,
312+ ) . then ( ( staged ) => {
313+ if ( ! cancelled && staged ) setAgentActivityStaged ( true ) ;
314+ } ) ;
315+ return ( ) => {
316+ cancelled = true ;
317+ } ;
318+ } , [ agentActivityStaged , hasFixture , scene ] ) ;
319+
267320 useEffect ( ( ) => {
268321 if (
269322 ! SHOWCASE_ENABLED ||
@@ -276,6 +329,7 @@ export function ShowcaseCaptureCoordinator(props: { readonly pathname: string })
276329 ! orientationSettled ||
277330 // Likewise for the palette: an early screenshot shows the default theme.
278331 ! themeApplied ||
332+ ( scene === "agent-activity" && ! agentActivityStaged ) ||
279333 ! isShowcaseNativeContentReady ( { scene, themeId, renderSignal } )
280334 ) {
281335 setReadyScene ( null ) ;
@@ -298,7 +352,16 @@ export function ShowcaseCaptureCoordinator(props: { readonly pathname: string })
298352 if ( renderFrame !== null ) cancelAnimationFrame ( renderFrame ) ;
299353 if ( readyFrame !== null ) cancelAnimationFrame ( readyFrame ) ;
300354 } ;
301- } , [ hasFixture , orientationSettled , renderSignal , requestedScene , scene , themeApplied , themeId ] ) ;
355+ } , [
356+ agentActivityStaged ,
357+ hasFixture ,
358+ orientationSettled ,
359+ renderSignal ,
360+ requestedScene ,
361+ scene ,
362+ themeApplied ,
363+ themeId ,
364+ ] ) ;
302365
303366 if ( ! SHOWCASE_ENABLED || readyScene === null ) return null ;
304367
0 commit comments