Skip to content

[Improvement]: hooks: extract shared lifecycle hook runner into src/hooks/lifecycle.ts #10

@Arry8

Description

@Arry8

Summary

Extract the generic parts of src/cron/hooks.ts into a shared src/hooks/lifecycle.ts module so all future workflow hook PRs (delivery, agent, subagent, tool) import from a common foundation instead of the cron module.

Problem

runCronHooks, CronHookEntry, and CronHookRunResult in src/cron/hooks.ts are 100% workflow-agnostic but have cron-specific names. Building delivery (#6), agent (#7), subagent (#8), and tool (#9) hooks on top of the cron module creates a naming smell and a wrong dependency direction.

Acceptance criteria

  • src/hooks/lifecycle.ts exports runLifecycleHooks, LifecycleHookRunResult, loadHookModule, isValidJobHookPath
  • LifecycleHookEntry type lives in src/config/types.hooks.ts
  • src/cron/hooks.ts re-exports CronHookEntry (alias for LifecycleHookEntry) and runCronHooks (alias for runLifecycleHooks) for back-compat with upstream PR cron: add lifecycle hooks for job execution openclaw/openclaw#45465
  • No behavior change — all existing cron hook tests still pass
  • pnpm build and pnpm check pass clean

Implementation plan

  1. Add LifecycleHookEntry and LifecycleHookRunResult to src/config/types.hooks.ts
  2. Create src/hooks/lifecycle.ts with runLifecycleHooks, loadHookModule, isValidJobHookPath, createTimeout (moved verbatim from src/cron/hooks.ts)
  3. Update src/cron/hooks.ts to import from src/hooks/lifecycle.ts and re-export CronHookEntry = LifecycleHookEntry and runCronHooks = runLifecycleHooks
  4. Run pnpm build && pnpm check && pnpm test -- src/cron/hooks.test.ts

Files affected

  • src/config/types.hooks.ts (add LifecycleHookEntry, LifecycleHookRunResult)
  • src/hooks/lifecycle.ts (new)
  • src/cron/hooks.ts (import from shared module, re-export aliases)

Additional notes

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions