Skip to content

feat: add hooks system with on_exit interceptor for interactive mode#1236

Merged
chaliy merged 1 commit intomainfrom
claude/vibrant-shannon-pV7ec
Apr 12, 2026
Merged

feat: add hooks system with on_exit interceptor for interactive mode#1236
chaliy merged 1 commit intomainfrom
claude/vibrant-shannon-pV7ec

Conversation

@chaliy
Copy link
Copy Markdown
Contributor

@chaliy chaliy commented Apr 12, 2026

Summary

  • Add hooks module with HookAction<T>, Interceptor<T> types and Hooks registry
  • Implement on_exit hook fired by the interpreter when ControlFlow::Exit is processed
  • Wire interactive REPL to use the hook for exit / exit N session termination
  • Hooks registered via BashBuilder::on_exit(), frozen at build time — no mutex

Design

All hooks are interceptors: they receive owned data and return HookAction::Continue(data) (possibly modified) or HookAction::Cancel(reason). Sync callbacks only — async consumers bridge via channels/atomics.

Only on_exit is wired up. Other hooks (before_exec, after_tool, before_http, etc.) will follow in #1235.

Test plan

  • on_exit_hook_fires — hook called on bare exit
  • on_exit_hook_carries_codeexit 42 passes code through
  • on_exit_hook_fires_in_command_listecho bye; exit 1 works through pipeline
  • on_exit_hook_not_fired_for_normal_commandsecho hello does not trigger hook
  • on_exit_hook_code_truncated_to_byteexit 256 truncates to 0
  • Builder doctest for BashBuilder::on_exit()
  • All 91 CLI tests pass
  • clippy clean, fmt clean

Introduce `hooks` module with `HookAction<T>`, `Interceptor<T>`, and
`Hooks` registry.  Hooks are registered via `BashBuilder::on_exit()`
and frozen at build time — no mutex needed.

The interpreter fires `on_exit` when `ControlFlow::Exit` is processed.
The interactive REPL registers a hook that sets an atomic flag, checked
after each exec() call to terminate the session.

Only `on_exit` is wired up; other hooks will follow (#1235).
@chaliy chaliy merged commit 65238bc into main Apr 12, 2026
27 checks passed
@chaliy chaliy deleted the claude/vibrant-shannon-pV7ec branch April 12, 2026 04:52
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