fix: UserPromptSubmit hook loses prompt when user_input is list[ContentPart] || fix: UserPromptSubmit hook loses prompt when user_input is list[ContentPart]#1832
Open
Hcaepllams wants to merge 1 commit intoMoonshotAI:mainfrom
Conversation
…ntPart] In terminal mode, Shell.run_soul_command passes user_input.content (which is list[ContentPart]) to KimiSoul.run. The existing code only handled the str case, causing the hook payload's 'prompt' to always be empty. Extract text parts from ContentPart list so hooks can capture the actual user input.
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.
Bug Description
The
UserPromptSubmithook always receives an emptypromptfield, making it impossible for third-party hooks to capture the actual user input.Root Cause
In
src/kimi_cli/soul/kimisoul.py, theUserPromptSubmithook preparation does:However, in practice user_input is always passed as list[ContentPart]:
• Terminal shell mode: ui/shell/init.py passes user_input.content (typed as list[ContentPart] in prompt.py)
• Wire/ACP mode: the server also passes structured content parts
Because isinstance(user_input, str) is effectively never true, text_input_for_hook is always "", and events.user_prompt_submit(prompt=...) sends empty text to hooks.
Fix
Extract text from ContentPart items when user_input is a list:
if isinstance(user_input, str):
text_input_for_hook = user_input
else:
_parts: list[str] = []
for _part in user_input:
if getattr(_part, "type", None) == "text":
_parts.append(getattr(_part, "text", ""))
text_input_for_hook = "".join(_parts)
Impact
• Any UserPromptSubmit hook that logs, audits, or forwards the user's prompt to external services (e.g. Telegram, Slack) currently receives empty content.
• This affects all Kimi CLI users regardless of launch mode (terminal, VS Code extension, or ACP).
Checklist
• [x] Bug fix (non-breaking change which fixes an issue)
• [ ] New feature
• [ ] Breaking change
Prek checks
• make format-kimi-cli ✅
• make check-kimi-cli ✅
Bug Description
The
UserPromptSubmithook always receives an emptypromptfield, making it impossible for third-party hooks to capture the actual user input.Root Cause
In
src/kimi_cli/soul/kimisoul.py, theUserPromptSubmithook preparation does:However, in practice user_input is always passed as list[ContentPart]:
• Terminal shell mode: ui/shell/init.py passes user_input.content (typed as list[ContentPart] in prompt.py)
• Wire/ACP mode: the server also passes structured content parts
Because isinstance(user_input, str) is effectively never true, text_input_for_hook is always "", and events.user_prompt_submit(prompt=...) sends empty text to hooks.
Fix
Extract text from ContentPart items when user_input is a list:
if isinstance(user_input, str):
text_input_for_hook = user_input
else:
_parts: list[str] = []
for _part in user_input:
if getattr(_part, "type", None) == "text":
_parts.append(getattr(_part, "text", ""))
text_input_for_hook = "".join(_parts)
Impact
• Any UserPromptSubmit hook that logs, audits, or forwards the user's prompt to external services (e.g. Telegram, Slack) currently receives empty content.
• This affects all Kimi CLI users regardless of launch mode (terminal, VS Code extension, or ACP).
Checklist
• [x] Bug fix (non-breaking change which fixes an issue)
• [ ] New feature
• [ ] Breaking change
Prek checks
• make format-kimi-cli ✅
• make check-kimi-cli ✅