Skip to content

fix: re-own Kimi turn-end hook after config rewrite - #1176

Open
august-agent wants to merge 5 commits into
kunchenguid:mainfrom
august-agent:fix/kimi-turnend-reown
Open

fix: re-own Kimi turn-end hook after config rewrite#1176
august-agent wants to merge 5 commits into
kunchenguid:mainfrom
august-agent:fix/kimi-turnend-reown

Conversation

@august-agent

@august-agent august-agent commented Jul 28, 2026

Copy link
Copy Markdown

Intent

Fix #1064: Kimi crew turn-end wakes must keep working after the Kimi CLI rewrites ~/.kimi-code/config.toml and strips the comments that marked Firstmate's hook region. The installer must structurally re-identify and re-mark only an exact Firstmate-owned hook table, while refusing foreign or ambiguous hook configuration without modifying it.

What Changed

  • Re-identify an exact unmarked Firstmate Kimi hook after comment-stripping config rewrites, then re-mark it in place without creating duplicates.
  • Preserve fail-closed handling for modified, duplicated, inline, or foreign hook tables.
  • Add colocated regression coverage for re-ownership, idempotence, removal, and foreign-hook refusal.
  • Make docs/turnend-guard.md the single owner of the Kimi installer's prerequisites and config-edit/removal contract, with docs/configuration.md pointing to it.
  • Make the teardown conformance fixture accept either a historical permissive baseline selector or an already-hardened exact baseline selector, while still requiring the current implementation's exact tmux selector.

Risk Assessment

Low. The hook recovery path requires a type-strict exact structural match and validates the candidate span by reparsing the config after excision. Ambiguous or captain-owned entries remain untouched and are refused. The fixture-only CI correction changes no production behavior.

Testing

  • bash tests/fm-backend.test.sh
  • env PATH="/opt/homebrew/opt/python@3.12/libexec/bin:$PATH" bash tests/fm-kimi-harness.test.sh
  • bin/fm-lint.sh
  • bin/fm-doc-audience-check.sh
  • git diff --check

Fixes #1064

The Kimi CLI rewrites ~/.kimi-code/config.toml and strips comments, which
removes the marker comments delimiting Firstmate's hook region. On the next
install the region was no longer recognizable, so the installer either refused
or appended a duplicate hook entry, and Kimi crew turn-end wakes stopped.

The installer now re-identifies an unmarked region structurally: when the
config holds a single hook table that matches Firstmate's own entry exactly, it
re-owns and re-marks that table in place instead of refusing or duplicating.
Any hook table Firstmate does not own is still refused, so a captain's own hook
configuration is never claimed or rewritten.

tests/fm-kimi-harness.test.sh covers the comment-stripping rewrite path
alongside the existing format-preservation, idempotence, refusal, token-guard,
spawn-registration, and teardown cases. docs/turnend-guard.md records the
re-ownership behavior and docs/configuration.md points at it as the single
owner of the installer's config-edit contract.

Fixes kunchenguid#1064
@august-agent
august-agent force-pushed the fix/kimi-turnend-reown branch from b90cf1b to 62c81c8 Compare July 28, 2026 17:49
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.

kimi turn-end hook markers are TOML comments and do not survive Kimi CLI config rewrites

1 participant