Skip to content

fix(inject-context): stop dumping Kimi rules corpus and AGENTS.md into terminal - #96

Merged
fusengine merged 2 commits into
mainfrom
fix/kimi-model-only-channel
Jul 30, 2026
Merged

fix(inject-context): stop dumping Kimi rules corpus and AGENTS.md into terminal#96
fusengine merged 2 commits into
mainfrom
fix/kimi-model-only-channel

Conversation

@fusengine

Copy link
Copy Markdown
Owner

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.md were dumped into the terminal on every single prompt. This doesn't happen on Claude Code, where systemMessage and additionalContext are two separate channels.

Why it's redundant

Kimi already loads <kimiHome>/AGENTS.md natively 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. SessionStart and SubagentStart always 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|dev and |plain); every claude-code/codex/gemini-cli cell, every lessons cell, and every SessionStart/SubagentStart cell is byte-identical. Verified by recapturing the baseline from a detached worktree on HEAD and diffing key by key.

The golden is compared with toEqual against a committed JSON, deliberately not toMatchSnapshot() (which --update-snapshots would regenerate even in CI), and its falsifiability was checked by mutation (mutate a cell -> expect failure -> restore -> expect pass again).

Commits

  • daec4a1 test(inform-matrix): add characterization witness for context-injection matrix (golden, captured before the fix)
  • 01d2556 fix(inject-context): stop dumping rules corpus and root AGENTS.md to Kimi terminal

Test plan

  • bun test: 1021 pass / 1 skip / 0 fail (186 files)
  • tsc --noEmit clean
  • CI green

…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.
@fusengine
fusengine merged commit 934aa5e into main Jul 30, 2026
1 check passed
@fusengine
fusengine deleted the fix/kimi-model-only-channel branch July 30, 2026 19:46
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