@@ -2,10 +2,10 @@ import fs from "node:fs";
22import path from "node:path" ;
33import { resolveBundledSkillsDir } from "../agents/skills/bundled-dir.js" ;
44import { resolveStateDir } from "../config/paths.js" ;
5- import { loadSessionStore } from "../config/sessions/store-load.js" ;
65import { resolveAllAgentSessionStoreTargetsSync } from "../config/sessions/targets.js" ;
76import type { SessionEntry } from "../config/sessions/types.js" ;
87import type { OpenClawConfig } from "../config/types.openclaw.js" ;
8+ import { expandHomePrefix } from "../infra/home-dir.js" ;
99import { note } from "../terminal/note.js" ;
1010import { shortenHomePath } from "../utils.js" ;
1111
@@ -168,14 +168,20 @@ function resolveExpectedBundledSkillPath(params: {
168168 cachedPath : string ;
169169 bundledSkillsDir : string ;
170170 pathExists : ( filePath : string ) => boolean ;
171+ homeDir ?: string ;
172+ env ?: NodeJS . ProcessEnv ;
171173} ) : string | undefined {
172- if ( ! isAbsolutePathLike ( params . cachedPath ) ) {
174+ const expandedCachedPath = expandHomePrefix ( params . cachedPath , {
175+ home : params . homeDir ,
176+ env : params . env ,
177+ } ) ;
178+ if ( ! isAbsolutePathLike ( expandedCachedPath ) ) {
173179 return undefined ;
174180 }
175- if ( isInsidePath ( params . bundledSkillsDir , params . cachedPath ) ) {
181+ if ( isInsidePath ( params . bundledSkillsDir , expandedCachedPath ) ) {
176182 return undefined ;
177183 }
178- const relativeSegments = extractBundledSkillRelativeSegments ( params . cachedPath ) ;
184+ const relativeSegments = extractBundledSkillRelativeSegments ( expandedCachedPath ) ;
179185 if ( ! relativeSegments ) {
180186 return undefined ;
181187 }
@@ -187,6 +193,8 @@ export function scanSessionStoreForStaleRuntimeSnapshotPaths(params: {
187193 store : Record < string , SessionEntry > ;
188194 bundledSkillsDir : string | undefined ;
189195 pathExists ?: ( filePath : string ) => boolean ;
196+ homeDir ?: string ;
197+ env ?: NodeJS . ProcessEnv ;
190198} ) : StaleSessionSnapshotPathFinding [ ] {
191199 const bundledSkillsDir = params . bundledSkillsDir ?. trim ( ) ;
192200 if ( ! bundledSkillsDir ) {
@@ -204,6 +212,8 @@ export function scanSessionStoreForStaleRuntimeSnapshotPaths(params: {
204212 cachedPath : cached . path ,
205213 bundledSkillsDir,
206214 pathExists,
215+ homeDir : params . homeDir ,
216+ env : params . env ,
207217 } ) ;
208218 if ( ! expectedPath ) {
209219 continue ;
@@ -252,6 +262,11 @@ function resolveSessionStorePaths(params: {
252262 . toSorted ( ( a , b ) => a . localeCompare ( b ) ) ;
253263}
254264
265+ function loadSessionStoreForSnapshotScan ( storePath : string ) : Record < string , SessionEntry > {
266+ const parsed = JSON . parse ( fs . readFileSync ( storePath , "utf-8" ) ) as unknown ;
267+ return isRecord ( parsed ) ? ( parsed as Record < string , SessionEntry > ) : { } ;
268+ }
269+
255270export async function noteSessionSnapshotHealth ( params ?: {
256271 storePaths ?: string [ ] ;
257272 bundledSkillsDir ?: string ;
@@ -270,15 +285,19 @@ export async function noteSessionSnapshotHealth(params?: {
270285 for ( const storePath of storePaths ) {
271286 let store : Record < string , SessionEntry > ;
272287 try {
273- store = loadSessionStore ( storePath ) ;
288+ store = loadSessionStoreForSnapshotScan ( storePath ) ;
274289 } catch ( err ) {
275290 note (
276291 `- Failed to inspect session snapshot metadata in ${ shortenHomePath ( storePath ) } : ${ String ( err ) } ` ,
277292 "Session snapshots" ,
278293 ) ;
279294 continue ;
280295 }
281- const findings = scanSessionStoreForStaleRuntimeSnapshotPaths ( { store, bundledSkillsDir } ) ;
296+ const findings = scanSessionStoreForStaleRuntimeSnapshotPaths ( {
297+ store,
298+ bundledSkillsDir,
299+ env : params ?. env ,
300+ } ) ;
282301 if ( findings . length > 0 ) {
283302 findingsByStore . set ( storePath , findings ) ;
284303 }
0 commit comments