@@ -736,6 +736,8 @@ export function generateDockerCompose(
736736 `${ workspaceDir } :${ workspaceDir } :rw` ,
737737 // Mount agent logs directory to workDir for persistence
738738 `${ config . workDir } /agent-logs:${ effectiveHome } /.copilot/logs:rw` ,
739+ // Mount agent session-state directory to workDir for persistence (events.jsonl)
740+ `${ config . workDir } /agent-session-state:${ effectiveHome } /.copilot/session-state:rw` ,
739741 // Init signal volume for iptables init container coordination
740742 `${ initSignalDir } :/tmp/awf-init:rw` ,
741743 ] ;
@@ -1548,6 +1550,13 @@ export async function writeConfigs(config: WrapperConfig): Promise<void> {
15481550 }
15491551 logger . debug ( `Agent logs directory created at: ${ agentLogsDir } ` ) ;
15501552
1553+ // Create agent session-state directory for persistence (events.jsonl written by Copilot CLI)
1554+ const agentSessionStateDir = path . join ( config . workDir , 'agent-session-state' ) ;
1555+ if ( ! fs . existsSync ( agentSessionStateDir ) ) {
1556+ fs . mkdirSync ( agentSessionStateDir , { recursive : true } ) ;
1557+ }
1558+ logger . debug ( `Agent session-state directory created at: ${ agentSessionStateDir } ` ) ;
1559+
15511560 // Create squid logs directory for persistence
15521561 // If proxyLogsDir is specified, write directly there (timeout-safe)
15531562 // Otherwise, use workDir/squid-logs (will be moved to /tmp after cleanup)
@@ -2104,6 +2113,18 @@ export async function cleanup(workDir: string, keepFiles: boolean, proxyLogsDir?
21042113 }
21052114 }
21062115
2116+ // Preserve agent session-state before cleanup (contains events.jsonl from Copilot CLI)
2117+ const agentSessionStateDir = path . join ( workDir , 'agent-session-state' ) ;
2118+ const agentSessionStateDestination = path . join ( os . tmpdir ( ) , `awf-agent-session-state-${ timestamp } ` ) ;
2119+ if ( fs . existsSync ( agentSessionStateDir ) && fs . readdirSync ( agentSessionStateDir ) . length > 0 ) {
2120+ try {
2121+ fs . renameSync ( agentSessionStateDir , agentSessionStateDestination ) ;
2122+ logger . info ( `Agent session state preserved at: ${ agentSessionStateDestination } ` ) ;
2123+ } catch ( error ) {
2124+ logger . debug ( 'Could not preserve agent session state:' , error ) ;
2125+ }
2126+ }
2127+
21072128 // Preserve api-proxy logs before cleanup
21082129 if ( proxyLogsDir ) {
21092130 // Logs were written directly to sibling of proxyLogsDir during runtime (timeout-safe)
0 commit comments