fix(kimi): install Kimi turn-end hook without stdlib tomllib - #15
Merged
Merged
Conversation
Stock macOS python3 3.9 lacks stdlib tomllib, so hook install refused a valid config.toml. Prefer tomllib and fall back to a bundled tomli 2.2.1 reader so the installer can still validate without serializing captain config.
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.
Intent
fm-kimi-harness test 'Kimi hook install refused a realistic config' fails on base. This is a pre-existing base-branch failure, not caused by a recent change. Reproduce that exact test first and capture the real failure. The title names a realistic-config hook-install refusal; find out whether Kimi's actual behaviour changed, the test's fixture is stale, or the assertion was always wrong. If Kimi's own behaviour moved, verify against the currently installed Kimi rather than assuming the test is right. Reproduce the defect in the way an operator hits it before writing the fix. That reproduction is the regression test: it must FAIL before the change and PASS after. If it passes before, stop rather than shipping a fix that proves nothing. Verify against the real tool where possible, not only a hand-written fixture, and record what was verified against.
Accepted findings from reproduction: the named test failed because stock macOS /usr/bin/python3 is 3.9.6 and has no stdlib tomllib, so fm-kimi-turnend-hook.sh install refused before parsing. The realistic fixture is valid TOML (parses on CPython 3.12.13; install succeeds when that interpreter is python3). Installed kimi 1.49.0 is Moonshot kimi-cli (default ~/.kimi/config.toml) and is not the kimi-code ~/.kimi-code/config.toml surface this installer edits, so Kimi's own hook schema was not the refusal cause. The accepted fix is: keep validating without serializing captain TOML; use stdlib tomllib when present and otherwise the bundled tomli 2.2.1 reader in bin/fm_toml so stock python3 3.9 can install. Do not skip the test, and do not change the realistic fixture to paper over the refusal.
What Changed
bin/fm-kimi-turnend-hook.shnow falls back to a bundled pure-Python TOML reader (bin/fm_toml) for config validation when the activepython3lacks stdlibtomllib, instead of refusing to install; it resolves the hook's own directory and adds it tosys.pathfor the fallback import.bin/fm_toml(__init__.py,_parser.py,_re.py,_types.py), a vendored TOML parser used only for validation - the installer still never serializes the captain's TOML.docs/configuration.mdanddocs/turnend-guard.mdto describe thetomllib-or-fm_tomlvalidation path, and updatestests/fm-kimi-harness.test.sh(including a newtest_kimi_hook_install_works_without_stdlib_tomllibcase) to cover installing with stdlibtomllibhidden.Risk Assessment
✅ Low: The change is a well-scoped fallback-import fix (stdlib tomllib -> vendored fm_toml/tomli 2.2.1) with a HOOK_DIR resolved via the script's own invocation path (always invoked as $FM_ROOT/bin/fm-kimi-turnend-hook.sh, never symlinked), a deterministic regression test that hides tomllib via PYTHONPATH shadowing to reproduce the failure independent of the CI interpreter's version, no changes to the realistic fixture or any skipped tests, and no unsafe code in the vendored parser.
Testing
Reproduced the named test's exact pre-existing base-branch failure in this environment (real stock python3 3.9.6, no tomllib), confirmed it fails on base and passes on target both via the automated test suite and via manual operator-level install runs against the realistic fixture, and cross-checked against the actually installed Kimi CLI to confirm the refusal was a TOML-parsing gap rather than a Kimi behavior change; all evidence supports the accepted fix and no issues were found.
Evidence: Base commit (f991512) reproduction: test fails with stock python3.9, no tomllib
Evidence: Target commit (45cfa0d) full kimi-harness suite passing with same stock python3.9
Evidence: Manual operator repro on base: install refused with realistic config + stock python3
Evidence: Manual operator repro on target: install succeeds, shows resulting config.toml with Firstmate hook region installed and captain bytes preserved
Pipeline
Updates from git push no-mistakes
✅ **intent** - passed
✅ No issues found.
✅ **Rebase** - passed
✅ No issues found.
✅ **Review** - passed
✅ No issues found.
✅ **Test** - passed
✅ No issues found.
bash tests/fm-kimi-harness.test.sh (base commit f991512d865f73f10c78bb934f166f83aa27b1f7, isolated worktree) — reproduced failure: 'not ok - Kimi hook install refused a realistic config'bash tests/fm-kimi-harness.test.sh (target commit 45cfa0d7f2e4d774503a8e4325b6521075f852b0, this worktree) — full suite passes, including new test_kimi_hook_install_works_without_stdlib_tomllibManual: HOME=<tmp> bin/fm-kimi-turnend-hook.sh install against the realistic fixture config with stock /usr/bin/python3 3.9.6 on base commit — refused, no config writeManual: HOME=<tmp> bin/fm-kimi-turnend-hook.sh install against the same fixture with the same stock python3 on target commit — succeeded, wrote guarded Firstmate hook region, captain config bytes untouchedwhich -a python3 / python3 --version / python3 -c 'import tomllib' — confirmed environment's python3 is stock 3.9.6 without tomllib, matching the intent's accepted findingskimi --version / ls ~/.kimi ~/.kimi-code — confirmed installed Kimi is Moonshot kimi-cli 1.49.0 using ~/.kimi, distinct from the ~/.kimi-code surface this installer edits✅ **Document** - passed
✅ No issues found.
✅ **Lint** - passed
✅ No issues found.
✅ **Push** - passed
✅ No issues found.