Skip to content

feat(hooks): add inject_prompt for simplified context injection#1683

Open
Dqz00116 wants to merge 6 commits intoMoonshotAI:feat/hooksfrom
Dqz00116:feat/hook-inject-prompt
Open

feat(hooks): add inject_prompt for simplified context injection#1683
Dqz00116 wants to merge 6 commits intoMoonshotAI:feat/hooksfrom
Dqz00116:feat/hook-inject-prompt

Conversation

@Dqz00116
Copy link
Copy Markdown

@Dqz00116 Dqz00116 commented Mar 31, 2026

Related Issue

N/A - This is a new feature proposal for simplifying context injection in hooks.

Description

This PR adds a simplified way to inject context into conversations via the UserPromptSubmit hook.

Changes

  1. Added inject_prompt field to HookDef (src/kimi_cli/hooks/config.py)

    • Alternative to command for simple static content injection
    • Supports both inline text and file paths (auto-detected)
    • command and inject_prompt are mutually exclusive
  2. Added additional_context support (src/kimi_cli/hooks/runner.py, src/kimi_cli/hooks/engine.py)

    • New field in HookResult to carry context from hooks
    • Parsed from hookSpecificOutput.additionalContext in JSON responses
    • Native support for inject_prompt without spawning subprocess
  3. Context injection in KimiSoul (src/kimi_cli/soul/kimisoul.py)

    • Collects additional_context from all hook results
    • Injects as system reminder message before user input processing
  4. Documentation (docs/en/customization/hooks.md)

    • Documented inject_prompt field and usage examples
    • Documented additionalContext JSON output
  5. Tests (tests/hooks/)

    • Added tests for inject_prompt validation
    • Added tests for additional_context parsing
    • Added integration tests for file-based injection

Usage Example

Static content:

[[hooks]]
event = "UserPromptSubmit"
inject_prompt = "Always write tests first."

From file:
[[hooks]]
event = "UserPromptSubmit"
inject_prompt = "~/.kimi/prompts/coding-guidelines.md"

Checklist

  • I have read the https://github.com/MoonshotAI/kimi-cli/blob/main/CONTRIBUTING.md 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.
  • I have run make gen-docs to update the user documentation.

Open with Devin

- Add inject_prompt field as alternative to command
- Add validator to ensure command and inject_prompt are mutually exclusive
- Add tests for inject_prompt validation
- Add additional_context field to HookResult
- Parse additionalContext from hookSpecificOutput in JSON response
- Add _run_inject_prompt_hook and _resolve_inject_prompt methods to HookEngine
- Support file path auto-detection and content reading
- Add tests for additional_context parsing and injection
- Collect additional_context from hook results in KimiSoul.run()
- Inject collected context as system reminder message before processing user input
- Document inject_prompt field as alternative to command
- Add inject_prompt usage examples
- Document additionalContext JSON output for dynamic injection
- Update config-files documentation
- Update hooks documentation (zh)
devin-ai-integration[bot]

This comment was marked as resolved.

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.

1 participant