(meta: ConversationMeta)
| 147 | } |
| 148 | |
| 149 | function parseFileSync(meta: ConversationMeta): ConversationItem | null { |
| 150 | try { |
| 151 | const raw = readFileSync(meta.filePath, "utf-8"); |
| 152 | const allLines = raw.split("\n").filter((l) => l.trim()); |
| 153 | if (allLines.length === 0) return null; |
| 154 | |
| 155 | const lines = allLines.length > MAX_LINES_PER_FILE |
| 156 | ? allLines.slice(0, MAX_LINES_PER_FILE) |
| 157 | : allLines; |
| 158 | |
| 159 | const { messages, firstTimestamp, lastTimestamp } = extractMessages(lines); |
| 160 | if (messages.length === 0) return null; |
| 161 | |
| 162 | const firstHuman = messages.find((m) => m.role === "human"); |
| 163 | const title = firstHuman |
| 164 | ? firstHuman.text.slice(0, 120).replace(/\n/g, " ") |
| 165 | : "(empty conversation)"; |
| 166 | |
| 167 | return { |
| 168 | id: meta.uuid, |
| 169 | uuid: meta.uuid, |
| 170 | project: meta.project, |
| 171 | projectPath: meta.projectPath, |
| 172 | title, |
| 173 | messages, |
| 174 | messageCount: messages.length, |
| 175 | firstTimestamp, |
| 176 | lastTimestamp, |
| 177 | tags: [], |
| 178 | customTags: [], |
| 179 | isFavorite: false, |
| 180 | filePath: meta.filePath, |
| 181 | }; |
| 182 | } catch { return null; } |
| 183 | } |
| 184 | |
| 185 | async function parseFileAsync(meta: ConversationMeta): Promise<ConversationItem | null> { |
| 186 | return new Promise((resolve) => { |
no test coverage detected