@myclaw163/clawclaw-cli 0.8.21 → 0.8.23
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/docs/custom-modules/api-reference.md +2 -0
- package/docs/custom-modules/perception.md +25 -0
- package/docs/runtime/official-perception-modules.md +23 -0
- package/docs/runtime/owner-lifecycle-and-observability.md +6 -2
- package/package.json +1 -1
- package/skills/clawclaw/references/CUSTOM-MODULE-API.md +2 -0
- package/skills/clawclaw/references/CUSTOM-PERCEPTION-DEVELOPMENT.md +25 -0
- package/src/runtime/clawclaw/agent-event-policy.ts +7 -0
- package/src/runtime/clawclaw/owner.ts +16 -10
- package/src/runtime/clawclaw/plugins/behavior/behavior-plugin.ts +18 -11
- package/src/runtime/clawclaw/plugins/mailbox/adapters/claude-channel-adapter.ts +2 -0
- package/src/runtime/clawclaw/plugins/mailbox/adapters/game-sync-perception-report-adapter.ts +10 -1
- package/src/runtime/clawclaw/plugins/mailbox/agent-mailbox-coordinator.ts +17 -1
- package/src/runtime/clawclaw/plugins/mailbox/mailbox-presentation.ts +5 -2
- package/src/runtime/clawclaw/plugins/mailbox/mailbox-service.ts +46 -15
- package/src/runtime/clawclaw/plugins/perception/perception-module-output.ts +2 -1
- package/src/runtime/clawclaw/plugins/perception/perception-plugin.ts +1 -0
- package/src/runtime/clawclaw/plugins/perception/perception-source.ts +4 -0
- package/src/runtime/framework/events/event-ingress.ts +1 -0
- package/src/runtime/framework/events/memory-event-repository.ts +5 -4
- package/src/runtime/framework/events/sqlite-event-repository.ts +36 -9
- package/src/runtime/framework/events/types.ts +4 -0
- package/src/runtime/framework/mailbox/types.ts +4 -0
- package/src/runtime/framework/plugins/contracts.ts +2 -0
- package/src/runtime/framework/runtime.ts +1 -0
- package/src/runtime/game-sync-ingress-protocol.ts +3 -2
- package/src/runtime/game-sync-ingress-worker.ts +153 -38
- package/src/runtime/mailbox-host-relay.ts +13 -12
- package/src/runtime/threaded-ws-client.ts +17 -9
- package/src/runtime/ws-client.ts +18 -8
- package/src/sdk/perception-plugin/index.ts +4 -0
|
@@ -440,6 +440,7 @@ interface PerceptionApi {
|
|
|
440
440
|
|
|
441
441
|
```ts
|
|
442
442
|
interface PerceptionEventProposal {
|
|
443
|
+
wakeAgent?: boolean; // 覆盖 Manifest 默认值;省略时继承,最终默认 true
|
|
443
444
|
readonly type: string;
|
|
444
445
|
readonly dedupeKey: string;
|
|
445
446
|
readonly dedupeScope?: 'segment' | 'session';
|
|
@@ -492,6 +493,7 @@ debugSnapshot?(): unknown;
|
|
|
492
493
|
| `localizations` | object,可选 | 本地化资源文本 |
|
|
493
494
|
| `subjectScope` | `'others' \| 'self_and_others' \| 'visible_pairs' \| 'corpses'` | 描述 Event 主体范围 |
|
|
494
495
|
| `produces` | `string[]` | 允许输出的 Event type |
|
|
496
|
+
| `wakeAgent` | boolean,可选 | 模块默认是否主动唤醒 Agent,省略为 true;单条 proposal 可覆盖 |
|
|
495
497
|
| `eventMetadata` | object,可选 | 每种 Event 的名称、说明和本地化 |
|
|
496
498
|
| `execution` | `'parallel_analysis'`,可选 | 启用 `analyze/commit` 接口 |
|
|
497
499
|
| `boundaryBaseline` | `'current_only'`,可选 | 声明边界重建能力 |
|
|
@@ -80,6 +80,7 @@ export default class MyPerception extends ClawclawPerception {
|
|
|
80
80
|
| `localizations` | 可选的本地化名称与说明 |
|
|
81
81
|
| `subjectScope` | Event 描述其他玩家、自身与他人、玩家对,还是尸体 |
|
|
82
82
|
| `produces` | 这个模块可能发布的 Event type |
|
|
83
|
+
| `wakeAgent` | 可选布尔值;模块默认是否主动唤醒 Agent,省略为 `true` |
|
|
83
84
|
| `eventMetadata` | 可选,为 `produces` 中的 Event 提供展示名称、说明与本地化 |
|
|
84
85
|
| `execution` | 可选;耗时分析模块写 `parallel_analysis` |
|
|
85
86
|
| `boundaryBaseline` | 可选;声明并行 reducer 能否仅用当前帧安全建立边界基线 |
|
|
@@ -226,11 +227,35 @@ Perception 只能返回 Event proposal:
|
|
|
226
227
|
| `payload` | 结构化业务事实 |
|
|
227
228
|
| `dedupeScope` | 可选,`segment` 或 `session` |
|
|
228
229
|
| `occurredAt` | 可选的事实发生时间 |
|
|
230
|
+
| `wakeAgent` | 可选布尔值,覆盖模块默认唤醒策略 |
|
|
229
231
|
|
|
230
232
|
`dedupeKey` 不会自动阻止模块在后续 frame 再次发布同类事实。需要“只发布一次”时,应像最小示例一样在实例或 reducer 中维护状态。
|
|
231
233
|
|
|
232
234
|
Perception 不能返回 Action、Behavior Status 或 GameState patch。
|
|
233
235
|
|
|
236
|
+
|
|
237
|
+
## 是否主动唤醒 Agent
|
|
238
|
+
|
|
239
|
+
Manifest 可声明 `wakeAgent: false`,让模块默认只积累感知。省略时默认 `true`,保持已有模块行为。单条 `PerceptionEventProposal.wakeAgent` 可以覆盖模块默认值;仅接受布尔值。
|
|
240
|
+
|
|
241
|
+
```ts
|
|
242
|
+
static readonly manifest = {
|
|
243
|
+
apiVersion: 2,
|
|
244
|
+
id: 'visual.first_sighting',
|
|
245
|
+
name: '第一次看见玩家',
|
|
246
|
+
description: '记录首次目击,随下一次通知交付。',
|
|
247
|
+
subjectScope: 'others',
|
|
248
|
+
produces: ['visual.first_sighting'],
|
|
249
|
+
wakeAgent: false,
|
|
250
|
+
} as const;
|
|
251
|
+
```
|
|
252
|
+
|
|
253
|
+
静默 Event 仍立即持久化并供 Behavior 消费。只有待交付批次中存在允许唤醒的 Event 时,Mailbox 才主动推送,并携带已积累的静默感知;`ccl events` 主动查询可直接读取。定时 flush、预算恢复、重连和 Runtime 重启都不会单独释放静默积压。该选项不改变视觉事实、Event type、去重身份或 Trigger 的输入。
|
|
254
|
+
|
|
255
|
+
Monitor 沿用既有预算、视觉限频和溢出提示规则。可唤醒感知的投递优先级为 50,静默感知为 40;普通名额选择、积压提示锚点和同批拆包投递优先保留较高优先级。同优先级保留原有类别与时间规则。其他事件维持原优先级,80 及以上的直推保护不变,感知不会仅因允许唤醒而绕过普通预算。只有静默感知时不生成积压提醒。Monitor 成功推出通知时,该 Ready 批次涵盖的感知就向服务器上报,包括被积压提醒覆盖的感知,无需等待 `ccl events`;Channels/Desktop 则随批次交付确认上报。上报保持 best-effort,不参与 Agent ACK。
|
|
256
|
+
|
|
257
|
+
官方模块仅尸体与跟随可唤醒。跟随在 12 个有效 tick 后确认并静默输出,累计有效跟随证据严格超过 30 tick(3 秒)时补发一次可唤醒的 `visual.following`。之后的查询快照不重复唤醒;达到阈值的关系结束可唤醒,短关系结束保持静默。短暂不满足条件的 tick 不计入有效证据。
|
|
258
|
+
|
|
234
259
|
## 怎样保存跨帧信息
|
|
235
260
|
|
|
236
261
|
普通 `update()` 模式会在同一个实例上按帧调用,因此可以用类字段保存轨迹状态。状态应只描述当前连续视觉片段。
|
|
@@ -345,3 +345,26 @@ ccl perception --enable visual.follow
|
|
|
345
345
|
## 实现真值
|
|
346
346
|
|
|
347
347
|
本文的官方清单对应 `src/runtime/clawclaw/plugins/perception/official-module-ids.ts` 和 `official-modules.ts` 的闭合注册表。判断某个模块是否属于当前发布的官方资源,以该注册表、模块 manifest 和 `ccl perception --list` 的静态目录为准;判断某一局是否实际加载成功,还要看当次 Runtime 启动和诊断。仅存在设计稿、测试辅助模块或 Event Catalog 条目,不代表它已被官方默认装载。
|
|
348
|
+
|
|
349
|
+
|
|
350
|
+
## 是否主动唤醒 Agent
|
|
351
|
+
|
|
352
|
+
Manifest 可声明 `wakeAgent: false`,让模块默认只积累感知。省略时默认 `true`,保持已有模块行为。单条 `PerceptionEventProposal.wakeAgent` 可以覆盖模块默认值;仅接受布尔值。
|
|
353
|
+
|
|
354
|
+
```ts
|
|
355
|
+
static readonly manifest = {
|
|
356
|
+
apiVersion: 2,
|
|
357
|
+
id: 'visual.first_sighting',
|
|
358
|
+
name: '第一次看见玩家',
|
|
359
|
+
description: '记录首次目击,随下一次通知交付。',
|
|
360
|
+
subjectScope: 'others',
|
|
361
|
+
produces: ['visual.first_sighting'],
|
|
362
|
+
wakeAgent: false,
|
|
363
|
+
} as const;
|
|
364
|
+
```
|
|
365
|
+
|
|
366
|
+
静默 Event 仍立即持久化并供 Behavior 消费。只有待交付批次中存在允许唤醒的 Event 时,Mailbox 才主动推送,并携带已积累的静默感知;`ccl events` 主动查询可直接读取。定时 flush、预算恢复、重连和 Runtime 重启都不会单独释放静默积压。该选项不改变视觉事实、Event type、去重身份或 Trigger 的输入。
|
|
367
|
+
|
|
368
|
+
Monitor 沿用既有预算、视觉限频和溢出提示规则。只有静默感知时不生成积压提醒。Monitor 成功推出通知时,该 Ready 批次涵盖的感知就向服务器上报,包括被积压提醒覆盖的感知,无需等待 `ccl events`;Channels/Desktop 则随批次交付确认上报。上报保持 best-effort,不参与 Agent ACK。
|
|
369
|
+
|
|
370
|
+
官方模块仅尸体与跟随可唤醒。跟随在 12 个有效 tick 后确认并静默输出,累计有效跟随证据严格超过 30 tick(3 秒)时补发一次可唤醒的 `visual.following`。之后的查询快照不重复唤醒;达到阈值的关系结束可唤醒,短关系结束保持静默。短暂不满足条件的 tick 不计入有效证据。
|
|
@@ -73,13 +73,17 @@ Owner 的 GameSync WS、序号校验、delta 还原、ping/pong 和原始收包
|
|
|
73
73
|
|
|
74
74
|
Scheduler 每次重新调度会让出一个事件循环轮次,给待处理的传输/Worker消息进入Source的机会,避免连续微任务一直先执行计算。插件依赖、顺序提交、关键epoch保护和计算并发上限保持原有语义;不会承诺资源耗尽时无限吞吐。
|
|
75
75
|
|
|
76
|
-
Worker
|
|
76
|
+
收流 Worker 完成协议/序号校验,将原始消息成功保存到自己的内存缓存后即推进后端 ACK,不等待 Owner / Source 接纳或插件计算。缓存默认 **32 MiB 原始 JSON UTF-8 载荷**;对象、索引和少量完整状态开销另计。Source 消费后才释放对应缓存。Worker 按投递名额还原完整帧,默认最多十帧已投递但尚未消费;十帧是投递窗口,不再是断连条件,窗口用完后仍继续接收和 ACK。
|
|
77
|
+
|
|
78
|
+
网络恢复位置与 Source 消费位置分开管理:普通 socket 重连使用 Worker 已缓存确认的位置,未消费缓存保留;旧帧消费完后再向 Source 交付新连接的生命周期及恢复帧,保证状态、事件和连接顺序。Source 的 `acknowledgeGameSync` 调用在 threaded 模式下仅确认消费、释放名额,并保留 Source 基线用于 Worker 丢失后的恢复。inline 短命令客户端仍由调用方确认 ACK。
|
|
79
|
+
|
|
80
|
+
真正达到原始缓存字节上限时仍记录 `CCL_INGRESS_BACKLOG_LIMIT`(本地1013);未保存的消息不 ACK,保留已有缓存,排空后从已缓存确认的位置恢复。普通计算落后不会再因十帧限制触发此保护。未完成的网络重放不会暴露给 Source,恢复仍遵循 resume 校验或 snapshot fallback。缓存仅在内存,Worker/进程丢失可能丢失尚未消费的已 ACK 数据;不能承诺跨进程崩溃零丢失或超出后端恢复窗口的历史补回。
|
|
77
81
|
|
|
78
82
|
生产级复盘使用 `CLAWCLAW_OBSERVABILITY_LEVEL=full`,在Owner启动前设置。需要确认日志出现以下记录;仅看CLI版本号或导出目录名不能证明新实现已运行:
|
|
79
83
|
|
|
80
84
|
| 记录 | 关键字段和含义 |
|
|
81
85
|
| --- | --- |
|
|
82
|
-
| `runtime.ws.ingress_window` | 每5秒的Worker计数快照;`implementation=
|
|
86
|
+
| `runtime.ws.ingress_window` | 每5秒的Worker计数快照;`implementation=buffered_gamesync_v2`、package/Node版本、transport_generation、thread_id;`received_seq` / `buffered_seq` / `source_accepted_seq` / `ack_submitted_seq` 区分接收、缓存、Source消费和协议ACK提交;缓存帧数、原始字节及峰值、完整帧在途数/名额、未完成重放字节;`max_source_consumption_delay_ms` 是收到到消费的延迟,不是网络ACK延迟;另含过载次数和ping/pong、Worker事件循环指标 |
|
|
83
87
|
| `runtime.source.frame_admitted` | 每个接纳帧的epoch_seq/source_seq/domain_tick;socket接收、decode完成、Worker发出、Owner收到、Source开始和接纳完成的本机时间;decode、跨线程交付、Source排队和接纳耗时 |
|
|
84
88
|
| `runtime.view.ready` | 同epoch的intake/scheduler/finalize/total时间,以及`received_to_ready_ms`;full级别保留这条记录,不再视作数据库重复项过滤 |
|
|
85
89
|
| `runtime.diagnostics.sample` | Owner进程内存/保留记录数、CPU增量、事件循环利用率和延迟、GC次数/时间、各计算池状态 |
|
package/package.json
CHANGED
|
@@ -436,6 +436,7 @@ interface PerceptionApi {
|
|
|
436
436
|
|
|
437
437
|
```ts
|
|
438
438
|
interface PerceptionEventProposal {
|
|
439
|
+
wakeAgent?: boolean; // 覆盖 Manifest 默认值;省略时继承,最终默认 true
|
|
439
440
|
readonly type: string;
|
|
440
441
|
readonly dedupeKey: string;
|
|
441
442
|
readonly dedupeScope?: 'segment' | 'session';
|
|
@@ -488,6 +489,7 @@ debugSnapshot?(): unknown;
|
|
|
488
489
|
| `localizations` | object,可选 | 本地化资源文本 |
|
|
489
490
|
| `subjectScope` | `'others' \| 'self_and_others' \| 'visible_pairs' \| 'corpses'` | 描述 Event 主体范围 |
|
|
490
491
|
| `produces` | `string[]` | 允许输出的 Event type |
|
|
492
|
+
| `wakeAgent` | boolean,可选 | 模块默认是否主动唤醒 Agent,省略为 true;单条 proposal 可覆盖 |
|
|
491
493
|
| `eventMetadata` | object,可选 | 每种 Event 的名称、说明和本地化 |
|
|
492
494
|
| `execution` | `'parallel_analysis'`,可选 | 启用 `analyze/commit` 接口 |
|
|
493
495
|
| `boundaryBaseline` | `'current_only'`,可选 | 声明边界重建能力 |
|
|
@@ -80,6 +80,7 @@ export default class MyPerception extends ClawclawPerception {
|
|
|
80
80
|
| `localizations` | 可选的本地化名称与说明 |
|
|
81
81
|
| `subjectScope` | Event 描述其他玩家、自身与他人、玩家对,还是尸体 |
|
|
82
82
|
| `produces` | 这个模块可能发布的 Event type |
|
|
83
|
+
| `wakeAgent` | 可选布尔值;模块默认是否主动唤醒 Agent,省略为 `true` |
|
|
83
84
|
| `eventMetadata` | 可选,为 `produces` 中的 Event 提供展示名称、说明与本地化 |
|
|
84
85
|
| `execution` | 可选;耗时分析模块写 `parallel_analysis` |
|
|
85
86
|
| `boundaryBaseline` | 可选;声明并行 reducer 能否仅用当前帧安全建立边界基线 |
|
|
@@ -226,11 +227,35 @@ Perception 只能返回 Event proposal:
|
|
|
226
227
|
| `payload` | 结构化业务事实 |
|
|
227
228
|
| `dedupeScope` | 可选,`segment` 或 `session` |
|
|
228
229
|
| `occurredAt` | 可选的事实发生时间 |
|
|
230
|
+
| `wakeAgent` | 可选布尔值,覆盖模块默认唤醒策略 |
|
|
229
231
|
|
|
230
232
|
`dedupeKey` 不会自动阻止模块在后续 frame 再次发布同类事实。需要“只发布一次”时,应像最小示例一样在实例或 reducer 中维护状态。
|
|
231
233
|
|
|
232
234
|
Perception 不能返回 Action、Behavior Status 或 GameState patch。
|
|
233
235
|
|
|
236
|
+
|
|
237
|
+
## 是否主动唤醒 Agent
|
|
238
|
+
|
|
239
|
+
Manifest 可声明 `wakeAgent: false`,让模块默认只积累感知。省略时默认 `true`,保持已有模块行为。单条 `PerceptionEventProposal.wakeAgent` 可以覆盖模块默认值;仅接受布尔值。
|
|
240
|
+
|
|
241
|
+
```ts
|
|
242
|
+
static readonly manifest = {
|
|
243
|
+
apiVersion: 2,
|
|
244
|
+
id: 'visual.first_sighting',
|
|
245
|
+
name: '第一次看见玩家',
|
|
246
|
+
description: '记录首次目击,随下一次通知交付。',
|
|
247
|
+
subjectScope: 'others',
|
|
248
|
+
produces: ['visual.first_sighting'],
|
|
249
|
+
wakeAgent: false,
|
|
250
|
+
} as const;
|
|
251
|
+
```
|
|
252
|
+
|
|
253
|
+
静默 Event 仍立即持久化并供 Behavior 消费。只有待交付批次中存在允许唤醒的 Event 时,Mailbox 才主动推送,并携带已积累的静默感知;`ccl events` 主动查询可直接读取。定时 flush、预算恢复、重连和 Runtime 重启都不会单独释放静默积压。该选项不改变视觉事实、Event type、去重身份或 Trigger 的输入。
|
|
254
|
+
|
|
255
|
+
Monitor 沿用既有预算、视觉限频和溢出提示规则。可唤醒感知的投递优先级为 50,静默感知为 40;普通名额选择、积压提示锚点和同批拆包投递优先保留较高优先级。同优先级保留原有类别与时间规则。其他事件维持原优先级,80 及以上的直推保护不变,感知不会仅因允许唤醒而绕过普通预算。只有静默感知时不生成积压提醒。Monitor 成功推出通知时,该 Ready 批次涵盖的感知就向服务器上报,包括被积压提醒覆盖的感知,无需等待 `ccl events`;Channels/Desktop 则随批次交付确认上报。上报保持 best-effort,不参与 Agent ACK。
|
|
256
|
+
|
|
257
|
+
官方模块仅尸体与跟随可唤醒。跟随在 12 个有效 tick 后确认并静默输出,累计有效跟随证据严格超过 30 tick(3 秒)时补发一次可唤醒的 `visual.following`。之后的查询快照不重复唤醒;达到阈值的关系结束可唤醒,短关系结束保持静默。短暂不满足条件的 tick 不计入有效证据。
|
|
258
|
+
|
|
234
259
|
## 怎样保存跨帧信息
|
|
235
260
|
|
|
236
261
|
普通 `update()` 模式会在同一个实例上按帧调用,因此可以用类字段保存轨迹状态。状态应只描述当前连续视觉片段。
|
|
@@ -46,6 +46,13 @@ export function clawclawMonitorPriority(type: string): number {
|
|
|
46
46
|
return CLAWCLAW_MONITOR_EVENT_PRIORITY[type] ?? DEFAULT_MONITOR_PRIORITY;
|
|
47
47
|
}
|
|
48
48
|
|
|
49
|
+
/** Resolved per-event priority; wake policy only changes visual Event ranking. */
|
|
50
|
+
export function clawclawMonitorEventPriority(event: { type: string; wakeAgent?: boolean }): number {
|
|
51
|
+
return event.type.startsWith('visual.')
|
|
52
|
+
? event.wakeAgent === false ? 40 : 50
|
|
53
|
+
: clawclawMonitorPriority(event.type);
|
|
54
|
+
}
|
|
55
|
+
|
|
49
56
|
export function clawclawMonitorDelayMs(type: string): number {
|
|
50
57
|
return CLAWCLAW_MONITOR_DELAY_MS[type] ?? 0;
|
|
51
58
|
}
|
|
@@ -897,9 +897,19 @@ export async function runClawclawOwner(
|
|
|
897
897
|
throw new Error('The configured Runtime repository does not support durable Mailbox delivery.');
|
|
898
898
|
}
|
|
899
899
|
const mailboxRepository = runtime.repository;
|
|
900
|
+
const perceptionReportAdapter = new GameSyncPerceptionReportAdapter({
|
|
901
|
+
producerPluginId: assembly.perception.id,
|
|
902
|
+
descriptor: (eventType) => assembly.perception.localizedModuleDescriptorForEvent(
|
|
903
|
+
eventType,
|
|
904
|
+
client.gameSyncLocale,
|
|
905
|
+
),
|
|
906
|
+
send: (reports) => client.reportGameSyncPerceptions(reports),
|
|
907
|
+
diagnostic: (name, attributes) => runtime?.diagnostic(name, attributes),
|
|
908
|
+
});
|
|
900
909
|
cclEventsMailbox = new AgentMailboxCoordinator({
|
|
901
910
|
repository: mailboxRepository,
|
|
902
911
|
readyView: () => runtime!.readReadyView(0, 1),
|
|
912
|
+
onDelivered: (events) => perceptionReportAdapter.reportDelivered(events),
|
|
903
913
|
presentEvent: ownerAgentEventPresenter('ccl_events', !!options.desktopEvents),
|
|
904
914
|
compactState: compactStateForEvents,
|
|
905
915
|
eventFilter: clawclawEventRequiresDetails,
|
|
@@ -921,24 +931,15 @@ export async function runClawclawOwner(
|
|
|
921
931
|
monitorEnabled: !!options.notificationHost,
|
|
922
932
|
diagnostic: (name, attributes, severity) => runtime?.diagnostic(name, attributes, severity),
|
|
923
933
|
});
|
|
924
|
-
const perceptionReportAdapter = new GameSyncPerceptionReportAdapter({
|
|
925
|
-
producerPluginId: assembly.perception.id,
|
|
926
|
-
descriptor: (eventType) => assembly.perception.localizedModuleDescriptorForEvent(
|
|
927
|
-
eventType,
|
|
928
|
-
client.gameSyncLocale,
|
|
929
|
-
),
|
|
930
|
-
send: (reports) => client.reportGameSyncPerceptions(reports),
|
|
931
|
-
diagnostic: (name, attributes) => runtime?.diagnostic(name, attributes),
|
|
932
|
-
});
|
|
933
934
|
const mailboxDrivers: ClawclawMailboxDriver[] = [
|
|
934
935
|
mailboxService,
|
|
935
936
|
cclEventsMailbox,
|
|
936
|
-
perceptionReportAdapter,
|
|
937
937
|
];
|
|
938
938
|
if (options.desktopEvents) {
|
|
939
939
|
desktopMailbox = new AgentMailboxCoordinator({
|
|
940
940
|
repository: mailboxRepository,
|
|
941
941
|
readyView: () => runtime!.readReadyView(0, 1),
|
|
942
|
+
onDelivered: (events) => perceptionReportAdapter.reportDelivered(events),
|
|
942
943
|
presentEvent: ownerAgentEventPresenter('desktop_ipc', true),
|
|
943
944
|
compactState: compactStateForEvents,
|
|
944
945
|
consumerId: DESKTOP_IPC_MAILBOX_CONSUMER_ID,
|
|
@@ -993,6 +994,7 @@ export async function runClawclawOwner(
|
|
|
993
994
|
assembly.behavior.attachDriver(createClawclawBehaviorControlDriver(runtime));
|
|
994
995
|
if (channelPolicy.enabled) {
|
|
995
996
|
channelAdapter = new ClaudeChannelMailboxAdapter({
|
|
997
|
+
onDelivered: (events) => perceptionReportAdapter.reportDelivered(events),
|
|
996
998
|
repository: mailboxRepository,
|
|
997
999
|
readyView: () => runtime!.readReadyView(0, 1),
|
|
998
1000
|
diagnostic: (name, attributes) => runtime?.diagnostic(name, attributes),
|
|
@@ -1080,6 +1082,10 @@ export async function runClawclawOwner(
|
|
|
1080
1082
|
mailboxRepository,
|
|
1081
1083
|
'short',
|
|
1082
1084
|
MONITOR_MAILBOX_CONSUMER_ID,
|
|
1085
|
+
undefined,
|
|
1086
|
+
(eventIds) => {
|
|
1087
|
+
perceptionReportAdapter.reportDelivered(mailboxService!.monitorDeliveredEvents(eventIds));
|
|
1088
|
+
},
|
|
1083
1089
|
);
|
|
1084
1090
|
relayAbort = new AbortController();
|
|
1085
1091
|
relayAlive = true;
|
|
@@ -705,7 +705,13 @@ implements RuntimeEpochPlugin<Record<string, any>>, BehaviorReflexActivationDriv
|
|
|
705
705
|
computation: Readonly<RuntimeEpochPluginResult>,
|
|
706
706
|
context: RuntimeEpochPluginContext<Record<string, any>>,
|
|
707
707
|
): Promise<RuntimeEpochPluginResult> {
|
|
708
|
-
return this.enqueueControl(() =>
|
|
708
|
+
return this.enqueueControl(async () => {
|
|
709
|
+
const result = await this.commitOrdered(input, proposal(computation.proposal), context);
|
|
710
|
+
// Report the final activation after this epoch's advances, finishes and
|
|
711
|
+
// boundary transitions, rather than the activation it started with.
|
|
712
|
+
this.refreshBackendStrategyReport(input, context);
|
|
713
|
+
return result;
|
|
714
|
+
});
|
|
709
715
|
}
|
|
710
716
|
|
|
711
717
|
async stop(reason: 'segment_ending' | 'shutdown'): Promise<void> {
|
|
@@ -797,7 +803,6 @@ implements RuntimeEpochPlugin<Record<string, any>>, BehaviorReflexActivationDriv
|
|
|
797
803
|
const runtimeState = input.epoch.state;
|
|
798
804
|
|
|
799
805
|
await this.syncRoleFallback(frameForClock, now);
|
|
800
|
-
this.refreshBackendStrategyReport(input, context);
|
|
801
806
|
|
|
802
807
|
await this.applyTransitions(this.manager.advance(now));
|
|
803
808
|
const currentForFrame = this.manager.current();
|
|
@@ -1344,17 +1349,19 @@ implements RuntimeEpochPlugin<Record<string, any>>, BehaviorReflexActivationDriv
|
|
|
1344
1349
|
|
|
1345
1350
|
/**
|
|
1346
1351
|
* The backend still calls this display-only field a Strategy. Report the
|
|
1347
|
-
*
|
|
1352
|
+
* current activation, including short/reflex overrides. A configured fallback
|
|
1353
|
+
* or suspended long is not active until the manager gives it control.
|
|
1348
1354
|
*/
|
|
1349
1355
|
private backendStrategyDescriptor(): ClawclawResolvedResourceMetadata | undefined {
|
|
1350
|
-
const
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
|
|
1356
|
-
|
|
1357
|
-
|
|
1356
|
+
const current = this.manager.current();
|
|
1357
|
+
if (!current) return {
|
|
1358
|
+
// The backend requires non-empty display text and has no clear action.
|
|
1359
|
+
id: 'clawclaw:no-active-behavior',
|
|
1360
|
+
name: '无策略在运行',
|
|
1361
|
+
description: '当前没有活跃的策略。',
|
|
1362
|
+
};
|
|
1363
|
+
const prepared = this.runtimes.get(current.activationId)?.prepared;
|
|
1364
|
+
if (!prepared || prepared.manifest.id !== current.behaviorId) return undefined;
|
|
1358
1365
|
return resolveClawclawResourceMetadata({
|
|
1359
1366
|
id: prepared.manifest.id,
|
|
1360
1367
|
name: prepared.manifest.name,
|
|
@@ -15,6 +15,7 @@ export const CLAUDE_CHANNEL_CONSUMER_ID = CLAUDE_CHANNEL_MAILBOX_CONSUMER_ID;
|
|
|
15
15
|
export const CLAUDE_CHANNEL_COALESCE_MS = 220;
|
|
16
16
|
|
|
17
17
|
export interface ClaudeChannelMailboxAdapterOptions {
|
|
18
|
+
onDelivered?: (events: readonly CanonicalEvent[]) => void;
|
|
18
19
|
repository: EventRepository;
|
|
19
20
|
readyView: () => RuntimeReadyView;
|
|
20
21
|
consumerId?: string;
|
|
@@ -39,6 +40,7 @@ export class ClaudeChannelMailboxAdapter implements ClawclawMailboxDriver {
|
|
|
39
40
|
consumerId: this.consumerId,
|
|
40
41
|
};
|
|
41
42
|
this.coordinator = new AgentMailboxCoordinator({
|
|
43
|
+
onDelivered: options.onDelivered,
|
|
42
44
|
repository: options.repository,
|
|
43
45
|
readyView: options.readyView,
|
|
44
46
|
presentEvent: presentCanonicalEventForChannel,
|
package/src/runtime/clawclaw/plugins/mailbox/adapters/game-sync-perception-report-adapter.ts
CHANGED
|
@@ -56,14 +56,22 @@ export class GameSyncPerceptionReportAdapter implements ClawclawMailboxDriver {
|
|
|
56
56
|
};
|
|
57
57
|
|
|
58
58
|
private stopped = false;
|
|
59
|
+
private sessionId?: string;
|
|
60
|
+
private readonly reported = new Set<string>();
|
|
59
61
|
|
|
60
62
|
constructor(private readonly options: GameSyncPerceptionReportAdapterOptions) {}
|
|
61
63
|
|
|
62
|
-
|
|
64
|
+
/** Called only at Agent delivery, including Monitor backlog notification. */
|
|
65
|
+
reportDelivered(events: readonly CanonicalEvent[]): void {
|
|
63
66
|
if (this.stopped) return;
|
|
64
67
|
let skipped = 0;
|
|
65
68
|
const reports: GameSyncPerceptionReport[] = [];
|
|
66
69
|
for (const event of events) {
|
|
70
|
+
if (this.sessionId !== event.sessionId) {
|
|
71
|
+
this.sessionId = event.sessionId;
|
|
72
|
+
this.reported.clear();
|
|
73
|
+
}
|
|
74
|
+
if (this.reported.has(event.eventId)) continue;
|
|
67
75
|
if (
|
|
68
76
|
event.producerPluginId !== this.options.producerPluginId
|
|
69
77
|
|| event.deliveryClass === 'internal_only'
|
|
@@ -75,6 +83,7 @@ export class GameSyncPerceptionReportAdapter implements ClawclawMailboxDriver {
|
|
|
75
83
|
skipped += 1;
|
|
76
84
|
continue;
|
|
77
85
|
}
|
|
86
|
+
this.reported.add(event.eventId);
|
|
78
87
|
reports.push({
|
|
79
88
|
id: uuidForEvent(event),
|
|
80
89
|
name: descriptor.name.trim(),
|
|
@@ -51,6 +51,8 @@ export interface AgentMailboxCoordinatorOptions {
|
|
|
51
51
|
state: Record<string, any> | null | undefined,
|
|
52
52
|
events?: Array<Record<string, any>>,
|
|
53
53
|
) => Record<string, any> | null;
|
|
54
|
+
/** Best-effort observer after this consumer accepts a batch. */
|
|
55
|
+
onDelivered?: (events: readonly CanonicalEvent[]) => void;
|
|
54
56
|
/** Adapter-specific selection; omitted adapters receive every Agent-visible Event. */
|
|
55
57
|
eventFilter?: (
|
|
56
58
|
event: CanonicalEvent,
|
|
@@ -164,6 +166,7 @@ function compactBehaviorStateForAgent(
|
|
|
164
166
|
*/
|
|
165
167
|
export class AgentMailboxCoordinator {
|
|
166
168
|
readonly adapter?: ClawclawMailboxAdapterDescriptor;
|
|
169
|
+
private readonly onDelivered?: AgentMailboxCoordinatorOptions['onDelivered'];
|
|
167
170
|
private readonly repository: EventRepository;
|
|
168
171
|
private readonly readyView: () => RuntimeReadyView;
|
|
169
172
|
private readonly presentEvent: AgentMailboxCoordinatorOptions['presentEvent'];
|
|
@@ -183,6 +186,7 @@ export class AgentMailboxCoordinator {
|
|
|
183
186
|
private stopped = false;
|
|
184
187
|
|
|
185
188
|
constructor(options: AgentMailboxCoordinatorOptions) {
|
|
189
|
+
this.onDelivered = options.onDelivered;
|
|
186
190
|
this.repository = options.repository;
|
|
187
191
|
this.readyView = options.readyView;
|
|
188
192
|
this.presentEvent = options.presentEvent;
|
|
@@ -255,6 +259,11 @@ export class AgentMailboxCoordinator {
|
|
|
255
259
|
return { batch: emptyBatch(state), readyEpochSeq: ready.epochSeq };
|
|
256
260
|
}
|
|
257
261
|
|
|
262
|
+
if (!options.bypassDelay && !pending.some(({ event }) => event.wakeAgent !== false)) {
|
|
263
|
+
this.delayWindow = undefined;
|
|
264
|
+
return { batch: emptyBatch(state), readyEpochSeq: ready.epochSeq };
|
|
265
|
+
}
|
|
266
|
+
|
|
258
267
|
if (this.delayWindow?.sessionId !== ready.scope.sessionId) {
|
|
259
268
|
this.delayWindow = {
|
|
260
269
|
sessionId: ready.scope.sessionId,
|
|
@@ -375,6 +384,12 @@ export class AgentMailboxCoordinator {
|
|
|
375
384
|
} as Parameters<EventRepository['transitionDetails']>[0];
|
|
376
385
|
const changed = this.repository.transitionDetails(transition);
|
|
377
386
|
if (changed !== prepared.eventIds.length) return false;
|
|
387
|
+
try {
|
|
388
|
+
this.onDelivered?.(prepared.eventIds.flatMap((id) => {
|
|
389
|
+
const event = this.repository.eventById(id);
|
|
390
|
+
return event ? [event] : [];
|
|
391
|
+
}));
|
|
392
|
+
} catch { /* Display reporting must not affect delivery ACK. */ }
|
|
378
393
|
this.prepared.delete(deliveryToken);
|
|
379
394
|
this.repository.releaseLease(prepared.lease);
|
|
380
395
|
this.notifyPreparedSlotAvailable();
|
|
@@ -452,7 +467,7 @@ export class AgentMailboxCoordinator {
|
|
|
452
467
|
}, this.consumerId, ['details']).filter((row) => (
|
|
453
468
|
this.selectsEvent(row.event, ready.state.state)
|
|
454
469
|
));
|
|
455
|
-
if (pending.
|
|
470
|
+
if (!pending.some(({ event }) => event.wakeAgent !== false) && this.prepared.size === 0) return true;
|
|
456
471
|
await new Promise<void>((resolve) => {
|
|
457
472
|
const timer = setTimeout(resolve, READY_VIEW_RETRY_MS);
|
|
458
473
|
timer.unref?.();
|
|
@@ -471,6 +486,7 @@ export class AgentMailboxCoordinator {
|
|
|
471
486
|
event: CanonicalEvent,
|
|
472
487
|
state: Record<string, any> | null | undefined,
|
|
473
488
|
): boolean {
|
|
489
|
+
if (this.delegatedMonitorConsumerId && event.deliveryClass !== 'internal_only' && event.wakeAgent === false) return true;
|
|
474
490
|
if (this.eventFilter(event, state)) return true;
|
|
475
491
|
if (!this.delegatedMonitorConsumerId) return false;
|
|
476
492
|
return this.repository.delivery(event.eventId, this.delegatedMonitorConsumerId)
|
|
@@ -7,6 +7,7 @@ import type { CanonicalEvent } from '../../../framework/events/index.js';
|
|
|
7
7
|
import type { RuntimeReadyView } from '../../../framework/runtime.js';
|
|
8
8
|
import {
|
|
9
9
|
clawclawMonitorPriority,
|
|
10
|
+
clawclawMonitorEventPriority,
|
|
10
11
|
} from '../../agent-event-policy.js';
|
|
11
12
|
import { isRoomMode } from '../../../../lib/room.js';
|
|
12
13
|
|
|
@@ -31,6 +32,7 @@ export const CLAWCLAW_DETAIL_EVENT_TYPES = new Set<string>([
|
|
|
31
32
|
export interface ClawclawMonitorItemPayload extends Record<string, unknown> {
|
|
32
33
|
schema: 'clawclaw.monitor-item.v1';
|
|
33
34
|
event_id: string;
|
|
35
|
+
monitor_priority?: number;
|
|
34
36
|
ready: {
|
|
35
37
|
epoch_seq: number;
|
|
36
38
|
frame_seq: number;
|
|
@@ -92,6 +94,7 @@ export function monitorItemPayload(
|
|
|
92
94
|
const fullMessage = fullMonitorMessage(presented, ready.state.state);
|
|
93
95
|
return {
|
|
94
96
|
schema: 'clawclaw.monitor-item.v1',
|
|
97
|
+
monitor_priority: clawclawMonitorEventPriority(event),
|
|
95
98
|
event_id: event.eventId,
|
|
96
99
|
ready: {
|
|
97
100
|
epoch_seq: ready.epochSeq,
|
|
@@ -111,8 +114,8 @@ function orderedItems(items: readonly ClawclawMonitorItemPayload[]): ClawclawMon
|
|
|
111
114
|
return items
|
|
112
115
|
.map((item, index) => ({ item, index }))
|
|
113
116
|
.sort((left, right) => (
|
|
114
|
-
clawclawMonitorPriority(String(right.item.event.type ?? ''))
|
|
115
|
-
- clawclawMonitorPriority(String(left.item.event.type ?? ''))
|
|
117
|
+
(right.item.monitor_priority ?? clawclawMonitorPriority(String(right.item.event.type ?? '')))
|
|
118
|
+
- (left.item.monitor_priority ?? clawclawMonitorPriority(String(left.item.event.type ?? '')))
|
|
116
119
|
|| left.index - right.index
|
|
117
120
|
))
|
|
118
121
|
.map(({ item }) => item);
|
|
@@ -13,7 +13,7 @@ import {
|
|
|
13
13
|
} from '../../../framework/mailbox/index.js';
|
|
14
14
|
import type { RuntimeDiagnosticSeverity } from '../../../framework/plugins/contracts.js';
|
|
15
15
|
import type { RuntimeReadyView } from '../../../framework/runtime.js';
|
|
16
|
-
import {
|
|
16
|
+
import { clawclawMonitorEventPriority } from '../../agent-event-policy.js';
|
|
17
17
|
import { AgentMailboxCoordinator } from './agent-mailbox-coordinator.js';
|
|
18
18
|
import type {
|
|
19
19
|
ClawclawMailboxAdapterDescriptor,
|
|
@@ -59,15 +59,15 @@ const MONITOR_NOISY_VISUAL_EVENT_TYPES = new Set([
|
|
|
59
59
|
'visual.players_moving_together',
|
|
60
60
|
]);
|
|
61
61
|
|
|
62
|
-
function monitorEventMustRemainDirect(event: Pick<CanonicalEvent, 'type'>): boolean {
|
|
62
|
+
function monitorEventMustRemainDirect(event: Pick<CanonicalEvent, 'type' | 'wakeAgent'>): boolean {
|
|
63
63
|
return MONITOR_TERMINAL_EVENT_TYPES.has(event.type)
|
|
64
|
-
||
|
|
64
|
+
|| clawclawMonitorEventPriority(event) >= MONITOR_PROTECTED_PRIORITY;
|
|
65
65
|
}
|
|
66
66
|
|
|
67
|
-
function monitorDirectAdmissionPriority(event: Pick<CanonicalEvent, 'type'>): number {
|
|
67
|
+
function monitorDirectAdmissionPriority(event: Pick<CanonicalEvent, 'type' | 'wakeAgent'>): number {
|
|
68
68
|
return MONITOR_TERMINAL_EVENT_TYPES.has(event.type)
|
|
69
69
|
? Number.MAX_SAFE_INTEGER
|
|
70
|
-
:
|
|
70
|
+
: clawclawMonitorEventPriority(event);
|
|
71
71
|
}
|
|
72
72
|
|
|
73
73
|
function ordinaryMonitorRetentionRank(event: Pick<CanonicalEvent, 'type' | 'commitSeq'>): number {
|
|
@@ -77,7 +77,7 @@ function ordinaryMonitorRetentionRank(event: Pick<CanonicalEvent, 'type' | 'comm
|
|
|
77
77
|
return event.type.startsWith('visual.') ? 1 : 0;
|
|
78
78
|
}
|
|
79
79
|
|
|
80
|
-
function monitorEventIsNoisyVisual(event: Pick<CanonicalEvent, 'type'>): boolean {
|
|
80
|
+
function monitorEventIsNoisyVisual(event: Pick<CanonicalEvent, 'type' | 'wakeAgent'>): boolean {
|
|
81
81
|
return MONITOR_NOISY_VISUAL_EVENT_TYPES.has(event.type);
|
|
82
82
|
}
|
|
83
83
|
|
|
@@ -340,7 +340,7 @@ export class ClawclawMailboxService implements ClawclawMailboxDriver {
|
|
|
340
340
|
row.event.eventId,
|
|
341
341
|
'short',
|
|
342
342
|
));
|
|
343
|
-
if (unprojected.length === 0) return 0;
|
|
343
|
+
if (unprojected.length === 0 || !unprojected.some(({ event }) => event.wakeAgent !== false)) return 0;
|
|
344
344
|
|
|
345
345
|
const nowMs = this.now();
|
|
346
346
|
this.pruneMonitorAdmissionWindows(nowMs);
|
|
@@ -414,15 +414,19 @@ export class ClawclawMailboxService implements ClawclawMailboxDriver {
|
|
|
414
414
|
const noisyVisualEvents = allOrdinaryEvents
|
|
415
415
|
.filter((row) => monitorEventIsNoisyVisual(row.event))
|
|
416
416
|
.sort((left, right) => left.event.commitSeq - right.event.commitSeq);
|
|
417
|
-
const directVisualCandidate = visualAdmissionAvailable ? noisyVisualEvents.
|
|
417
|
+
const directVisualCandidate = visualAdmissionAvailable ? [...noisyVisualEvents].sort((left, right) => (
|
|
418
|
+
clawclawMonitorEventPriority(right.event) - clawclawMonitorEventPriority(left.event)
|
|
419
|
+
|| right.event.commitSeq - left.event.commitSeq
|
|
420
|
+
))[0] : undefined;
|
|
418
421
|
const coalescedVisualOverflow = directVisualCandidate
|
|
419
|
-
? noisyVisualEvents.
|
|
422
|
+
? noisyVisualEvents.filter((row) => row !== directVisualCandidate)
|
|
420
423
|
: noisyVisualEvents;
|
|
421
424
|
const ordinaryEvents = allOrdinaryEvents
|
|
422
425
|
.filter((row) => !monitorEventIsNoisyVisual(row.event))
|
|
423
426
|
.concat(directVisualCandidate ? [directVisualCandidate] : [])
|
|
424
427
|
.sort((left, right) => (
|
|
425
|
-
|
|
428
|
+
clawclawMonitorEventPriority(right.event) - clawclawMonitorEventPriority(left.event)
|
|
429
|
+
|| ordinaryMonitorRetentionRank(left.event) - ordinaryMonitorRetentionRank(right.event)
|
|
426
430
|
|| left.event.commitSeq - right.event.commitSeq
|
|
427
431
|
));
|
|
428
432
|
const ordinaryDirectAdmissionCount = Math.min(
|
|
@@ -438,7 +442,10 @@ export class ClawclawMailboxService implements ClawclawMailboxDriver {
|
|
|
438
442
|
...coalescedVisualOverflow,
|
|
439
443
|
].sort((left, right) => left.event.commitSeq - right.event.commitSeq);
|
|
440
444
|
let direct = [...directProtected, ...directOrdinary]
|
|
441
|
-
.sort((left, right) =>
|
|
445
|
+
.sort((left, right) => (
|
|
446
|
+
monitorDirectAdmissionPriority(right.event) - monitorDirectAdmissionPriority(left.event)
|
|
447
|
+
|| left.event.commitSeq - right.event.commitSeq
|
|
448
|
+
));
|
|
442
449
|
let dedicatedBacklogHintEventId: string | undefined;
|
|
443
450
|
// A full ordinary queue still needs one durable signal. Use the first new
|
|
444
451
|
// Event as that signal's factual anchor and allow one separately-budgeted
|
|
@@ -454,16 +461,18 @@ export class ClawclawMailboxService implements ClawclawMailboxDriver {
|
|
|
454
461
|
)
|
|
455
462
|
&& (overflow.length > 1 || (overflow.length > 0 && delegatedUnreadBefore > 0))
|
|
456
463
|
) {
|
|
457
|
-
const
|
|
464
|
+
const highestPriority = Math.max(...overflow.map(({ event }) => clawclawMonitorEventPriority(event)));
|
|
465
|
+
const preferred = overflow.filter(({ event }) => clawclawMonitorEventPriority(event) === highestPriority);
|
|
466
|
+
const firstNonVisualIndex = preferred.findIndex((row) => (
|
|
458
467
|
!row.event.type.startsWith('visual.')
|
|
459
468
|
));
|
|
460
469
|
const hintAnchorIndex = firstNonVisualIndex >= 0
|
|
461
470
|
? firstNonVisualIndex
|
|
462
|
-
:
|
|
463
|
-
const hintAnchor =
|
|
471
|
+
: preferred.length - 1;
|
|
472
|
+
const hintAnchor = preferred[hintAnchorIndex]!;
|
|
464
473
|
direct = [hintAnchor];
|
|
465
474
|
dedicatedBacklogHintEventId = hintAnchor.event.eventId;
|
|
466
|
-
overflow = overflow.filter((
|
|
475
|
+
overflow = overflow.filter((row) => row !== hintAnchor);
|
|
467
476
|
}
|
|
468
477
|
if (direct.length === 0 && overflow.length === 0) return 0;
|
|
469
478
|
// With only one newly blocked Event there is no factual anchor plus
|
|
@@ -511,6 +520,9 @@ export class ClawclawMailboxService implements ClawclawMailboxDriver {
|
|
|
511
520
|
return { coalesceKey, payload, row };
|
|
512
521
|
});
|
|
513
522
|
});
|
|
523
|
+
// Reassign only delivery slots within this batch; canonical sequence is unchanged.
|
|
524
|
+
const slots = entries.map(({ row }) => row.event.commitSeq).sort((a, b) => a - b);
|
|
525
|
+
const deliveryOrder = new Map(entries.map((entry, index) => [entry.row.event.eventId, slots[index]!]));
|
|
514
526
|
const enqueue = (entry: typeof entries[number]) => {
|
|
515
527
|
const event = entry.row.event;
|
|
516
528
|
return this.repository.enqueueMailboxItem<Record<string, unknown>>({
|
|
@@ -527,6 +539,7 @@ export class ClawclawMailboxService implements ClawclawMailboxDriver {
|
|
|
527
539
|
segmentId: event.segmentId,
|
|
528
540
|
eventId: event.eventId,
|
|
529
541
|
eventCommitSeq: event.commitSeq,
|
|
542
|
+
deliveryOrder: deliveryOrder.get(event.eventId),
|
|
530
543
|
mode: 'short',
|
|
531
544
|
coalesceKey: entry.coalesceKey,
|
|
532
545
|
payload: entry.payload,
|
|
@@ -623,6 +636,24 @@ export class ClawclawMailboxService implements ClawclawMailboxDriver {
|
|
|
623
636
|
return inserted;
|
|
624
637
|
}
|
|
625
638
|
|
|
639
|
+
/** Monitor delivery reports every perception covered by the accepted Ready batch.
|
|
640
|
+
* A backlog hint counts as delivery for display; detail ACK is independent.
|
|
641
|
+
*/
|
|
642
|
+
monitorDeliveredEvents(eventIds: readonly string[]): CanonicalEvent[] {
|
|
643
|
+
const bounds = new Map<string, number>();
|
|
644
|
+
for (const id of eventIds) {
|
|
645
|
+
const item = this.repository.mailboxItemForEvent<Record<string, any>>(this.consumerId, id, 'short');
|
|
646
|
+
if (!item || item.state !== 'accepted') continue;
|
|
647
|
+
const through = Number(item.payload.ready?.event_commit_seq ?? item.eventCommitSeq);
|
|
648
|
+
bounds.set(item.sessionId, Math.max(bounds.get(item.sessionId) ?? 0, through));
|
|
649
|
+
}
|
|
650
|
+
const events: CanonicalEvent[] = [];
|
|
651
|
+
for (const [sessionId, through] of bounds) {
|
|
652
|
+
events.push(...this.repository.listCommittedEvents({ sessionId, maxCommitSeq: through, order: 'asc' }));
|
|
653
|
+
}
|
|
654
|
+
return events;
|
|
655
|
+
}
|
|
656
|
+
|
|
626
657
|
composeMonitor(values: readonly Record<string, unknown>[]): Record<string, unknown> {
|
|
627
658
|
const hasBacklog = values.some((value) => (
|
|
628
659
|
!!value.backlog && typeof value.backlog === 'object'
|
|
@@ -17,13 +17,14 @@ export function normalizePerceptionEvents(
|
|
|
17
17
|
!event
|
|
18
18
|
|| typeof event !== 'object'
|
|
19
19
|
|| !declared.has(event.type)
|
|
20
|
+
|| (event.wakeAgent !== undefined && typeof event.wakeAgent !== 'boolean')
|
|
20
21
|
|| typeof event.dedupeKey !== 'string'
|
|
21
22
|
|| !event.dedupeKey
|
|
22
23
|
|| !event.payload
|
|
23
24
|
|| typeof event.payload !== 'object'
|
|
24
25
|
|| Array.isArray(event.payload)
|
|
25
26
|
) throw new Error(`perception_event_invalid:${index}`);
|
|
26
|
-
return structuredClone(event);
|
|
27
|
+
return structuredClone({ ...event, wakeAgent: event.wakeAgent ?? manifest.wakeAgent ?? true });
|
|
27
28
|
});
|
|
28
29
|
assertRuntimeModuleOutputSize(events, 'perception_event_output');
|
|
29
30
|
return events;
|
|
@@ -232,6 +232,7 @@ function perceptionLifecycle(frame: Readonly<PerceptionFrame>): string {
|
|
|
232
232
|
}
|
|
233
233
|
|
|
234
234
|
function hasValidPerceptionEventMetadata(manifest: ClawclawPerceptionManifest): boolean {
|
|
235
|
+
if (manifest.wakeAgent !== undefined && typeof manifest.wakeAgent !== 'boolean') return false;
|
|
235
236
|
const metadata = manifest.eventMetadata;
|
|
236
237
|
if (metadata === undefined) return true;
|
|
237
238
|
if (!metadata || typeof metadata !== 'object' || Array.isArray(metadata)) return false;
|