Skip to content

feat(hook): include response and stop_reason in Stop hook payload#2308

Open
AkaCoder404 wants to merge 4 commits into
MoonshotAI:mainfrom
AkaCoder404:feat/hook-stop-response
Open

feat(hook): include response and stop_reason in Stop hook payload#2308
AkaCoder404 wants to merge 4 commits into
MoonshotAI:mainfrom
AkaCoder404:feat/hook-stop-response

Conversation

@AkaCoder404
Copy link
Copy Markdown

Related Issue

Resolve #2307

Description

This PR enhances the Stop hook payload with the agent's response text and stop reason, enabling post-turn auditing, conditional approval, and analytics.

Changes

1. src/kimi_cli/hooks/events.py

  • Added response (default "") and stop_reason (default "") parameters to events.stop()

2. src/kimi_cli/soul/kimisoul.py

  • Captures the TurnOutcome returned by _turn()
  • Extracts natural-language text from turn_outcome.final_message when available
  • Passes response and stop_reason into the Stop hook payload
  • Initializes turn_outcome = None for slash-command and Ralph-loop paths so the hook still fires safely

3. tests/core/test_kimisoul_hooks.py

  • Added test_stop_hook_includes_response_and_stop_reason verifying the payload receives "The fix is complete." and "no_tool_calls" from a mocked TurnOutcome

4. Documentation

  • Updated docs/en/customization/hooks.md and docs/zh/customization/hooks.md to list the new response and stop_reason fields in the Stop row

New payload shape

{
  "hook_event_name": "Stop",
  "session_id": "abc123",
  "cwd": "/path/to/project",
  "stop_hook_active": false,
  "stop_reason": "no_tool_calls",
  "response": "The fix is complete. I updated src/main.py..."
}
  • stop_reason is "no_tool_calls" when the agent spoke naturally, or "tool_rejected" when a tool call was rejected
  • response is empty when the turn produced no natural-language output (e.g. pure tool rejection)

Backwards compatibility

The new fields are optional and default to empty strings. Existing hooks that do not read them continue to work unchanged.

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 11:21
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: c1a10da9aa

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread src/kimi_cli/soul/kimisoul.py
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

Enhances the Stop lifecycle hook payload with two new fields—response (the assistant's final natural-language text) and stop_reason ("no_tool_calls" / "tool_rejected")—so hook scripts can audit, gate, or analyze each turn's outcome. Both fields default to empty strings to preserve backward compatibility with existing hooks.

Changes:

  • events.stop() accepts and emits new optional response and stop_reason fields.
  • KimiSoul.run() captures the TurnOutcome from _turn() and forwards final_message text plus stop_reason into the Stop hook payload (empty for slash-command and Ralph-loop paths).
  • Adds a new test for the Stop hook payload and updates EN/ZH hook docs and changelogs.

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
src/kimi_cli/hooks/events.py Adds response and stop_reason keyword args to stop() payload builder.
src/kimi_cli/soul/kimisoul.py Captures TurnOutcome from _turn() and threads response/stop_reason into Stop hook trigger.
tests/core/test_kimisoul_hooks.py New test verifying Stop payload contains response and stop_reason.
docs/en/customization/hooks.md Lists new response/stop_reason fields in Stop row.
docs/zh/customization/hooks.md Localized doc update mirroring EN.
CHANGELOG.md Adds Unreleased entry describing the new payload fields.
docs/en/release-notes/changelog.md Synced English changelog entry.
docs/zh/release-notes/changelog.md Synced Chinese changelog entry.

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

Comment thread src/kimi_cli/soul/kimisoul.py
Comment thread docs/en/customization/hooks.md
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 18b3e0eb1a

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread src/kimi_cli/soul/kimisoul.py
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.

feat(hook): include LLM response and stop reason in Stop hook payload

2 participants