Files
hapi/cli/src/claude/utils/claudeCheckSession.ts
T
2025-12-16 15:03:50 +08:00

28 lines
922 B
TypeScript

import { logger } from "@/ui/logger";
import { existsSync, readFileSync } from "node:fs";
import { join } from "node:path";
import { getProjectPath } from "./path";
export function claudeCheckSession(sessionId: string, path: string) {
const projectDir = getProjectPath(path);
// Check if session id is in the project dir
const sessionFile = join(projectDir, `${sessionId}.jsonl`);
const sessionExists = existsSync(sessionFile);
if (!sessionExists) {
logger.debug(`[claudeCheckSession] Path ${sessionFile} does not exist`);
return false;
}
// Check if session contains any messages
const sessionData = readFileSync(sessionFile, 'utf-8').split('\n');
const hasGoodMessage = !!sessionData.find((v) => {
try {
return typeof JSON.parse(v).uuid === 'string'
} catch (e) {
return false;
}
});
return hasGoodMessage;
}