---
name: kimi-delegation
description: Use when delegating review, adversarial review, rescue, and setup to Kimi Code CLI.
user-invocable: true
---
<!-- GENERATED by scripts/ci/sync-external-model-contracts.mjs. Edit scripts/lib/external-model-contracts.mjs instead. -->

# Kimi Delegation

EXTERNAL_MODEL_CONTRACT_VERSION=1

`<plugin-root>` is `plugins/kimi` or an absolute path to that plugin directory. Use skill `relay-kimi:kimi-delegation`.

Run review:
- `node "<plugin-root>/scripts/kimi-companion.mjs" run --mode=review --foreground --lifecycle-events markdown --cwd "<workspace>" --scope-base REF -- "<review focus>"`

Run adversarial review:
- `node "<plugin-root>/scripts/kimi-companion.mjs" run --mode=adversarial-review --foreground --lifecycle-events markdown --cwd "<workspace>" --scope-base REF -- "<design or diff to challenge>"`

Run custom-review:
- `node "<plugin-root>/scripts/kimi-companion.mjs" run --mode=custom-review --foreground --lifecycle-events markdown --cwd "<bundle-or-workspace>" --scope-paths "PR.diff,docs/*.md" -- "<review focus using relative paths>"`
If concrete files or --scope-paths are already known, do not run branch-diff first; use custom-review with those paths and the original prompt.

Run rescue:
- `node "<plugin-root>/scripts/kimi-companion.mjs" run --mode=rescue --foreground --lifecycle-events markdown --cwd "<workspace>" -- "<task>"`
- `node "<plugin-root>/scripts/kimi-companion.mjs" run --mode=rescue --background --lifecycle-events markdown --cwd "<workspace>" -- "<task>"`

Continue a job:
- `node "<plugin-root>/scripts/kimi-companion.mjs" continue --job "<job-id>" --foreground --lifecycle-events markdown --cwd "<workspace>" -- "<follow-up>"`
- If a continue attempt returns `resend_confirmation_required`, do not retry automatically. Rerun with `--resend-confirmation-approved` only after explicit operator confirmation, or narrow the source packet.

Cancel a background job:
- `node "<plugin-root>/scripts/kimi-companion.mjs" cancel --job "<job-id>" --cwd "<workspace>"`

Run setup:
- `node "<plugin-root>/scripts/kimi-companion.mjs" doctor --cwd "<workspace>"`

For Kimi review, adversarial-review, custom-review, or rescue, add `--max-steps-per-turn N` before `--` when the user provides a positive integer step budget.

`<workspace>` is the repository or bundle directory to review. `<focus>` is the user's review prompt or focus area.
`<job-id>` is the identifier returned by a background launch or listed by the status workflow.

## Review Contract
This is a review-only contract.
Do not fix findings, apply patches, edit files, or start rescue work from a review result.
Preserve the caller's review text verbatim after routing documented flags.
Return the runtime output verbatim; do not summarize or rewrite findings.
If there is no substantive result or structured output, report review blocked / no findings produced.
Render `external_review_launched` as soon as it appears.
Render `external_review` before findings, status prose, or the review result.
Render findings first, ordered by severity. Keep blocking and non-blocking findings distinct.
Surface `mutations` prominently and do not auto-revert them.

## Rescue Contract
This is a rescue contract, not a review contract.
Rescue may investigate, edit files, and run verification when the user asks for implementation work.
Forward the user's task text after routing documented flags; do not replace it with a new plan.
Return the runtime output verbatim; do not hide failed or incomplete rescue work.
Failed or incomplete rescue is not success. Report the failed state and the next safe action.

Use the default Codex sandbox for each source-bearing `run` command when current sandbox permissions already cover workspace reads, plugin state writes, credentials, and network.
Do not request `sandbox_permissions: "require_escalated"` for a normal source send; use escalation only for source-free setup/access repair after a `sandbox_blocked` result.
If the default sandbox blocks provider auth, job state, temp files, or network access, stop and report `sandbox_blocked` with `source_content_transmission: "not_sent"` instead of retrying the same source send with broad escalation.

## Rendering Contract
Request `--lifecycle-events markdown` for foreground and background review flows.
Render lifecycle markdown cards directly.
If a legacy JSON lifecycle envelope appears, render `external_review_launched` immediately.
`external_review_progress` is a heartbeat for long foreground runs; keep the existing launch card visible and do not render it as a terminal result.
If a background launch envelope has `event: "launched"` with an `external_review` field, render the same launch card immediately with session pending.
If a legacy JSON `external_review` field appears, render it before normal prose.
Lifecycle cards should include provider, job, session, run kind, mode, scope, source transmission, source bearing, selected route, fallback reason, auth path, billing path, source-send approval state, approval scope, review quality, status, error code, error message, HTTP status, and suggested action when those fields are present.

```md
### EXTERNAL REVIEW

| Field | Value |
| --- | --- |
| Provider | <provider> |
| Job | <job_id> |
| Session | <session_id or pending> |
| Run | <foreground|background|unknown> |
| Mode | <mode> |
| Scope | <scope and scope_base/scope_paths> |
| Source | <source_content_transmission> |
| Source Bearing | <source_bearing> |
| Route | <selected_route> |
| Fallback | <fallback_reason> |
| Auth | <auth_path> |
| Billing | <billing_path> |
| Approval | <source_send_approval_state / approval_scope> |
| Review Quality | <review_quality.failed_review_slot / review_quality.semantic_failure_reasons> |
| Status | <status> |
| Error | <error_code> |
| Message | <error_message> |
| HTTP | <http_status> |
| Action | <suggested_action> |
```

Do not claim commands are available in Codex builds that do not register plugin command files.
## Secret Safety
Do not print raw OAuth tokens, API-key values, session cookies, tunnel API keys, bearer tokens, or raw secret values.
Credential diagnostics may show key names only.

## Scope Safety
A git worktree can filter gitignored files before selected source is sent.
A non-git directory cannot rely on gitignore filtering; distinguish non-git source directories from paths inside a git worktree.
Preflight scope failures such as `scope_base_missing`, `scope_base_invalid`, `scope_requires_git`, `scope_requires_head`, `scope_paths_required`, and `scope_empty` happen before external source transmission and should report `source_content_transmission: "not_sent"`.
