@@ -48,6 +48,7 @@ import type { SkillTool } from "@/tool/skill"
4848import { useKeyboard , useRenderer , useTerminalDimensions , type JSX } from "@opentui/solid"
4949import { useSDK } from "@tui/context/sdk"
5050import { useCommandDialog } from "@tui/component/dialog-command"
51+ import type { DialogContext } from "@tui/ui/dialog"
5152import { useKeybind } from "@tui/context/keybind"
5253import { Header } from "./header"
5354import { parsePatch } from "diff"
@@ -226,6 +227,8 @@ export function Session() {
226227 let scroll : ScrollBoxRenderable
227228 let prompt : PromptRef
228229 const keybind = useKeybind ( )
230+ const dialog = useDialog ( )
231+ const renderer = useRenderer ( )
229232
230233 // Allow exit when in child session (prompt is hidden)
231234 const exit = useExit ( )
@@ -312,19 +315,40 @@ export function Session() {
312315
313316 const local = useLocal ( )
314317
318+ function moveFirstChild ( ) {
319+ if ( children ( ) . length === 1 ) return
320+ const next = children ( ) . find ( ( x ) => ! ! x . parentID )
321+ if ( next ) {
322+ navigate ( {
323+ type : "session" ,
324+ sessionID : next . id ,
325+ } )
326+ }
327+ }
328+
315329 function moveChild ( direction : number ) {
316330 if ( children ( ) . length === 1 ) return
317- let next = children ( ) . findIndex ( ( x ) => x . id === session ( ) ?. id ) + direction
318- if ( next >= children ( ) . length ) next = 0
319- if ( next < 0 ) next = children ( ) . length - 1
320- if ( children ( ) [ next ] ) {
331+
332+ const sessions = children ( ) . filter ( ( x ) => ! ! x . parentID )
333+ let next = sessions . findIndex ( ( x ) => x . id === session ( ) ?. id ) + direction
334+
335+ if ( next >= sessions . length ) next = 0
336+ if ( next < 0 ) next = sessions . length - 1
337+ if ( sessions [ next ] ) {
321338 navigate ( {
322339 type : "session" ,
323- sessionID : children ( ) [ next ] . id ,
340+ sessionID : sessions [ next ] . id ,
324341 } )
325342 }
326343 }
327344
345+ function childSessionHandler ( func : ( dialog : DialogContext ) => void ) {
346+ return ( dialog : DialogContext ) => {
347+ if ( ! session ( ) ?. parentID || dialog . stack . length > 0 ) return
348+ func ( dialog )
349+ }
350+ }
351+
328352 const command = useCommandDialog ( )
329353 command . register ( ( ) => [
330354 {
@@ -884,24 +908,13 @@ export function Session() {
884908 } ,
885909 } ,
886910 {
887- title : "Next child session" ,
888- value : "session.child.next" ,
889- keybind : "session_child_cycle" ,
890- category : "Session" ,
891- hidden : true ,
892- onSelect : ( dialog ) => {
893- moveChild ( 1 )
894- dialog . clear ( )
895- } ,
896- } ,
897- {
898- title : "Previous child session" ,
899- value : "session.child.previous" ,
900- keybind : "session_child_cycle_reverse" ,
911+ title : "Go to child session" ,
912+ value : "session.child.first" ,
913+ keybind : "session_child_first" ,
901914 category : "Session" ,
902915 hidden : true ,
903916 onSelect : ( dialog ) => {
904- moveChild ( - 1 )
917+ moveFirstChild ( )
905918 dialog . clear ( )
906919 } ,
907920 } ,
@@ -911,7 +924,7 @@ export function Session() {
911924 keybind : "session_parent" ,
912925 category : "Session" ,
913926 hidden : true ,
914- onSelect : ( dialog ) => {
927+ onSelect : childSessionHandler ( ( dialog ) => {
915928 const parentID = session ( ) ?. parentID
916929 if ( parentID ) {
917930 navigate ( {
@@ -920,7 +933,29 @@ export function Session() {
920933 } )
921934 }
922935 dialog . clear ( )
923- } ,
936+ } ) ,
937+ } ,
938+ {
939+ title : "Next child session" ,
940+ value : "session.child.next" ,
941+ keybind : "session_child_cycle" ,
942+ category : "Session" ,
943+ hidden : true ,
944+ onSelect : childSessionHandler ( ( dialog ) => {
945+ moveChild ( 1 )
946+ dialog . clear ( )
947+ } ) ,
948+ } ,
949+ {
950+ title : "Previous child session" ,
951+ value : "session.child.previous" ,
952+ keybind : "session_child_cycle_reverse" ,
953+ category : "Session" ,
954+ hidden : true ,
955+ onSelect : childSessionHandler ( ( dialog ) => {
956+ moveChild ( - 1 )
957+ dialog . clear ( )
958+ } ) ,
924959 } ,
925960 ] )
926961
@@ -971,9 +1006,6 @@ export function Session() {
9711006 }
9721007 } )
9731008
974- const dialog = useDialog ( )
975- const renderer = useRenderer ( )
976-
9771009 // snap to bottom when session changes
9781010 createEffect ( on ( ( ) => route . sessionID , toBottom ) )
9791011
@@ -1933,7 +1965,7 @@ function Task(props: ToolProps<typeof TaskTool>) {
19331965 </ box >
19341966 < Show when = { props . metadata . sessionId } >
19351967 < text fg = { theme . text } >
1936- { keybind . print ( "session_child_cycle " ) }
1968+ { keybind . print ( "session_child_first " ) }
19371969 < span style = { { fg : theme . textMuted } } > view subagents</ span >
19381970 </ text >
19391971 </ Show >
0 commit comments