fix: chore

This commit is contained in:
d-kimsuon
2025-10-18 04:14:35 +09:00
parent 4b58f611cb
commit dabc4b29e3
2 changed files with 14 additions and 7 deletions

View File

@@ -33,7 +33,7 @@ export class SessionMetaService extends Context.Tag("SessionMetaService")<
this,
Effect.gen(function* () {
const fs = yield* FileSystem.FileSystem;
const firstCommandCache =
const firstUserMessageCache =
yield* FileCacheStorage<ParsedUserMessage | null>();
const sessionMetaCacheRef = yield* Ref.make(
new Map<string, SessionMeta>(),
@@ -44,7 +44,7 @@ export class SessionMetaService extends Context.Tag("SessionMetaService")<
lines: string[],
): Effect.Effect<ParsedUserMessage | null, Error> =>
Effect.gen(function* () {
const cached = yield* firstCommandCache.get(jsonlFilePath);
const cached = yield* firstUserMessageCache.get(jsonlFilePath);
if (cached !== undefined) {
return cached;
}
@@ -70,7 +70,7 @@ export class SessionMetaService extends Context.Tag("SessionMetaService")<
}
if (firstUserMessage !== null) {
yield* firstCommandCache.set(jsonlFilePath, firstUserMessage);
yield* firstUserMessageCache.set(jsonlFilePath, firstUserMessage);
}
return firstUserMessage;

View File

@@ -28,13 +28,20 @@ const LayerImpl = Effect.gen(function* () {
yield* fs.writeFileString(cacheFilePath, "[]");
} else {
const content = yield* fs.readFileString(cacheFilePath);
const parsed = saveSchema.safeParse(JSON.parse(content));
const parsed = (() => {
try {
return saveSchema.parse(JSON.parse(content));
} catch (error) {
console.error(`Cache file parse error: ${error}`);
return undefined;
}
})();
if (!parsed.success) {
if (parsed === undefined || parsed.length === 0) {
console.error(`Cache file removed: ${cacheFilePath}`);
yield* fs.writeFileString(cacheFilePath, "[]");
} else {
parsed.data;
return parsed.data;
return parsed;
}
}