Conversation
🦋 Changeset detectedLatest commit: 1c67949 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
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 |
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
commit: |
There was a problem hiding this comment.
Copilot review overview
🟡 Changes recommended
Event chunking, queued-batch tracking, and TUI replay currently produce incorrect behavior for several supported output cases.
Review effort: Balanced
Findings: 1
Open (6)
Queue final batches behind in-flight deliveries · New Preserve and combine backend and UI omission counts · New Use lossless XML escaping for consistent live and replay output · New Buffer oversized logical lines until their terminating newline · New Use lowercase “agent” in English prose · New Correct the phrase to “一旦就绪” · New
What changed in this PR
Adds an opt-in Monitor tool that streams background command output to the main agent.
Changes:
- Implements monitored processes, batching, rate limits, notifications, and
WaitForintegration. - Exposes monitor events through the SDK and renders them in the TUI.
- Adds comprehensive tests, bilingual documentation, and a changeset.
| File | Description |
|---|---|
.changeset/monitor-tool.md |
Records the experimental feature. |
packages/node-sdk/src/events.ts |
Exports the monitor event type. |
packages/node-sdk/test/session-event-types.test.ts |
Covers the new event union member. |
packages/agent-core-v2/src/index.ts |
Registers and exports Monitor. |
packages/agent-core-v2/src/events.ts |
Adds monitor delivery events. |
packages/agent-core-v2/src/app/telemetry/events.ts |
Adds the event wait outcome. |
packages/agent-core-v2/src/session/agentLifecycle/profile/profiles.ts |
Enables Monitor for the main profile. |
packages/agent-core-v2/src/agent/tools/mainAgentOnly.ts |
Adds the main-agent restriction message. |
packages/agent-core-v2/src/agent/tools/task/monitor/flag.ts |
Defines the experimental flag. |
packages/agent-core-v2/src/agent/tools/task/monitor/monitor.ts |
Defines Monitor arguments and limits. |
packages/agent-core-v2/src/agent/tools/task/monitor/monitor.md |
Provides model-facing usage guidance. |
packages/agent-core-v2/src/agent/tools/task/monitor/monitorTool.ts |
Implements monitored process startup. |
packages/agent-core-v2/src/agent/tools/task/task-wait/taskWaitTool.ts |
Lets events interrupt WaitFor. |
packages/agent-core-v2/src/agent/tools/os/bash/shellProcess.ts |
Extracts reusable shell helpers. |
packages/agent-core-v2/src/agent/tools/os/bash/process-task.ts |
Forwards selected stdout as events. |
packages/agent-core-v2/src/agent/tools/os/bash/bashTool.ts |
Uses the extracted shell helpers. |
packages/agent-core-v2/src/agent/task/task.ts |
Extends the task service contract. |
packages/agent-core-v2/src/agent/task/types.ts |
Adds the event sink callback. |
packages/agent-core-v2/src/agent/task/taskEvents.ts |
Implements line buffering and batching. |
packages/agent-core-v2/src/agent/task/taskOps.ts |
Defines the observable delivery event. |
packages/agent-core-v2/src/agent/task/taskService.ts |
Delivers and publishes monitor events. |
packages/agent-core-v2/src/agent/permissionPolicy/policies/dangerous-command-ask.ts |
Applies dangerous-command checks. |
packages/agent-core-v2/test/os/backends/node-local/tools/bash.test.ts |
Tests Monitor startup constraints. |
packages/agent-core-v2/test/agent/task/tools/task-tools.test.ts |
Tests event-driven waits. |
packages/agent-core-v2/test/agent/task/taskManager.test.ts |
Tests event stream behavior. |
packages/agent-core-v2/test/agent/task/idle-notification-repro.test.ts |
Tests idle-agent wake-up. |
packages/agent-core-v2/test/agent/permissionPolicy/permissionPolicyService.test.ts |
Tests dangerous Monitor commands. |
apps/kimi-code/src/tui/types.ts |
Adds monitor status presentation data. |
apps/kimi-code/src/tui/utils/monitor-event.ts |
Parses and formats monitor events. |
apps/kimi-code/src/tui/utils/background-task-status.ts |
Labels monitor task IDs. |
apps/kimi-code/src/tui/controllers/session-replay.ts |
Replays monitor notifications. |
apps/kimi-code/src/tui/controllers/session-event-handler.ts |
Handles live monitor events. |
apps/kimi-code/src/tui/components/messages/background-agent-status.ts |
Renders recent event lines. |
apps/kimi-code/src/tui/components/messages/tool-call.ts |
Adds Monitor tool headers. |
apps/kimi-code/src/tui/components/messages/tool-renderers/wait-for.ts |
Renders event-ended waits. |
apps/kimi-code/src/tui/components/dialogs/approval-panel.ts |
Adds Monitor approval text. |
apps/kimi-code/test/tui/message-replay.test.ts |
Tests replay rendering. |
apps/kimi-code/test/tui/controllers/session-event-handler-background-task.test.ts |
Tests live event handling. |
apps/kimi-code/test/tui/components/messages/tool-call.test.ts |
Tests Monitor and wait headers. |
apps/kimi-code/test/tui/components/messages/background-agent-status.test.ts |
Tests event-line rendering. |
apps/kimi-code/test/tui/background-task-status.test.ts |
Tests monitor task wording. |
docs/en/reference/tools.md |
Documents Monitor in English. |
docs/zh/reference/tools.md |
Documents Monitor in Chinese. |
💡 Configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 81391ebc83
ℹ️ 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".
|
@codex review |
|
@codex review |
|
Codex Review: Didn't find any major issues. 👍 Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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". |
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 7c95f634e0
ℹ️ 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".
|
@codex review |
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 6c74038e1d
ℹ️ 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".
… monitors are running
|
@codex review |
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 588eed7a7e
ℹ️ 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".
…l is aborted during spawn
|
@codex review |
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: de6ff0e8fd
ℹ️ 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".
…de exit with monitors running
|
@codex review |
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
|
@codex review |
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: b7c3c92130
ℹ️ 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".
…s without an engine import
|
@codex review |
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 1c6794960f
ℹ️ 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".
| export const backgroundTaskEventDeliveredEventSchema = z.object({ | ||
| type: z.literal('background.task.event'), |
There was a problem hiding this comment.
Sync the web bundle for monitor events
When an experimental Monitor runs through the built-in web UI, kap-server now sends this new event, but the committed apps/kimi-code/dist-web bundle is unchanged from the parent commit and contains no background.task.event handler, while only the TUI gained a renderer. Web users therefore cannot see the monitored lines that the new card is meant to expose; sync and commit the corresponding code-app bundle with this protocol change.
AGENTS.md reference: AGENTS.md:L18-L18
Useful? React with 👍 / 👎.
| export const MONITOR_FLAG_ID = 'monitor'; | ||
| export const MONITOR_FLAG_ENV = 'KIMI_CODE_EXPERIMENTAL_MONITOR'; |
There was a problem hiding this comment.
Add the Monitor flag to the environment-variable reference
Users who rely on the environment-variable reference cannot discover this newly supported switch: the exhaustive runtime-switch table in both docs/en/configuration/env-vars.md and its Chinese mirror lists the other KIMI_CODE_EXPERIMENTAL_* variables and the master flag, but omits KIMI_CODE_EXPERIMENTAL_MONITOR. Add the variable and its accepted truthy/falsy values to both pages so the new opt-in path is documented consistently.
Useful? React with 👍 / 👎.
| timeout: z | ||
| .number() | ||
| .int() | ||
| .positive() | ||
| .max(MONITOR_MAX_TIMEOUT_S) | ||
| .optional() | ||
| .describe( | ||
| `Seconds before the monitor is stopped. Default ${String(MONITOR_DEFAULT_TIMEOUT_S)}, max ${String(MONITOR_MAX_TIMEOUT_S)}. Ignored when persistent is true.`, |
There was a problem hiding this comment.
Ignore timeout validation for persistent monitors
When a call sets persistent: true, the field description says timeout is ignored, but this unconditional .max(MONITOR_MAX_TIMEOUT_S) still rejects values above one hour before MonitorTool.start() can discard them. Thus an otherwise valid persistent monitor such as { persistent: true, timeout: 7200 } fails argument validation despite the advertised contract; make the upper-bound check conditional on persistent !== true or accept and ignore the field.
Useful? React with 👍 / 👎.



中文版
需求或 Bug
新功能。目前智能体只能在后台任务结束时收到通知;想在"日志出现某行""服务器就绪""测试失败"时立即做出反应,只能用 Bash sleep 循环轮询,或在 WaitFor 中阻塞。本 PR 新增实验性的
Monitor工具:在后台运行一条命令,其 stdout 的每一行在智能体继续工作的同时送达。Bug 复现步骤
N/A(新功能)。
根本原因
N/A(新功能)。
代码变更
行为变化与受影响用户
Monitor工具type="task.event"、status: running的通知Notificationhooktask.event)background.task.eventwait_statusevent(仅在传入 monitor 的 task_id 时)keep_alive_on_exit契约文件:
agent-core-v2/src/events.ts(AgentEvent联合类型)、SDK 的events.ts和 kap-server 的events-zod.ts(WebSocket 事件 schema)只做了新增;API 快照不变。packages/acp-server/只改了 spawn 路由:ACP 客户端(如 Zed)不会看到 monitor 的终端,Bash 仍在客户端终端运行。旧版客户端收到 monitor 事件时:desktop / web(code-app)把它显示为普通任务通知卡片;旧版 TUI 回放时显示为 "bash task started"。state-manifest与wire-manifest没有变化。桌面端和 Web 的卡片在单独的 code-app PR 中实现。工具文档与 hooks 文档(中英文)已更新。测试:
taskService.test.ts(设置 keep_alive_on_exit 时 monitor 仍在退出时停止)、taskManager.test.ts(shell 退出后仍送达迟到的行、此时停止仍能结束、行切分、批处理、未消费时暂存、结束时刷新、截断、速率上限;monitor 任务的通知、stderr 不送达、普通 Bash 不产生事件、超限停止)、idle-notification-repro.test.ts(真实智能体:事件唤醒空闲智能体,回放一致)、task-tools.test.ts(WaitFor 被指定 monitor 的事件结束、已有事件立即返回、不传 task_id 时不受 monitor 事件影响、只剩 monitor 时返回 no_tasks)、bash.test.ts(Monitor 默认超时、persistent、子智能体拒绝、无 TaskStop 拒绝、达到任务上限时不启动命令、启动期间中断时终止进程、timeout 上限)、permissionPolicyService.test.ts(Monitor 危险命令)、planGuard.test.ts(Plan 模式拒绝 Monitor)、sessionEventBroadcaster.test.ts(WebSocket schema)、acp-terminal.test.ts(mergeStderr: false 的 spawn 在本地运行)、v2-run-print.test.ts(drain / steer 不等待 monitor);TUI 的回放、实时事件、状态文案、标题和事件行渲染。端到端场景在单独的 PR 中。Requirement or Bug
A new feature. Today the agent hears from a background task only when it ends. To react to a log line, a server becoming ready or a failing test as it happens, it has to poll with Bash sleep loops or block in WaitFor. This PR adds an experimental
Monitortool: it runs a background command, and each stdout line reaches the agent while it keeps working.Bug Reproduction Steps
N/A (new feature).
Root Cause
N/A (new feature).
Code Changes
Behavior Changes and Affected Users
Monitortooltype="task.event"notifications withstatus: runningNotificationhooktask.event)background.task.eventwait_statusvaluesevent(only with a monitor's task_id)keep_alive_on_exitContract files:
agent-core-v2/src/events.ts(theAgentEventunion), the SDK'sevents.tsand kap-server'sevents-zod.ts(the WebSocket event schema) only gain members; the API snapshot is unchanged. Inpackages/acp-server/only spawn routing changes: ACP clients such as Zed get no terminal for a monitor, while Bash still runs in the client terminal. Older clients that receive a monitor event: desktop and web (code-app) show it as an ordinary task notification card, and an older TUI replays it as "bash task started".state-manifestandwire-manifestare unchanged. The desktop and web card comes in a separate code-app PR. Tool and hook docs (en/zh) updated.Tests:
taskService.test.ts(monitors still stop at exit with keep_alive_on_exit),taskManager.test.ts(late lines after the shell exits still delivered, stopping in that window still settles, line splitting, batching, holding while unconsumed, flush at close, truncation, rate cap; monitor task notifications, stderr not delivered, plain Bash produces no events, stopped over the limit),idle-notification-repro.test.ts(real agent: an event wakes an idle agent, resume replay matches),task-tools.test.ts(WaitFor ended by the named monitor's event, immediate return when one is pending, a WaitFor without task_id unaffected by monitor events, no_tasks when only monitors run),bash.test.ts(Monitor default timeout, persistent, refused in a subagent, refused without TaskStop, command never started at the task limit, killed when aborted during spawn, timeout cap),permissionPolicyService.test.ts(Monitor dangerous command),planGuard.test.ts(Plan mode refuses Monitor),sessionEventBroadcaster.test.ts(WebSocket schema),acp-terminal.test.ts(a spawn with mergeStderr: false runs locally),v2-run-print.test.ts(drain / steer do not wait for monitors); TUI replay, live events, status wording, headers and the event row. End-to-end scenarios come in a separate PR.Checklist
/approve).gen-changesetsskill, or this PR needs no changeset.gen-docsskill, or this PR needs no doc update.