| 1173 | // ─── Write ─── |
| 1174 | |
| 1175 | insertChunk(chunk: Chunk): void { |
| 1176 | const stmt = this.db.prepare(` |
| 1177 | INSERT OR REPLACE INTO chunks (id, session_key, turn_id, seq, role, content, kind, summary, task_id, content_hash, owner, dedup_status, dedup_target, dedup_reason, created_at, updated_at) |
| 1178 | VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) |
| 1179 | `); |
| 1180 | stmt.run( |
| 1181 | chunk.id, |
| 1182 | chunk.sessionKey, |
| 1183 | chunk.turnId, |
| 1184 | chunk.seq, |
| 1185 | chunk.role, |
| 1186 | chunk.content, |
| 1187 | chunk.kind, |
| 1188 | chunk.summary, |
| 1189 | chunk.taskId, |
| 1190 | contentHash(chunk.content), |
| 1191 | chunk.owner ?? "agent:main", |
| 1192 | chunk.dedupStatus ?? "active", |
| 1193 | chunk.dedupTarget ?? null, |
| 1194 | chunk.dedupReason ?? null, |
| 1195 | chunk.createdAt, |
| 1196 | chunk.updatedAt, |
| 1197 | ); |
| 1198 | } |
| 1199 | |
| 1200 | markDedupStatus(chunkId: string, status: "duplicate" | "merged", targetChunkId: string | null, reason: string): void { |
| 1201 | this.db.prepare( |