fix(hooks): pass prompt text to UserPromptSubmit from structured input#2454
Open
logicwu0 wants to merge 1 commit into
Open
fix(hooks): pass prompt text to UserPromptSubmit from structured input#2454logicwu0 wants to merge 1 commit into
logicwu0 wants to merge 1 commit into
Conversation
The UserPromptSubmit hook derived its prompt text with `user_input if isinstance(user_input, str) else ""`. Input submitted from the interactive shell UI is structured content (list[ContentPart]), not a plain str, so it fell into the else branch: hooks received an empty `prompt` and `matcher_value`, and regex-based prompt hooks never matched. Add `user_input_to_text()` (extracts text from str or structured content) and use it when building the hook payload. Fixes MoonshotAI#2303
This was referenced Jun 16, 2026
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.
Problem
A
UserPromptSubmithook always received"prompt": ""(and an emptymatcher_value) when the user typed plain text in the interactive shell, so regex-based prompt hooks never matched. (Fixes #2303)Root cause
In
KimiSoul._turn, the hook text was derived as:user_inputis typedstr | list[ContentPart]. Input submitted from the shell UI is structured content (list[ContentPart]), not a plainstr, so it hit theelsebranch and became an empty string.Fix
Add
user_input_to_text()inkimi_cli/utils/message.py, which returns the string as-is or extracts the concatenated text from structured content (Message.extract_text(" "), the same mechanism already used a few lines later to build the turn text). Use it when constructing the hook payload. The plain-strpath is unchanged.Tests
Added unit tests in
tests/utils/test_message_utils.pycoveringuser_input_to_textfor: plain string, structuredTextParts, mixed text/non-text parts, and empty input.uv run pytest tests/utils/test_message_utils.py tests/hooks/→ 49 passed.ruff format/checkclean.