fix(hashline-edit): address Oracle review feedback

- Extract WRITE_SUCCESS_MARKER constant to couple guard and output string
- Remove double blank line after parseLineRefWithHint
- Add comment clarifying normalized equals ref.trim() in error paths
This commit is contained in:
YeonGyu-Kim 2026-02-24 17:41:30 +09:00
parent 55ad4297d4
commit a567cd0d68
2 changed files with 5 additions and 3 deletions

View File

@ -1,6 +1,8 @@
import type { PluginInput } from "@opencode-ai/plugin" import type { PluginInput } from "@opencode-ai/plugin"
import { computeLineHash } from "../../tools/hashline-edit/hash-computation" import { computeLineHash } from "../../tools/hashline-edit/hash-computation"
const WRITE_SUCCESS_MARKER = "File written successfully."
interface HashlineReadEnhancerConfig { interface HashlineReadEnhancerConfig {
hashline_edit?: { enabled: boolean } hashline_edit?: { enabled: boolean }
} }
@ -136,7 +138,7 @@ function extractFilePath(metadata: unknown): string | undefined {
} }
async function appendWriteHashlineOutput(output: { output: string; metadata: unknown }): Promise<void> { async function appendWriteHashlineOutput(output: { output: string; metadata: unknown }): Promise<void> {
if (output.output.startsWith("File written successfully.")) { if (output.output.startsWith(WRITE_SUCCESS_MARKER)) {
return return
} }
@ -152,7 +154,7 @@ async function appendWriteHashlineOutput(output: { output: string; metadata: unk
const content = await file.text() const content = await file.text()
const lineCount = content === "" ? 0 : content.split("\n").length const lineCount = content === "" ? 0 : content.split("\n").length
output.output = `File written successfully. ${lineCount} lines written.` output.output = `${WRITE_SUCCESS_MARKER} ${lineCount} lines written.`
} }
export function createHashlineReadEnhancerHook( export function createHashlineReadEnhancerHook(

View File

@ -38,6 +38,7 @@ export function parseLineRef(ref: string): LineRef {
hash: match[2], hash: match[2],
} }
} }
// normalized equals ref.trim() in all error paths — extraction only succeeds for valid refs
const hashIdx = normalized.indexOf('#') const hashIdx = normalized.indexOf('#')
if (hashIdx > 0) { if (hashIdx > 0) {
const prefix = normalized.slice(0, hashIdx) const prefix = normalized.slice(0, hashIdx)
@ -151,7 +152,6 @@ function parseLineRefWithHint(ref: string, lines: string[]): LineRef {
} }
} }
export function validateLineRefs(lines: string[], refs: string[]): void { export function validateLineRefs(lines: string[], refs: string[]): void {
const mismatches: HashMismatch[] = [] const mismatches: HashMismatch[] = []