(data)
| 126 | // Hook Session Resolution |
| 127 | // ============================================================ |
| 128 | function resolveHookTranscript(data) { |
| 129 | if (!data || typeof data !== 'object') return null; |
| 130 | const hookCwd = data.cwd ? path.resolve(String(data.cwd)) : ''; |
| 131 | if (hookCwd && normalizeFsPath(hookCwd) !== normalizeFsPath(state.CWD)) return null; |
| 132 | const sessionId = data.session_id ? String(data.session_id) : ''; |
| 133 | const expectedDir = projectTranscriptDir(); |
| 134 | const transcriptPath = data.transcript_path ? path.resolve(String(data.transcript_path)) : ''; |
| 135 | if (transcriptPath) { |
| 136 | const transcriptDir = path.dirname(transcriptPath); |
| 137 | const transcriptSessionId = path.basename(transcriptPath, '.jsonl'); |
| 138 | const dirMatches = normalizeFsPath(transcriptDir) === normalizeFsPath(expectedDir); |
| 139 | const idMatches = !sessionId || transcriptSessionId === sessionId; |
| 140 | if (dirMatches && idMatches) { |
| 141 | return { full: transcriptPath, sessionId: transcriptSessionId }; |
| 142 | } |
| 143 | } |
| 144 | if (!sessionId) return null; |
| 145 | return { full: path.join(expectedDir, `${sessionId}.jsonl`), sessionId }; |
| 146 | } |
| 147 | |
| 148 | function maybeAttachHookSession(data, source) { |
| 149 | const target = resolveHookTranscript(data); |
no test coverage detected