Skip to content

feat(core): 主循环报告运行阶段 RunPhase,控制台终端页按它显示状态 - #181

Merged
Phantivia merged 4 commits into
mainfrom
feat/run-phase
Oct 6, 2026
Merged

Phantivia merged 4 commits into
mainfrom
feat/run-phase

Conversation

@Phantivia

@Phantivia Phantivia commented Oct 6, 2026 •

Copy link
Copy Markdown
Member

基于已合并的 #180。处理 #157 的 A4。

改动

Core:RunPhase。 主循环记录此刻在做什么,每个字段都是 Core 直接观察到的事实:

  • state:idle(等下一批,批末钩子也在此状态运行)、delivering(把一批事件写入主 session,含等待 Persona.onDelivery)、model、tools(本轮输出已结束,执行工具调用)、backoff(模型调用失败后等待重试)、handoff。
  • round:本批的轮序号;running:正在执行的工具名,含流式提前执行的调用;retryAt:backoff 时下一次请求的时刻;enteredAt:进入当前 state 的时刻。
  • state、round 或 retryAt 改变,或工具开始、结束时,同步通知可见 World 的 onRunPhase 与 MainLoop.onRunPhase 的订阅;getStatus().phase 返回当前值。暂停与投递闸门不并入,仍由 paused、scheduleBlocked 报告。

控制台。 /ws/debug 新增 phase 帧,每次变化推送;status 帧要估算 token、扫描投递积压,不随工具开始与结束重算。终端页时间线下方那行原先在最后一条是 user Item 时显示「已进上下文,尚无 assistant 输出」(从时间线推断);现在按 phase 显示投递、等待模型、执行工具(带工具名)、重试时刻或交接,idle 时收起。

测试

  • tests/core/loop.test.ts:带工具调用的一批,可见 World 依次看到 delivering → model(1) → tools(1) → 工具开始与结束 → model(2) → idle,隐藏 World 收不到;可重试的失败进入 backoff,retryAt 是重新请求的时刻。
  • tests/web/feature-live.test.ts:追加 user 消息不再点亮状态行,phase 帧决定显示与收起(旧代码上第一条断言失败)。
  • pnpm test 4826 通过,pnpm run typecheck、pnpm typecheck:web 无报错。

World 在运行中挂载或重新可见时,要等下一次变化才收到当前值;WorldHost 没有读取当前 phase 的接口。

English

Core's main loop now keeps a RunPhase (idle, delivering, model, tools, backoff, handoff, with the round, the running tool names, the retry time and when the state was entered). Visible Worlds receive it through onRunPhase and getStatus().phase returns it.

The console's Terminal page shows this phase instead of inferring "in context, no assistant output yet" from the timeline. The phase travels in a separate /ws/debug frame, because the status frame estimates tokens and scans the delivery backlog. Builds on the merged #180; addresses #157 A4.

🤖 Generated with Claude Code

Comment thread src/core/types.ts Outdated

@cursor cursor 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.

先前关于 RunPhase.since 未用 §2 *At 命名的意见不再适用:字段已改名为 enteredAt。

— Cortico PR Gate via Cursor Cloud Agent

Open in Web View Automation 

Sent by Cursor Automation: Cortico PR Gate

Base automatically changed from feat/interrupt-delivery to main October 6, 2026 03:39
Phantivia and others added 4 commits October 5, 2026 22:40
- RunPhase 的 state 为 idle、delivering、model、tools、backoff、handoff,带本批轮序号、
  执行中的工具名(含流式提前执行的调用)、backoff 的 retryAt 与进入时刻;getStatus().phase
  返回当前值。
- state 或 round 改变、工具开始或结束时,同步通知可见 World 的 onRunPhase 与
  MainLoop.onRunPhase 的订阅,异常记 warn。
- 一批的轮次结束即回到 idle,onBatchEnd、onIdle 在 idle 下运行。暂停与投递闸门不并入,
  仍由 paused、scheduleBlocked 报告。
- 测试覆盖带工具调用一批的阶段序列、隐藏 World 不收通知,以及 backoff 的 retryAt 与重试时刻。

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- /ws/debug 新增 phase 帧,RunPhase 每次变化时推送。status 帧要估算 token、扫描投递积压,
  不随工具开始与结束重算。
- 时间线下方那行原先在最后一条是 user Item 时显示「已进上下文,尚无 assistant 输出」;
  现在显示投递、等待模型、执行工具(带工具名)、重试时刻或交接,idle 时收起。查看后台会话
  或调试通道断开时不显示。
- 测试覆盖追加 user 消息不再点亮状态行,phase 帧决定显示与收起。

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
ISO 时刻按 AGENTS.md §2 以 *At 命名,与同一接口的 retryAt 一致。

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Phantivia
Phantivia merged commit b163eb1 into main Oct 6, 2026
3 of 5 checks passed
@Phantivia
Phantivia deleted the feat/run-phase branch October 6, 2026 03:59
@Phantivia Phantivia mentioned this pull request Oct 6, 2026
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