Repository navigation
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>
This branch has not been deployed
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).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.mcp_server(new in 2.1.295, marked@internal) is left toraw_input.Hook-specific outputs
*HookSpecificOutputclasses are declared through a small@api privateHookSpecificOutputFieldshelper that 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.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.Test plan
bundle exec rspec: 4310 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: 3899 examples, 0 failuresInitMessage#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