Skip to content

Commit 6582487

Browse files
committed
refactor(session-log): simplify resolver and findSessionLogs for clarity
1 parent e3e8f28 commit 6582487

2 files changed

Lines changed: 13 additions & 4 deletions

File tree

apps/hook/server/index.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,14 @@ import { hostnameOrFallback } from "@plannotator/shared/project";
8181
import { planDenyFeedback } from "@plannotator/shared/feedback-templates";
8282
import { readImprovementHook } from "@plannotator/shared/improvement-hooks";
8383
import { AGENT_CONFIG, type Origin } from "@plannotator/shared/agents";
84-
import { findSessionLogsForCwd, resolveSessionLogByAncestorPids, resolveSessionLogByCwdScan, findSessionLogsByAncestorWalk, getLastRenderedMessage, type RenderedMessage } from "./session-log";
84+
import {
85+
findSessionLogsByAncestorWalk,
86+
findSessionLogsForCwd,
87+
getLastRenderedMessage,
88+
resolveSessionLogByAncestorPids,
89+
resolveSessionLogByCwdScan,
90+
type RenderedMessage,
91+
} from "./session-log";
8592
import { findCodexRolloutByThreadId, getLastCodexMessage } from "./codex-session";
8693
import { findCopilotPlanContent, findCopilotSessionForCwd, getLastCopilotMessage } from "./copilot-session";
8794
import {

apps/hook/server/session-log.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ export function findSessionLogs(projectDir: string): string[] {
8181
try {
8282
withMtime.push({ path: full, mtime: statSync(full).mtimeMs });
8383
} catch {
84-
continue;
84+
// File disappeared between readdir and stat — skip
8585
}
8686
}
8787

@@ -270,13 +270,15 @@ export function resolveSessionLogByCwdScan(
270270
);
271271
if (meta?.cwd === cwd && meta?.sessionId) candidates.push(meta);
272272
} catch {
273-
continue;
273+
// Malformed metadata file — skip
274274
}
275275
}
276276

277+
// Newest sessions first — pick the most recently started session that has a matching jsonl
277278
candidates.sort((a, b) => (b.startedAt ?? 0) - (a.startedAt ?? 0));
279+
280+
const logs = findSessionLogsForCwd(cwd, opts.projectsDir);
278281
for (const meta of candidates) {
279-
const logs = findSessionLogsForCwd(meta.cwd, opts.projectsDir);
280282
const match = logs.find((p) => p.includes(meta.sessionId));
281283
if (match) return match;
282284
}

0 commit comments

Comments
 (0)