Skip to content

refactor(hooks): extract shared sync chain executor — core/dispatcher.ts #1287

@yonatangross

Description

@yonatangross

Phase 2 of v8.0.0 Architecture Overhaul

Extract the duplicated sequential-with-short-circuit pattern from 3 sync dispatchers into a shared function.

Before (3 files × ~80 LOC = 240 LOC)

`sync-bash-dispatcher.ts`, `sync-write-edit-dispatcher.ts`, `permission/unified-dispatcher.ts` each implement:

  • Sequential hook execution
  • Short-circuit on block (`!result.continue`)
  • Context accumulation with token budget
  • Error isolation per hook

After (1 shared + 3 callers = 60 LOC)

`core/dispatcher.ts`:
```typescript
export function executeSyncChain(
hooks: SyncHookConfig[],
input: HookInput, ctx: HookContext,
options: { name: string; budget?: number }
): HookResult
```

Each dispatcher becomes ~5 lines:
```typescript
export function syncBashDispatcher(input, ctx) {
return executeSyncChain(BASH_HOOKS, input, ctx, { name: 'bash', budget: 800 });
}
```

Impact

  • -180 LOC (240 → 60)
  • Bug fixes in executor benefit all 3 chains
  • New sync dispatchers are trivial to add

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requesthooksHook system enhancements

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions