feat(hooks): support updatedInput for transparent command rewriting#1935
Closed
zoorpha wants to merge 2 commits intoMoonshotAI:mainfrom
Closed
feat(hooks): support updatedInput for transparent command rewriting#1935zoorpha wants to merge 2 commits intoMoonshotAI:mainfrom
zoorpha wants to merge 2 commits intoMoonshotAI:mainfrom
Conversation
Author
|
Thanks for the automated review. We've addressed the issues identified:
All tests and checks pass. Resolving this review. |
Author
|
we already created another PR for the rtk tool |
|
great to have this feature |
Allow PreToolUse hooks to rewrite tool input via hookSpecificOutput.updatedInput. This enables integrations like RTK that transparently rewrite commands (e.g. 'git status' -> 'rtk git status') without blocking and retrying. Changes: - HookResult: add updated_input field - run_hook: parse updatedInput from hookSpecificOutput JSON - toolset: apply updated_input to tool arguments before execution - tests: add coverage for updated_input parsing and deny precedence
- Add isinstance guard before accepting updatedInput to prevent TypeError - Document updatedInput transparent rewrite in EN and ZH hooks guides - Add test coverage for invalid updatedInput values (null, string, list) - Include CHANGELOG entries for the feature
7adb3d7 to
38099b7
Compare
|
seems like we cant help kimi improvements |
Author
|
I'll close the ticket |
This was referenced Apr 29, 2026
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.
Related Issue
N/A — This is a small feature addition (34 lines) that enables transparent command rewriting via PreToolUse hooks, aligning with the existing hooks Beta documentation.
Description
This PR adds support for
hookSpecificOutput.updatedInputin the PreToolUse hook lifecycle, enabling hooks to transparently rewrite tool arguments without blocking and requiring a retry.Motivation
The current Kimi CLI hook system supports two actions from a PreToolUse hook:
allow— execute the tool as-isblock— prevent execution and return an error to the LLMThis works well for guardrails (e.g. "don't rm -rf /"), but is insufficient for integrations like RTK that want to rewrite commands for token optimization (e.g.
git status→rtk git status) without forcing the LLM to retry.With this change, a hook can output:
{ "hookSpecificOutput": { "updatedInput": { "command": "rtk git status" } } }And Kimi will execute the tool with the rewritten arguments, transparently to the LLM.
Changes
src/kimi_cli/hooks/runner.pyupdated_input: dict[str, Any] | None = NonetoHookResultrun_hook()to parsehookSpecificOutput.updatedInputfrom JSON stdoutupdatedInputsrc/kimi_cli/soul/toolset.pyupdated_input, merge it into the tool arguments dict beforetool.call(arguments)isinstance(arguments, dict)to ensure type safetytests/hooks/test_runner.pytest_json_updated_input_parsing— verifiesupdatedInputis parsed intoHookResult.updated_inputtest_json_deny_takes_precedence_over_updated_input— verifiespermissionDecision: denystill blocks even whenupdatedInputis presentBackward Compatibility
updatedInputbehave exactly as before.Use Case: RTK Integration
RTK (Rust Token Killer) is a CLI proxy that reduces LLM token consumption by 60–90% on common commands. With this PR + the RTK PR #1391, Kimi users can:
And have all
Shelltool calls transparently rewritten to their RTK equivalents.Testing
All 8 tests pass, including the 2 new ones:
The full hooks test suite (36 tests) also passes:
Checklist
make gen-changelogto update the changelog. (Command timed out in this environment)make gen-docsto update the user documentation. (Command timed out in this environment)