Skip to content

feat(sleep): add Kimi Code transcript source - #342

Open
safeblood wants to merge 2 commits into
microsoft:mainfrom
safeblood:feat/kimi-code-harvest
Open

safeblood wants to merge 2 commits into
microsoft:mainfrom
safeblood:feat/kimi-code-harvest

Conversation

@safeblood

Copy link
Copy Markdown

Summary

Adds a native Kimi Code harvest source so python -m skillopt_sleep --source kimi works alongside claude/codex/cursor/pi/opencode. Kimi Code (the Kimi agent CLI/desktop app) stores sessions as wire.jsonl under ~/.kimi-code/sessions/wd_<workspace>/session_<id>/agents/main/, which the existing sources cannot read.

Changes

File What changed Why
skillopt_sleep/harvest_kimi.py New harvester + digest parser Parses both wire message envelopes (context.append_message, agent.message.appended), keeps only genuine user input (origin.kind == "user"), skips system reminders/injections and think blocks; reuses the shared meta-prompt filter, secret redaction, and feedback detector; adds Chinese feedback phrases (谢谢/不对/重来...) since Kimi Code sessions are predominantly Chinese
skillopt_sleep/config.py kimi_home default (~/.kimi-code), kimi_sessions_dir Source path configuration, same pattern as the other homes
skillopt_sleep/harvest_sources.py transcript_source == "kimi" branch Route the new source
skillopt_sleep/__main__.py --kimi-home, kimi in --source choices CLI surface
tests/test_harvest_kimi.py 7 offline tests Envelope parsing, reminder/injection skipping, since window, invoked-scope slug matching, source routing

Design notes

Wires do not record the session cwd, so the digest project is the workspace slug (wd_358_<hash> → 358) and invoked-scope matching is name-based: a session is in scope when its slug appears among the invoked project's path segments. Scope all harvests every workspace.

Verification

  • pytest tests/test_harvest_kimi.py — 7 passed.
  • Focused suite (pytest tests/ -k "harvest or source or config or cli") — 450 passed; the 15 failures in test_sleep_config_encoding.py reproduce on Windows main without this change (error message embeds a repr-escaped path).
  • End-to-end on Windows: dry-run --source kimi harvested 66 sessions from ~/.kimi-code/sessions and ran the full harvest → mine → replay → consolidate → gate cycle with the mock backend.

Add a native harvest source for Kimi Code sessions (wire.jsonl), so
`--source kimi` works alongside claude/codex/cursor/pi/opencode.

- skillopt_sleep/harvest_kimi.py: parses the two wire message envelopes
  (context.append_message, agent.message.appended), keeps only genuine
  user input (origin.kind == 'user'), skips system reminders/injections
  and think blocks, and reuses the shared meta-prompt filter, secret
  redaction, and feedback detector. Chinese feedback phrases are added
  because Kimi Code sessions are predominantly Chinese.
- Wires record no cwd, so the digest project is the workspace slug
  (wd_358_<hash> -> '358'); invoked-scope matching is name-based against
  the invoked project path segments.
- config.py: kimi_home default (~/.kimi-code) + kimi_sessions_dir.
- harvest_sources.py: route transcript_source == 'kimi'.
- __main__.py: --kimi-home override and 'kimi' --source choice.
- tests/test_harvest_kimi.py: 7 offline tests (envelopes, reminders,
  since window, scope matching, source routing).

Verified end-to-end on Windows: dry-run --source kimi harvests 66
sessions from ~/.kimi-code/sessions and runs the full
harvest -> mine -> replay -> consolidate -> gate cycle.
@safeblood

Copy link
Copy Markdown
Author

@microsoft-github-policy-service agree

…vest

The kimicode backend (and any headless  replay) persists
wires into ~/.kimi-code/sessions, so the next night's incremental harvest
was eating those programmatic sessions instead of real user work —
mining zero tasks after a killed run. Skip digests with no user intent
and prompts carrying the attempt-template sentinel or a
[skillopt-sleep: marker.
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