@@ -33,12 +33,9 @@ import Views from './views'
3333 * Registers the diff pane: `/diff` once the built-in stands down, the
3434 * pane's drawing and refresh, its opening on Claude's first edit, the ask.
3535 *
36- * Git runs when the built-in's would: `session.start` binds the host and
37- * registers `/diff`, and off its dispatch reads the transcript, so a resumed
38- * session whose turns already edited opens as its first edit would; `/diff`
39- * or the main loop's first checkpointed edit with room pins the backend,
40- * until `/clear`, which reads afresh under a pane it leaves open; a docked
41- * pane fetches, then opens.
36+ * Git runs when the built-in's would: none at the start; `/diff` or the main
37+ * loop's first checkpointed edit with room pins the backend, until `/clear`,
38+ * which reads afresh under a pane it leaves open.
4239 *
4340 * @param on the engine's registrar
4441 */
@@ -150,6 +147,8 @@ export function register(on: On) {
150147 return asked . isAnswered || backend !== null
151148 }
152149
150+ startPoll ( engine , probed )
151+
153152 const stored = PaneState . baseModeOf (
154153 await engine
155154 . storeGet ( Names . baseStoreKeyOf ( probed . repository . toplevel ) )
@@ -282,6 +281,25 @@ export function register(on: On) {
282281 ) . includes ( null )
283282 }
284283
284+ function keepBaseline ( ) {
285+ const pinned = backend
286+
287+ if ( ! pinned || polled . headKey !== '' ) {
288+ return
289+ }
290+
291+ void pinned
292+ . headKeyOf ( )
293+ . catch ( ( ) => '' )
294+ . then ( key => {
295+ const isFirst = backend === pinned && polled . headKey === ''
296+
297+ if ( isFirst ) {
298+ polled . headKey = key
299+ }
300+ } )
301+ }
302+
285303 function startPoll ( engine : Host , pinned : Backend . Backend ) {
286304 const readHeadKey = ( ) => pinned . headKeyOf ( ) . catch ( ( ) => '' )
287305
@@ -353,10 +371,6 @@ export function register(on: On) {
353371 case 'data' :
354372 generation += 1
355373
356- if ( pinned ) {
357- startPoll ( engine , pinned )
358- }
359-
360374 break
361375 }
362376
@@ -400,6 +414,18 @@ export function register(on: On) {
400414 )
401415 }
402416
417+ async function markShown (
418+ engine : Host ,
419+ trigger : ( typeof Record . SHOWN_TRIGGERS ) [ number ] ,
420+ ) : Promise < void > {
421+ const sessionId = await engine . sessionId ( ) . catch ( ( ) => null )
422+
423+ if ( sessionId !== null && sessionId !== shownSessionId ) {
424+ shownSessionId = sessionId
425+ Record . recorderOf ( engine ) . shown ( trigger , Record . widthBucketOf ( columns ) )
426+ }
427+ }
428+
403429 async function openPane (
404430 engine : Host ,
405431 trigger : ( typeof Record . SHOWN_TRIGGERS ) [ number ] ,
@@ -436,13 +462,9 @@ export function register(on: On) {
436462 }
437463
438464 isPaneOpen = true
465+ keepBaseline ( )
439466
440- const sessionId = await engine . sessionId ( ) . catch ( ( ) => null )
441-
442- if ( sessionId !== null && sessionId !== shownSessionId ) {
443- shownSessionId = sessionId
444- Record . recorderOf ( engine ) . shown ( trigger , Record . widthBucketOf ( columns ) )
445- }
467+ await markShown ( engine , trigger )
446468
447469 const isStale = isDialog || landed !== landedBefore
448470
@@ -506,9 +528,10 @@ export function register(on: On) {
506528 }
507529
508530 async function openOnRestore ( engine : Host ) : Promise < void > {
509- const messages = await engine . messages ( ) . catch ( ( ) : SessionMessage [ ] => [ ] )
510-
511- hasRestoredEdits = Turns . turnDiffsOf ( messages ) . length > 0
531+ hasRestoredEdits =
532+ Turns . turnDiffsOf (
533+ await engine . messages ( ) . catch ( ( ) : SessionMessage [ ] => [ ] ) ,
534+ ) . length > 0
512535
513536 if ( hasRestoredEdits ) {
514537 await openOnFirstEdit ( engine )
@@ -687,8 +710,7 @@ export function register(on: On) {
687710
688711 on ( 'ui.render' , { component : 'PromptHint' } , ( $ , e , next ) => {
689712 if ( isOnPaneSurface ( e ) ) {
690- const viewport : { columns ?: number ; isFullscreen ?: boolean } | undefined =
691- e . viewport
713+ const { viewport } = e
692714
693715 const isFirstMeasure = columns === null && viewport ?. columns !== undefined
694716
@@ -903,7 +925,9 @@ export function register(on: On) {
903925 ( isResume ? sessionStartMs : await host . now ( ) )
904926
905927 if ( isKeptOpen ) {
928+ await markShown ( host , 'manual' )
906929 await pinBackend ( host )
930+ keepBaseline ( )
907931 void refresh ( host )
908932 }
909933
0 commit comments