Skip to content

Commit 3655196

Browse files
authored
feat: add volume mount for ~/.copilot/session-state
Agent-Logs-Url: https://github.com/github/gh-aw-firewall/sessions/44f79fbe-75fd-4c92-ae2a-fe47fee65922
1 parent 7afc2d1 commit 3655196

File tree

2 files changed

+36
-3
lines changed

2 files changed

+36
-3
lines changed

docs/usage.md

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -845,6 +845,12 @@ sudo awf \
845845
- Location: `/tmp/awf-agent-logs-<timestamp>/`
846846
- View with: `cat /tmp/awf-agent-logs-<timestamp>/*.log`
847847

848+
**Agent Session State:**
849+
- Contains structured conversation data written by Copilot CLI (e.g., `events.jsonl`)
850+
- Location: `/tmp/awf-agent-session-state-<timestamp>/`
851+
- View with: `cat /tmp/awf-agent-session-state-<timestamp>/events.jsonl`
852+
- Useful for triage dashboards, benchmarking, and debugging Copilot CLI runs
853+
848854
**Squid Logs:**
849855
- Contains all HTTP/HTTPS traffic (allowed and denied)
850856
- Location: `/tmp/squid-logs-<timestamp>/`
@@ -859,9 +865,15 @@ sudo cat /tmp/squid-logs-<timestamp>/access.log
859865
```
860866

861867
**How it works:**
862-
- GitHub Copilot CLI writes to `~/.copilot/logs/`, Squid writes to `/var/log/squid/`
863-
- Volume mounts map these to `${workDir}/agent-logs/` and `${workDir}/squid-logs/`
864-
- Before cleanup, logs are automatically moved to `/tmp/awf-agent-logs-<timestamp>/` and `/tmp/squid-logs-<timestamp>/` (if they exist)
868+
- GitHub Copilot CLI writes to `~/.copilot/logs/` and `~/.copilot/session-state/`; Squid writes to `/var/log/squid/`
869+
- Volume mounts map container paths to:
870+
- `${workDir}/agent-logs/``~/.copilot/logs/`
871+
- `${workDir}/agent-session-state/``~/.copilot/session-state/`
872+
- `${workDir}/squid-logs/``/var/log/squid/`
873+
- Before cleanup, non-empty directories are automatically moved to timestamped `/tmp` paths:
874+
- `/tmp/awf-agent-logs-<timestamp>/`
875+
- `/tmp/awf-agent-session-state-<timestamp>/`
876+
- `/tmp/squid-logs-<timestamp>/`
865877
- Empty log directories are not preserved (avoids cluttering /tmp)
866878

867879
### Keep Containers for Inspection

src/docker-manager.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)