feat(kimi): full Kimi Code CLI hook support (PreToolUse deny, Stop, subagent briefing)#246
Merged
Conversation
… subagent briefing Kimi Code CLI support was UserPromptSubmit plus a read-tool nudge only. Bring it to parity with the Claude/Codex adapters so weaker-instruction-following models get the full deterministic hook loop: - PreToolUse now routes native Read/Grep/Glob/Bash through the shared enrich machinery: a hard permissionDecision:"deny" for an indexed whole-file read, soft plain-stdout guidance otherwise, while keeping the historical read_file/get_editing_context compress-bodies nudge. - Stop runs the post-turn diagnostics (changed symbols -> test targets, guards, dead code, coverage, contracts) and appends them so the agent self-corrects before handoff. - SubagentStart briefs a spawned subagent with smart_context results and the tool-swap table so it doesn't default to raw Read/Grep. A hard block uses the one JSON shape Kimi documents (hookSpecificOutput.permissionDecision); everything else rides Kimi's plain-stdout context channel. Every path stays gated to Gortex-enabled projects and degrades to a silent no-op when the payload is malformed, the cwd is outside a project, or the daemon is unreachable. The Stop/subagent diagnostics reach a normally-running daemon over its unix socket: callServerTool now falls back from the by-default-unserved HTTP port to the AF_UNIX socket, scoped to the hook cwd and gated on a recorded cwd so the pure-HTTP unit tests are unaffected and non-Kimi agents keep their current behavior. Closes #214
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.
Closes #214.
Kimi Code CLI support was previously UserPromptSubmit + a read-tool nudge only. This brings it to parity with the Claude Code and Codex adapters, so weaker-instruction-following models get the full deterministic hook loop the issue asks for: context injection, tool redirection, and post-turn correction.
What's added
UserPromptSubmitPreToolUseRead/Grep/Glob/Bashrun through the shared enrich machinery: a harddenyfor an indexed whole-file read, soft plain-stdout guidance otherwise; keeps theread_file/get_editing_contextcompress-bodies nudge.StopSubagentStartsmart_contextresults and the tool-swap table so it doesn't default to rawRead/Grep.Wire protocol
Kimi cloned Claude Code's hook schema, so a hard block uses the one JSON shape Kimi documents —
hookSpecificOutput.permissionDecision = "deny"— and all soft guidance rides Kimi's plain-stdout context channel (matching the established Kimi contract). Every path stays gated to Gortex-enabled projects and degrades to a silent no-op when the payload is malformed, the cwd is outside a project, or the daemon is unreachable — so normal Kimi flow is never blocked by the integration.Transport fix (why the Stop path is non-vacuous)
callServerTool(used by the Stop and subagent diagnostics) only spoke the HTTP:8765surface, which the daemon serves only under--http-addr— so it was dead by default. It now falls back to the daemon's AF_UNIX socket, scoped to the hook cwd. The fallback is gated on a recorded cwd, so the pure-HTTP unit tests are unaffected and non-Kimi agents keep their current behavior.Not included
SubagentStopis intentionally left out — theStophook already covers end-of-turn diagnostics, and a per-subagent variant would mostly add noise. Easy to add later if it proves useful.Verification
go build ./...,go vet,gofmt,golangci-lint— all clean.go test -race ./internal/hooks/... ./internal/agents/...— 527 pass (new tests cover the native-tool deny JSON, soft-stdout guidance, Stop diagnostics, subagent briefing + fallback, project gating, and the transport fallback gating).go test ./cmd/gortex/ -run 'AgentRender|Hook|Kimi|Install|Init'— 29 pass.docs/agents.mdadapter matrix + per-agent### kiminote added.