Skip to content

feat(cli): add headless mode#579

Open
chengluyu wants to merge 28 commits into
MoonshotAI:mainfrom
chengluyu:feat/go-headless-first
Open

feat(cli): add headless mode#579
chengluyu wants to merge 28 commits into
MoonshotAI:mainfrom
chengluyu:feat/go-headless-first

Conversation

@chengluyu

Copy link
Copy Markdown
Collaborator

Related Issue

No linked issue. This PR adds the headless CLI workflow needed for non-interactive runs, progress polling, file output, and goal control.

Problem

kimi -p is useful for one-off prompt output, but it does not give scripts or other coding agents a durable control surface for long-running work. Callers need a non-TUI mode that can report live state, write structured output, run goal-backed continuations, and accept pause/cancel/interrupt requests without depending on the TUI.

What changed

  • Added kimi headless commands for prompt runs, goal runs, status inspection, and goal control.
  • Added live status JSON, atomic sidecar writes, response file output, metadata stdout, and plan approval handling for headless runs.
  • Added session run locks so concurrent headless runs do not mutate the same session, with stale and corrupt lock recovery.
  • Restored turn IDs correctly after session replay so resumed headless sessions keep stable turn numbering.
  • Documented the headless command in English and Chinese docs, and expanded CLI help so humans and agents can understand options, examples, outcomes, and polling guidance from --help.
  • Added regression coverage for parsing, status files, output files, goal control, interrupt handling, stale control requests, goal continuation state, lock recovery, and resume turn IDs.

Verification:

pnpm vitest run apps/kimi-code/test/cli/headless.test.ts apps/kimi-code/test/cli/options.test.ts packages/node-sdk/test/session-lock.test.ts packages/agent-core/test/agent/turn.test.ts
pnpm -C apps/kimi-code run dev:cli-only headless --help
pnpm -C apps/kimi-code run dev:cli-only headless run --help
pnpm -C apps/kimi-code run dev:cli-only headless status --help
pnpm -C apps/kimi-code run dev:cli-only headless goal --help

Identifier audit:

  • Checked the diff for user-specific paths, private worktree paths, private URLs, emails, and token-looking values.
  • Sanitized local trial-plan paths to neutral /tmp/kimi-headless-examples and /path/to/kimi-code examples.

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.

@changeset-bot

changeset-bot Bot commented Jun 9, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 3b00a40

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

This PR includes changesets to release 5 packages
Name Type
@moonshot-ai/kimi-code Minor
@moonshot-ai/kimi-code-sdk Minor
@moonshot-ai/agent-core Minor
@moonshot-ai/acp-adapter Patch
@moonshot-ai/migration-legacy Patch

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

@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: 12fa0c34f7

ℹ️ About Codex in GitHub

Your team has set up Codex to 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 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread apps/kimi-code/src/cli/headless/run.ts Outdated
Comment thread apps/kimi-code/src/cli/headless/run.ts
@pkg-pr-new

pkg-pr-new Bot commented Jun 9, 2026

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

commit: 3b00a40

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