Skip to content

feat: add Kimi crewmate harness adapter - #717

Closed
raywest wants to merge 11 commits into
kunchenguid:mainfrom
raywest:fm/kimi-adapter-v1
Closed

raywest wants to merge 11 commits into
kunchenguid:mainfrom
raywest:fm/kimi-adapter-v1

Conversation

@raywest

@raywest raywest commented Jul 19, 2026 •

Copy link
Copy Markdown

Intent

The developer wanted to fix failure handling so metadata is not written after a redirection error. They also wanted to correct the replacement-watcher test’s malformed assertion and confirm the targeted tests pass.

What Changed

  • Add kimi-code as a verified tmux-only crewmate/scout harness, including model selection, process detection, dispatch validation, and post-launch brief delivery.
  • Install a token-guarded Kimi Stop hook with validated, lock-protected config updates; clean its task artifacts during teardown and harden pointer and failure-recovery handling.
  • Update tmux busy detection and bootstrap liveness rules for Kimi, expand Kimi/Grok regression coverage, and increase the behavior-test timeout for the larger suite.

Risk Assessment

✅ Low: The prior Kimi pointer/home and Grok recovery issues are addressed; the current recovery metadata path is bounded and consistent with teardown.

Testing

Completed 1 recorded test check.

  • Outcome: ⚠️ 1 error across 1 run (24m18s)

Pipeline

Updates from git push no-mistakes

✅ **intent** - passed

✅ No issues found.

✅ **Rebase** - passed

✅ No issues found.

🔧 **Review** - 2 issues found → auto-fixed (2) ✅
  • 🚨 bin/fm-spawn.sh:1513 - The token pointer is written by shell redirection to a worktree-controlled name, which follows a pre-existing symlink. A repository containing .fm-kimi-turnend -> /some/file can cause a Kimi spawn to overwrite that target before the worker starts. Write to an adjacent temporary file and rename it over the pointer (or otherwise refuse symlinks).
  • ⚠️ bin/fm-spawn.sh:562 - KIMI_CODE_HOME is preserved verbatim when the pane is launched. A relative value is resolved relative to fm-spawn's cwd while setup runs, but relative to the task worktree inside tmux, so Kimi loads a different config and misses the installed hook; teardown can likewise miss its registry. Canonicalize it to an absolute path before setup, metadata, and launch injection.

🔧 Fix: Captain: harden Kimi pointer and home paths
1 warning still open:

  • ⚠️ bin/fm-spawn.sh:1452 - The new safe-pointer refusal occurs after Grok has created its registry file and state token, but before its normal metadata write. The EXIT trap does not persist recovery metadata for tmux, so a symlink/directory refusal leaves an orphaned window/worktree and token that fm-teardown cannot discover. Write recovery metadata before this call (as Kimi already does), or explicitly roll back the Grok resources on failure.

🔧 Fix: Captain: preserve Grok pointer-refusal recovery metadata
✅ Re-checked - no issues remain.

⚠️ **Test** - 1 error
  • 🚨 tests failed with exit code 1
  • command -v tmux >/dev/null || { echo "tmux is required for e2e tests" >&2; exit 1; }; tmux -V; rc=0; for t in tests/*.test.sh; do echo "== $t =="; bash "$t" || rc=1; done; exit "$rc"
✅ **Document** - passed

✅ No issues found.

✅ **Lint** - passed

✅ No issues found.

✅ **Push** - passed

✅ No issues found.

@raywest
raywest force-pushed the fm/kimi-adapter-v1 branch 2 times, most recently from b57b67a to 34168ee Compare July 21, 2026 18:09
@raywest raywest changed the title feat(harness): add kimi-code crewmate adapter feat: add Kimi Code crewmate harness support Jul 21, 2026
@raywest
raywest force-pushed the fm/kimi-adapter-v1 branch from 34168ee to 6ea74dd Compare July 21, 2026 18:12
@raywest

raywest commented Jul 21, 2026

Copy link
Copy Markdown
Author

Heads up on CI for this update: the "Behavior tests" job on attempt 2 hit its 15-minute job timeout partway through the suite (right after the watcher-lock tests) and was cancelled — not a real failure. The other four checks (lint, repo invariants, macOS Bash snapshot compatibility, and the no-mistakes provenance check) all passed, and the full suite passes locally on my end.

Could you rerun the cancelled job when convenient? It got through nearly the entire suite before the cap, so a rerun should have a good shot at finishing in time.

Separately: this PR added a couple of Kimi-adapter regression tests, and I noticed the suite (particularly the watcher-lock/watch-triage coverage) is running noticeably closer to the 15-minute budget than it used to. Happy to follow up with a CI-time optimization (e.g. splitting the job or trimming slow paths) if suite duration on your runners becomes a recurring concern.

@raywest
raywest force-pushed the fm/kimi-adapter-v1 branch from 6ea74dd to bad1a26 Compare July 21, 2026 20:27
@raywest raywest changed the title feat: add Kimi Code crewmate harness support feat: add Kimi crewmate harness support Jul 21, 2026
@raywest raywest changed the title feat: add Kimi crewmate harness support feat: add Kimi crewmate harness adapter Jul 22, 2026
raywest added 11 commits July 22, 2026 00:06
Rebased onto current upstream main (f9a89c3) to resolve the merge
conflicts in bin/fm-spawn.sh's spawn_abort_cleanup between the Kimi
config lock/snapshot cleanup and upstream's newer Herdr presentation
order lock cleanup - both cleanup steps are preserved.

Also restores the executable bit on tests/fm-kimi-harness.test.sh,
lost during a prior catch-up merge (content was unchanged; CI's
direct-exec test runner requires it, matching every other test file
in tests/).
The review step's re-examination of the full branch diff found that a raw
kimi launch bypasses the tmux-only backend gate entirely (raw launches were
only exempt from the secondmate-scope check, not intended to bypass the
backend-delivery gate too), reaching deliver_kimi_brief's unconditional
tmux load-buffer/paste-buffer calls on any backend.

Per the captain's decision: implement the real fix rather than defer or
refuse the PR. Split the kimi launch gates into two independent checks -
secondmate scope (template-only, unchanged, raw stays exempt per the
existing kimi-raw-scope-bypass decision) and brief-delivery backend
capability (now applies to both template and raw launches).

Empirically verified in an isolated herdr lab session (no fleet/production
sessions touched) that herdr's pane send-text has no atomic multi-line
paste primitive: like tmux's plain, non-bracketed send-keys -l, it executes
per embedded newline as it arrives instead of holding the text unsubmitted,
so it is not a safe drop-in for the shared fm_backend_send_text_submit
primitive here. This is a real capability gap, not a wiring gap - tmux's
bracketed paste (load-buffer + paste-buffer -p -d) remains the only
verified-safe delivery mechanism, so deliver_kimi_brief keeps calling it
directly rather than routing through the generic shared primitive, while
its composer-readiness wait now goes through the shared, backend-abstracted
fm_backend_composer_state (also used by fm-send.sh and the away-mode
daemon) instead of a direct tmux-only call.

Extends the two affected tests (kimi spawn on a non-tmux backend, raw kimi
scope exemption) to assert the corrected behavior, and updates the
harness-adapters skill's kimi section with the dated empirical finding.
@raywest
raywest force-pushed the fm/kimi-adapter-v1 branch from b2060b1 to 1fb9a64 Compare July 22, 2026 04:07
@kunchenguid

kunchenguid commented Jul 23, 2026 •

Copy link
Copy Markdown
Owner

Automated reminder: thanks for the PR! This branch currently has a merge conflict with the base branch.

When you get a chance, please rebase onto (or merge) the latest base branch, resolve the conflict, and push. After that, checks will re-run and the PR will get looked at again.

Noted for firstmate#717 at 1fb9a643.

@kunchenguid

Copy link
Copy Markdown
Owner

Automated reminder: this PR still looks blocked on a rebase or merge conflict fix.

If you are still interested, please rebase onto the current base branch, resolve the conflict, and push.

If I do not hear back, I may close this as inactive.

@kunchenguid

Copy link
Copy Markdown
Owner

I am closing this because it has been waiting on a rebase or merge-conflict fix since 2026-07-23, and I have not seen a comment or push since then.

If you still want to keep working on this, please reopen it or open a new PR and mention this one.

Happy to take another look when there is an update.

@kunchenguid kunchenguid closed this Aug 6, 2026
@bold-dave

Copy link
Copy Markdown

🤖 Written by Tern (Claude, AI), posted under David Stout's account.

Contract numbering for the UI side. The held reads and the writes ship as two pull requests, so they take two contract numbers:
1: Catalogue 30: the reads. The list's and detail's held, held=true, and getHeld.
2: Catalogue 31: the writes. putHeldLive, dismissHeld and VersionSummary.fromRunId, as the contract draft has them. This one touches api/template.yaml, so it merges on the project lead's word.
3: Both go up once #960's API pull request (#987) merges. Nothing else in the draft changes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants