feat: add hooks system with on_exit interceptor for interactive mode#1236
Merged
feat: add hooks system with on_exit interceptor for interactive mode#1236
Conversation
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).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
hooksmodule withHookAction<T>,Interceptor<T>types andHooksregistryon_exithook fired by the interpreter whenControlFlow::Exitis processedexit/exit Nsession terminationBashBuilder::on_exit(), frozen at build time — no mutexDesign
All hooks are interceptors: they receive owned data and return
HookAction::Continue(data)(possibly modified) orHookAction::Cancel(reason). Sync callbacks only — async consumers bridge via channels/atomics.Only
on_exitis wired up. Other hooks (before_exec,after_tool,before_http, etc.) will follow in #1235.Test plan
on_exit_hook_fires— hook called on bareexiton_exit_hook_carries_code—exit 42passes code throughon_exit_hook_fires_in_command_list—echo bye; exit 1works through pipelineon_exit_hook_not_fired_for_normal_commands—echo hellodoes not trigger hookon_exit_hook_code_truncated_to_byte—exit 256truncates to 0BashBuilder::on_exit()