Skip to content

fix(hooks): pass prompt text to UserPromptSubmit from structured input#2454

Open
logicwu0 wants to merge 1 commit into
MoonshotAI:mainfrom
logicwu0:fix/2303-userpromptsubmit-empty-prompt
Open

fix(hooks): pass prompt text to UserPromptSubmit from structured input#2454
logicwu0 wants to merge 1 commit into
MoonshotAI:mainfrom
logicwu0:fix/2303-userpromptsubmit-empty-prompt

Conversation

@logicwu0

@logicwu0 logicwu0 commented Jun 15, 2026

Copy link
Copy Markdown

Problem

A UserPromptSubmit hook always received "prompt": "" (and an empty matcher_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:

text_input_for_hook = user_input if isinstance(user_input, str) else ""

user_input is typed str | list[ContentPart]. Input submitted from the shell UI is structured content (list[ContentPart]), not a plain str, so it hit the else branch and became an empty string.

Fix

Add user_input_to_text() in kimi_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-str path is unchanged.

Tests

Added unit tests in tests/utils/test_message_utils.py covering user_input_to_text for: plain string, structured TextParts, mixed text/non-text parts, and empty input.

uv run pytest tests/utils/test_message_utils.py tests/hooks/ → 49 passed. ruff format/check clean.


Open in Devin Review

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

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no bugs or issues to report.

Open in Devin Review

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

UserPromptSubmit hook receives empty prompt when input comes from shell UI

1 participant