@@ -232,10 +232,7 @@ function createOpencode() {
232232 const host = "127.0.0.1"
233233 const port = 4096
234234 const url = `http://${ host } :${ port } `
235- const proc = spawn ( `opencode` , [ `serve` , `--hostname=${ host } ` , `--port=${ port } ` ] , {
236- // TODO
237- stdio : "inherit" ,
238- } )
235+ const proc = spawn ( `opencode` , [ `serve` , `--hostname=${ host } ` , `--port=${ port } ` ] )
239236 const client = createOpencodeClient ( { baseUrl : url } )
240237
241238 return {
@@ -248,8 +245,6 @@ async function assertOpencodeConnected() {
248245 let retry = 0
249246 let connected = false
250247 do {
251- // TODO
252- console . log ( "!@#!@#!@# TRYING" )
253248 try {
254249 await client . app . get < true > ( )
255250 connected = true
@@ -459,50 +454,53 @@ async function subscribeSessionEvents() {
459454 let text = ""
460455 ; ( async ( ) => {
461456 while ( true ) {
462- const { done, value } = await reader . read ( )
463- if ( done ) break
464-
465- const chunk = decoder . decode ( value , { stream : true } )
466- const lines = chunk . split ( "\n" )
467-
468- for ( const line of lines ) {
469- // TODO
470- console . log ( "!@#!@#!@#! line" , line )
471- if ( ! line . startsWith ( "data: " ) ) continue
472-
473- const jsonStr = line . slice ( 6 ) . trim ( )
474- if ( ! jsonStr ) continue
475-
476- try {
477- const evt = JSON . parse ( jsonStr )
478-
479- if ( evt . type !== "message.part.updated" ) continue
480- if ( evt . properties . part . sessionID !== session . id ) continue
481- const part = evt . properties . part
482-
483- if ( part . type === "tool" && part . state . status === "completed" ) {
484- const [ tool , color ] = TOOL [ part . tool ] ?? [ part . tool , "\x1b[34m\x1b[1m" ]
485- const title =
486- part . state . title || Object . keys ( part . state . input ) . length > 0
487- ? JSON . stringify ( part . state . input )
488- : "Unknown"
489- console . log ( )
490- console . log ( color + `|` , "\x1b[0m\x1b[2m" + ` ${ tool . padEnd ( 7 , " " ) } ` , "" , "\x1b[0m" + title )
491- }
457+ try {
458+ const { done, value } = await reader . read ( )
459+ if ( done ) break
492460
493- if ( part . type === "text" ) {
494- text = part . text
461+ const chunk = decoder . decode ( value , { stream : true } )
462+ const lines = chunk . split ( "\n" )
495463
496- if ( part . time ?. end ) {
497- console . log ( )
498- console . log ( text )
464+ for ( const line of lines ) {
465+ if ( ! line . startsWith ( "data: " ) ) continue
466+
467+ const jsonStr = line . slice ( 6 ) . trim ( )
468+ if ( ! jsonStr ) continue
469+
470+ try {
471+ const evt = JSON . parse ( jsonStr )
472+
473+ if ( evt . type !== "message.part.updated" ) continue
474+ if ( evt . properties . part . sessionID !== session . id ) continue
475+ const part = evt . properties . part
476+
477+ if ( part . type === "tool" && part . state . status === "completed" ) {
478+ const [ tool , color ] = TOOL [ part . tool ] ?? [ part . tool , "\x1b[34m\x1b[1m" ]
479+ const title =
480+ part . state . title || Object . keys ( part . state . input ) . length > 0
481+ ? JSON . stringify ( part . state . input )
482+ : "Unknown"
499483 console . log ( )
500- text = ""
484+ console . log ( color + `|` , "\x1b[0m\x1b[2m" + ` ${ tool . padEnd ( 7 , " " ) } ` , "" , "\x1b[0m" + title )
485+ }
486+
487+ if ( part . type === "text" ) {
488+ text = part . text
489+
490+ if ( part . time ?. end ) {
491+ console . log ( )
492+ console . log ( text )
493+ console . log ( )
494+ text = ""
495+ }
501496 }
497+ } catch ( e ) {
498+ // Ignore parse errors
502499 }
503- } catch ( e ) {
504- // Ignore parse errors
505500 }
501+ } catch ( e ) {
502+ console . log ( "Subscribing to session events done" , e )
503+ break
506504 }
507505 }
508506 } ) ( )
0 commit comments