Skip to content

fix(hook): fix UserPromptSubmit payload to capture input text instead of empty string#2305

Open
AkaCoder404 wants to merge 2 commits into
MoonshotAI:mainfrom
AkaCoder404:fix/hook-userpromptsubmit-payload
Open

fix(hook): fix UserPromptSubmit payload to capture input text instead of empty string#2305
AkaCoder404 wants to merge 2 commits into
MoonshotAI:mainfrom
AkaCoder404:fix/hook-userpromptsubmit-payload

Conversation

@AkaCoder404
Copy link
Copy Markdown

@AkaCoder404 AkaCoder404 commented May 15, 2026

Related Issue

Resolve #2303 #1779

Description

Fixes the UserPromptSubmit hook payload so that the prompt field contains the actual user input text instead of an empty string.

Problem:
The shell UI passes user input as list[ContentPart] to soul.run(). The existing code only checked isinstance(user_input, str), causing text_input_for_hook to always fall back to "". As a result:

  • The prompt field in the UserPromptSubmit hook payload was always empty.
  • Regex-based matcher filters on prompt text never matched.

Fix:
When user_input is not a string, extract the text from the ContentPart list using the same Message.extract_text() approach already used by the agent turn loop:

if isinstance(user_input, str):
    text_input_for_hook = user_input
else:
    user_message = Message(role="user", content=user_input)
    text_input_for_hook = user_message.extract_text(" ").strip()

This ensures plain-text input (and any text extractable from multimodal input) is correctly passed to the hook engine for both payload generation and matcher evaluation. As a result, the payload.prompt can contain the message sent by the user (or adjusted message when SubagentStart is called).

Checklist

  • I have read the CONTRIBUTING document.
  • I have linked the related issue, if any.
  • I have added tests that prove my fix is effective or that my feature works.
  • I have run make gen-changelog to update the changelog.

Copilot AI review requested due to automatic review settings May 15, 2026 09:47
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Fixes the UserPromptSubmit hook payload so hooks and matchers receive the actual user-entered prompt text when the shell UI passes input as list[ContentPart] instead of a plain string (resolves #2303).

Changes:

  • Extract hook prompt / matcher_value from non-string user_input via Message.extract_text(...) in KimiSoul.run().
  • Add a regression test ensuring UserPromptSubmit receives "hello world" when input is provided as content parts.
  • Document the fix in the unreleased changelog entries.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated no comments.

Show a summary per file
File Description
src/kimi_cli/soul/kimisoul.py Ensures UserPromptSubmit hook uses extracted text for non-string user_input instead of always "".
tests/core/test_kimisoul_hooks.py Adds coverage for content-part input so the hook payload prompt is populated correctly.
CHANGELOG.md Adds an Unreleased entry describing the hook payload fix.
docs/en/release-notes/changelog.md Mirrors the Unreleased changelog note in the English docs.
docs/zh/release-notes/changelog.md Mirrors the Unreleased changelog note in the Chinese docs.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@AkaCoder404 AkaCoder404 changed the title FIX(HOOK) Fix UserPromptSubmit Payload to Capture Input Text instead of Empty String fix(hook) Fix UserPromptSubmit Payload to Capture Input Text instead of Empty String May 15, 2026
@AkaCoder404 AkaCoder404 changed the title fix(hook) Fix UserPromptSubmit Payload to Capture Input Text instead of Empty String fix(hook): fix UserPromptSubmit payload to capture input text instead of empty string May 15, 2026
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

2 participants