@@ -12,6 +12,31 @@ let snapshotCache = null;
1212let snapshotCacheUpdatedAt = 0 ;
1313let snapshotRefreshPromise = null ;
1414
15+ function resolveSnapshotCachePath ( ) {
16+ return path . join ( resolveCodexHome ( ) , '.gettokens-session-management-snapshot-cache.json' ) ;
17+ }
18+
19+ async function hydrateSnapshotCacheFromDisk ( ) {
20+ try {
21+ const raw = await fs . readFile ( resolveSnapshotCachePath ( ) , 'utf8' ) ;
22+ const parsed = JSON . parse ( raw ) ;
23+ if ( parsed && Array . isArray ( parsed . projects ) ) {
24+ snapshotCache = parsed ;
25+ snapshotCacheUpdatedAt = Date . now ( ) ;
26+ }
27+ } catch {
28+ // Ignore cache hydration failures.
29+ }
30+ }
31+
32+ async function persistSnapshotCacheToDisk ( snapshot ) {
33+ try {
34+ await fs . writeFile ( resolveSnapshotCachePath ( ) , JSON . stringify ( snapshot ) , 'utf8' ) ;
35+ } catch {
36+ // Ignore disk cache failures.
37+ }
38+ }
39+
1540function resolveCodexHome ( ) {
1641 return process . env . CODEX_HOME || path . join ( os . homedir ( ) , '.codex' ) ;
1742}
@@ -390,6 +415,7 @@ async function refreshSnapshotCache() {
390415 . then ( ( snapshot ) => {
391416 snapshotCache = snapshot ;
392417 snapshotCacheUpdatedAt = Date . now ( ) ;
418+ void persistSnapshotCacheToDisk ( snapshot ) ;
393419 return snapshot ;
394420 } )
395421 . finally ( ( ) => {
@@ -425,6 +451,8 @@ export async function loadSessionManagementDetail(sessionID) {
425451 return ( await parseSessionFile ( codexHome , absolutePath ) ) . detail ;
426452}
427453
428- void refreshSnapshotCache ( ) . catch ( ( ) => {
429- // Warm cache in the background for browser dev sessions.
430- } ) ;
454+ void hydrateSnapshotCacheFromDisk ( )
455+ . finally ( ( ) => refreshSnapshotCache ( ) )
456+ . catch ( ( ) => {
457+ // Warm cache in the background for browser dev sessions.
458+ } ) ;
0 commit comments