feat(coder): add edit safety guards against truncation
This commit is contained in:
@@ -4,6 +4,7 @@ import { randomBytes } from 'node:crypto';
|
||||
import type { Sql } from '../db.js';
|
||||
import { resolveWritePath } from './write_guard.js';
|
||||
import { locateMatch } from './fuzzy-match.js';
|
||||
import { validateEditResult, formatGuardError } from './edit-guards.js';
|
||||
|
||||
/**
|
||||
* Write a file atomically: stage to a sibling temp file, then rename over the
|
||||
@@ -285,6 +286,10 @@ export async function applyOne(
|
||||
);
|
||||
}
|
||||
if (plan.kind === 'apply') {
|
||||
const guard = validateEditResult(toLf(raw), plan.updated, change.file_path);
|
||||
if (!guard.ok) {
|
||||
throw new Error(formatGuardError(guard, change.file_path));
|
||||
}
|
||||
const out = eol === '\r\n' ? plan.updated.replaceAll('\n', '\r\n') : plan.updated;
|
||||
await writeFileAtomic(change.file_path, out);
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user