Skip to content
This repository was archived by the owner on Sep 23, 2026. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from 43 commits
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
65c2e18
feat(soul): RalphFlow architecture with ephemeral context and converg…
ordl-winsock Apr 20, 2026
1d20525
fix: address automated review feedback for RalphFlow PR
ordl-winsock Apr 20, 2026
43fbd98
test: fix pre-existing e2e flaky test and update flow skill snapshot …
ordl-winsock Apr 20, 2026
0cdc34d
fix(soul,auth): address remaining Codex review feedback
ordl-winsock Apr 20, 2026
453199e
fix(soul,mcp,kosong): address remaining Devin and Codex review feedback
ordl-winsock Apr 20, 2026
bed6842
fix(soul,mcp): address remaining open review feedback for RalphFlow PR
ordl-winsock Apr 20, 2026
dfc66df
fix(soul): address Devin convergence and flow_decision tool reviews
ordl-winsock Apr 20, 2026
5b1e524
fix(soul): address Codex P1/P2 reviews on ephemeral merge and converg…
ordl-winsock Apr 21, 2026
8675d33
fix(soul,test): address Devin P1/P2 reviews
ordl-winsock Apr 21, 2026
1d643f0
fix(soul,mcp,kosong): address outstanding review feedback for PR #1960
ordl-winsock Apr 21, 2026
89cd5cd
fix(soul): ignore decision text in convergence checks on self-loops
ordl-winsock Apr 21, 2026
06894ad
Merge branch 'main' into main
ORDL-AMF Apr 21, 2026
95b3606
Merge remote-tracking branch 'upstream/main'
ordl-winsock Apr 21, 2026
224d7fd
Merge branch 'main' of https://github.com/Open-Research-Development-L…
ordl-winsock Apr 21, 2026
1c77d7e
fix(soul): sync _system_prompt in ephemeral compaction merge path
ordl-winsock Apr 21, 2026
aaf47c9
fix(soul,tools,ui): address remaining Devin and Codex review feedback…
ordl-winsock Apr 22, 2026
9f348fc
Merge remote-tracking branch 'upstream/main'
ordl-winsock Apr 22, 2026
d0e0022
fix(soul): scope flow_decision tool to decision nodes and halt loop a…
ordl-winsock Apr 22, 2026
d49a608
Merge remote-tracking branch 'upstream/main'
ordl-winsock Apr 22, 2026
26e1695
docs: update RalphFlow documentation across README, changelogs, and r…
ordl-winsock Apr 22, 2026
ee13856
Merge remote-tracking branch 'upstream/main'
ordl-winsock Apr 23, 2026
c7464de
test(ralphflow): fix convergence test to actually test convergence
ordl-winsock Apr 23, 2026
1aaf77c
fix(soul): sanitize flow temp file names and use atomic replace on co…
ordl-winsock Apr 23, 2026
a623fba
chore: add untracked dev scripts and RalphFlow docs
ordl-winsock Apr 23, 2026
b239907
chore: add AGENT-SPEC-REFERENCE.md to gitignore
ordl-winsock Apr 23, 2026
6483f56
chore: correct gitignore path for AGENT-SPEC-REFERENCE.md
ordl-winsock Apr 23, 2026
3e7c55a
docs(AGENTS): add hard rule for flow_decision tool usage
ordl-winsock Apr 24, 2026
c0d99fa
Merge remote-tracking branch 'upstream/main'
ordl-winsock Apr 24, 2026
6899a0b
Merge remote-tracking branch 'upstream/main' into main
ordl-winsock Apr 25, 2026
0b59e56
fix(soul,convergence,mcp): address outstanding Codex/Devin review fee…
ordl-winsock Apr 25, 2026
2666379
fix(soul): address additional Codex/Devin review feedback for PR #1960
ordl-winsock Apr 25, 2026
a5dc50a
fix(tools): upload videos via Kimi files API for agent-gw sessions
ordl-winsock Apr 25, 2026
f607db4
fix(soul,mcp): fix agent loop regression and PAUSE merge behavior for…
ordl-winsock Apr 25, 2026
a1bc3b2
fix(soul,convergence): address new Codex/Devin review feedback for PR…
ordl-winsock Apr 25, 2026
4c2125e
fix(soul,tools,config,auth,tests): address review feedback and fix pr…
ordl-winsock Apr 28, 2026
bacf903
fix(soul,auth,llm): address remaining RalphFlow review comments
ordl-winsock Apr 28, 2026
1c83727
fix(config,ui): enforce ge=1000 on KIMI_RESERVED_CONTEXT_SIZE and pre…
ordl-winsock Apr 28, 2026
43870e3
Merge remote-tracking branch 'upstream/main'
ordl-winsock Apr 28, 2026
f50975b
fix(soul): retry invalid flow decisions before terminating loop
ordl-winsock Apr 28, 2026
084398d
fix(ui): preserve user-configured max_context_size during /setup
ordl-winsock Apr 28, 2026
5a01d8b
Merge remote-tracking branch 'upstream/main'
ordl-winsock Apr 28, 2026
599d757
fix(flow): force flow_decision tool usage by hiding all other tools d…
ordl-winsock Apr 28, 2026
13bfecc
Merge upstream/main: yolo/afk mode refactor + kimi-cli 1.40.0 / koson…
ordl-winsock Apr 29, 2026
bb58646
Merge upstream/main into PR #1960
ordl-winsock May 5, 2026
2097fcf
fix(flow): rerun task work after CONTINUE decisions
ordl-winsock May 5, 2026
92e8ca9
fix(web): remove vulnerable node polyfill dependency
ordl-winsock May 5, 2026
7f4ce36
fix(vis): update vulnerable frontend dependencies
ordl-winsock May 5, 2026
8bbc06f
fix(deps): resolve Python dependency vulnerabilities
ordl-winsock May 5, 2026
468dbf9
fix(deps): update black security patch
ordl-winsock May 5, 2026
3d49c11
fix(security): disable clean-builder reclone path
ordl-winsock May 6, 2026
db55a86
build(script): parallelize clean builder
ordl-winsock May 6, 2026
174d491
fix(wire): restore ipc server mode
ordl-winsock May 6, 2026
74c2516
fix(wire): return ipc json-rpc errors
ordl-winsock May 6, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ build/
dist/
wheels/
*.egg-info
.claude/

# Virtual environments
.venv
Expand Down Expand Up @@ -40,11 +41,21 @@ result-*
# macOS files
.DS_Store

# Development artifacts
build.sh
cleanup.sh
handoffs/
kimi.log
.codex
PYEOF

# Rust files
target/

node_modules/
static/
.memo/
.entire
.claude
.watch_merge.sh
.watch_merge.log
docs/AGENT-SPEC-REFERENCE.md
Comment thread
ORDL-AMF marked this conversation as resolved.
80 changes: 80 additions & 0 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,70 @@ If running tools directly, use `uv run ...`.
Kimi Code CLI is a Python CLI agent for software engineering workflows. It supports an interactive
shell UI, ACP server mode for IDE integrations, and MCP tool loading.

## LLM Provider Configuration

### Default model

The default model is `kimi-for-coding` (beta preview), served through the **agent gateway**.

### Agent Gateway

When the provider `base_url` contains `agent-gw.kimi.com`, the CLI automatically switches from
OpenAI Chat Completions format to **Anthropic Messages API** format. This is handled transparently
in `src/kimi_cli/llm.py`.

```toml
[models."kimi-code/kimi-for-coding"]
provider = "managed:kimi-code"
model = "kimi-for-coding"
max_context_size = 2000000
capabilities = ["video_in", "image_in", "thinking"]

[providers."managed:kimi-code"]
type = "kimi"
base_url = "https://agent-gw.kimi.com/coding/v1"
api_key = "sk-kimi-..."
```

### API format details

| Endpoint | Method | Format |
|----------|--------|--------|
| `/coding/v1/messages` | POST | Anthropic Messages API |
| `/coding/v1/models` | GET | OpenAI-compatible list |
| `/coding/v1/usages` | GET | Platform quota info |
| `/coding/v1/feedback` | POST | Feedback submission |

The Anthropic SDK appends `/v1/messages` to the base URL. The CLI strips the trailing `/v1`
from `base_url` before passing it to the Anthropic client when `agent-gw` is detected.

### Environment overrides

| Variable | Effect |
|----------|--------|
| `KIMI_BASE_URL` | Overrides provider `base_url` |
| `KIMI_API_KEY` | Overrides provider `api_key` |
| `KIMI_MODEL_NAME` | Overrides model name |
| `KIMI_MODEL_MAX_CONTEXT_SIZE` | Overrides `max_context_size` |
| `KIMI_MODEL_TEMPERATURE` | Sets generation temperature |
| `KIMI_MODEL_TOP_P` | Sets top-p sampling |
| `KIMI_MODEL_MAX_TOKENS` | Sets max output tokens |

### Model capabilities (kimi-for-coding)

- **Architecture**: MoE, 1T params (32B active)
- **Context**: 262,144 tokens (reported by API) / up to 2M (configurable)
- **Input**: text, image, video
- **Reasoning**: thinking/reasoning content supported
- **Embeddings**: `bge_m3_embed`, 1024-dim via `/coding/v1/embeddings`
- **Training cutoff**: January 2025

### Preserving custom base URLs on login

When running `/login`, the OAuth flow normally overwrites the provider config with the platform's
hardcoded `api.kimi.com` URL. The CLI now preserves an existing custom `base_url` (e.g.
`agent-gw.kimi.com`) during login, so the agent gateway setting is not lost.

## Tech stack

- Python 3.12+ (tooling configured for 3.14)
Expand Down Expand Up @@ -87,6 +151,8 @@ shell UI, ACP server mode for IDE integrations, and MCP tool loading.
- `src/kimi_cli/tools/`: built-in tools
- `src/kimi_cli/ui/`: UI frontends (shell/print/acp/wire)
- `src/kimi_cli/acp/`: ACP server components
- `src/kimi_cli/auth/`: OAuth, platform definitions, and API key resolution
- `src/kimi_cli/mcp.py`: MCP server management and configuration
- `packages/kosong/`, `packages/kaos/`: workspace deps
+ Kosong is an LLM abstraction layer designed for modern AI agent applications.
It unifies message structures, asynchronous tool orchestration, and pluggable
Expand All @@ -104,6 +170,8 @@ shell UI, ACP server mode for IDE integrations, and MCP tool loading.
- Tests use pytest + pytest-asyncio; files are `tests/test_*.py`.
- CLI entry points: `kimi` / `kimi-cli` -> `src/kimi_cli/__main__.py` (routes to `src/kimi_cli/cli/__init__.py`).
- User config: `~/.kimi/config.toml`; logs, sessions, and MCP config live in `~/.kimi/`.
- OpenClaw config: `~/.openclaw/openclaw.json` (separate agent gateway bridge)
- Kimi Claw config: `~/.kimi/kimi-claw/kimi-claw-config.json` (WebSocket bridge to agent gateway)

## Git commit messages

Expand Down Expand Up @@ -143,3 +211,15 @@ and skill workflows.
- `git tag 0.68` or `git tag pykaos-0.5.3`
- `git push --tags`
9. GitHub Actions handles the release after tags are pushed.

## Agent behavior — flow control

When a `[Flow control]` system-reminder appears, **you MUST use the `flow_decision` tool** to
choose CONTINUE, STOP, or PAUSE. Do not reply with plain text. Do not reason your way around
the instruction. The tool is real, it works, and you have used it before.

**Hard rules:**
- If the system says "You MUST use the flow_decision tool," call it immediately.
- Never claim the tool does not exist, is a pseudo-tool, or is unavailable.
- Never substitute a text response when the system demands a flow_decision call.
- If you are confused about whether the tool exists, trust the system instruction and call it anyway.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ Only write entries that are worth mentioning to users.
- Core: Approval requests no longer auto-timeout after 5 minutes, which previously surfaced as `Rejected by user`; active foreground and subagent approvals now wait indefinitely for user response
- Shell: Fix `/usage` remaining quota rendering — the progress bar, warning colors, and `% left` label now all use the remaining quota ratio consistently, so high remaining quota shows as green/full and near-exhausted quota shows as yellow or red
- Shell: Show active background agent task count in the prompt status bar — the existing `⚙ bash: N` badge only counted background Shell tasks and filtered out background Agent subagents, so when many subagents were running the prompt looked idle and users could not tell work was in progress; the toolbar now renders `⚙ bash: N` and `⚙ agent: N` as two independent badges (each hidden when its count is 0) and drops the agent badge first when the terminal is too narrow to fit both
- Soul: RalphFlow architecture improvements — `flow_decision` tool is now scoped to decision nodes only, preventing misuse during task execution; the agent loop halts immediately after a `flow_decision` call, stopping extra content generation after the decision is recorded; convergence detection auto-stops repeating flows when the model repeats identical work across iterations
- Soul: Fix ephemeral context merge after compaction during RalphFlow — when context compaction occurs inside a flow, the merged result now correctly preserves the compacted state instead of dropping messages
- Auth: Fix managed model list refresh silently failing for OAuth users with expired tokens — the background `/models` sync now detects 401 responses, forces an OAuth token refresh, and retries with the refreshed token; if the refresh fails or the refreshed token is still rejected, it falls back to the originally configured static API key instead of skipping the provider
- Core: Fix connection recovery not triggering OAuth refresh when the retry returns 401 — after recreating the HTTP client on `APIConnectionError` or `APITimeoutError`, the retry now re-enters the full recovery path so a subsequent 401 correctly refreshes the OAuth token instead of bubbling to the user as an unrecoverable error
- Shell: Echo `/skill:*` and `/flow:*` inputs in the transcript so workflow commands stay visible after enter; operational slash commands like `/usage` and `/model` remain hidden
Expand Down
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,17 @@ Run `kimi` with `--mcp-config-file` option to connect to the specified MCP serve
kimi --mcp-config-file /path/to/mcp.json
```

### RalphFlow automated iteration

Kimi Code CLI supports RalphFlow, an automated iteration architecture that lets the agent loop through a task until it decides to stop. Each iteration runs in an isolated ephemeral context that merges back into the main conversation history when the loop finishes. Convergence detection automatically stops repeating work to prevent infinite loops.

Enable RalphFlow by setting `max_ralph_iterations` in your config:

```toml
[loop_control]
max_ralph_iterations = 10 # 0 disables, -1 is unlimited
```

### More

See more features in the [Documentation](https://moonshotai.github.io/kimi-cli/en/).
Expand Down
203 changes: 203 additions & 0 deletions clean-kimi-builder-rhel97.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,203 @@
#!/usr/bin/env bash
set -Eeuo pipefail
shopt -s nullglob

REPO_URL="${REPO_URL:-https://github.com/Open-Research-Development-Laboratories/kimi-cli-dev.git}"
SRC="${SRC:-$HOME/src/kimi-cli-dev}"
NODE_STREAM="${NODE_STREAM:-nodejs:24}"
RECLONE="${RECLONE:-0}"

# Default is conservative. Strict mode only prepares/removes user-installed RPMs if explicitly confirmed.
STRICT_PACKAGE_PURGE="${STRICT_PACKAGE_PURGE:-0}"
CONFIRM_STRICT_REMOVE="${CONFIRM_STRICT_REMOVE:-0}"

SNAP="${SNAP:-$HOME/kimi-clean-snapshots/$(date -u +%Y%m%dT%H%M%SZ)}"
PATH="$HOME/.local/bin:$PATH"

log() { printf '\n==> %s\n' "$*"; }
need() { command -v "$1" >/dev/null 2>&1; }

mkdir -p "$SNAP"

log "Snapshot package state: $SNAP"
rpm -qa | sort > "$SNAP/rpm-qa.before.txt" || true
dnf repoquery --userinstalled --qf '%{name}' | sort -u > "$SNAP/dnf-userinstalled.before.txt" || true
dnf history list > "$SNAP/dnf-history.before.txt" || true

# Minimal builder/runtime base for rebuilding kimi-cli from source.
# Keep system Python/DNF/RPM intact; uv will provide the project Python 3.14.
REQUIRED_RPMS=(
ca-certificates
curl
wget
git
make
tar
gzip
bzip2
xz
unzip
zip
which
file
patch
diffutils
findutils
grep
sed
gawk
rsync
procps-ng
util-linux

dnf
rpm
python3
python3-libs
python3-dnf
sudo
openssh-clients
redhat-release

gcc
gcc-c++
glibc-devel
binutils
redhat-rpm-config
pkgconf-pkg-config
openssl-devel
libffi-devel
zlib-devel
bzip2-devel
xz-devel
sqlite-devel
readline-devel
ncurses-devel
tk-devel
libuuid-devel
)

# Optional fallback for Python packages that lack wheels on your architecture/Python ABI.
OPTIONAL_RPMS=(
rust
cargo
)

log "Install/keep minimal builder RPMs"
sudo dnf -y install --setopt=install_weak_deps=False "${REQUIRED_RPMS[@]}"

log "Install Node/npm module stream: $NODE_STREAM"
sudo dnf -y module reset nodejs || true
sudo dnf -y module install "$NODE_STREAM"

log "Install optional Rust fallback toolchain if available"
sudo dnf -y install --setopt=install_weak_deps=False "${OPTIONAL_RPMS[@]}" || true

log "Mark required RPMs as user-installed so autoremove does not eat the builder"
sudo dnf -y mark install "${REQUIRED_RPMS[@]}" nodejs npm || true

log "Remove orphaned dependency RPMs and clean DNF metadata/package cache"
sudo dnf -y autoremove
sudo dnf -y clean all

log "Install/update uv and Python 3.14 under the build user"
if ! need uv; then
curl --proto '=https' --tlsv1.2 -LsSf https://astral.sh/uv/install.sh | sh
export PATH="$HOME/.local/bin:$PATH"
fi

uv self update || true
uv python install 3.14

log "Validate Node version required by kimi-cli web/vis build"
node - <<'NODE'
const [maj, min] = process.versions.node.split(".").map(Number);
const ok = (maj === 20 && min >= 19) || (maj === 22 && min >= 12) || maj > 22;
if (!ok) {
console.error(`Node ${process.version} is too old; need ^20.19.0 or >=22.12.0.`);
process.exit(1);
}
console.log(`Node ${process.version} OK`);
NODE
npm --version

log "Clean project tree or reclone"
if [[ "$RECLONE" == "1" ]]; then
rm -rf -- "$SRC"
fi

if [[ ! -d "$SRC/.git" ]]; then
mkdir -p "$(dirname "$SRC")"
git clone "$REPO_URL" "$SRC"
else
git -C "$SRC" status --short > "$SNAP/git-status.before.txt" || true
git -C "$SRC" clean -ndX > "$SNAP/git-clean-ignored-preview.txt" || true

# Removes ignored build artifacts only: .venv, dist, build, node_modules, caches, generated static assets, etc.
# It does not remove untracked source files unless they are ignored by .gitignore.
git -C "$SRC" clean -fdX
fi

log "Clean Python/Node/global build caches"
uv cache clean || true
npm cache clean --force || true

rm -rf -- \
"$HOME/.cache/pip" \
"$HOME/.cache/pipx" \
"$HOME/.cache/pypoetry" \
"$HOME/.cache/pre-commit" \
"$HOME/.cache/ruff" \
"$HOME/.cache/pyright" \
"$HOME/.cache/node-gyp" \
"$HOME/.node-gyp" \
"$HOME/.npm/_npx" \
"$HOME/.npm/_cacache"

find "$SRC" -depth \( \
-name "__pycache__" -o \
-name ".pytest_cache" -o \
-name ".ruff_cache" -o \
-name ".mypy_cache" -o \
-name ".pyright" \
\) -exec rm -rf -- {} + 2>/dev/null || true

if [[ "$STRICT_PACKAGE_PURGE" == "1" ]]; then
log "Prepare strict user-installed RPM removal candidate list"

{
printf '%s\n' "${REQUIRED_RPMS[@]}"
printf '%s\n' nodejs npm
printf '%s\n' "${OPTIONAL_RPMS[@]}"
} | sort -u > "$SNAP/rpm-keep-builder.txt"

dnf repoquery --userinstalled --qf '%{name}' | sort -u > "$SNAP/dnf-userinstalled.current.txt" || true

comm -23 "$SNAP/dnf-userinstalled.current.txt" "$SNAP/rpm-keep-builder.txt" \
| grep -Ev '^(NetworkManager|audit|authselect|basesystem|bash|chrony|coreutils|crypto-policies|dbus|dnf|dracut|filesystem|firewalld|glibc|grub2|kernel|lib.*|linux-firmware|lvm2|microcode_ctl|openssh|passwd|policycoreutils|python3|redhat|rpm|selinux|setup|shadow-utils|shim|sssd|subscription-manager|sudo|systemd|tuned|util-linux|xfsprogs)$' \
> "$SNAP/rpm-remove-candidates.txt" || true

if [[ -s "$SNAP/rpm-remove-candidates.txt" ]]; then
log "Strict purge candidates written to $SNAP/rpm-remove-candidates.txt"
xargs -r sudo dnf --assumeno remove < "$SNAP/rpm-remove-candidates.txt" | tee "$SNAP/dnf-strict-remove-dryrun.txt" || true

if [[ "$CONFIRM_STRICT_REMOVE" == "1" ]]; then
xargs -r sudo dnf -y remove < "$SNAP/rpm-remove-candidates.txt"
sudo dnf -y autoremove
sudo dnf -y clean all
else
echo "Review the dry-run first. To actually remove those RPMs, rerun with:"
echo "STRICT_PACKAGE_PURGE=1 CONFIRM_STRICT_REMOVE=1 $0"
fi
else
echo "No strict purge candidates."
fi
fi

log "Done. Rebuild with:"
cat <<EOF
cd "$SRC"
make prepare
make build
make build-bin
EOF
Loading