Repository navigation
Every hook returns a string - #21
Closed
nigelgilbert wants to merge 8 commits into
Closed
nigelgilbert wants to merge 8 commits into
nigelgilbert wants to merge 8 commits into
Conversation
Owner
Author
|
Sloppy drift. I'm re-writing the plan and running a new factory run. |
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.
A hook is now one stage of a pipe: it takes the text and returns the text. Returning
None, or nothing, used to mean "leave it as it was". That shorthand is gone, and a hook that does not return a string fails.This is a breaking change to the hook API.
The contract
on_transcribed(t)on_cleaned(t)on_sent(t)on_done(t)on_donehook getson_error(e, message)""stops the chain for that point, and nothing downstream runs.Noneincluded, raisesTypeError: on_cleaned returned NoneType, not str.What changed
lifecycle.py:callrejects any return that is not astr.fireno longer checks forNone.fire_doneandhook_messageare deleted, andfire_errorreplaces the latter.reportno longer needs its ordering comment or itsNonecheck.on_done: it runs throughfirelike the other text hooks, so eachon_donehook gets what the one before it returned. The return of the last one goes nowhere.on_error: it takes the message as a second argument. The message is piped through theon_errorhooks in filename order, starting from the default. A hook that fails is recorded inerrors.txtand skipped.docs/hooks.mdandsidecar/README.mdstate the new contract, and the six recipes that relied on returning nothing now return explicitly.examples/returnedNoneon some paths. Each now returns the text it was given on those paths, so behaviour is the same.examples/terminal.py: the docstrings said to start with "shell" where the code matches "terminal". Fixed in passing.What breaks for existing hook files
on_cleaned in voice.py: TypeError: on_cleaned returned NoneType, not str. The fix isreturn t.on_error(e)hook is called with two arguments and raisesTypeError. It is skipped, its failure goes inerrors.txt, and the default message is reported. The fix ison_error(e, message)andreturn message.Both need to go in the release notes of the next release.
Left as it was
on_errorhook that doesraise eadds anon_error in <file>note to the original exception, so a lateron_errorhook reads that as the last note. The base branch behaves the same way.after_replybut notfireorprocess. Also unchanged.Testing
In
sidecar/:uv run python -m pytest -qgives 107 passed (99 on the base branch).uv run python -m pyrightanduv run ruff checkare clean.The review record is in
docs/factory-report-feature-hook-returns-1.md.