# @ycodium-ai/agent-kimi

Kimi Code executor plugin. Spawns `kimi acp` over stdio and runs the shared
`ycodium-acp-executor` state machine.

- `driverKind` is `kimiCode`. The envelope is `{ driver: "kimiCode", config: { binaryPath, homePath,
customModels } }`; launch arguments (`acp`) and the account-directory variable (`KIMI_CODE_HOME`)
  come from the card.
- Kimi's differences go through `AcpVendorHooks` (`src/kimi.ts`): its `AskUserQuestion` /
  `ExitPlanMode` ride on `session/request_permission` and must stay structured user input, and its
  context usage is read from the CLI's own session log.
- Models come from the read-only `kimi provider list --json` (`src/kimiModels.ts`); the version
  from `kimi --version`. No probe session is created.
- Sign-in is `kimi login` (device-code flow), upgrade is `kimi upgrade --yes`.
- Runtime modes map to native permissions: auto and auto-accept-edits → yolo, full-access → auto, approval-required → default.
  The auto-accept-edits mapping is an approximation and may allow more than edits. Kimi has no
  edits-only automatic native mode: default asks for approvals and plan does not execute tools.
  YOLO means Ask When Needed: routine edits and commands run automatically, while risky
  operations, questions, and plans still ask. Auto means Never Ask:
  everything runs automatically, including risky operations.
  Kimi 2.3.1's ACP handshake describes these two modes incorrectly; the report follows `kimi --help`
  and maintainer CLI verification.
  A selected native mode governs approvals. Without native modes, auto permits MCP dynamic tools
  (ACP kind `other` with an MCP name); questions and plan confirmations remain user input.
- Turn failures: Kimi 2.7.0 can return ACP `end_turn` after a provider error. The executor checks
  the main agent’s newly appended `turn.prompt` and `turn.ended` records for the same native turn.
  It waits up to one second for a delayed log flush. Missing or inconclusive records leave the ACP
  result in effect. A confirmed quota error carries the provider’s message and the `quota` category.
- Usage (ADR-0034), per instance, read only when the user asks. The account directory is the
  `homePath` setting, an explicit `KIMI_CODE_HOME` in the instance environment, then the process
  environment, then `~/.kimi-code`:
  - Quota (`src/kimiQuota.ts`): `GET <base_url>/usages` with the access token from
    `credentials/kimi-code.json`, through `host.fetch`. `base_url` is `KIMI_CODE_BASE_URL`, else the
    one in `config.toml`, else the CLI default `https://api.kimi.com/coding/v1`; a non-official host
    reports `customEndpoint`. The token lives ~15 minutes and only the CLI renews it: an expired token
    reports `missingCredentials`, the refresh token is never used. Windows are labelled from
    `{duration, timeUnit}` (`5h`, `7d`).
  - Tokens (`src/kimiTokens.ts`): `readTokenUsage` reads the `usage.record` lines of every
    `sessions/*/*/agents/*/wire.jsonl` (the ACP reply carries no usage), deduplicating fork copies, with an
    in-memory byte-offset resume.
- Terminal session import discovers Kimi Code sessions in the selected working directory.
  Reads main-agent transcripts from the selected Kimi Code account directory. Resume uses the existing ACP session ID.
- Manifest permission is `{ kind: "executor" }`.

Shipped pre-installed as `core.agent-kimi`.

Golden replay (`src/replay.test.ts`) runs the real bytes recorded from `kimi acp` 2.0.1 through
`test/wireReplayPeer.mjs`. Re-record with `apps/server/scripts/record-acp-session.ts`; provenance
and what is **not** capturable on this machine are in `docs/internals/provider-recordings.md`.

Develop with `vp run --filter @ycodium-ai/agent-kimi typecheck`, `build`, and `test`.

## License

UNLICENSED.
