feat(hashline): port hashline edit tool from oh-my-pi
This PR ports the hashline edit tool from oh-my-pi to oh-my-opencode as an experimental feature. ## Features - New experimental.hashline_edit config flag - hashline_edit tool with 4 operations: set_line, replace_lines, insert_after, replace - Hash-based line anchors for safe concurrent editing - Edit tool disabler for non-OpenAI providers - Read output enhancer with LINE:HASH prefixes - Provider state tracking module ## Technical Details - xxHash32-based 2-char hex hashes - Bottom-up edit application to prevent index shifting - OpenAI provider exemption (uses native apply_patch) - 90 tests covering all operations and edge cases - All files under 200 LOC limit ## Files Added/Modified - src/tools/hashline-edit/ (7 files, ~400 LOC) - src/hooks/hashline-edit-disabler/ (4 files, ~200 LOC) - src/hooks/hashline-read-enhancer/ (3 files, ~400 LOC) - src/features/hashline-provider-state.ts (13 LOC) - src/config/schema/experimental.ts (hashline_edit flag) - src/config/schema/hooks.ts (2 new hook names) - src/plugin/tool-registry.ts (conditional registration) - src/plugin/chat-params.ts (provider state tracking) - src/tools/index.ts (export) - src/hooks/index.ts (exports)
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
import { setProvider } from "../features/hashline-provider-state"
|
||||
|
||||
type ChatParamsInput = {
|
||||
sessionID: string
|
||||
agent: { name?: string }
|
||||
@@ -66,6 +68,8 @@ export function createChatParamsHandler(args: {
|
||||
if (!normalizedInput) return
|
||||
if (!isChatParamsOutput(output)) return
|
||||
|
||||
setProvider(normalizedInput.sessionID, normalizedInput.model.providerID)
|
||||
|
||||
await args.anthropicEffort?.["chat.params"]?.(normalizedInput, output)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,6 +10,8 @@ import {
|
||||
createRulesInjectorHook,
|
||||
createTasksTodowriteDisablerHook,
|
||||
createWriteExistingFileGuardHook,
|
||||
createHashlineEditDisablerHook,
|
||||
createHashlineReadEnhancerHook,
|
||||
} from "../../hooks"
|
||||
import {
|
||||
getOpenCodeVersion,
|
||||
@@ -28,6 +30,8 @@ export type ToolGuardHooks = {
|
||||
rulesInjector: ReturnType<typeof createRulesInjectorHook> | null
|
||||
tasksTodowriteDisabler: ReturnType<typeof createTasksTodowriteDisablerHook> | null
|
||||
writeExistingFileGuard: ReturnType<typeof createWriteExistingFileGuardHook> | null
|
||||
hashlineEditDisabler: ReturnType<typeof createHashlineEditDisablerHook> | null
|
||||
hashlineReadEnhancer: ReturnType<typeof createHashlineReadEnhancerHook> | null
|
||||
}
|
||||
|
||||
export function createToolGuardHooks(args: {
|
||||
@@ -85,6 +89,14 @@ export function createToolGuardHooks(args: {
|
||||
? safeHook("write-existing-file-guard", () => createWriteExistingFileGuardHook(ctx))
|
||||
: null
|
||||
|
||||
const hashlineEditDisabler = isHookEnabled("hashline-edit-disabler")
|
||||
? safeHook("hashline-edit-disabler", () => createHashlineEditDisablerHook(pluginConfig))
|
||||
: null
|
||||
|
||||
const hashlineReadEnhancer = isHookEnabled("hashline-read-enhancer")
|
||||
? safeHook("hashline-read-enhancer", () => createHashlineReadEnhancerHook(ctx, { hashline_edit: { enabled: pluginConfig.experimental?.hashline_edit ?? false } }))
|
||||
: null
|
||||
|
||||
return {
|
||||
commentChecker,
|
||||
toolOutputTruncator,
|
||||
@@ -94,5 +106,7 @@ export function createToolGuardHooks(args: {
|
||||
rulesInjector,
|
||||
tasksTodowriteDisabler,
|
||||
writeExistingFileGuard,
|
||||
hashlineEditDisabler,
|
||||
hashlineReadEnhancer,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -43,5 +43,6 @@ export function createToolExecuteAfterHandler(args: {
|
||||
await hooks.delegateTaskRetry?.["tool.execute.after"]?.(input, output)
|
||||
await hooks.atlasHook?.["tool.execute.after"]?.(input, output)
|
||||
await hooks.taskResumeInfo?.["tool.execute.after"]?.(input, output)
|
||||
await hooks.hashlineReadEnhancer?.["tool.execute.after"]?.(input, output)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,6 +29,7 @@ export function createToolExecuteBeforeHandler(args: {
|
||||
await hooks.prometheusMdOnly?.["tool.execute.before"]?.(input, output)
|
||||
await hooks.sisyphusJuniorNotepad?.["tool.execute.before"]?.(input, output)
|
||||
await hooks.atlasHook?.["tool.execute.before"]?.(input, output)
|
||||
await hooks.hashlineEditDisabler?.["tool.execute.before"]?.(input, output)
|
||||
|
||||
if (input.tool === "task") {
|
||||
const argsObject = output.args
|
||||
|
||||
@@ -25,6 +25,7 @@ import {
|
||||
createTaskGetTool,
|
||||
createTaskList,
|
||||
createTaskUpdateTool,
|
||||
createHashlineEditTool,
|
||||
} from "../tools"
|
||||
import { getMainSessionID } from "../features/claude-code-session-state"
|
||||
import { filterDisabledTools } from "../shared/disabled-tools"
|
||||
@@ -117,6 +118,11 @@ export function createToolRegistry(args: {
|
||||
}
|
||||
: {}
|
||||
|
||||
const hashlineEnabled = pluginConfig.experimental?.hashline_edit ?? false
|
||||
const hashlineToolsRecord: Record<string, ToolDefinition> = hashlineEnabled
|
||||
? { hashline_edit: createHashlineEditTool() }
|
||||
: {}
|
||||
|
||||
const allTools: Record<string, ToolDefinition> = {
|
||||
...builtinTools,
|
||||
...createGrepTools(ctx),
|
||||
@@ -132,6 +138,7 @@ export function createToolRegistry(args: {
|
||||
slashcommand: slashcommandTool,
|
||||
interactive_bash,
|
||||
...taskToolsRecord,
|
||||
...hashlineToolsRecord,
|
||||
}
|
||||
|
||||
const filteredTools = filterDisabledTools(allTools, pluginConfig.disabled_tools)
|
||||
|
||||
Reference in New Issue
Block a user