fix(kimi): gate --work-dir flag on probe, like --print (#1476) - #1483
Merged
chenhg5 merged 1 commit intoAug 15, 2026
Merged
Conversation
Same pattern as the #1456 / PR #1461 --print fix. Newer Kimi Code CLI builds no longer accept --work-dir, exiting with `error: unknown option --work-dir` whenever the user's config sets a non-default workspace directory. - agent/kimi/probe.go: kimiFlagSupport gains a WorkDir bool; the probe fills it from `kimi --help` (parseKimiHelpFlags already scans the --work-dir token, no parser changes needed). - agent/kimi/session.go buildArgs: --work-dir is now emitted only when flagSupport.WorkDir is true. The agent still runs in the correct directory via exec.Command.Dir (set separately), so omitting the flag on modern CLIs is functionally equivalent for users on default dirs and graceful for users on non-default dirs whose CLI just ignores it. - agent/kimi/probe_test.go: extend the legacy test to assert --work-dir is detected, add modernKimiHelpWithoutWorkDir constant that mirrors the build the reporter hits, plus full TestKimiFlagSupport_LegacyHelpSetsWorkDir / TestKimiFlagSupport_ModernWithoutWorkDir coverage of the probe mapping. - agent/kimi/session_test.go: TestBuildArgs_WorkDirFlagGated (no flag on modern CLI) + TestBuildArgs_WorkDirFlagEmitted (legacy CLI keeps it). Also asserts the work-dir value doesn't leak into args when the gate is closed, catching a partial-gate future bug. go test ./agent/kimi/... — all pass.
This was referenced Jul 17, 2026
chenhg5
commented
Aug 15, 2026
chenhg5
left a comment
Owner
Author
There was a problem hiding this comment.
Conclusion: Comment
Overall assessment:
- Solid, minimal fix that closes the
--work-dirgap for the Kimi Code CLI build (#1476) using the exact same probe-gating pattern already validated by PR #1461 / #1456 for--print. Single commit onorigin/main, CI fully green, localgo test -race ./agent/kimi/...passes 10/10. Mergeable as-is.
Review scope:
- Reviewed the full diff (5 files, +124 / -6):
agent/kimi/probe.go,agent/kimi/session.go,agent/kimi/probe_test.go,agent/kimi/session_test.go,CHANGELOG.md. - Focused on correctness (the gate and the probe), test coverage (both supported and unsupported CLI surfaces), backward compatibility, and stacking vs PR #1564.
✅ What looks good:
- Pattern consistency with #1461:
if ks.workDir != "" && ks.flagSupport.WorkDir { ... }mirrors the existing--printgate atsession.go:79-81exactly. Reviewers who already approved #1461 can verify this in 30 seconds. exec.Command.Diris set unconditionally atsession.go:187, so omitting--work-diron modern CLI is functionally equivalent for users on default dirs and a graceful cwd fallback for users on non-default dirs. Author's claim is verified by reading the code path.- Two-realistic-surfaces approach in tests: kept the existing
modernKimiHelp(transition build: no--print, still has--work-dir) and added a separatemodernKimiHelpWithoutWorkDirfixture for the #1476 surface. This preserves the #1456 regression contract instead of mutating an anchored fixture. - Partial-gate future bug catch:
TestBuildArgs_WorkDirFlagGatedasserts the value/doesn't leak into args when the gate is closed. A future refactor that drops the flag-name but keeps the value would be caught. - Probe-failure contract preserved: zero-value
kimiFlagSupport{}on probe failure remains the conservative "modern CLI" default — unchanged from #1461. - No scope creep: only
agent/kimi/is touched (plus one CHANGELOG line); no other agent adapters, no platform, no core. - CHANGELOG entry is informative: names the issue, references prior art, explains the cwd fallback, gives one-line legacy/modern outcomes.
🚨/🔴 Must fix:
- No merge-blocking issues found.
🟠 Should improve:
- None.
🔵 Optional:
- Add a
buildArgs-level test for the in-between surface (Print=false, WorkDir=true). The parser is tested at that surface viaTestParseKimiHelpFlags_ModernHidesPrint, but aTestBuildArgs_ModernWithWorkDir(or extendingTestBuildArgs_PlanMode) would explicitly assert the gate fires whenWorkDir=truewhilePrint=false. Not needed for correctness today, but a 6-line addition that locks in the integration. Follow-up only.
❓ Questions:
- Maintainer decision (not for the author): this PR is the base commit of PR #1564 (
feat(kimi): native Kimi Code CLI dialect support). #1564's first commit (e1ec734f) is byte-identical to this PR's HEAD, and #1564's second commit (8dc7707c) likely consumes thekimiFlagSupport.WorkDirfield added here — meaning #1564 will not compile standalone without #1483 merged first. Recommendation: merge #1483 first, then askwhyihaveyou(#1564 author, first-time contributor) to rebase #1564 onto the newmainso its diff reflects only the actual Kimi Code dialect work, not the stacked base.
Testing / Risk:
- Verified locally:
go test -race ./agent/kimi/... -count=1 -timeout 60s→ ALL PASS (10/10 tests; 6 new in this PR).go vet ./agent/kimi/...clean.gofmt -l agent/kimi/clean.
- Verified parser correctness manually against both fixtures:
legacyKimiHelp→--work-dir:true,modernKimiHelpWithoutWorkDir→--work-dir:absent. - CI: lint, unit-test, smoke-test, regression-test, performance-test all SUCCESS at
e1ec734f(runs/28550372464). - Remaining risk: if a future Kimi CLI build keeps
--work-dirbut moves it to a sub-command or aliases it differently, the parser might miss it. The existing two-realistic-surfaces fixtures cover both "in-between" and "fully removed" transitions; future moves would need a new fixture. - Backward compatibility: zero regression risk — legacy users keep
--work-dir, modern users get clean startup, in-between users keep--work-dir(parser still detects it).
Next step:
24 tasks
OctopusWen
pushed a commit
to OctopusWen/cc-connect
that referenced
this pull request
Aug 15, 2026
Fixes chenhg5#1561 The kimi agent targeted the legacy Python kimi-cli dialect; the newer Node.js Kimi Code CLI (kimi-code) speaks a different one. Extend the chenhg5#1461/chenhg5#1483 probe-gating approach to cover the remaining differences: - probe: also detect --quiet; add isModernFlavor() using --print absence as the family discriminator established in chenhg5#1456 - buildArgs: resume with -r instead of --resume on the modern dialect (--resume is rejected; -r matches the CLI's own resume hint); gate --quiet and emulate quiet mode via local event suppression when the binary dropped it; never pass --yolo/--auto (bare --prompt already auto-approves, and Kimi Code rejects combining them) - stream-json: accept plain-string content for assistant/tool messages alongside the legacy block-array shape (format-tolerant, no gating) - session continuity: capture the session id from Kimi Code's stdout meta line {"role":"meta","type":"session.resume_hint"} instead of the legacy plain-text/stderr hint - session listing: scan both ~/.kimi/sessions and ~/.kimi-code/sessions, understand the Kimi Code state.json schema, honor its workDir field Tests: real v0.26.0 --help fixture, per-dialect arg tests, content-shape and meta-hint regression tests, dual-flavor session listing test, and an env-guarded live e2e (KIMI_LIVE_E2E=1) that verifies anchor recall across a resumed turn against the production binary. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
whyihaveyou
added a commit
to whyihaveyou/cc-connect
that referenced
this pull request
Aug 15, 2026
Fixes chenhg5#1561 The kimi agent targeted the legacy Python kimi-cli dialect; the newer Node.js Kimi Code CLI (kimi-code) speaks a different one. Extend the chenhg5#1461/chenhg5#1483 probe-gating approach to cover the remaining differences: - probe: also detect --quiet; add isModernFlavor() using --print absence as the family discriminator established in chenhg5#1456 - buildArgs: resume with -r instead of --resume on the modern dialect (--resume is rejected; -r matches the CLI's own resume hint); gate --quiet and emulate quiet mode via local event suppression when the binary dropped it; never pass --yolo/--auto (bare --prompt already auto-approves, and Kimi Code rejects combining them) - stream-json: accept plain-string content for assistant/tool messages alongside the legacy block-array shape (format-tolerant, no gating) - session continuity: capture the session id from Kimi Code's stdout meta line {"role":"meta","type":"session.resume_hint"} instead of the legacy plain-text/stderr hint - session listing: scan both ~/.kimi/sessions and ~/.kimi-code/sessions, understand the Kimi Code state.json schema, honor its workDir field Tests: real v0.26.0 --help fixture, per-dialect arg tests, content-shape and meta-hint regression tests, dual-flavor session listing test, and an env-guarded live e2e (KIMI_LIVE_E2E=1) that verifies anchor recall across a resumed turn against the production binary. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
chenhg5
pushed a commit
that referenced
this pull request
Aug 16, 2026
* fix(kimi): gate --work-dir flag on probe, like --print (#1476) Same pattern as the #1456 / PR #1461 --print fix. Newer Kimi Code CLI builds no longer accept --work-dir, exiting with `error: unknown option --work-dir` whenever the user's config sets a non-default workspace directory. - agent/kimi/probe.go: kimiFlagSupport gains a WorkDir bool; the probe fills it from `kimi --help` (parseKimiHelpFlags already scans the --work-dir token, no parser changes needed). - agent/kimi/session.go buildArgs: --work-dir is now emitted only when flagSupport.WorkDir is true. The agent still runs in the correct directory via exec.Command.Dir (set separately), so omitting the flag on modern CLIs is functionally equivalent for users on default dirs and graceful for users on non-default dirs whose CLI just ignores it. - agent/kimi/probe_test.go: extend the legacy test to assert --work-dir is detected, add modernKimiHelpWithoutWorkDir constant that mirrors the build the reporter hits, plus full TestKimiFlagSupport_LegacyHelpSetsWorkDir / TestKimiFlagSupport_ModernWithoutWorkDir coverage of the probe mapping. - agent/kimi/session_test.go: TestBuildArgs_WorkDirFlagGated (no flag on modern CLI) + TestBuildArgs_WorkDirFlagEmitted (legacy CLI keeps it). Also asserts the work-dir value doesn't leak into args when the gate is closed, catching a partial-gate future bug. go test ./agent/kimi/... — all pass. * feat(kimi): native Kimi Code CLI dialect support Fixes #1561 The kimi agent targeted the legacy Python kimi-cli dialect; the newer Node.js Kimi Code CLI (kimi-code) speaks a different one. Extend the #1461/#1483 probe-gating approach to cover the remaining differences: - probe: also detect --quiet; add isModernFlavor() using --print absence as the family discriminator established in #1456 - buildArgs: resume with -r instead of --resume on the modern dialect (--resume is rejected; -r matches the CLI's own resume hint); gate --quiet and emulate quiet mode via local event suppression when the binary dropped it; never pass --yolo/--auto (bare --prompt already auto-approves, and Kimi Code rejects combining them) - stream-json: accept plain-string content for assistant/tool messages alongside the legacy block-array shape (format-tolerant, no gating) - session continuity: capture the session id from Kimi Code's stdout meta line {"role":"meta","type":"session.resume_hint"} instead of the legacy plain-text/stderr hint - session listing: scan both ~/.kimi/sessions and ~/.kimi-code/sessions, understand the Kimi Code state.json schema, honor its workDir field Tests: real v0.26.0 --help fixture, per-dialect arg tests, content-shape and meta-hint regression tests, dual-flavor session listing test, and an env-guarded live e2e (KIMI_LIVE_E2E=1) that verifies anchor recall across a resumed turn against the production binary. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> * fix(kimi): don't report 0 messages for Kimi Code sessions in /list Kimi Code CLI sessions have no context.jsonl; their transcript lives at agents/main/wire.jsonl. Without a fallback, /list showed 0 messages for every modern session. Count user turns from wire.jsonl (and use the first user turn as the summary), matching legacy kimi-cli behavior. Addresses review feedback on #1564. * fix(kimi): adapt live e2e to main's Send(messageID, ...) signature CI lint failed on the PR merge ref: main added a messageID string param to AgentSession.Send (core/interfaces.go), but the PR still called the old 3-arg form in live_e2e_test.go, so the merged code failed to compile ('not enough arguments in call to s.Send'). origin/main was merged into kimi-code-flavor (no conflicts); kimi's Send now carries the 4-arg signature matching main. This updates the remaining 3-arg call site to the new signature. agent/kimi and core compile, vet and tests green. * fix(kimi): check f.Close error in transcript helpers (errcheck) golangci-lint flagged the deferred file Close calls in the new parseKimiTranscript/count* helpers as unchecked errors. Use an explicit blank-assignment close to satisfy errcheck. agent/kimi still compiles, vets and tests green. * feat(kimi): native Kimi Code CLI dialect support Fixes #1561 The kimi agent targeted the legacy Python kimi-cli dialect; the newer Node.js Kimi Code CLI (kimi-code) speaks a different one. Extend the #1461/#1483 probe-gating approach to cover the remaining differences: - probe: also detect --quiet; add isModernFlavor() using --print absence as the family discriminator established in #1456 - buildArgs: resume with -r instead of --resume on the modern dialect (--resume is rejected; -r matches the CLI's own resume hint); gate --quiet and emulate quiet mode via local event suppression when the binary dropped it; never pass --yolo/--auto (bare --prompt already auto-approves, and Kimi Code rejects combining them) - stream-json: accept plain-string content for assistant/tool messages alongside the legacy block-array shape (format-tolerant, no gating) - session continuity: capture the session id from Kimi Code's stdout meta line {"role":"meta","type":"session.resume_hint"} instead of the legacy plain-text/stderr hint - session listing: scan both ~/.kimi/sessions and ~/.kimi-code/sessions, understand the Kimi Code state.json schema, honor its workDir field Tests: real v0.26.0 --help fixture, per-dialect arg tests, content-shape and meta-hint regression tests, dual-flavor session listing test, and an env-guarded live e2e (KIMI_LIVE_E2E=1) that verifies anchor recall across a resumed turn against the production binary. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> * fix(kimi): don't report 0 messages for Kimi Code sessions in /list Kimi Code CLI sessions have no context.jsonl; their transcript lives at agents/main/wire.jsonl. Without a fallback, /list showed 0 messages for every modern session. Count user turns from wire.jsonl (and use the first user turn as the summary), matching legacy kimi-cli behavior. Addresses review feedback on #1564. * fix(kimi): adapt live e2e to main's Send(messageID, ...) signature CI lint failed on the PR merge ref: main added a messageID string param to AgentSession.Send (core/interfaces.go), but the PR still called the old 3-arg form in live_e2e_test.go, so the merged code failed to compile ('not enough arguments in call to s.Send'). origin/main was merged into kimi-code-flavor (no conflicts); kimi's Send now carries the 4-arg signature matching main. This updates the remaining 3-arg call site to the new signature. agent/kimi and core compile, vet and tests green. * fix(kimi): check f.Close error in transcript helpers (errcheck) golangci-lint flagged the deferred file Close calls in the new parseKimiTranscript/count* helpers as unchecked errors. Use an explicit blank-assignment close to satisfy errcheck. agent/kimi still compiles, vets and tests green. * test(kimi): pin assistant string-content + tool_calls flush order (#1561) Ported from #1586: an assistant event carrying plain-string content AND tool_calls must surface the text as a thinking event (via flushPendingAsThinking) before the tool-use event, not drop it silently. * docs(changelog): add #1561 kimi-code dialect entry --------- Co-authored-by: dev-claudecode <dev-claudecode@cc-connect.local> Co-authored-by: whyihaveyou <whyihaveyou@users.noreply.github.com> Co-authored-by: Claude Fable 5 <noreply@anthropic.com> Co-authored-by: QZP <qzp@QZPdeMacBook-Air.local> Co-authored-by: octopus <2841776039@qq.com>
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.
Fixes #1476
问题
Kimi Code CLI builds newer than what #1456 covered dropped the
--work-dirflag. Passing it now produces:
The reporter (
#1476,v1.4.1, Kimi Code agent) hits this on every spawnbecause
session.go:97-99always appended the flag whenever a non-defaultworkDirwas set. The #1461 / #1456 fix gated--printthe same way; thisPR closes the gap for
--work-dir.改动
Follows the exact same probe-based pattern as #1456 / PR #1461 (referenced
for both users and reviewers who already validated that approach).
agent/kimi/probe.gokimiFlagSupportgainsWorkDir bool.probeKimiFlagspopulates it from the existingparseKimiHelpFlagsmap:agent/kimi/session.goexec.Command.Diris set on the spawned
*exec.Cmd(downstream of this line) — same as inthe fix(kimi): conditionally pass --print so newer Kimi Code CLI works (#1456) #1461 fix.
agent/kimi/probe_test.goTestParseKimiHelpFlags_LegacyAdvertisesPrintnow also assertsflags["--work-dir"]istrue(legacy CLI supports it).modernKimiHelpWithoutWorkDirmirrors the Kimi Code CLIbuild the reporter hits (no
--print, no--work-dir).TestParseKimiHelpFlags_ModernWithoutWorkDirasserts neither flagis detected on the deeper-no-work-dir surface.
TestParseKimiHelpFlags_ModernHidesPrintleft intact (itcovers the in-between surface where
--printis gone but--work-dirstill exists — useful regression coverage).
TestKimiFlagSupport_LegacyHelpSetsWorkDir+TestKimiFlagSupport_ModernWithoutWorkDirexercise the full probe-mapping, not just
parseKimiHelpFlags, since that's whatbuildArgsactually consumes.agent/kimi/session_test.goTestBuildArgs_WorkDirFlagGated—workDir=/,flagSupport{WorkDir:false}→
--work-dirMUST NOT appear, AND the value/MUST NOT leak into args(catches a partial-gate bug where only the flag name is dropped).
TestBuildArgs_WorkDirFlagEmitted—workDir=/,flagSupport{WorkDir:true}→
--work-dir /MUST appear (legacy CLI keeps non-default dir support).触发条件 / trade-off
parseKimiHelpFlagsinstead of adding a new parser?--work-diralready appears in the help-text of both legacy and thein-between build the existing
modernKimiHelpconstant models. Theexisting parser picks it up the same way it picked up
--print— nonew parser logic, no new layout assumptions.
modernKimiHelpWithoutWorkDirinstead of editingmodernKimiHelp? ThemodernKimiHelpconstant is anchored in the[Bug] ❌ 错误: error: unknown option '--print' (Did you mean --prompt?) #1456 fix history; editing it would silently invalidate that test's
assertion contract. Two-realistic-surfaces is the cleaner modeling.
cmd.Diris setunconditionally, so whether the CLI sees
--work-dir $Xor just takescwd from
cmd.Dir, the agent runs in the same directory. The onlypractical difference is users on non-default dirs whose modern CLI
previously crashed: they now get clean startup (cwd fallback).
--work-dirin help, the probe sees it,buildArgsstill emits it.验证
gofmt -l agent/kimi/— cleango vet ./agent/kimi/...— cleango test -count=1 ./agent/kimi/...— all pass (4 prior + 6 new =10 tests in the probe/session suites)
不做什么
etc. each have their own flag handling; out of scope)
kimi --help解析 + 短超时fallback to modern surface on probe failure)
buildArgs/kimiFlagSupport— 仅加一个 bool 字段关联
group_reply_allfor QQ platform) 是独立PR,本次不合并。
🤖 Generated with Claude Code