Commit a node's staged edits to disk and record the snapshot.
(node: TaskNode, result: WorkerResult)
| 180 | |
| 181 | /** Commit a node's staged edits to disk and record the snapshot. */ |
| 182 | async commit(node: TaskNode, result: WorkerResult): Promise<void> { |
| 183 | for (const edit of result.fileEdits) { |
| 184 | const abs = this.abs(edit.path); |
| 185 | await fs.mkdir(path.dirname(abs), { recursive: true }); |
| 186 | // Atomic write: temp + rename. |
| 187 | const tmp = `${abs}.qodex-tmp-${process.pid}`; |
| 188 | await fs.writeFile(tmp, edit.content, 'utf-8'); |
| 189 | await fs.rename(tmp, abs); |
| 190 | this.committed.set(edit.path, edit.content); |
| 191 | this.staged.delete(edit.path); |
| 192 | this.deleted.delete(edit.path); |
| 193 | logger.debug('Committed staged edit', { task: node.id, file: edit.path }); |
| 194 | } |
| 195 | } |
| 196 | |
| 197 | committedPaths(): string[] { return [...this.committed.keys()]; } |
| 198 | } |