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:
@@ -1,6 +1,8 @@
|
||||
import type { PluginInput } from "@opencode-ai/plugin"
|
||||
import { computeLineHash } from "../../tools/hashline-edit/hash-computation"
|
||||
|
||||
const WRITE_SUCCESS_MARKER = "File written successfully."
|
||||
|
||||
interface HashlineReadEnhancerConfig {
|
||||
hashline_edit?: { enabled: boolean }
|
||||
}
|
||||
@@ -136,7 +138,7 @@ function extractFilePath(metadata: unknown): string | undefined {
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
@@ -152,7 +154,7 @@ async function appendWriteHashlineOutput(output: { output: string; metadata: unk
|
||||
|
||||
const content = await file.text()
|
||||
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(
|
||||
|
||||
@@ -38,6 +38,7 @@ export function parseLineRef(ref: string): LineRef {
|
||||
hash: match[2],
|
||||
}
|
||||
}
|
||||
// normalized equals ref.trim() in all error paths — extraction only succeeds for valid refs
|
||||
const hashIdx = normalized.indexOf('#')
|
||||
if (hashIdx > 0) {
|
||||
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 {
|
||||
const mismatches: HashMismatch[] = []
|
||||
|
||||
|
||||
Reference in New Issue
Block a user