Skip to content

feat(kap-server): push agent, usage, goal and todo state over WebSocket - #4606

Merged
wbxl2000 merged 14 commits into
mainfrom
qer/agent-todo-frames
Nov 3, 2026
Merged

wbxl2000 merged 14 commits into
mainfrom
qer/agent-todo-frames

Conversation

@wbxl2000

@wbxl2000 wbxl2000 commented Nov 2, 2026 •

Copy link
Copy Markdown
Collaborator

Requirement or Bug

Agent 的运行状态、设置(模型、思考强度、权限、计划 / swarm / tower 模式)、上下文用量、目标和待办,之前混在转录里用 meta.merge / todo.upsert 推送;desktop / web 还要另外拉 GET /status 补齐,两路来源互相覆盖,客户端为此维护了一套防竞态逻辑。本 PR 把它们改成四种独立的 WebSocket 帧,状态直接取自引擎服务,转录只保留对话本身。

顺带修复:撤销一条消息后,待办列表仍停在撤销前的内容。

客户端配套:MoonshotAI/kimi-code-app#1094。

Bug Reproduction Steps

N/A(主体是协议改动)。顺带修复的问题:让 agent 用 TodoList 写几条待办 → 撤销这条消息 → 待办栏仍显示撤销前的列表,刷新也不变。

Root Cause

旧路径从 wire 记录里取最后一次 tools.update_store 作为待办,撤销不会回滚这条记录。引擎的待办服务是可撤销的持久状态,撤销时会回到上一个值;改为从它读取后,这个问题从根本上消失,不需要单独处理。

Code Changes

核心思路

  • 转录只描述对话,"此刻状态"走独立的帧。 turn、step、工具调用、marker 仍在转录里;agent 的状态、设置、用量、目标、待办由服务端从引擎服务读出,变化时推送。
  • 按负责方和变化频率分成四种帧。 agent(运行状态 + 设置,变化少)、usage(上下文 token,每一步都变,尾部节流 250 ms)、goal(只有主 agent 有)、todo。分开推送,一种状态变化不会让另外几种跟着重发。
  • 订阅时先发全量,之后只发变化。 连接开始接收某个 agent 时(subscribe_v2 里该 agent 的粒度从 off 或未订阅变为非 off),先发它的四种帧,再按变化推送。这和第四组的 task.list 用的是同一份"每个连接已经收到过哪些 agent"的记录。
  • 顺序有保证。 同一个事件引起的转录 op 先发,agent 帧在随后的微任务里发出;每个连接只有一条先进先出的发送队列。所以客户端收到 status: "idle" 时,这一轮的 turn 结束 op 已经到了。
  • 只听会改变状态的事件。 feed 订阅 agent 的 turn.started、turn.ended、agent.status.updated、goal.updated 四类事件和待办服务的变化事件,和旧的 meta 投影听的是同一组;流式增量(assistant.delta 等)不会触发重读。
  • 订阅时确保主 agent 存在。 新会话在第一条输入之前还没有主 agent,以前是 GET /status 在读取时顺带创建它,客户端选中会话时总会读一次。现在订阅时创建,主 agent 的四种帧总能紧跟订阅到达。
  • 删除 GET /sessions/{id}/status。 desktop / web 已改为从帧读取,仓内其他客户端(VS Code、SDK、TUI、kimi-inspect)都不调用它;:undo 响应里同一份 status 也一并去掉,只保留 messages。

源码(不含测试和文档)+513 / −1033:kap-server +508 / −564(其中新增帧 feed 248 行、状态读取 84 行、帧 schema 76 行;删除 legacyStatus 的活动跟踪 146 行和转录里的状态投影约 170 行),transcript +5 / −469(meta、todos 的模型、schema、op 和折叠逻辑整体删除)。

协议

server → client  { type: "agent", session_id, agent_id, event_created_at,
                   status: "idle" | "running", model?, thinking?,
                   permission_mode?: "manual" | "yolo" | "auto",
                   plan_mode: boolean, swarm_mode: boolean, tower_mode: boolean }
server → client  { type: "usage", session_id, agent_id, event_created_at,
                   context_tokens, max_context_tokens? }
server → client  { type: "goal", session_id, agent_id, event_created_at,
                   goal?: { objective, status: "active" | "paused" | "blocked" | "complete",
                            completion_criterion?, turns_used, tokens_used, wall_clock_ms } }
server → client  { type: "todo", session_id, agent_id, event_created_at,
                   items: { title, status: "pending" | "in_progress" | "done" }[] }
  • agent:每个 agent 都有。status 跟随 turn.started / turn.ended 事件,初值取 loop 快照。不直接读 loop 快照,是因为 loop 在派发 TurnEnded 之前就清掉了当前 turn,直接读会让 idle 先于转录里的 turn 结束到达。
  • usage:每个 agent 都有,没有上下文数据时不发。连续变化在 250 ms 窗口里合并成一帧。
  • agent 的三个模式字段是布尔值,和 profile 接口写入用的 plan_mode / swarm_mode 同名;不再带计划文件路径、swarm 触发方式这类细节,客户端没有读取方。
  • goal:只有主 agent。没有目标时省略 goal 字段,不发 null,与 KAP 草案"可选字段没有值时省略"的约定一致。去重时忽略 wall_clock_ms(它是实时计算的),所以目标没变时不会每步重发。
  • todo:每个 agent 都有,整份列表替换。
  • 帧只发给对该 agent 粒度不为 off 的连接。会话重新变为 live 时重新挂上监听,和任务帧一样。

结构

kap-server
+ protocol/ws-agent.ts                        # four frame schemas
  protocol/ws-control.ts                      # AsyncAPI: agent / usage / goal / todo operations
+ transport/ws/v1/agentState.ts               # read state from engine services
+ transport/ws/v1/sessionAgentFeed.ts         # per live session: watch every agent on state events, diff and send
  transport/ws/v1/sessionEventBroadcaster.ts
    attachTasks → attachAgentFeeds            # task feed + agent feed, same lifecycle
    sendTaskLists → sendAgentLists            # task.list + agent snapshot for newly received agents
    sendTask → sendAgentFrame                 # to every target whose grade is not off
    subscribe                                 # ensure the main agent exists before listing agents
  services/transcript/coreEventMap.ts
-   meta.merge / todo.upsert projection       # agent status, phase, goal, modes, todos
  services/transcript/transcriptService.ts
-   cold meta (activity, tower clearing)
- services/legacyStatus/legacyActivity.ts     # phase tracker, only fed meta
  routes/transcript.ts                        # REST transcript drops meta / todos

transcript
- model/meta.ts, model/todo.ts, TodoId
- meta / todos in snapshot, schema, ops, apply, store, history folding
旧路径的功能清单与新位置
旧路径做的事 新位置
live 会话:LegacyActivityTracker 跟踪 activity 和 phase agent.status 跟随 turn 事件;phase 不再提供(见行为表)
冷会话:activity 取 loop 快照 帧只针对 live 会话(订阅会让会话变为 live),初值取 loop 快照
冷会话:tower 不归本机时清掉 modes.tower 直接读 live 会话上的 tower 服务 isActive
agent.status.updated → 模型、思考强度、权限、上下文 token profile 服务、权限服务、readLegacyStatus(与 GET /status 同源)
goal.updated → meta.goal 收到事件后读目标服务
计划 / swarm 模式:事件和 marker 折叠 读 agent 状态服务的计划键、swarm 服务 isActive;marker 仍留在转录里
待办:live 取 TodoList 工具调用参数,冷读取 tools.update_store 记录 读待办服务 get(),监听 onDidChange

提交

  1. feat(kap-server):四种帧、删除转录里的 meta / todos、更新 API 文档。
  2. chore:三条 changeset(四种帧并删除转录里的 meta / todos;撤销后待办回退;删除 GET /sessions/{id}/status 和 :undo 响应里的 status),均为 patch,第三条在第 7 个提交里。
  3. refactor(kap-server):agent 帧的模式改为三个布尔字段;没有目标时 goal 帧省略 goal。
  4. fix(kap-server):feed 改为只订阅上述四类状态事件;订阅时确保主 agent 存在。
  5. chore: sync web dist from code-app(多次,以最后一次为准):apps/kimi-code/dist-web 当前由 MoonshotAI/kimi-code-app#1094 在 43cc54ef9 构建(基于 code-app main 的 e75e3752f,所以产物同时带着 main 的 web 改动),构建时 submodule 对齐本 PR 的 2d7e9ce39,产物注入的 CLI 版本是 2.4.1。
  6. refactor(kap-server):删除 GET /sessions/{id}/status、它的响应 schema 和 ISessionLegacyService.status,:undo 响应去掉 status;原来借 /status 检查状态的测试改用 agent 帧的读取函数,另加一条 usage 帧上下文上限的测试;更新 API 文档和 apiSurface 快照。

Behavior Changes and Affected Users

行为 之前(main) 之后 依赖旧行为的人群 退路
转录里的 meta / todos,以及 meta.merge / todo.upsert op(WebSocket transcript.ops 和快照) 有 没有 main 上的 desktop / web;订阅转录的外部脚本 改读 agent / usage / goal / todo 帧。客户端随配套 PR 一起改;desktop 内嵌 server 随包发布。changeset 写明了删除
REST 转录响应(GET …/transcript 等)里的 meta、todos 字段 有 删除 读这些字段的外部脚本 WebSocket 帧;GET /sessions/{id}/status、GET /sessions/{id}/goal 不变
meta 里没有新去处的字段:phase(running / tool_call / retrying / awaiting_approval / interrupted / ended)、activity 的 disposing / unknown、agent.usage(按模型、本轮、累计用量)、modes.plan.reviewPath / version、modes.swarm.trigger、goal.budgetUsed / budgetLimit 有 不再提供 code-app 和本仓都没有读取方;可能读它们的外部脚本 计划修订和 swarm 仍有转录 marker;累计用量在 session 对象的 usage;每步用量在 step 上;目标预算在 GET /sessions/{id}/goal
撤销后的待办 停在撤销前最后一次写入 跟随撤销回到之前的列表 无 —
上下文用量的推送频率 每次状态更新一条 meta.merge 250 ms 窗口内合并成一帧 无 —
子 agent 的状态 混在各自转录的 meta 里 每个 agent 各自一组帧,不向父 agent 冒泡 — —
GET /sessions/{id}/status 返回主 agent 的状态汇总 删除(404) desktop / web 在配套 PR 里已不再调用;调用它的外部脚本 WebSocket 订阅后的 agent / usage 帧。changeset 写明了删除
:undo 响应 { messages, status } { messages } desktop / web 不读响应体;读 status 的外部脚本 同上
订阅一个还没有主 agent 的会话 不创建;GET /status、GET /goal 读取时才创建 订阅时创建 无:desktop / web 选中会话时本来就会读 /status,效果相同 —
内置在 CLI 里的 web 产物(apps/kimi-code/dist-web) 读转录的 meta / todos 本 PR 一并同步了按新协议构建的产物:运行状态、设置、用量、目标、待办都读新帧 kimi web 用户 不需要:产物与服务端在同一个提交里更新

TUI、print 模式、SDK(getTodos 直接读引擎待办服务)、ACP 和 VS Code 插件都不读转录的 meta / todos,不受影响。契约文件中 docs/*-manifest 和 apiSurface 快照没有变化。

受影响的模块与测试:

  • kap-server sessionEventBroadcaster.test.ts:订阅时下发快照;没有任何 agent 时订阅会创建主 agent;流式增量不触发状态重读;agent 帧跟随 turn 事件且排在 transcript.ops 之后;待办、目标、权限变化时推送,其他时候不发;用量合并;后加入的 agent 发出初始帧。
  • kap-server transcriptContract.e2e.test.ts:S1 断言 idle 帧排在 turn 结束的 ops 帧之后,转录里没有 meta.merge;S3–S6 改为断言帧;新增 S10(新会话订阅后立即收到主 agent 的帧,TodoList 写入产生 todo 帧)。
  • kap-server transcript.test.ts:agent 状态更新不再产生转录 op。transcript layers.test.ts、store.test.ts 去掉 meta / todos 的用例。
  • 文档:docs/{en,zh}/reference/server-api.md 去掉 REST 转录的 meta / todos,补上四种帧和重连说明。
  • 基于最新 main:kap-server 72 个文件 1439 条通过,transcript 112 条通过,根目录 pnpm typecheck、pnpm lint(0 error)通过。
  • kap-server sessions.test.ts:GET /status 返回 404;profile 写入的模式和权限、Tower 不可用时的拒绝、未绑定模型时的默认上下文窗口,改用 agent / usage 帧的读取函数检查。agent-core-v2 删除只测 status() 的 sessionLegacy.test.ts;klient 的撤销用例去掉 status。apiSurface 快照只少了这一条路由。
  • kap-server connections.test.ts:订阅后改为轮询等订阅生效,不再依赖固定的 50 毫秒(订阅多了一步创建主 agent)。
  • 手动冒烟(本分支 server + 配套客户端分支的 web):新会话订阅后立即收到主 agent 的帧、整个过程客户端没有请求 /status;运行中 → 空闲、待办栏、撤销后待办清空、经 REST profile 改权限 / 计划模式 / 目标后页面无需刷新即更新、刷新页面后从快照恢复、重启 server 后冷会话恢复待办和设置,均符合预期。没有验证 tower 模式(需要实验开关)。

Checklist

  • I have read the CONTRIBUTING document.
  • I have linked a related issue (external PRs: issue must have a maintainer's /approve).
  • I have added tests that prove my feature works.
  • The behavior-change table above is complete, and every removed behavior or flipped default is named in the changeset and either has an escape hatch or was explicitly approved by a maintainer in this PR.
  • Ran gen-changesets skill, or this PR needs no changeset.
  • Ran gen-docs skill, or this PR needs no doc update.

Subscribers of an agent now receive four flat frames that carry the
agent's own state, read straight from the engine services:

- agent: run status, model, thinking effort, permission mode, modes
- usage: context tokens, coalesced to a few frames per second
- goal: the main agent's goal, or null
- todo: the agent's todo store, so it follows undo and cold restores

Each frame is sent in full when a connection starts receiving the agent
and again whenever its value changes. Run status follows turn events and
is flushed in a microtask, so it always lands after the transcript batch
of the same turn change.

The transcript drops the state these frames replace: the meta.merge and
todo.upsert ops, the meta and todo models and their cold folding, the
tool frame todoId, the phase tracker behind meta.agent.phase, and the
meta and todos fields of the REST transcript.
code-app: a0d00377f772d2cf53f8193a06e5dcacfae0e4a2
@changeset-bot

changeset-bot Bot commented Nov 2, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 446ed24

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 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 commented Nov 2, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-02T11:11:16.928271Z 446ed24 Manual request
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@pkg-pr-new

pkg-pr-new Bot commented Nov 2, 2026 •

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

commit: 446ed24

@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: aa4128b632

ℹ️ 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": patch

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 Preserve transcript fields across the patch update

For existing desktop, web, and VS Code clients, this patch removes the previously documented meta and todos REST fields and their transcript operations, while the replacement WebSocket frames require a coordinated client upgrade. A patch auto-update can therefore silently leave prior-release clients without agent, goal, or todo state. Preserve the deprecated fields during a transition, or treat this as a breaking release rather than a patch.

AGENTS.md reference: AGENTS.md:L62-L62

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.

转录 meta / todos 的读取方只有 desktop 和 web:desktop 内嵌的 server 随安装包一起发布,web 产物在本 PR 里一起更新;VS Code 插件、TUI、SDK、ACP 都不读这两个字段(SDK 的 getTodos 直接读引擎的待办服务)。"旧客户端连新 server"不是受支持的组合,所以不保留过渡字段。版本级别沿用第四组删除 REST 任务接口时的 patch,删除内容写在 changeset 和 PR 描述的行为变化表里。

Comment on lines +52 to +56
objective: goal.objective,
status: goal.status,
completion_criterion: text(goal.completionCriterion),
turns_used: goal.turnsUsed,
tokens_used: goal.tokensUsed,

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 Preserve the complete goal snapshot in goal frames

When a goal has token, turn, or wall-clock budgets, IAgentGoalService.getGoal() also returns goalId, the complete budget report, and terminalReason, but this projection discards all of them. The committed web client applies each goal frame by replacing its previously REST-loaded goal object, so subscribing immediately erases those fields and subsequent budget progress cannot reach the client. Reuse the existing full goal snapshot contract or include these fields in the frame.

AGENTS.md reference: AGENTS.md:L126-L128

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.

有意为之:goal 帧只带界面用到的字段(目标内容、状态、完成标准、已用轮数 / token / 时长)。desktop / web 不读预算、goalId 和 terminalReason,目标工具卡片上的预算来自工具调用参数。需要预算的调用方仍可读 GET /sessions/{id}/goal。

Comment on lines +108 to +110
bus.subscribe((event) => {
this.onEvent(event);
}),

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 Filter delta events before recomputing every state slice

While a client watches an active session, this unfiltered subscription schedules a full agent/goal/todo/usage read for every AssistantDelta, ThinkingDelta, and ToolCallDelta emitted during streaming, even though none of those events changes these state slices. In particular, the usage read calls statusSize(), which can repeatedly estimate the conversation context (notably with the supported estimated strategy), so long contexts and high-frequency streams incur avoidable CPU work despite the 250 ms throttle applying only after recomputation. Subscribe only to state-changing event types or throttle the reads themselves.

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.

已修复(240dcaa46):feed 不再订阅整条事件总线,只订阅 turn.started、turn.ended、agent.status.updated、goal.updated 和待办服务的变化事件,和旧的 meta 投影听的是同一组;流式增量不再触发重读,sessionEventBroadcaster.test.ts 里加了断言。

The agent frame carries plan_mode, swarm_mode and tower_mode booleans
instead of a modes object of empty objects, matching the profile write
fields. The goal frame omits goal when the session has none, following
the protocol rule that optional fields are omitted rather than null.
code-app: 206b70b98f7ce77bccdbeef37b15cd97a0933fd0
…main agent on subscribe

The agent feed listened to the whole agent event bus and re-read every
state slice on each streaming delta. It now listens only to turn.started,
turn.ended, agent.status.updated and goal.updated, plus the todo
service's change event, which are the events that change those slices.

Subscribing to a session now creates its main agent when it does not
exist yet, so a fresh session sends its main agent frames right after
the subscription. GET /status used to create it as a side effect, and
clients no longer need that read for subscribed sessions.
code-app: cb0dbffca84f67e0cf72cc00d4f05eb71ad3c079
@wbxl2000

wbxl2000 commented Nov 2, 2026

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

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

Reviewed commit: eccded544e

ℹ️ 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".

code-app: ef7c84980d26c156295c2d56bf001b34a84a9c4e
Desktop and web read the main agent's state from the agent and usage
frames and no longer call this endpoint, and subscribing now creates the
main agent that the status read used to create as a side effect.

- The status route, its response schema and ISessionLegacyService.status
  are gone; the :undo response keeps only messages.
- The profile and tower tests check the main agent state through the
  same reader the agent frame uses, and the default-model context window
  test goes through the usage reader.
- A broadcaster test pins the usage frame's context limit rules.
@wbxl2000

wbxl2000 commented Nov 2, 2026

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

💡 Codex Review

https://github.com/MoonshotAI/kimi-code/blob/3376ff0dcffee9454f9215f95dd6da1ae620da6a/apps/kimi-code/dist-web/assets/index-Boxa5rQt.js#L191
P2 Badge Clear a missing context limit in the web client

When a session switches from a model with a known context limit to one whose capabilities do not provide a positive limit, the new usage frame omits max_context_tokens, but this bundled client applies it as t.contextLimit ?? n.usage.contextLimit, preserving the previous model's limit even though these frames are documented as full replacements. The former REST mapper converted an omitted limit to 0, so this regression leaves the context percentage and limit display stale until another model with a known limit is selected; update the code-app source to clear the value on omission and resync this bundle.

AGENTS.md reference: AGENTS.md:L18-L18

ℹ️ 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".

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits.
Repo admins can enable using credits for code reviews in their settings.

@wbxl2000

wbxl2000 commented Nov 2, 2026

Copy link
Copy Markdown
Collaborator Author

Clear a missing context limit in the web client

已修复:code-app 源码改为 usage 帧缺 max_context_tokens 时把上下文上限置为 0(与原 REST 映射一致),不再保留上一个模型的上限(MoonshotAI/kimi-code-app#1094 43cc54ef9,附测试);本 PR 的 web 产物已在 446ed24d1 按该提交重新同步。

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits.
Repo admins can enable using credits for code reviews in their settings.

@wbxl2000

wbxl2000 commented Nov 2, 2026

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. 🚀

Reviewed commit: 446ed24d12

ℹ️ 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".

@wbxl2000
wbxl2000 merged commit 011b1d4 into main Nov 3, 2026
17 checks passed
@wbxl2000
wbxl2000 deleted the qer/agent-todo-frames branch November 3, 2026 04:31
@github-actions github-actions Bot mentioned this pull request Nov 3, 2026
7723qqq pushed a commit to 7723qqq/kimi-code that referenced this pull request Nov 4, 2026
First half of upstream MoonshotAI#4606. A connection that starts receiving an agent
now gets four more flat frames next to `task.list`: `agent` (status,
model, thinking level, permission/plan/swarm/tower modes), `usage`
(context tokens, throttled to one frame per 250 ms), `goal` (the main
agent's goal, or a frame with no goal) and `todo` (the item list). Each
frame is re-sent on change, so a client no longer has to poll
`GET /sessions/{id}/status` for any of it.

`SessionAgentFeed` watches every agent the session exposes, subscribes to
its event bus for `turn.started`/`turn.ended`/`agent.status.updated`/
`goal.updated`, to the todo service, and to `onDidCreate`/`onDidClose`;
`agentState.ts` reads the state through the scoped services.

Local shape notes:

- The fork's goal status has two extra values, `budget_limited` and
  `usage_limited`, so `goalStateSchema` accepts them.
- `subscribe` now calls `ensureMainAgent` after resuming, matching
  upstream: without a main agent the feed has nothing to watch and no
  frames are produced. A failure is logged, not fatal.
- `sendTaskLists`/`sendTask` became `sendAgentLists`/`sendAgentFrame` so
  the task and agent frames share one subscription-bookkeeping path; the
  broadcaster test's collecting target buckets the four new frames with
  the task ones, and six fake profile services gained the
  `getEffectiveThinkingLevel` method the state reader calls.

Not yet done in this row: removing `GET /sessions/{id}/status`, the
transcript's `meta`/`todo` entities, and the docs/changesets.

Gates: kap-server 1386 pass / 9 skip, both packages `tsc` clean,
`check:no-comments`, `check:no-hardcoded-prose`,
`check:strict-request-bodies` green, structural review unchanged at the
three pre-existing findings.
7723qqq pushed a commit to 7723qqq/kimi-code that referenced this pull request Nov 4, 2026
The four agent/usage/goal/todo frames are served and covered end to end; removing the REST status endpoint and the transcript meta/todo entities is what remains.
7723qqq pushed a commit to 7723qqq/kimi-code that referenced this pull request Nov 5, 2026
Completes MoonshotAI#4606: the agent, usage, goal and todo frames pushed over the
server WebSocket replace the polling surface, so the REST side goes away.

`GET /sessions/{id}/status` and its schema are removed, the `:undo`
response no longer carries `status`, and `legacyActivity` — which existed
only to project the polled view — is deleted. The transcript contract
loses its `meta` and `todo` entities: `TranscriptMeta`, `TranscriptTodo`,
the operation kinds that maintained them, the `goalMeta`/`modesMeta`/
`agentPhaseMeta` schemas and the `toolCallFrame.todoId` link all go, with
the fold and store following. Clients read the same state from the
`agent`, `usage`, `goal` and `todo` frames instead.

The todo list is now derived from the tool frames that produce it, so an
undo reverts it with the turn that wrote it rather than leaving a stale
copy behind.

Verified: kap-server 315 pass across services/transcript, sessionEvent-
Broadcaster and sessions; transcript 154 pass; agent-core-v2, kap-server,
transcript and apps/kimi-code typechecks clean; oxlint 0 errors;
check:no-comments, check:deep-imports and check:no-hardcoded-prose green.

Not from this change: the `S2` transcript-contract e2e case fails its
afterEach hook with a 10s timeout on a clean HEAD as well, so it is a
pre-existing flake, not a regression here.
7723qqq pushed a commit to 7723qqq/kimi-code that referenced this pull request Nov 5, 2026
The frames in cc3a968 and the REST/transcript teardown in 14fa166
together carry the whole row: a subscriber reads agent, usage, goal and
todo from the socket, and nothing polls a status route or folds a
transcript meta/todo entity any more.
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.

2 participants