2026-02-19 17:09:46 +09:00
|
|
|
import { tool, type ToolContext, type ToolDefinition } from "@opencode-ai/plugin/tool"
|
2026-02-22 14:13:59 +09:00
|
|
|
import { executeHashlineEditTool } from "./hashline-edit-executor"
|
2026-02-22 03:38:04 +09:00
|
|
|
import { HASHLINE_EDIT_DESCRIPTION } from "./tool-description"
|
2026-02-23 18:51:32 +09:00
|
|
|
import type { RawHashlineEdit } from "./normalize-edits"
|
2026-02-16 16:32:33 +09:00
|
|
|
|
|
|
|
|
interface HashlineEditArgs {
|
2026-02-19 17:09:46 +09:00
|
|
|
filePath: string
|
2026-02-23 18:51:32 +09:00
|
|
|
edits: RawHashlineEdit[]
|
2026-02-22 03:38:04 +09:00
|
|
|
delete?: boolean
|
|
|
|
|
rename?: string
|
2026-02-16 16:32:33 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function createHashlineEditTool(): ToolDefinition {
|
|
|
|
|
return tool({
|
2026-02-22 03:38:04 +09:00
|
|
|
description: HASHLINE_EDIT_DESCRIPTION,
|
2026-02-16 16:32:33 +09:00
|
|
|
args: {
|
2026-02-19 17:09:46 +09:00
|
|
|
filePath: tool.schema.string().describe("Absolute path to the file to edit"),
|
2026-02-22 03:38:04 +09:00
|
|
|
delete: tool.schema.boolean().optional().describe("Delete file instead of editing"),
|
|
|
|
|
rename: tool.schema.string().optional().describe("Rename output file path after edits"),
|
2026-02-16 16:32:33 +09:00
|
|
|
edits: tool.schema
|
|
|
|
|
.array(
|
2026-02-23 18:51:32 +09:00
|
|
|
tool.schema.object({
|
|
|
|
|
type: tool.schema
|
|
|
|
|
.union([
|
|
|
|
|
tool.schema.literal("set_line"),
|
|
|
|
|
tool.schema.literal("replace_lines"),
|
|
|
|
|
tool.schema.literal("insert_after"),
|
|
|
|
|
tool.schema.literal("insert_before"),
|
|
|
|
|
tool.schema.literal("insert_between"),
|
|
|
|
|
tool.schema.literal("replace"),
|
|
|
|
|
tool.schema.literal("append"),
|
|
|
|
|
tool.schema.literal("prepend"),
|
|
|
|
|
])
|
|
|
|
|
.describe("Edit operation type"),
|
|
|
|
|
line: tool.schema.string().optional().describe("Anchor line in LINE#ID format"),
|
|
|
|
|
start_line: tool.schema.string().optional().describe("Range start in LINE#ID format"),
|
|
|
|
|
end_line: tool.schema.string().optional().describe("Range end in LINE#ID format"),
|
|
|
|
|
after_line: tool.schema.string().optional().describe("Insert boundary (after) in LINE#ID format"),
|
|
|
|
|
before_line: tool.schema.string().optional().describe("Insert boundary (before) in LINE#ID format"),
|
|
|
|
|
text: tool.schema
|
|
|
|
|
.union([tool.schema.string(), tool.schema.array(tool.schema.string())])
|
|
|
|
|
.optional()
|
|
|
|
|
.describe("Operation content"),
|
|
|
|
|
old_text: tool.schema.string().optional().describe("Legacy text replacement source"),
|
|
|
|
|
new_text: tool.schema
|
|
|
|
|
.union([tool.schema.string(), tool.schema.array(tool.schema.string())])
|
|
|
|
|
.optional()
|
|
|
|
|
.describe("Legacy text replacement target"),
|
|
|
|
|
})
|
2026-02-16 16:32:33 +09:00
|
|
|
)
|
2026-02-22 03:38:04 +09:00
|
|
|
.describe("Array of edit operations to apply (empty when delete=true)"),
|
2026-02-16 16:32:33 +09:00
|
|
|
},
|
2026-02-22 14:13:59 +09:00
|
|
|
execute: async (args: HashlineEditArgs, context: ToolContext) => executeHashlineEditTool(args, context),
|
2026-02-16 16:32:33 +09:00
|
|
|
})
|
|
|
|
|
}
|