Repository navigation
hooks: session_start and session_end (refs #26) - #36
Merged
Merged
Conversation
The method was cfg(test) while its only caller, the bridged-turn test, is cfg(unix), so a Windows test build held it as dead code and clippy -D warnings refused the crate.
The operator's hooks gain the session's own start and end. Start fires once the session exists (cli::prepare_session for the REPL and --acp, before the first line in -t); end fires beside the memory engine's own end, so the two stay paired. In -t a line refused by user_prompt_submit now ends what it started. Neither can refuse; stdout is shown. Project plugins still give only the tool events. lifecycle.json is marked superseded and still runs.
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.
Operator hooks for the session's own start and end (refs #26).
What
session_startandsession_endjoin the operator'shooks(admin.json, alsodesktop_hooks, and the operator's own plugins):session_startruns once a session exists, withsource: "startup".session_endruns when the session closes. Itsreasonisprompt_input_exitin the REPL andotherfor--acpand-t.The event is JSON on stdin (
hook_event_name,session_id,cwd, plussourceorreason). The command runs in the workspace and is bounded at 10 s, like the other events.Neither hook can refuse: exit 2 is an ordinary exit here. Their stdout is shown:
print_infoprint_info-t--acpWhere it fires
cli::prepare_session: start. Both the REPL and--acpgo through it.end_memory: end. Covers the REPL (cli/mod.rs) and--acp(acp_agent::drive), so the operator's end is paired with the memory engine's end by construction.task_run: start beforeuser_prompt_submit, end after the engine's end. A refused instruction now also runssession_end, so no start is left without its end. To make that testable,run_task_reportingnow hands its runner to a newrun_task_hooked.Project plugins still give only the tool events (allowlist in
plugins::hooks_of), so a cloned repo's plugin cannot add a session hook..incode/lifecycle.json'son_session_start/on_session_endare marked superseded. They still run.Tests (each with a control that puts the bug back)
hooks::tests::session_start_and_end_are_told_and_cannot_refusechecks the payload fields and that exit 2 does not refuse. Control: makingsession_endable to refuse fails it ("a session_end hook refused").cli::agent_turn::tests::session_start_and_end_hooks_run_in_the_workspace_and_are_shownchecks that the hook runs in the workspace, that its output comes back, and that nothing happens without hooks. Control: passing nocwdfails it (the hook ran in the repo, not the workspace).task_run::tests::a_refused_instruction_still_runs_the_session_end_hook. Control: removing the end call on the refusal path fails it.Not covered
/runledger workers (cli::run_memory) are sessions with no person behind them. They do not runsession_start/session_end, as they already do not runuser_prompt_submit.source: "startup"is fired. Nothing restarts a session in place yet, so there is noclear.