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)
49 lines
2.2 KiB
TypeScript
49 lines
2.2 KiB
TypeScript
import { consumeToolMetadata } from "../features/tool-metadata-store"
|
|
import type { CreatedHooks } from "../create-hooks"
|
|
|
|
export function createToolExecuteAfterHandler(args: {
|
|
hooks: CreatedHooks
|
|
}): (
|
|
input: { tool: string; sessionID: string; callID: string },
|
|
output:
|
|
| { title: string; output: string; metadata: Record<string, unknown> }
|
|
| undefined,
|
|
) => Promise<void> {
|
|
const { hooks } = args
|
|
|
|
return async (
|
|
input: { tool: string; sessionID: string; callID: string },
|
|
output: { title: string; output: string; metadata: Record<string, unknown> } | undefined,
|
|
): Promise<void> => {
|
|
if (!output) return
|
|
|
|
const stored = consumeToolMetadata(input.sessionID, input.callID)
|
|
if (stored) {
|
|
if (stored.title) {
|
|
output.title = stored.title
|
|
}
|
|
if (stored.metadata) {
|
|
output.metadata = { ...output.metadata, ...stored.metadata }
|
|
}
|
|
}
|
|
|
|
await hooks.claudeCodeHooks?.["tool.execute.after"]?.(input, output)
|
|
await hooks.toolOutputTruncator?.["tool.execute.after"]?.(input, output)
|
|
await hooks.preemptiveCompaction?.["tool.execute.after"]?.(input, output)
|
|
await hooks.contextWindowMonitor?.["tool.execute.after"]?.(input, output)
|
|
await hooks.commentChecker?.["tool.execute.after"]?.(input, output)
|
|
await hooks.directoryAgentsInjector?.["tool.execute.after"]?.(input, output)
|
|
await hooks.directoryReadmeInjector?.["tool.execute.after"]?.(input, output)
|
|
await hooks.rulesInjector?.["tool.execute.after"]?.(input, output)
|
|
await hooks.emptyTaskResponseDetector?.["tool.execute.after"]?.(input, output)
|
|
await hooks.agentUsageReminder?.["tool.execute.after"]?.(input, output)
|
|
await hooks.categorySkillReminder?.["tool.execute.after"]?.(input, output)
|
|
await hooks.interactiveBashSession?.["tool.execute.after"]?.(input, output)
|
|
await hooks.editErrorRecovery?.["tool.execute.after"]?.(input, output)
|
|
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)
|
|
}
|
|
}
|