Skip to content

feat(sleep): add kimicode backend (Kimi Code CLI) - #343

Open
safeblood wants to merge 2 commits into
microsoft:mainfrom
safeblood:feat/kimicode-backend
Open

safeblood wants to merge 2 commits into
microsoft:mainfrom
safeblood:feat/kimicode-backend

Conversation

@safeblood

Copy link
Copy Markdown

Summary

Adds a CLI backend that drives the authenticated Kimi Code CLI (kimi --prompt <task> --output-format text), so --backend kimicode works alongside claude/codex/cursor/pi/opencode. Kimi Code (Moonshot's agent CLI/desktop app) already has its sessions harvested via #342; this PR completes the loop by letting the sleep cycle replay, judge, and reflect through the same agent.

Changes

File What changed Why
skillopt_sleep/backend.py New KimiCliBackend (name="kimicode", aliases kimi/kimi_code/kimi-cli) + get_backend/build_backend routing Prompts go inline via --prompt (kimi's -p takes a value, unlike claude -p which reads stdin). Output is captured as bytes and decoded as UTF-8 (the CLI emits UTF-8 regardless of the Windows console codepage). Binary resolution: PATH first, desktop install (~/.kimi-code/bin/kimi) as fallback for the bare default name only; an explicit --kimi-path is kept verbatim. Auth failures set last_call_error and log a warning.
skillopt_sleep/config.py kimi_path default Same pattern as the other CLI paths
skillopt_sleep/cycle.py Pass kimi_path through both build_backend call sites
skillopt_sleep/__main__.py --backend kimicode, --kimi-path CLI surface
tests/test_backend_kimi.py 8 offline tests Aliases, path resolution, command construction, UTF-8 decoding, auth-error detection, routing — no network

Known limits (documented)

  • Each call takes ~60s (Kimi CLI cold start), so a full cycle is markedly slower than other backends; the 180s default timeout fits.
  • The CLI has no --bare equivalent: the user's global ~/.kimi-code/AGENTS.md is still injected into optimizer calls (the Claude backend disables the analogous leak via --disable-slash-commands). Flagged here so the trade-off is explicit.

Verification

  • pytest tests/test_backend_kimi.py — 8 passed.
  • Live single call: _call('Reply with exactly: OK') returns a real model response.
  • End-to-end on Windows: dry-run --backend kimicode over a 2-task reviewed file completes attempt/judge/reflect/gate with live Kimi calls (baseline 1.0, candidate 1.0, gate reject — no headroom on trivial demo tasks, as expected).

Add a CLI backend that drives the authenticated Kimi Code CLI
(`kimi --prompt <task> --output-format text`), so
`--backend kimicode` works alongside claude/codex/cursor/pi/opencode.

- backend.py: KimiCliBackend (name "kimicode", aliases kimi/kimi_code/
  kimi-cli). Resolves the binary via PATH, falling back to the desktop
  install location (~/.kimi-code/bin/kimi) only for the bare default
  name; an explicit --kimi-path is kept verbatim. Prompts go INLINE via
  --prompt (kimi's -p takes a value, unlike claude -p which reads
  stdin). Output is captured as bytes and decoded as UTF-8: the CLI
  emits UTF-8 regardless of the Windows console codepage, where
  text=True would decode with gbk and crash. Likely auth errors set
  last_call_error and log a warning.
- config.py: kimi_path default; cycle.py passes it through;
  __main__.py: --backend kimicode, --kimi-path.
- tests/test_backend_kimi.py: 8 offline tests (aliases, path
  resolution, command construction, UTF-8 decoding, auth-error
  detection, build_backend routing).

Verified on Windows: a single _call returns a real model response, and
a full dry-run (--backend kimicode, 2-task reviewed file) completes
attempt/judge/reflect/gate with live Kimi calls.

Known limits (documented): each call takes ~60s (CLI cold start), so a
full cycle is markedly slower than other backends; the CLI has no
--bare equivalent, so the user's global ~/.kimi-code/AGENTS.md is
still injected into optimizer calls.
First real-cycle runs showed cold starts ballooning past 180s whenever
the Kimi desktop app is active on the same account, silently zeroing
most rollouts. Default the timeout to 600s (SKILLOPT_SLEEP_KIMI_TIMEOUT
overrides) and report TimeoutExpired as its own error instead of the
misleading 'spawn failed'.
lucatreiber2007 added a commit to lucatreiber2007/SkillOpt that referenced this pull request Nov 1, 2026
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
lucatreiber2007 added a commit to lucatreiber2007/SkillOpt that referenced this pull request Nov 1, 2026
Tests schlagen auf macOS fehl (Kimi-Pfad/Slug bzw. bash-3.2-Syntax).

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>

This branch has not been deployed

No deployments
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