Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
6 changes: 6 additions & 0 deletions src/kimi_cli/cli/web.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""Web UI command for Kimi Code CLI."""

from pathlib import Path
from typing import Annotated

import typer
Expand Down Expand Up @@ -55,6 +56,10 @@ def web(
help="Only allow access from local network (default) or allow public access.",
),
] = True,
agent_file: Annotated[
Path | None,
typer.Option("--agent-file", help="Path to agent spec YAML file."),
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Validate --agent-file before starting web server

The new web CLI option accepts any path string without Typer path constraints, so an invalid/non-existent file is accepted at startup and the server still launches. The failure is deferred to worker startup when KimiCLI.create tries to load the agent spec, causing session-level crashes instead of an immediate actionable CLI error. Adding exists=True, file_okay=True, dir_okay=False, and readable=True here would prevent starting a broken server.

Useful? React with 👍 / 👎.

] = None,
):
"""Run Kimi Code CLI web interface."""
from kimi_cli.web.app import run_web_server
Expand All @@ -77,4 +82,5 @@ def web(
dangerously_omit_auth=dangerously_omit_auth,
restrict_sensitive_apis=restrict_sensitive_apis,
lan_only=lan_only,
agent_file=agent_file,
)
7 changes: 7 additions & 0 deletions src/kimi_cli/web/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ def _load_env_flag(key: str) -> bool:


ENV_LAN_ONLY = "KIMI_WEB_LAN_ONLY"
ENV_AGENT_FILE = "KIMI_WEB_AGENT_FILE"


def create_app(
Expand Down Expand Up @@ -235,6 +236,7 @@ def run_web_server(
dangerously_omit_auth: bool = False,
restrict_sensitive_apis: bool | None = None,
lan_only: bool = True,
agent_file: Path | None = None,
) -> None:
"""Run the web server."""
import sys
Expand Down Expand Up @@ -312,6 +314,11 @@ def run_web_server(
os.environ[ENV_RESTRICT_SENSITIVE_APIS] = "1" if restrict_sensitive_apis else "0"
os.environ[ENV_LAN_ONLY] = "1" if lan_only else "0"

if agent_file is not None:
os.environ[ENV_AGENT_FILE] = str(agent_file.resolve())
else:
os.environ.pop(ENV_AGENT_FILE, None)

# Determine display URLs
display_hosts: list[tuple[str, str]] = []
if host == "0.0.0.0":
Expand Down
12 changes: 10 additions & 2 deletions src/kimi_cli/web/runner/worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@

import asyncio
import json
import os
import sys
from pathlib import Path
from typing import Any
from uuid import UUID

Expand Down Expand Up @@ -45,16 +47,22 @@ async def run_worker(session_id: UUID) -> None:
path=default_mcp_file,
)

# Resolve agent file from environment (set by `kimi web --agent-file`)
agent_file_str = os.environ.get("KIMI_WEB_AGENT_FILE")
agent_file = Path(agent_file_str) if agent_file_str else None

# Create KimiCLI instance with MCP configuration
try:
kimi_cli = await KimiCLI.create(session, mcp_configs=mcp_configs or None)
kimi_cli = await KimiCLI.create(
session, agent_file=agent_file, mcp_configs=mcp_configs or None
)
Comment on lines +56 to +58
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Apply custom agent file only to new web sessions

This always passes the --agent-file value into KimiCLI.create, including when a session is being resumed. In KimiCLI.create (see src/kimi_cli/app.py), the restored context only overwrites system_prompt; the agent’s toolset/subagent config still comes from the newly loaded agent spec, so existing sessions can silently change capabilities after restart when web is launched with --agent-file. That can break follow-up turns for previously created sessions and violates the expected “new sessions only” behavior.

Useful? React with 👍 / 👎.

except MCPConfigError as exc:
logger.warning(
"Invalid MCP config in {path}: {error}. Starting without MCP.",
path=default_mcp_file,
error=exc,
)
kimi_cli = await KimiCLI.create(session, mcp_configs=None)
kimi_cli = await KimiCLI.create(session, agent_file=agent_file, mcp_configs=None)

# Run in wire stdio mode
await kimi_cli.run_wire_stdio()
Expand Down
Loading