feat: add session.stopping hook for plugins#16598
Open
yehudacohen wants to merge 9 commits intoanomalyco:devfrom
Open
feat: add session.stopping hook for plugins#16598yehudacohen wants to merge 9 commits intoanomalyco:devfrom
yehudacohen wants to merge 9 commits intoanomalyco:devfrom
Conversation
Fires before the agent loop exits, allowing plugins to inject a follow-up message and re-enter the loop instead of going idle. Changes: - packages/plugin/src/index.ts: add session.stopping to Hooks interface - packages/opencode/src/session/prompt.ts: fire hook before loop break, inject message and continue if plugin returns stop=false - test/plugin/session-stopping.test.ts: tests for hook loading and trigger
Contributor
|
Thanks for updating your PR! It now meets our contributing guidelines. 👍 |
425a791 to
daf9c96
Compare
Contributor
|
Thanks for updating your PR! It now meets our contributing guidelines. 👍 |
1 task
6 tasks
1 task
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.
Issue for this PR
Closes #16626
Related to #12472 (the Stop hook re-activation use case is a subset of what that issue describes).
Type of change
What does this PR do?
Adds a
session.stoppinghook to the plugin API. It fires before the agent loop breaks, giving plugins a chance to inject a follow-up user message and continue the loop instead of stopping. If no plugin is installed, behaviour is unchanged.Known limitation: if a plugin unconditionally sets
stop=falseon every call, the loop will run indefinitely. There is no built-in re-entry cap. Plugins are responsible for their own termination condition. This is intentional: the correct guard depends entirely on the plugin's use case (a counter, a state flag, a file on disk) and cannot be generalised in core without constraining valid use cases. The same responsibility applies to any plugin that callsclient.session.chatfromsession.idle.How did you verify your code works?
Four tests in
test/plugin/session-stopping.test.ts— no mocks, real plugin files written to a temp dir and loaded viaPlugin.init(): plugin mutation propagates throughPlugin.trigger; no plugin leavesstopastrue;stop=falsewith no message does not satisfy the re-entry condition; hook message is persisted as a real user message viaSessionPrompt.prompt.End-to-end against the dev build: created a one-shot plugin that sets
stop=falseon first fire. Ranopencode run "say exactly the word HELLO and nothing else". Session export confirmed 4 messages in order: original user prompt, HELLO, hook-injected user message, second assistant reply. The loop stopped cleanly on the second hook fire because the plugin saw its own marker file and returned without modifying output.bun typecheckclean.Screenshots / recordings
N/A — no UI changes.
Checklist