import Foundation struct CodexHistoryParser: ImportParser { func parse(sourceURL: URL, dedupIndex: DedupIndex) throws -> ImportParseResult { let files = try ImportFiles.immediateFiles( at: sourceURL, expected: "eine Codex history.jsonl oder den zugehörigen Konfigurationsordner", directFileMatches: { $0.pathExtension.lowercased() == "jsonl" }, directoryFileMatches: { $0.lastPathComponent == "history.jsonl" } ) var accumulator = ImportAccumulator( minimumLength: 20, maximumLength: 10_000, dedupIndex: dedupIndex ) for fileURL in files { for line in try ImportFiles.lines(from: fileURL) { let root: Any do { root = try ImportJSON.object(fromLine: line) } catch { accumulator.skipMalformed() continue } guard let object = root as? [String: Any], let text = object["text"] as? String else { accumulator.skipMalformed() continue } accumulator.accept( text, sourcePrefix: "codex-raw", tags: "codex", promptedAt: ImportTimestamp.normalize(object["ts"]) ) } } return accumulator.result() } }