11import { spawn , type IPty } from 'bun-pty'
22import { RingBuffer } from './buffer.ts'
3- import type { PTYSession , PTYSessionInfo , SpawnOptions } from './types.ts'
3+ import type { PTYSession , PTYSessionInfo , SpawnOptions , PTYStatus } from './types.ts'
44import { DEFAULT_TERMINAL_COLS , DEFAULT_TERMINAL_ROWS } from '../constants.ts'
55
66const SESSION_ID_BYTE_LENGTH = 4
@@ -16,29 +16,32 @@ export class SessionLifecycleManager {
1616 private sessions : Map < string , PTYSession > = new Map ( )
1717
1818 private createSessionObject ( opts : SpawnOptions ) : PTYSession {
19+ console . log ( 'Creating session object with opts:' , opts )
1920 const id = generateId ( )
2021 const args = opts . args ?? [ ]
2122 const workdir = opts . workdir ?? process . cwd ( )
2223 const title =
2324 opts . title ?? ( `${ opts . command } ${ args . join ( ' ' ) } ` . trim ( ) || `Terminal ${ id . slice ( - 4 ) } ` )
2425
2526 const buffer = new RingBuffer ( )
26- return {
27+ const session = {
2728 id,
2829 title,
2930 description : opts . description ,
3031 command : opts . command ,
3132 args,
3233 workdir,
3334 env : opts . env ,
34- status : 'running' ,
35+ status : 'running' as PTYStatus ,
3536 pid : 0 , // will be set after spawn
3637 createdAt : new Date ( ) ,
3738 parentSessionId : opts . parentSessionId ,
3839 notifyOnExit : opts . notifyOnExit ?? false ,
3940 buffer,
4041 process : null , // will be set
4142 }
43+ console . log ( 'Session object created:' , session )
44+ return session
4245 }
4346
4447 private spawnProcess ( session : PTYSession ) : void {
@@ -55,6 +58,12 @@ export class SessionLifecycleManager {
5558 console . log ( 'PTY process spawned with pid:' , ptyProcess . pid )
5659 session . process = ptyProcess
5760 session . pid = ptyProcess . pid
61+ console . log ( 'Session after spawn:' , {
62+ id : session . id ,
63+ pid : session . pid ,
64+ command : session . command ,
65+ status : session . status ,
66+ } )
5867 } catch ( error ) {
5968 console . error ( 'Failed to spawn PTY process:' , error )
6069 throw error
@@ -152,6 +161,8 @@ export class SessionLifecycleManager {
152161 pid : session . pid ,
153162 status : session . status ,
154163 process : ! ! session . process ,
164+ command : session . command ,
165+ args : session . args ,
155166 } )
156167 return session
157168 }
0 commit comments