feat(hooks): add read-image-resizer hook

Intercepts Read tool output with image attachments and resizes to comply with Anthropic API limits (≤1568px long edge, ≤5MB). Only activates for Anthropic provider sessions and appends resize metadata (original/new resolution, token count) to tool output.

Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-opencode)

Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
This commit is contained in:
YeonGyu-Kim
2026-02-28 13:16:43 +09:00
parent aba68d9555
commit 4b69667aa8
12 changed files with 1121 additions and 0 deletions
@@ -12,6 +12,7 @@ import {
createTasksTodowriteDisablerHook,
createWriteExistingFileGuardHook,
createHashlineReadEnhancerHook,
createReadImageResizerHook,
createJsonErrorRecoveryHook,
} from "../../hooks"
import {
@@ -33,6 +34,7 @@ export type ToolGuardHooks = {
writeExistingFileGuard: ReturnType<typeof createWriteExistingFileGuardHook> | null
hashlineReadEnhancer: ReturnType<typeof createHashlineReadEnhancerHook> | null
jsonErrorRecovery: ReturnType<typeof createJsonErrorRecoveryHook> | null
readImageResizer: ReturnType<typeof createReadImageResizerHook> | null
}
export function createToolGuardHooks(args: {
@@ -105,6 +107,10 @@ export function createToolGuardHooks(args: {
? safeHook("json-error-recovery", () => createJsonErrorRecoveryHook(ctx))
: null
const readImageResizer = isHookEnabled("read-image-resizer")
? safeHook("read-image-resizer", () => createReadImageResizerHook(ctx))
: null
return {
commentChecker,
toolOutputTruncator,
@@ -116,5 +122,6 @@ export function createToolGuardHooks(args: {
writeExistingFileGuard,
hashlineReadEnhancer,
jsonErrorRecovery,
readImageResizer,
}
}
+1
View File
@@ -43,6 +43,7 @@ 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.readImageResizer?.["tool.execute.after"]?.(input, output)
await hooks.hashlineReadEnhancer?.["tool.execute.after"]?.(input, output)
await hooks.jsonErrorRecovery?.["tool.execute.after"]?.(input, output)
}