Repository navigation
Follow Python SDK #1331/#1332: hook types, raw hook input, init fields - #174
Merged
Merged
Conversation
- Build hook inputs from the whole payload through an event => class table instead of a per-event field list, and keep the payload as #raw_input on every hook input, so CLI fields the SDK does not model are no longer dropped. - Add prompt_id/effort, duration_ms and the other input fields the CLI sends; typed inputs for PostToolBatch, UserPromptExpansion, PreModelSwitch, PostModelSwitch, DirectoryAdded and MessageDisplay. - Declare the *HookSpecificOutput classes from HookOutputKeys and add the ten output classes and new fields of Python #1331. - PermissionDeniedHookSpecificOutput#retry defaults to nil. - InitMessage: capabilities, plugin_errors, terminal_slash_commands, fast_mode_disabled_reason (Python #1332). Amp-Thread-ID: https://ampcode.com/threads/T-01a127a8-ad00-706d-a216-afc5c6d86e27 Co-authored-by: ya-luotao <luotao@hey.com>
…ields - Declare each *HookSpecificOutput's fields with attr_accessor in the class body again; hook_specific_output only fixes the event and defines #initialize / #to_h (wire keys still from HookOutputKeys). With the fields behind the helper, YARD saw none of them and the API reference of all 22 classes was empty. A macro documents the generated members. - Typed hook inputs leave raw_input out of #inspect, as typed system messages leave out data; an UnknownHookInput keeps it. - PreModelSwitchHookInput / PostModelSwitchHookInput: cache_ttl and pricing, the two fields of the CLI 2.1.295 schema they did not read. - README, the skill (both copies), the plugin manifest and the lifecycle example said 27 hook events and listed 12 output classes; now 33 and 22. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01XZys11v9xdM7DXGx9JpC7y
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
Follows the two unreleased Python SDK changes on
main(anthropics/claude-agent-sdk-python#1331, #1332), and fixes the Ruby-side gap that made the first one matter: typed hook inputs used to drop every field the SDK did not list by hand.Hook inputs
Query#parse_hook_inputwas a 27-branchcasethat copied a fixed field list per event, so any field a newer CLI added (prompt_id,effort,duration_ms, ...) never reached the callback. It is now an event → class table (HOOK_INPUT_CLASSES, likeMessageParser::SYSTEM_MESSAGE_CLASSES) built with the lenientfrom_hash, and every hook input keeps the payload as#raw_input(previouslyUnknownHookInputonly).#inspectshowsraw_inputon anUnknownHookInputonly, as typed system messages leave outdata: a typed input already prints those fields as attributes.prompt_id,effort(all inputs);duration_ms(PostToolUse / PostToolUseFailure);session_title,source(UserPromptSubmit);session_title,seconds_since_last_response,prompt_cache_likely_expired,context_tokens,estimated_cache_write_usd(SessionStart);parent_file_path(InstructionsLoaded).PostToolBatch,UserPromptExpansion,PreModelSwitch,PostModelSwitch,DirectoryAdded,MessageDisplay;HOOK_EVENTSnow matches the CLI's 33 events. The two model-switch inputs read every field of the CLI schema,cache_ttlandpricingincluded.mcp_server(new in 2.1.295, marked@internal) is left toraw_input.Hook-specific outputs
*HookSpecificOutputclass declares its fields withattr_accessor(so YARD documents them) and a small@api privateHookSpecificOutputFieldshelper adds the event name,#initializeand a#to_hthat takes wire keys fromHookOutputKeys::HOOK_SPECIFIC, so the table is the single vocabulary instead of being kept in step with 12 hand-written#to_hs. A YARD macro documents the generated members.ArgumentError.InitMessage
capabilities,plugin_errors,terminal_slash_commands,fast_mode_disabled_reason(#1332'sSystemInitData).Behavior changes (in CHANGELOG)
PermissionDeniedHookSpecificOutput#retrydefaults toniland is omitted (wasfalse, always sent; the CLI reads both the same).falseis now sent; onlynilis omitted (most fields used to dropfalsetoo).sig/,docs/hooks-and-permissions.md(new output-class table),docs/types.mdand CHANGELOG are updated; README, the skill (both copies), the plugin manifest and the lifecycle example now say 33 hook events and list the 22 output classes.Test plan
bundle exec rspec: 4314 examples, 0 failures (query_hook_input_specnow has rows for all 33 events, checksraw_input, and covers an unknown event)bundle exec rubocop: no offensesbundle exec rake rbs:validate rbs:test: 3903 examples, 0 failuresyard doc: every*HookSpecificOutputpage lists its fields,#hook_event_name,#initializeand#to_h; no warning fromtypes/hooks.rbInitMessage#capabilities/#fast_mode_disabled_reasonpopulated,UserPromptSubmitHookInput#prompt_idreceived, typedUserPromptSubmitHookSpecificOutput(session_title:)accepted. Tool-use and Stop hooks were not exercised live (the test account's API credit was exhausted).https://ampcode.com/threads/T-01a127a8-ad00-706d-a216-afc5c6d86e27