Skip to content

feat(agents): add kimi adapter#134

Merged
harshitsinghbhandari merged 2 commits into
agents/14-clinefrom
agents/15-kimi
Jun 6, 2026
Merged

feat(agents): add kimi adapter#134
harshitsinghbhandari merged 2 commits into
agents/14-clinefrom
agents/15-kimi

Conversation

@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps Bot commented Jun 6, 2026

Greptile Summary

This PR adds the Kimi (Moonshot AI) CLI agent adapter as a Tier C harness, following the same structural pattern as the existing grok, cline, and other adapters in the registry.

  • kimi/kimi.go: Implements ports.Agent with binary resolution (PATH + common install locations, cross-platform), permission-mode mapping to --auto/-y flags, and intentional no-ops for GetAgentHooks and SessionInfo until Kimi exposes a hook surface.
  • kimi/kimi_test.go: Covers manifest, config spec, prompt delivery, all permission modes, restore-command cases, and context cancellation for every method except GetLaunchCommand.
  • registry/registry.go + wiring_test.go: Single-line kimi.New() registration and corresponding resolver assertion, consistent with how all other adapters are wired.

Confidence Score: 5/5

Safe to merge; the adapter is well-isolated, no-ops are clearly documented, and the change follows established patterns throughout the codebase.

The new Kimi adapter is a straightforward addition with no impact on existing adapters or critical paths. Binary resolution, permission mapping, and session restore logic are all consistent with peer adapters. The one inconsistency — GetLaunchCommand skipping the early context guard — is a minor behavioral edge case that only surfaces when the binary is already cached on a cancelled context, not a data-loss or security concern.

backend/internal/adapters/agent/kimi/kimi.go — specifically the missing ctx.Err() guard at the top of GetLaunchCommand.

Important Files Changed

Filename Overview
backend/internal/adapters/agent/kimi/kimi.go New Tier C adapter for the Kimi CLI; clean structure following peer adapters, but GetLaunchCommand skips the ctx.Err() early-return guard present on every other exported method.
backend/internal/adapters/agent/kimi/kimi_test.go Thorough unit tests covering permission modes, restore-command, no-op hooks, and context cancellation; TestContextCancellation omits GetLaunchCommand, leaving the cached-binary path untested for cancellation.
backend/internal/adapters/agent/registry/registry.go Single-line addition of kimi.New() to Constructors(); follows the established registration pattern with no issues.
backend/internal/daemon/wiring_test.go Adds domain.HarnessKimi/"kimi" to the resolver test table; correct and consistent with how other adapters are verified.

Sequence Diagram

sequenceDiagram
    participant Caller
    participant Plugin as kimi.Plugin
    participant Cache as resolvedBinary cache
    participant Resolve as ResolveKimiBinary

    Caller->>Plugin: GetLaunchCommand(ctx, cfg)
    Plugin->>Cache: resolvedBinary set?
    alt binary cached
        Cache-->>Plugin: return cached path
    else not cached
        Plugin->>Resolve: ResolveKimiBinary(ctx)
        Resolve-->>Plugin: binary path / error
        Plugin->>Cache: store resolved path
    end
    Plugin->>Plugin: appendApprovalFlags(cmd, cfg.Permissions)
    Plugin->>Plugin: append -p prompt (if set)
    Plugin-->>Caller: "[]string{binary, [flags], -p, prompt}"

    Caller->>Plugin: GetRestoreCommand(ctx, cfg)
    Plugin->>Plugin: ctx.Err() check
    Plugin->>Plugin: TrimSpace(agentSessionID)
    alt no agentSessionID
        Plugin-->>Caller: nil, false, nil
    else has agentSessionID
        Plugin->>Cache: resolvedBinary set?
        Plugin->>Plugin: appendApprovalFlags + --session id
        Plugin-->>Caller: "[]string{binary, [flags], --session, id}, true, nil"
    end
Loading

Reviews (2): Last reviewed commit: "feat(agents): add kimi adapter" | Re-trigger Greptile

Comment thread backend/internal/adapters/agent/kimi/kimi.go Outdated
Comment thread backend/internal/adapters/agent/kimi/kimi.go Outdated
Registers the kimi harness, stacked on the agent platform.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@yyovil yyovil force-pushed the agents/14-cline branch from 4a34b6c to 3925e6b Compare June 6, 2026 03:31
@harshitsinghbhandari harshitsinghbhandari added this to the rewrite milestone Jun 6, 2026
Kimi rejects `--prompt` combined with `--yolo`/`--auto`/`--plan`, and
rejects `--yolo`/`--auto` combined with `--session`/`--continue`
(non-interactive and resumed sessions inherit the auto permission
policy). The previous mapping appended one of those flags before `-p`
on every launch and before `--session` on every restore, so every
non-interactive launch would fail at startup. The local binary
(v1.37.0) additionally has no `--auto` option at all, which would
fail even on otherwise-permissible paths.

- GetLaunchCommand: emit approval flags only on the interactive path
  (no prompt). The `-p <prompt>` path is now bare.
- GetRestoreCommand: never emit approval flags; resumed sessions
  inherit the original session's approval settings.
- Tests assert no approval/plan flag leaks onto either path for any
  PermissionMode, and keep the interactive mapping unchanged.

Refs: https://moonshotai.github.io/kimi-code/en/reference/kimi-command.html
Copy link
Copy Markdown
Contributor

@greptile-apps greptile-apps Bot left a comment

Choose a reason for hiding this comment

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

yyovil has reached the 50-review limit for trial accounts. To continue receiving code reviews, upgrade your plan.

@harshitsinghbhandari
Copy link
Copy Markdown
Collaborator

Verified against upstream Kimi Code docs and shipped binary (v1.37.0), then pushed a fix on top of ce6018e.

Findings re-verified (confirmed):

Two flag-conflict rules from https://moonshotai.github.io/kimi-code/en/reference/kimi-command.html:

"--prompt cannot be used with --yolo, --auto, or --plan — non-interactive mode uses auto permission by default"

"--yolo and --auto cannot be used together with --continue or --session — resumed sessions inherit the approval settings of the original session"

Binary-level check (kimi --help, v1.37.0):

  • --yolo / -y (aliases --yes, --auto-approve) — auto-approve all actions
  • --prompt / -p (alias --command / -c) — provide prompt non-interactively
  • --plan — plan mode
  • --auto is not present on this binary at allkimi --auto … errors with No such option: --auto (Possible options: --agent, --auto-approve, --quiet). So the existing --auto mapping was doubly broken on v1.37.0.

The previous adapter unconditionally prepended --auto or -y before both -p (launch) and --session (restore), violating both rules. Every non-interactive launch and every resume would be rejected at startup.

Changes (backend/internal/adapters/agent/kimi/):

  • kimi.go:76-95GetLaunchCommand: approval flags emitted only on the interactive path (no prompt). The -p <prompt> path is now bare.
  • kimi.go:108-128GetRestoreCommand: never emits approval flags; resumed sessions inherit the original session's approval settings. Updated docstring to note cfg.Permissions is intentionally ignored here.
  • kimi.go:148-162appendApprovalFlags docstring spells out it's interactive-only.
  • kimi_test.go — two new table tests assert no --auto/-y/--yolo/--yes/--auto-approve/--plan leaks onto the -p launch or the --session restore for any PermissionMode. The interactive launch mapping is preserved and still verified.

Validation:

  • go build ./... — clean
  • go test -race ./... — 940 tests / 56 packages, 0 failures

Pushed with --force-with-lease (cleanly fast-forwarded from ce6018e). No design changes, no touch outside kimi/.

@harshitsinghbhandari harshitsinghbhandari merged commit 44964c5 into agents/14-cline Jun 6, 2026
8 checks passed
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.

2 participants