fix(inject-context): stop dumping Kimi rules corpus and AGENTS.md into terminal - #96
Merged
Conversation
…on matrix Captures renderInform() output across 3 context emitters x 4 harnesses x 3 lifecycle events (32 cells) into a golden fixture, compared with toEqual (never toMatchSnapshot, which --update-snapshots would silently regenerate even in CI). Capture runs in a hermetic child process with a whitelisted env (explicit PATH/HOME/etc, never process.env spread) so the golden is independent of the calling harness/session. This witness lands before any behavior change: on this commit alone (src/ still at HEAD), the characterization test passes, proving the golden is a genuine pre-fix baseline and not a snapshot adjusted to match new code.
…Kimi terminal Kimi Code CLI has no model-only output channel: a hook's stdout is delivered to both the model AND the terminal. Before this fix, promptSubmit injection for the kimi harness pushed the full rules corpus plus the project root AGENTS.md through that shared channel on every prompt, spilling it into the user's terminal. The rules corpus is already loaded natively by Kimi from <kimiHome>/AGENTS.md, so inject-rules.ts now skips re-injecting it for kimi at UserPromptSubmit specifically, via the new kimi-rules-native helper. SessionStart and SubagentStart are untouched and still receive the full corpus, since those events don't have a native-load equivalent. Fail-safe preserved: if the native AGENTS.md fences are absent for any reason, the full corpus is injected as before — never a silent loss of rules, only a redundant re-injection avoided when we know Kimi already has it.
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.
Problem
Kimi Code CLI has no model-only channel for hooks. On exit 0, stdout goes both into the model's context AND is printed raw to the user's terminal. Result: the ~18 KB rules corpus plus the entire root
AGENTS.mdwere dumped into the terminal on every single prompt. This doesn't happen on Claude Code, wheresystemMessageandadditionalContextare two separate channels.Why it's redundant
Kimi already loads
<kimiHome>/AGENTS.mdnatively at session start, and the rules corpus is merged into it between<!-- fusengine:kimi-rules:start/end -->fences by the installer. Re-injecting the full corpus on every prompt was pure duplication of what Kimi had already loaded.Fail-safe
Missing fences, missing file, or a read error all fall back to the full corpus. Worst case is a verbose terminal, never lost rules.
SessionStartandSubagentStartalways keep the full corpus regardless.Non-regression proof
A characterization golden (32 cells = 3 emitters x 4 harnesses x 3 events) was captured BEFORE the fix, in a separate, earlier commit (
daec4a1). After the fix, exactly 2 cells change (promptSubmit|kimi|UserPromptSubmit|devand|plain); everyclaude-code/codex/gemini-clicell, everylessonscell, and everySessionStart/SubagentStartcell is byte-identical. Verified by recapturing the baseline from a detached worktree onHEADand diffing key by key.The golden is compared with
toEqualagainst a committed JSON, deliberately nottoMatchSnapshot()(which--update-snapshotswould regenerate even in CI), and its falsifiability was checked by mutation (mutate a cell -> expect failure -> restore -> expect pass again).Commits
daec4a1test(inform-matrix): add characterization witness for context-injection matrix (golden, captured before the fix)01d2556fix(inject-context): stop dumping rules corpus and root AGENTS.md to Kimi terminalTest plan
bun test: 1021 pass / 1 skip / 0 fail (186 files)tsc --noEmitclean