review: broaden CLAUDE_TRANSCRIPT_PATH fallback to cover missing/empty JSON fields

Previously the env fallback ran only when JSON.parse threw. If stdin was valid
JSON but omitted transcript_path or provided a non-string/empty value, the
script dropped to the getSessionIdShort() fallback path, re-introducing the
collision this PR targets.

Validate the parsed transcript_path and apply the env-var fallback for any
unusable value, not just malformed JSON. Matches coderabbit's outside-diff
suggestion and keeps both input-source paths equivalent.

Refs #1494
This commit is contained in:
Taro Kawakami
2026-04-19 14:35:21 +09:00
parent 01d816781e
commit 0c3fc7074e

View File

@@ -179,14 +179,22 @@ function mergeSessionHeader(content, today, currentTime, metadata) {
} }
async function main() { async function main() {
// Parse stdin JSON to get transcript_path // Parse stdin JSON to get transcript_path; fall back to env var on missing,
// empty, or non-string values as well as on malformed JSON.
let transcriptPath = null; let transcriptPath = null;
try { try {
const input = JSON.parse(stdinData); const input = JSON.parse(stdinData);
if (input && typeof input.transcript_path === 'string' && input.transcript_path.length > 0) {
transcriptPath = input.transcript_path; transcriptPath = input.transcript_path;
}
} catch { } catch {
// Fallback: try env var for backwards compatibility // Malformed stdin: fall through to the env-var fallback below.
transcriptPath = process.env.CLAUDE_TRANSCRIPT_PATH; }
if (!transcriptPath) {
const envTranscriptPath = process.env.CLAUDE_TRANSCRIPT_PATH;
if (typeof envTranscriptPath === 'string' && envTranscriptPath.length > 0) {
transcriptPath = envTranscriptPath;
}
} }
const sessionsDir = getSessionsDir(); const sessionsDir = getSessionsDir();