MoonshotAI / MoonshotAI/kimi-code
fix(hooks): raw hook JSON rendered to terminal when hook output has no message field
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 7.5k
- Forks
- 1.2k
- Avg merge
- 11h 53m
- Merged PRs (30d)
- 350
Description
Environment
- kimi-code 0.40.1, Windows 11 (also reproducible cross-platform)
Problem
When a UserPromptSubmit hook prints a JSON object that contains only non-message fields (or is empty), the TUI falls back to rendering the raw stdout JSON as a chat message. The user sees the raw JSON blob in the transcript.
Repro
- Register a
UserPromptSubmithook that prints{}(or JSON without amessagefield). - Send any prompt — the raw JSON appears on screen.
Analysis
Both engine generations (v1 and v2) share the same fallback: when structured-output parsing yields no message, stdout is treated as plain text and injected/rendered verbatim. Hooks that legitimately produce structured-only output cannot avoid leaking JSON to the screen.
Fix
When hook output parses as structured JSON, suppress the plain-stdout fallback. Fixed in both pipelines in our local build; happy to open a PR.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start at UserPromptSubmit handling in both the v1 and v2 hook pipelines, then trace the structured-output parsing and plain-stdout fallback. Add regression coverage for empty or message-less JSON and verify that structured JSON is not rendered as a chat message while outputs containing a message still appear correctly.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- cli
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 68/100