Skip to content

fix(kimi): gate --work-dir flag on probe, like --print (#1476) - #1483

Merged
chenhg5 merged 1 commit into
mainfrom
agent/cc-connect/dev-claudecode/t-20260701-ro21vi-1476-kimi-work-dir-gate
Aug 15, 2026
Merged

fix(kimi): gate --work-dir flag on probe, like --print (#1476)#1483
chenhg5 merged 1 commit into
mainfrom
agent/cc-connect/dev-claudecode/t-20260701-ro21vi-1476-kimi-work-dir-gate

Conversation

@chenhg5

@chenhg5 chenhg5 commented Jul 1, 2026

Copy link
Copy Markdown
Owner

Fixes #1476

问题

Kimi Code CLI builds newer than what #1456 covered dropped the --work-dir
flag. Passing it now produces:

error: unknown option --work-dir

The reporter (#1476, v1.4.1, Kimi Code agent) hits this on every spawn
because session.go:97-99 always appended the flag whenever a non-default
workDir was set. The #1461 / #1456 fix gated --print the same way; this
PR 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.go

agent/kimi/session.go

agent/kimi/probe_test.go

  • TestParseKimiHelpFlags_LegacyAdvertisesPrint now also asserts
    flags["--work-dir"] is true (legacy CLI supports it).
  • New constant modernKimiHelpWithoutWorkDir mirrors the Kimi Code CLI
    build the reporter hits (no --print, no --work-dir).
  • New TestParseKimiHelpFlags_ModernWithoutWorkDir asserts neither flag
    is detected on the deeper-no-work-dir surface.
  • Existing TestParseKimiHelpFlags_ModernHidesPrint left intact (it
    covers the in-between surface where --print is gone but --work-dir
    still exists — useful regression coverage).
  • New TestKimiFlagSupport_LegacyHelpSetsWorkDir +
    TestKimiFlagSupport_ModernWithoutWorkDir exercise the full probe-
    mapping, not just parseKimiHelpFlags, since that's what
    buildArgs actually consumes.

agent/kimi/session_test.go

  • TestBuildArgs_WorkDirFlagGatedworkDir=/, flagSupport{WorkDir:false}
    --work-dir MUST NOT appear, AND the value / MUST NOT leak into args
    (catches a partial-gate bug where only the flag name is dropped).
  • TestBuildArgs_WorkDirFlagEmittedworkDir=/, flagSupport{WorkDir:true}
    --work-dir / MUST appear (legacy CLI keeps non-default dir support).

触发条件 / trade-off

  • Why reuse parseKimiHelpFlags instead of adding a new parser?
    --work-dir already appears in the help-text of both legacy and the
    in-between build the existing modernKimiHelp constant models. The
    existing parser picks it up the same way it picked up --print — no
    new parser logic, no new layout assumptions.
  • Why a separate modernKimiHelpWithoutWorkDir instead of editing
    modernKimiHelp?
    The modernKimiHelp constant 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.
  • Risk for users on default dirs? None — cmd.Dir is set
    unconditionally, so whether the CLI sees --work-dir $X or just takes
    cwd from cmd.Dir, the agent runs in the same directory. The only
    practical difference is users on non-default dirs whose modern CLI
    previously crashed: they now get clean startup (cwd fallback).
  • Risk for users with legacy kimi-cli? None — they advertise
    --work-dir in help, the probe sees it, buildArgs still emits it.

验证

  • gofmt -l agent/kimi/ — clean
  • go vet ./agent/kimi/... — clean
  • go test -count=1 ./agent/kimi/... — all pass (4 prior + 6 new =
    10 tests in the probe/session suites)

不做什么

  • 不改 Kimi Code CLI 本身
  • 不改其他 agent adapter (Claude / Codex / Gemini / Cursor / OpenCode
    etc. each have their own flag handling; out of scope)
  • 不改 probe 探测逻辑本身 (沿用现有 kimi --help 解析 + 短超时
    fallback to modern surface on probe failure)
  • 不重构 buildArgs / kimiFlagSupport — 仅加一个 bool 字段

关联

🤖 Generated with Claude Code

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.

@chenhg5 chenhg5 left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Conclusion: Comment

Overall assessment:

  • Solid, minimal fix that closes the --work-dir gap for the Kimi Code CLI build (#1476) using the exact same probe-gating pattern already validated by PR #1461 / #1456 for --print. Single commit on origin/main, CI fully green, local go 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 --print gate at session.go:79-81 exactly. Reviewers who already approved #1461 can verify this in 30 seconds.
  • exec.Command.Dir is set unconditionally at session.go:187, so omitting --work-dir on 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 separate modernKimiHelpWithoutWorkDir fixture for the #1476 surface. This preserves the #1456 regression contract instead of mutating an anchored fixture.
  • Partial-gate future bug catch: TestBuildArgs_WorkDirFlagGated asserts 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 via TestParseKimiHelpFlags_ModernHidesPrint, but a TestBuildArgs_ModernWithWorkDir (or extending TestBuildArgs_PlanMode) would explicitly assert the gate fires when WorkDir=true while Print=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 the kimiFlagSupport.WorkDir field added here — meaning #1564 will not compile standalone without #1483 merged first. Recommendation: merge #1483 first, then ask whyihaveyou (#1564 author, first-time contributor) to rebase #1564 onto the new main so 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-dir but 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:

  • For the maintainer: merge #1483 first to unblock #1564. Then ask whyihaveyou to rebase #1564 onto the new main for a cleaner review surface.
  • For the author (chenhg5, self-PR): nothing required. The P3 follow-up (in-between-surface buildArgs test) can be a separate PR if desired.

@chenhg5
chenhg5 merged commit 6c86079 into main Aug 15, 2026
5 checks passed
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>
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.

[Bug] ❌ 错误: error: unknown option '--work-dir'

1 participant