import { join } from 'node:path';
import { homedir } from 'node:os';
import { readdir, stat } from 'node:fs/promises';

//#region ../core/dist/memory/transcript-scanner.js
/**
* Transcript scanner — locates Claude session JSONL files and lists
* sessions pending extraction.
*
* Claude stores session files at:
*   `~/.claude/projects/<encoded-project-path>/<session-uuid>.jsonl`
*
* The encoded path is the project absolute path with `/` → `-`.
*
* Functions:
*   - `findSessionTranscriptPath` — locate a specific session's JSONL
*   - `scanPendingTranscripts`    — list sessions queued for extraction
*   - `listAllTranscripts`        — enumerate all root-level session JSONLs
*
* @task T732
* @epic T726
*/
/**
* Locate the JSONL file for a specific Claude session ID.
*
* Searches across all project directories under `~/.claude/projects/` for a
* file named `<sessionId>.jsonl`. Returns the absolute path or `null` if not
* found.
*
* This is a best-effort search — if the session is a subagent transcript in a
* subdirectory, it is excluded (we only process root-level sessions).
*
* @param sessionId - The session UUID (e.g. `77edaed6-13e5-4af1-9311-ea94eae114f9`)
* @returns Absolute path to the JSONL, or null.
*/
async function findSessionTranscriptPath(sessionId) {
	const claudeProjectsRoot = join(homedir(), ".claude", "projects");
	try {
		const projectDirs = await readdir(claudeProjectsRoot, { withFileTypes: true });
		for (const entry of projectDirs) {
			if (!entry.isDirectory()) continue;
			const candidate = join(claudeProjectsRoot, entry.name, `${sessionId}.jsonl`);
			try {
				await stat(candidate);
				return candidate;
			} catch {}
		}
	} catch {}
	return null;
}

export { findSessionTranscriptPath };
//# sourceMappingURL=transcript-scanner-kJWhWmlg.js.map
