Skip to content

feat(hooks): implement async hook execution + asyncRewake delivery#60

Merged
LeXwDeX merged 1 commit into
devfrom
feat/hook-async-rewake
Jul 3, 2026
Merged

feat(hooks): implement async hook execution + asyncRewake delivery#60
LeXwDeX merged 1 commit into
devfrom
feat/hook-async-rewake

Conversation

@LeXwDeX

@LeXwDeX LeXwDeX commented Jul 3, 2026

Copy link
Copy Markdown
Owner

Summary

Implements async / asyncRewake hook execution — the last schema-placeholder fields in the hook system.

What changes

  • async: true hooks fork into a background fiber; output never gates the current TriggerResult
  • asyncRewake: true delivers rewake-worthy output (exit 2 stderr, systemMessage, decision:block, additionalContext) back to the agent via a HookRewake bridge service driving the V1 SessionPrompt loop
  • Sentinel-prefixed loop guard prevents hook → rewake → hook loops
  • SessionEnd / missing sessionID suppresses rewake

Architecture

  • src/hook/rewake.ts — tag-only leaf service (no import cycle)
  • src/hook/rewake-live.ts — live impl via SessionPrompt.prompt, wired in both AppLayer and httpapi server node graph (dual composition system — missing the server graph was a blocking review finding)
  • settings.ts — async fork branch + onAsyncComplete rewake callback
  • prompt.tsUserPromptSubmit loop guard

Test plan

  • 9 integration tests covering async non-blocking, output isolation, rewake e2e, suppression (exit-0/SessionEnd/no-sessionID with deterministic readiness signals), once-at-fork, sentinel validation
  • bun typecheck clean (all 35 packages)
  • 45/45 existing hook tests pass — no regression
  • No HTTP API / SDK changes

Async hooks (async:true) fork into a background fiber scoped to the
SettingsHook service layer; their output never participates in the current
TriggerResult. asyncRewake:true delivers rewake-worthy output (exit 2 stderr,
systemMessage, decision:block, additionalContext) back to the agent via the
HookRewake bridge service driving the V1 SessionPrompt loop.

- src/hook/rewake.ts: tag-only leaf service (no import cycle)
- src/hook/rewake-live.ts: live impl via SessionPrompt.prompt, wired in
  AppLayer + httpapi server node graph (dual composition system)
- settings.ts: async fork branch in trigger entry loop, onAsyncComplete
  rewake callback, HOOK_REWAKE_SENTINEL + buildRewakePrompt
- prompt.ts: loop guard skips UserPromptSubmit hooks for sentinel-prefixed
  prompts (prevents hook -> rewake -> hook loops)
- 9 integration tests (async non-blocking, output isolation, rewake e2e,
  suppression, once-at-fork, sentinel validation)
@LeXwDeX LeXwDeX enabled auto-merge (squash) July 3, 2026 18:45
@LeXwDeX LeXwDeX merged commit 5e3fcf7 into dev Jul 3, 2026
4 checks passed
@LeXwDeX LeXwDeX deleted the feat/hook-async-rewake branch July 3, 2026 18:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant