Skip to content

feat(cli): run kimi web and the TUI /web command in the foreground by default#1853

Open
wbxl2000 wants to merge 5 commits into
mainfrom
feat/web-foreground-default
Open

feat(cli): run kimi web and the TUI /web command in the foreground by default#1853
wbxl2000 wants to merge 5 commits into
mainfrom
feat/web-foreground-default

Conversation

@wbxl2000

@wbxl2000 wbxl2000 commented Jul 17, 2026

Copy link
Copy Markdown
Collaborator

Related Issue

No prior issue — the problem is explained below.

Problem

kimi web and the TUI /web command both started the Kimi server as a background daemon and returned/exited immediately. The desired default is the opposite: keep the server in the foreground (terminal stays attached, Ctrl+C stops it) and make background operation an explicit opt-in.

What changed

  • kimi web defaults to foreground. It shares the same buildRunCommand/handleRunCommand implementation as kimi server run; a new defaultForeground option flips only the web alias, and a new --background flag (registered only on web) restores the old daemon behavior. kimi server run is untouched — still background by default with --foreground to attach.
  • Foreground kimi web reuses a running server. Binding the default port while a daemon already runs would fail, so the command probes the live lock first (via the same findReusableDaemon check ensureDaemon uses) and opens the browser against the existing server instead.
  • TUI /web defaults to foreground too. After confirmation it shuts the TUI down and hands the terminal to an in-process foreground server via a new exitForegroundTask hook in the exit path (the old flow always ended in process.exit). /web --background keeps the previous daemon behavior. When a server is already running it is reused in both modes.
  • Ready-banner Stop hint follows the hosting mode: attached-foreground servers show Stop: Ctrl+C (including in the danger notice), while background/reused servers keep kimi server kill. The /web handoff prints the same ready banner as kimi web plus the session deep link.
  • Tests cover both defaults, --background, the reuse path, and the TUI handoff; docs (EN/ZH) updated for kimi web and a previously missing /web entry was added. Ship decision: the bump stays minor, but the changeset entry is flagged Breakingkimi web no longer returns immediately; scripts and launchers that depend on that must pass --background. Upgrade note: an already-running server is reused as-is across upgrades; when its recorded version differs from the CLI, a "Server version mismatch" line is printed (and shown as a /web status warning) — kimi server kill once restarts on the new version.

Checklist

  • I have read the CONTRIBUTING document.
  • I have linked a related issue, or explained the problem above.
  • I have added tests that prove my feature works.
  • Ran gen-changesets skill, or this PR needs no changeset.
  • Ran gen-docs skill, or this PR needs no doc update.

… default

kimi web and /web now start the server attached to the terminal (Ctrl+C
stops it) instead of backgrounding a daemon; --background opts back into
the daemon behavior. kimi server run is unchanged. A foreground kimi web
reuses an already-running server instead of failing to bind, the /web
handoff prints the same ready banner as kimi web (plus the session deep
link), and the banner Stop hint adapts to the hosting mode.
@changeset-bot

changeset-bot Bot commented Jul 17, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: decab3a

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@moonshot-ai/kimi-code Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@pkg-pr-new

pkg-pr-new Bot commented Jul 17, 2026

Copy link
Copy Markdown
pnpm dlx https://pkg.pr.new/@moonshot-ai/kimi-code@decab3a
npx https://pkg.pr.new/@moonshot-ai/kimi-code@decab3a

commit: decab3a

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 2eba4ae8d5

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread apps/kimi-code/src/tui/commands/web.ts Outdated
// and token in green under the status line so they can be copied before the
// terminal exits. Best-effort: an older/never-started server has no token
// file, so we fall back to the plain URL and skip the token line.
const token = tryResolveServerToken(getDataDir());

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 Resolve the server token after first-time startup

When /web is run with a fresh KIMI_CODE_HOME, this lookup occurs before either ensureDaemon() or startServerForeground() creates server.token, so token remains undefined and the browser opens without the required #token= credential. This affects both /web --background and the new foreground default, leaving first-time users at the authentication gate after the TUI has exited; resolve the token after ensureDaemon() returns or inside the foreground onReady callback.

Useful? React with 👍 / 👎.

The token lookup had moved ahead of ensureDaemon()/startServerForeground()
during the foreground-default refactor, so a first-time start (no
server.token on disk yet) opened the browser without the #token= fragment
and left the user at the auth gate. Resolve the token after the daemon is
healthy, and inside the foreground ready hook.
@wbxl2000

Copy link
Copy Markdown
Collaborator Author

@codex

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: cc9267cbbc

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

@@ -0,0 +1,5 @@
---
"@moonshot-ai/kimi-code": minor

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 Obtain approval for the required major version bump

For scripts or launchers that invoke kimi web expecting it to return after starting a daemon, this change makes the command block until the foreground server is interrupted, so it is an incompatible behavior-semantic change. The root AGENTS.md explicitly requires such changes to use a major bump only after user confirmation; publishing this as minor would unexpectedly break those callers. Obtain that confirmation and change the bump to major, or preserve the previous default behavior.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Acknowledged that this is a behavior-semantics change — that is intentional and was explicitly discussed before opening the PR. The maintainers' decision for this release line is to keep the bump at minor while flagging the break prominently instead of withholding the change behind a major: the changeset entry is now prefixed with Breaking and spells out both the new default (foreground until Ctrl+C) and the mitigation for scripts/launchers (--background restores the previous immediate-return daemon behavior). Anyone calling kimi web non-interactively gets a documented, one-flag migration path. @codex

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

…hangelog

The bump stays minor, but the entry now calls out the behavior break and
the --background mitigation for scripts that expect kimi web to return
immediately.
@wbxl2000

Copy link
Copy Markdown
Collaborator Author

@codex

…r CLI

After an upgrade, an older still-running server is reused as-is. The
lock's host_version is now surfaced: kimi web / server run print a
version-mismatch line next to the reuse notice, /web shows the same as a
status warning, and the docs plus changeset tell users a single
kimi server kill switches them onto the new version.
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. What shall we delve into next?

Reviewed commit: ccc3357267

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

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.

1 participant