mirror of
https://github.com/chenhg5/cc-connect.git
synced 2026-07-03 12:28:10 +08:00
* fix(kimi): conditionally pass --print so newer Kimi Code CLI works (#1456) ## Problem `cc-connect` unconditionally passes `--print --output-format stream-json --prompt …` to the Kimi CLI. The newer Kimi Code CLI removed the standalone `--print` flag and now exits immediately with error: unknown option '--print' (Did you mean --prompt?) so every Kimi chat is broken for users on the new CLI. Issue #1456. ## Root cause The two CLIs in the wild have opposing requirements for non-interactive runs: | CLI | --print? | --output-format requires | |----------------|----------|--------------------------| | legacy kimi-cli| yes | --print | | new Kimi Code | removed | --prompt | A fixed arg list cannot satisfy both, and `--print` cannot be emulated the way #1253 emulates `--quiet` — it is the CLI's own non-interactive mode toggle, not output formatting. ## Fix Probe `kimi --help` once when the Agent is constructed and cache the detected flag set. `buildArgs()` (newly extracted from `Send()` so it is unit-testable) only emits `--print` when the installed binary still advertises it. Probe failure / timeout falls back to "no --print", which matches the direction the Kimi CLI is moving and avoids the hard-failure mode of the current code. - `agent/kimi/probe.go` — `parseKimiHelpFlags()` pure parser + bounded `probeKimiFlags()` (5s timeout, swallows errors). - `agent/kimi/kimi.go` — Agent caches `kimiFlagSupport`, threads it into `newKimiSession`; doc comments updated. - `agent/kimi/session.go` — `kimiSession.flagSupport` + `buildArgs()` helper; conditional `--print`; permission-mode comment updated to cover both legacy (`--print` implicit `--yolo`) and modern (`--prompt` auto-permission) behaviors. ## Tests - `TestBuildArgs_NoPrintSupportOmitsPrintFlag` — regression test for #1456; fails on pre-fix code, passes on this branch. - `TestBuildArgs_PrintSupportIncludesPrintFlag` — legacy CLI branch. - `TestBuildArgs_PlanMode` / `TestBuildArgs_ResumeSession` — sanity coverage for other arg paths. - `TestParseKimiHelpFlags_LegacyAdvertisesPrint` / `TestParseKimiHelpFlags_ModernHidesPrint` — parser handles both typer box-drawing and standard click `-p, --prompt` layouts. - `TestParseKimiHelpFlags_IgnoresPositionalAndShortOnly` — robustness. - `TestProbeKimiFlags_FallbackOnMissingBinary` — probe failure path returns zero value (modern-CLI default). Full suite verified: `go test ./agent/kimi/...` (and `-race`), plus `go test ./core/ -run TestCUJ`. Pre-existing `agent/acp` integration test still fails on `origin/main` (requires `cursor agent login`) — unrelated to this change. ## Non-goals - Does not touch the cursor agent; Claude Code CLI still supports `--print` so cursor's hard-coded flag is fine. - Does not change `--quiet` handling; PR #1253 owns that fix for #806. - Does not introduce new config schema. Co-authored-by: Cursor <cursoragent@cursor.com> * test(kimi): wrap deferred Close in func to satisfy errcheck CI lint failed with 3 (and a 4th caught locally) `defer ks.Close()` sites that ignore the returned error. Wrap in a closure that explicitly discards the return value so golangci-lint errcheck is happy and the tests still run. No functional change. --------- Co-authored-by: dev-claudecode <dev-claudecode@cc-connect.local> Co-authored-by: Cursor <cursoragent@cursor.com>