Fix hashline-edit deduplication and validation

- Canonicalize anchors in dedupe keys to handle whitespace variants
- Make lines field required in edit operations
- Only allow unanchored append/prepend to create missing files
- Reorder delete/rename validation to prevent edge cases
- Add allow_non_gpt_model and max_prompt_tokens to config schema
  ```
This commit is contained in:
minpeter
2026-02-26 17:43:49 +09:00
parent d491a20fe4
commit 26004f93ec
7 changed files with 117 additions and 15 deletions
@@ -1,18 +1,24 @@
import type { HashlineEdit } from "./types"
import { toNewLines } from "./edit-text-normalization"
import { normalizeLineRef } from "./validation"
function normalizeEditPayload(payload: string | string[]): string {
return toNewLines(payload).join("\n")
}
function canonicalAnchor(anchor: string | undefined): string {
if (!anchor) return ""
return normalizeLineRef(anchor)
}
function buildDedupeKey(edit: HashlineEdit): string {
switch (edit.op) {
case "replace":
return `replace|${edit.pos}|${edit.end ?? ""}|${normalizeEditPayload(edit.lines)}`
return `replace|${canonicalAnchor(edit.pos)}|${edit.end ? canonicalAnchor(edit.end) : ""}|${normalizeEditPayload(edit.lines)}`
case "append":
return `append|${edit.pos ?? ""}|${normalizeEditPayload(edit.lines)}`
return `append|${canonicalAnchor(edit.pos)}|${normalizeEditPayload(edit.lines)}`
case "prepend":
return `prepend|${edit.pos ?? ""}|${normalizeEditPayload(edit.lines)}`
return `prepend|${canonicalAnchor(edit.pos)}|${normalizeEditPayload(edit.lines)}`
default:
return JSON.stringify(edit)
}