File tree Expand file tree Collapse file tree
packages/opencode/src/cli/cmd/tui Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -10,6 +10,7 @@ export type HomeRoute = {
1010export type SessionRoute = {
1111 type : "session"
1212 sessionID : string
13+ initialPrompt ?: PromptInfo
1314}
1415
1516export type Route = HomeRoute | SessionRoute
Original file line number Diff line number Diff line change @@ -71,22 +71,38 @@ export function DialogMessage(props: {
7171 dialog . clear ( )
7272 } ,
7373 } ,
74- {
75- title : "Fork" ,
76- value : "session.fork" ,
77- description : "create a new session" ,
78- onSelect : async ( dialog ) => {
79- const result = await sdk . client . session . fork ( {
80- sessionID : props . sessionID ,
81- messageID : props . messageID ,
82- } )
83- route . navigate ( {
84- sessionID : result . data ! . id ,
85- type : "session" ,
86- } )
87- dialog . clear ( )
88- } ,
89- } ,
74+ {
75+ title : "Fork" ,
76+ value : "session.fork" ,
77+ description : "create a new session" ,
78+ onSelect : async ( dialog ) => {
79+ const result = await sdk . client . session . fork ( {
80+ sessionID : props . sessionID ,
81+ messageID : props . messageID ,
82+ } )
83+ const msg = message ( )
84+ let initialPrompt : PromptInfo | undefined
85+ if ( msg ) {
86+ const parts = sync . data . part [ msg . id ]
87+ initialPrompt = parts . reduce (
88+ ( agg , part ) => {
89+ if ( part . type === "text" ) {
90+ if ( ! part . synthetic ) agg . input += part . text
91+ }
92+ if ( part . type === "file" ) agg . parts . push ( part )
93+ return agg
94+ } ,
95+ { input : "" , parts : [ ] as PromptInfo [ "parts" ] } ,
96+ )
97+ }
98+ route . navigate ( {
99+ sessionID : result . data ! . id ,
100+ type : "session" ,
101+ initialPrompt,
102+ } )
103+ dialog . clear ( )
104+ } ,
105+ } ,
90106 ] }
91107 />
92108 )
Original file line number Diff line number Diff line change @@ -144,24 +144,31 @@ export function Session() {
144144 return new CustomSpeedScroll ( 3 )
145145 } )
146146
147- createEffect ( async ( ) => {
148- await sync . session
149- . sync ( route . sessionID )
150- . then ( ( ) => {
151- if ( scroll ) scroll . scrollBy ( 100_000 )
152- } )
153- . catch ( ( e ) => {
154- console . error ( e )
155- toast . show ( {
156- message : `Session not found: ${ route . sessionID } ` ,
157- variant : "error" ,
158- } )
159- return navigate ( { type : "home" } )
160- } )
161- } )
162-
163- const toast = useToast ( )
164- const sdk = useSDK ( )
147+ createEffect ( async ( ) => {
148+ await sync . session
149+ . sync ( route . sessionID )
150+ . then ( ( ) => {
151+ if ( scroll ) scroll . scrollBy ( 100_000 )
152+ } )
153+ . catch ( ( e ) => {
154+ console . error ( e )
155+ toast . show ( {
156+ message : `Session not found: ${ route . sessionID } ` ,
157+ variant : "error" ,
158+ } )
159+ return navigate ( { type : "home" } )
160+ } )
161+ } )
162+
163+ const toast = useToast ( )
164+ const sdk = useSDK ( )
165+
166+ // Handle initial prompt from fork
167+ createEffect ( ( ) => {
168+ if ( route . initialPrompt && prompt ) {
169+ prompt . set ( route . initialPrompt )
170+ }
171+ } )
165172
166173 // Auto-navigate to whichever session currently needs permission input
167174 createEffect ( ( ) => {
You can’t perform that action at this time.
0 commit comments