@myclaw163/clawclaw-cli 0.7.7 → 0.7.9
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/desktop-event-push.md +14 -2
- package/docs//350/207/252/345/256/232/344/271/211/346/204/237/347/237/245.md +15 -1
- package/package.json +1 -1
- package/src/pipeline/event-format.test.ts +13 -0
- package/src/pipeline/event-format.ts +11 -1
- package/src/pipeline/game-sync-event-normalization.test.ts +87 -1
- package/src/pipeline/game-sync-event-normalization.ts +91 -15
- package/src/pipeline/player-projection.test.ts +19 -2
- package/src/pipeline/player-projection.ts +17 -2
- package/src/runtime/clawclaw/owner.ts +8 -0
- package/src/runtime/clawclaw/plugins/assembly.test.ts +13 -0
- package/src/runtime/clawclaw/plugins/assembly.ts +10 -0
- package/src/runtime/clawclaw/plugins/mailbox/desktop-event-push.integration.test.ts +17 -5
- package/src/runtime/clawclaw/plugins/mailbox/desktop-event-socket.test.ts +37 -3
- package/src/runtime/clawclaw/plugins/mailbox/desktop-event-socket.ts +49 -14
- package/src/runtime/clawclaw/plugins/mailbox/mailbox-service.test.ts +71 -0
- package/src/runtime/clawclaw/plugins/perception/contracts.ts +1 -0
- package/src/runtime/clawclaw/plugins/perception/modules/co-movement-module.ts +16 -0
- package/src/runtime/clawclaw/plugins/perception/modules/follow-module.ts +16 -0
- package/src/runtime/clawclaw/plugins/perception/modules/motion-module.ts +16 -0
- package/src/runtime/clawclaw/plugins/perception/modules/route-module.ts +23 -0
- package/src/runtime/clawclaw/plugins/perception/modules/spatial-module.ts +16 -0
- package/src/runtime/clawclaw/plugins/perception/modules/stop-module.ts +16 -0
- package/src/runtime/clawclaw/plugins/perception/modules/visibility-module.ts +23 -0
- package/src/runtime/clawclaw/plugins/perception/perception-plugin.test.ts +19 -0
- package/src/runtime/clawclaw/plugins/perception/perception-plugin.ts +41 -0
- package/src/runtime/clawclaw/plugins/perception/perception-source.test.ts +49 -0
- package/src/runtime/clawclaw/plugins/perception/perception-source.ts +105 -5
- package/src/runtime/clawclaw/plugins/source/source-plugin.test.ts +239 -0
- package/src/runtime/clawclaw/plugins/source/source-plugin.ts +146 -66
- package/src/runtime/framework/plugins/runtime-plugin-scheduler.test.ts +36 -0
- package/src/runtime/framework/plugins/runtime-plugin-scheduler.ts +0 -5
- package/src/sdk/perception-plugin/index.ts +8 -0
|
@@ -113,16 +113,28 @@ CCL 在以下条件全部满足时发送一个 `mailbox_batch`:
|
|
|
113
113
|
}
|
|
114
114
|
]
|
|
115
115
|
},
|
|
116
|
+
"event_descriptors": [
|
|
117
|
+
{
|
|
118
|
+
"type": "visual.player_moved",
|
|
119
|
+
"perception_id": "visual.motion",
|
|
120
|
+
"name": "玩家移动",
|
|
121
|
+
"description": "玩家持续移动形成一段可观察的移动轨迹。"
|
|
122
|
+
}
|
|
123
|
+
],
|
|
116
124
|
"payload": {
|
|
117
125
|
"schema": "clawclaw.channel-events.v1",
|
|
118
126
|
"state": {},
|
|
119
|
-
"events": [
|
|
127
|
+
"events": [
|
|
128
|
+
"visual.player_moved | 9:41,你从导航仓左上侧移动到2号走廊右下侧。"
|
|
129
|
+
]
|
|
120
130
|
}
|
|
121
131
|
}
|
|
122
132
|
```
|
|
123
133
|
|
|
124
134
|
`payload.state` 是当前 Ready View 的紧凑状态,`payload.events` 是本批完整 Agent 事件。`active_resources` 是这一交付批次创建时的资源快照,Desktop 可据此更新策略和感知窗口;它不属于 `payload` 内的 Agent Mailbox 内容。
|
|
125
135
|
|
|
136
|
+
`event_descriptors` 只包含本批 `payload.events` 实际出现、并且由当前激活感知模块声明的 Event type。同一 type 在一批出现多次只附一份描述;非感知事件、禁用模块的 Event type、未激活自定义模块的 Event type,以及没有出现在本批的 Event type 都不列入。名称和描述来自对应感知模块 manifest,当前按 `zh-CN` 解析。没有匹配项时省略整个字段,原有 `payload.events` 结构始终保持不变。
|
|
137
|
+
|
|
126
138
|
## 什么时候不发送
|
|
127
139
|
|
|
128
140
|
- Desktop 参数未配置或 IPC 尚未连接。
|
|
@@ -151,4 +163,4 @@ Desktop 将批次可靠放入自己的输入队列后返回:
|
|
|
151
163
|
|
|
152
164
|
`connection_id`、`seq` 和 `delivery_id` 必须与当前批次完全一致,否则 ACK 被忽略。CCL 只有收到正确 ACK 后才把事件标记为已交付。
|
|
153
165
|
|
|
154
|
-
ACK 超时或连接中断时,CCL 会重连并重发未确认批次;重试保持相同 `delivery_id`,并保留该交付首次创建时的 `active_resources` 快照。Desktop 应按 `delivery_id` 幂等入队,避免“已入队但 ACK 丢失”导致重复唤醒。
|
|
166
|
+
ACK 超时或连接中断时,CCL 会重连并重发未确认批次;重试保持相同 `delivery_id`,并保留该交付首次创建时的 `active_resources` 和 `event_descriptors` 快照。Desktop 应按 `delivery_id` 幂等入队,避免“已入队但 ACK 丢失”导致重复唤醒。
|
|
@@ -66,6 +66,18 @@ export default class EnterCounter extends ClawclawPerception {
|
|
|
66
66
|
description: 'Counts other players entering the field of view.',
|
|
67
67
|
subjectScope: 'others',
|
|
68
68
|
produces: ['visual.enter_count_changed'],
|
|
69
|
+
eventMetadata: {
|
|
70
|
+
'visual.enter_count_changed': {
|
|
71
|
+
name: 'Player enter count changed',
|
|
72
|
+
description: 'Reports a newly observed player entering view.',
|
|
73
|
+
localizations: {
|
|
74
|
+
'zh-CN': {
|
|
75
|
+
name: '玩家进入视野',
|
|
76
|
+
description: '发现一名此前不可见的玩家进入当前视野。',
|
|
77
|
+
},
|
|
78
|
+
},
|
|
79
|
+
},
|
|
80
|
+
},
|
|
69
81
|
};
|
|
70
82
|
|
|
71
83
|
seen = new Set();
|
|
@@ -96,9 +108,11 @@ export default class EnterCounter extends ClawclawPerception {
|
|
|
96
108
|
|
|
97
109
|
`static manifest` 必须使用可静态读取的字面量;CCL 在不执行用户代码的前提下读取它。类可以包含普通私有字段,用来保存轨迹、计数器、候选关系和“已经报告到哪里”等短期状态。
|
|
98
110
|
|
|
111
|
+
`eventMetadata` 为兼容已有自定义模块仍是可选字段;一旦提供,就必须完整覆盖 `produces`,不能声明额外 Event type。Desktop IPC 只会为当前激活模块、本批实际出现的 Event type 传递这里的本地化名称和描述。新模块建议始终提供该字段;文案属于模块,不应由 Mailbox 或 Desktop 建立中央映射。
|
|
112
|
+
|
|
99
113
|
| 类成员 | 是否必需 | 作用 |
|
|
100
114
|
|---|---:|---|
|
|
101
|
-
| `static manifest` | 是 | 声明模块 ID
|
|
115
|
+
| `static manifest` | 是 | 声明模块 ID、说明、事件主体范围、所有可能输出的 Event type,以及可选的 Event 显示元数据 |
|
|
102
116
|
| `update(frame, api)` | 是 | 消费一份新的视觉帧,更新私有状态,并可返回零到多条 Event |
|
|
103
117
|
| 普通实例字段 | 否 | 保存这个模块自己的跨帧状态;不同模块互不共享 |
|
|
104
118
|
| `flush(boundary, api)` | 否 | 在查询或硬边界处报告尚未自然结束的长片段 |
|
package/package.json
CHANGED
|
@@ -37,6 +37,19 @@ describe('event-format', () => {
|
|
|
37
37
|
expect(JSON.stringify(formatted)).not.toContain('Your hands are off the board');
|
|
38
38
|
});
|
|
39
39
|
|
|
40
|
+
it('formats a system killer without a fake player seat', () => {
|
|
41
|
+
const message = formatEventMessage({
|
|
42
|
+
type: 'killed',
|
|
43
|
+
tick: 41,
|
|
44
|
+
room: '制氧舱',
|
|
45
|
+
killer_kind: 'system',
|
|
46
|
+
killer_name: 'Shrimp God',
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
expect(message).toContain('被Shrimp God击杀');
|
|
50
|
+
expect(message).not.toContain('?号Shrimp God');
|
|
51
|
+
});
|
|
52
|
+
|
|
40
53
|
it('keeps meeting_briefing details aligned with the compact monitor payload', () => {
|
|
41
54
|
const formatted = compactEventFields({
|
|
42
55
|
type: 'meeting_briefing',
|
|
@@ -232,6 +232,16 @@ function playerLabel(name: unknown, seat: unknown, ctx: EventFormatContext): str
|
|
|
232
232
|
return `${seatLabel(name, seat, ctx)}${text(name, '未知玩家')}`;
|
|
233
233
|
}
|
|
234
234
|
|
|
235
|
+
function killerLabel(
|
|
236
|
+
name: unknown,
|
|
237
|
+
seat: unknown,
|
|
238
|
+
kind: unknown,
|
|
239
|
+
ctx: EventFormatContext,
|
|
240
|
+
): string {
|
|
241
|
+
if (kind === 'system') return text(name, '未知系统来源');
|
|
242
|
+
return playerLabel(name, seat, ctx);
|
|
243
|
+
}
|
|
244
|
+
|
|
235
245
|
function playerObject(name: unknown, seat: unknown, ctx: EventFormatContext): Record<string, any> | undefined {
|
|
236
246
|
if (typeof name !== 'string' || name.length === 0) return undefined;
|
|
237
247
|
return cleanObject({
|
|
@@ -367,7 +377,7 @@ function shortBody(event: Record<string, any>, ctx: EventFormatContext): string
|
|
|
367
377
|
case 'kill':
|
|
368
378
|
return `你在${firstString(event, ['room'])}击杀了${playerLabel(event.target_name, firstNumber(event, ['target_seat', 'target_player_seat']), ctx)}。`;
|
|
369
379
|
case 'killed':
|
|
370
|
-
return `你在${firstString(event, ['room'])}被${
|
|
380
|
+
return `你在${firstString(event, ['room'])}被${killerLabel(event.killer_name, firstNumber(event, ['killer_seat', 'killer_player_seat']), event.killer_kind, ctx)}击杀了,你已死亡。`;
|
|
371
381
|
case 'murder_witnessed':
|
|
372
382
|
return `你在${firstString(event, ['room'])}目击${playerLabel(event.killer_name, firstNumber(event, ['killer_seat', 'killer_player_seat']), ctx)}击杀${playerLabel(event.target_name, firstNumber(event, ['target_seat', 'target_player_seat']), ctx)}。`;
|
|
373
383
|
case 'warrior_shrimp_self_destruct':
|
|
@@ -4,6 +4,7 @@ import { presentCanonicalEvent } from './canonical-event-presentation.js';
|
|
|
4
4
|
import {
|
|
5
5
|
normalizeGameSyncEvent,
|
|
6
6
|
normalizeGameSyncEvents,
|
|
7
|
+
normalizeGameSyncEventsSafely,
|
|
7
8
|
} from './game-sync-event-normalization.js';
|
|
8
9
|
|
|
9
10
|
function canonical(event: Record<string, any>): CanonicalEvent {
|
|
@@ -80,6 +81,38 @@ describe('GameSync v2 Event normalization', () => {
|
|
|
80
81
|
expect(normalized[0]).not.toHaveProperty('newly_assigned_task');
|
|
81
82
|
});
|
|
82
83
|
|
|
84
|
+
it('isolates malformed Events while preserving original indexes and same-frame enrichment', () => {
|
|
85
|
+
const result = normalizeGameSyncEventsSafely([{
|
|
86
|
+
event_id: 'completed-1',
|
|
87
|
+
tick: 42,
|
|
88
|
+
type: 'task_completed',
|
|
89
|
+
actor: { seat: 1, name: 'self' },
|
|
90
|
+
task_name: '擦拭酒瓶',
|
|
91
|
+
}, {
|
|
92
|
+
event_id: 'malformed-killed',
|
|
93
|
+
tick: 42,
|
|
94
|
+
type: 'killed',
|
|
95
|
+
actor: { seat: 4, name: 'victim' },
|
|
96
|
+
killer: { kind: 'player', player: { seat: 2 } },
|
|
97
|
+
}, {
|
|
98
|
+
event_id: 'assigned-1',
|
|
99
|
+
tick: 42,
|
|
100
|
+
type: 'task_assigned',
|
|
101
|
+
actor: { seat: 1, name: 'self' },
|
|
102
|
+
task_name: '消毒淋浴器',
|
|
103
|
+
room: '制氧舱',
|
|
104
|
+
}]);
|
|
105
|
+
|
|
106
|
+
expect(result.rejected).toHaveLength(1);
|
|
107
|
+
expect(result.rejected[0]).toMatchObject({ index: 1 });
|
|
108
|
+
expect(result.rejected[0]?.error).toBeInstanceOf(TypeError);
|
|
109
|
+
expect(result.events.map(({ index }) => index)).toEqual([0, 2]);
|
|
110
|
+
expect(result.events[0]?.event).toMatchObject({
|
|
111
|
+
type: 'task_completed',
|
|
112
|
+
newly_assigned_task: { name: '消毒淋浴器', room: '制氧舱' },
|
|
113
|
+
});
|
|
114
|
+
});
|
|
115
|
+
|
|
83
116
|
it('projects actor and target PlayerRefs to the established canonical fields', () => {
|
|
84
117
|
const wire = {
|
|
85
118
|
event_id: '68a339d7-c5f6-4eef-8f40-b8779ca8bfcc',
|
|
@@ -112,7 +145,7 @@ describe('GameSync v2 Event normalization', () => {
|
|
|
112
145
|
tick: 22,
|
|
113
146
|
type: 'synthetic_contract_fixture',
|
|
114
147
|
caller: { seat: 1, name: 'caller' },
|
|
115
|
-
killer: { seat: 2, name: 'killer' },
|
|
148
|
+
killer: { kind: 'player', player: { seat: 2, name: 'killer' } },
|
|
116
149
|
resolver: { seat: 3, name: 'resolver' },
|
|
117
150
|
speaker: { seat: 4, name: 'speaker' },
|
|
118
151
|
current_speaker: { seat: 5, name: 'current' },
|
|
@@ -123,6 +156,7 @@ describe('GameSync v2 Event normalization', () => {
|
|
|
123
156
|
expect(normalized).toMatchObject({
|
|
124
157
|
meeting_caller_name: 'caller',
|
|
125
158
|
meeting_caller_seat: 1,
|
|
159
|
+
killer_kind: 'player',
|
|
126
160
|
killer_name: 'killer',
|
|
127
161
|
killer_seat: 2,
|
|
128
162
|
resolver_name: 'resolver',
|
|
@@ -141,6 +175,58 @@ describe('GameSync v2 Event normalization', () => {
|
|
|
141
175
|
}
|
|
142
176
|
});
|
|
143
177
|
|
|
178
|
+
it('projects structured player and system killers for Agent presentation', () => {
|
|
179
|
+
const playerKilled = normalizeGameSyncEvent({
|
|
180
|
+
event_id: 'player-killed',
|
|
181
|
+
tick: 41,
|
|
182
|
+
type: 'killed',
|
|
183
|
+
actor: { seat: 4, name: 'victim' },
|
|
184
|
+
killer: { kind: 'player', player: { seat: 2, name: 'killer' } },
|
|
185
|
+
room: 'engine',
|
|
186
|
+
});
|
|
187
|
+
expect(playerKilled).toMatchObject({
|
|
188
|
+
actor_name: 'victim',
|
|
189
|
+
actor_seat: 4,
|
|
190
|
+
killer_kind: 'player',
|
|
191
|
+
killer_name: 'killer',
|
|
192
|
+
killer_seat: 2,
|
|
193
|
+
});
|
|
194
|
+
expect(playerKilled).not.toHaveProperty('killer');
|
|
195
|
+
expect(presentCanonicalEvent(canonical(playerKilled), null).hint)
|
|
196
|
+
.toBe('YOU ARE DEAD: seat 2 killer removed you from play.');
|
|
197
|
+
|
|
198
|
+
const systemKilled = normalizeGameSyncEvent({
|
|
199
|
+
event_id: 'system-killed',
|
|
200
|
+
tick: 42,
|
|
201
|
+
type: 'killed',
|
|
202
|
+
actor: { seat: 4, name: 'victim' },
|
|
203
|
+
killer: { kind: 'system', name: 'Shrimp God' },
|
|
204
|
+
room: 'engine',
|
|
205
|
+
});
|
|
206
|
+
expect(systemKilled).toMatchObject({
|
|
207
|
+
actor_name: 'victim',
|
|
208
|
+
actor_seat: 4,
|
|
209
|
+
killer_kind: 'system',
|
|
210
|
+
killer_name: 'Shrimp God',
|
|
211
|
+
});
|
|
212
|
+
expect(systemKilled).not.toHaveProperty('killer');
|
|
213
|
+
expect(systemKilled).not.toHaveProperty('killer_seat');
|
|
214
|
+
expect(presentCanonicalEvent(canonical(systemKilled), null).hint)
|
|
215
|
+
.toBe('YOU ARE DEAD: Shrimp God removed you from play.');
|
|
216
|
+
});
|
|
217
|
+
|
|
218
|
+
it('rejects malformed structured killers', () => {
|
|
219
|
+
expect(() => normalizeGameSyncEvent({
|
|
220
|
+
type: 'killed', killer: { kind: 'player', player: { seat: 2 } },
|
|
221
|
+
})).toThrow('killer.player.name must be a string');
|
|
222
|
+
expect(() => normalizeGameSyncEvent({
|
|
223
|
+
type: 'killed', killer: { kind: 'system', name: 'GM', seat: 0 },
|
|
224
|
+
})).toThrow('killer contains unsupported fields: seat');
|
|
225
|
+
expect(() => normalizeGameSyncEvent({
|
|
226
|
+
type: 'killed', killer: { kind: 'npc', name: 'GM' },
|
|
227
|
+
})).toThrow("killer.kind must be 'player' or 'system'");
|
|
228
|
+
});
|
|
229
|
+
|
|
144
230
|
it('preserves a faction winner scalar and projects a neutral winner PlayerRef', () => {
|
|
145
231
|
expect(normalizeGameSyncEvent({
|
|
146
232
|
event_id: 'faction-event', tick: 1, type: 'game_over', winner: 'lobster',
|
|
@@ -3,6 +3,21 @@ export interface CanonicalPlayerRef {
|
|
|
3
3
|
seat: number;
|
|
4
4
|
}
|
|
5
5
|
|
|
6
|
+
export interface NormalizedGameSyncEventEntry {
|
|
7
|
+
index: number;
|
|
8
|
+
event: Record<string, any>;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export interface RejectedGameSyncEventEntry {
|
|
12
|
+
index: number;
|
|
13
|
+
error: unknown;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export interface GameSyncEventNormalizationResult {
|
|
17
|
+
events: NormalizedGameSyncEventEntry[];
|
|
18
|
+
rejected: RejectedGameSyncEventEntry[];
|
|
19
|
+
}
|
|
20
|
+
|
|
6
21
|
interface PlayerRefProjection {
|
|
7
22
|
wireField: string;
|
|
8
23
|
nameField: string;
|
|
@@ -20,12 +35,6 @@ const SINGLE_PLAYER_REF_PROJECTIONS: readonly PlayerRefProjection[] = [
|
|
|
20
35
|
seatField: 'meeting_caller_seat',
|
|
21
36
|
playerRefOnlyWhenObject: true,
|
|
22
37
|
},
|
|
23
|
-
{
|
|
24
|
-
wireField: 'killer',
|
|
25
|
-
nameField: 'killer_name',
|
|
26
|
-
seatField: 'killer_seat',
|
|
27
|
-
playerRefOnlyWhenObject: true,
|
|
28
|
-
},
|
|
29
38
|
{ wireField: 'resolver', nameField: 'resolver_name', seatField: 'resolver_seat' },
|
|
30
39
|
{
|
|
31
40
|
wireField: 'speaker',
|
|
@@ -100,6 +109,39 @@ function playerRef(value: unknown, field: string): CanonicalPlayerRef {
|
|
|
100
109
|
return { name: value.name, seat: Number(value.seat) };
|
|
101
110
|
}
|
|
102
111
|
|
|
112
|
+
function validateExactFields(
|
|
113
|
+
value: Record<string, unknown>,
|
|
114
|
+
allowed: readonly string[],
|
|
115
|
+
field: string,
|
|
116
|
+
): void {
|
|
117
|
+
const extraFields = Object.keys(value).filter((key) => !allowed.includes(key));
|
|
118
|
+
if (extraFields.length > 0) {
|
|
119
|
+
throw new TypeError(`${field} contains unsupported fields: ${extraFields.join(', ')}`);
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
function projectKiller(value: unknown): Record<string, unknown> {
|
|
124
|
+
if (!isRecord(value)) {
|
|
125
|
+
throw new TypeError('GameSync Event.killer must be an object');
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
if (value.kind === 'player') {
|
|
129
|
+
validateExactFields(value, ['kind', 'player'], 'GameSync Event.killer');
|
|
130
|
+
const killer = playerRef(value.player, 'GameSync Event.killer.player');
|
|
131
|
+
return { killer_kind: 'player', killer_name: killer.name, killer_seat: killer.seat };
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
if (value.kind === 'system') {
|
|
135
|
+
validateExactFields(value, ['kind', 'name'], 'GameSync Event.killer');
|
|
136
|
+
if (typeof value.name !== 'string') {
|
|
137
|
+
throw new TypeError('GameSync Event.killer.name must be a string');
|
|
138
|
+
}
|
|
139
|
+
return { killer_kind: 'system', killer_name: value.name };
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
throw new TypeError("GameSync Event.killer.kind must be 'player' or 'system'");
|
|
143
|
+
}
|
|
144
|
+
|
|
103
145
|
function playerRefArray(value: unknown, field: string): CanonicalPlayerRef[] {
|
|
104
146
|
if (!Array.isArray(value)) {
|
|
105
147
|
throw new TypeError(`${field} must be a PlayerRef array`);
|
|
@@ -146,6 +188,12 @@ export function normalizeGameSyncEvent(value: unknown): Record<string, any> {
|
|
|
146
188
|
normalized[projection.seatField] = projected.seat;
|
|
147
189
|
}
|
|
148
190
|
|
|
191
|
+
if (Object.hasOwn(normalized, 'killer')) {
|
|
192
|
+
const raw = normalized.killer;
|
|
193
|
+
delete normalized.killer;
|
|
194
|
+
if (raw !== null && raw !== undefined) Object.assign(normalized, projectKiller(raw));
|
|
195
|
+
}
|
|
196
|
+
|
|
149
197
|
for (const field of PLAYER_REF_ARRAY_FIELDS) {
|
|
150
198
|
if (!Object.hasOwn(normalized, field)) continue;
|
|
151
199
|
normalized[field] = playerRefArray(normalized[field], `GameSync Event.${field}`);
|
|
@@ -241,26 +289,54 @@ function newlyAssignedTask(event: Record<string, any>): Record<string, any> | nu
|
|
|
241
289
|
* Event Catalog.
|
|
242
290
|
*/
|
|
243
291
|
export function normalizeGameSyncEvents(values: readonly unknown[]): Record<string, any>[] {
|
|
244
|
-
|
|
292
|
+
return enrichTaskAssignments(values.map((value, index) => ({
|
|
293
|
+
index,
|
|
294
|
+
event: normalizeGameSyncEvent(value),
|
|
295
|
+
}))).map(({ event }) => event);
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
/** Normalize independent Events without rejecting their valid frame siblings. */
|
|
299
|
+
export function normalizeGameSyncEventsSafely(
|
|
300
|
+
values: readonly unknown[],
|
|
301
|
+
): GameSyncEventNormalizationResult {
|
|
302
|
+
const events: NormalizedGameSyncEventEntry[] = [];
|
|
303
|
+
const rejected: RejectedGameSyncEventEntry[] = [];
|
|
304
|
+
values.forEach((value, index) => {
|
|
305
|
+
try {
|
|
306
|
+
events.push({ index, event: normalizeGameSyncEvent(value) });
|
|
307
|
+
} catch (error) {
|
|
308
|
+
rejected.push({ index, error });
|
|
309
|
+
}
|
|
310
|
+
});
|
|
311
|
+
return { events: enrichTaskAssignments(events), rejected };
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
function enrichTaskAssignments(
|
|
315
|
+
entries: readonly NormalizedGameSyncEventEntry[],
|
|
316
|
+
): NormalizedGameSyncEventEntry[] {
|
|
245
317
|
const claimedAssignments = new Set<number>();
|
|
246
318
|
|
|
247
|
-
return
|
|
248
|
-
|
|
319
|
+
return entries.map((entry, index) => {
|
|
320
|
+
const { event } = entry;
|
|
321
|
+
if (event.type !== 'task_completed' || !Number.isInteger(event.tick)) return entry;
|
|
249
322
|
const actorKey = taskEventActorKey(event);
|
|
250
|
-
if (!actorKey) return
|
|
323
|
+
if (!actorKey) return entry;
|
|
251
324
|
|
|
252
|
-
const assignmentIndex =
|
|
325
|
+
const assignmentIndex = entries.findIndex(({ event: candidate }, candidateIndex) => (
|
|
253
326
|
candidateIndex > index
|
|
254
327
|
&& !claimedAssignments.has(candidateIndex)
|
|
255
328
|
&& candidate.type === 'task_assigned'
|
|
256
329
|
&& candidate.tick === event.tick
|
|
257
330
|
&& taskEventActorKey(candidate) === actorKey
|
|
258
331
|
));
|
|
259
|
-
if (assignmentIndex < 0) return
|
|
332
|
+
if (assignmentIndex < 0) return entry;
|
|
260
333
|
|
|
261
|
-
const task = newlyAssignedTask(
|
|
262
|
-
if (!task) return
|
|
334
|
+
const task = newlyAssignedTask(entries[assignmentIndex]!.event);
|
|
335
|
+
if (!task) return entry;
|
|
263
336
|
claimedAssignments.add(assignmentIndex);
|
|
264
|
-
return {
|
|
337
|
+
return {
|
|
338
|
+
...entry,
|
|
339
|
+
event: { ...event, newly_assigned_task: task },
|
|
340
|
+
};
|
|
265
341
|
});
|
|
266
342
|
}
|
|
@@ -170,8 +170,7 @@ describe('GameSync v2 player projection', () => {
|
|
|
170
170
|
{ ...ref(2, 'Killer'), known_status: { is_alive: true } },
|
|
171
171
|
],
|
|
172
172
|
},
|
|
173
|
-
//
|
|
174
|
-
// legacy killer_name instead of emitting the structured killer field.
|
|
173
|
+
// Both actor and killer remain optional at the wire-model boundary.
|
|
175
174
|
events: [{ type: 'killed' }],
|
|
176
175
|
});
|
|
177
176
|
|
|
@@ -180,6 +179,24 @@ describe('GameSync v2 player projection', () => {
|
|
|
180
179
|
]);
|
|
181
180
|
});
|
|
182
181
|
|
|
182
|
+
it('accepts structured player and system killers on recipient-private killed events', () => {
|
|
183
|
+
for (const killer of [
|
|
184
|
+
{ kind: 'player', player: ref(2, 'Killer') },
|
|
185
|
+
{ kind: 'system', name: 'Shrimp God' },
|
|
186
|
+
]) {
|
|
187
|
+
expect(() => projectPlayers({
|
|
188
|
+
summary: {
|
|
189
|
+
you: { player: ref(1, 'Self') },
|
|
190
|
+
players: [
|
|
191
|
+
{ ...ref(1, 'Self'), known_status: { is_alive: false, death_cause: 'killed' } },
|
|
192
|
+
{ ...ref(2, 'Killer'), known_status: { is_alive: true } },
|
|
193
|
+
],
|
|
194
|
+
},
|
|
195
|
+
events: [{ type: 'killed', actor: ref(1, 'Self'), killer }],
|
|
196
|
+
})).not.toThrow();
|
|
197
|
+
}
|
|
198
|
+
});
|
|
199
|
+
|
|
183
200
|
it('preserves richer event knowledge when a later state only confirms death', () => {
|
|
184
201
|
const players = advancePlayerProjection({
|
|
185
202
|
previous: [{
|
|
@@ -141,12 +141,13 @@ function rememberRoster(players: Map<string, MutablePlayerProjection>, source: u
|
|
|
141
141
|
for (const key of [
|
|
142
142
|
'actor',
|
|
143
143
|
'target',
|
|
144
|
-
'killer',
|
|
145
144
|
'caller',
|
|
146
145
|
'resolver',
|
|
147
146
|
'current_speaker',
|
|
148
147
|
'result_target',
|
|
149
148
|
]) rememberRef(players, item[key]);
|
|
149
|
+
const killer = record(item.killer);
|
|
150
|
+
rememberRef(players, killer?.kind === 'player' ? killer.player : undefined);
|
|
150
151
|
for (const key of [
|
|
151
152
|
'reported_corpses',
|
|
152
153
|
'dead_players',
|
|
@@ -200,6 +201,20 @@ function refName(value: unknown): string | undefined {
|
|
|
200
201
|
return playerRef(value)?.name;
|
|
201
202
|
}
|
|
202
203
|
|
|
204
|
+
function killerName(value: unknown): string | undefined {
|
|
205
|
+
const killer = record(value);
|
|
206
|
+
if (killer?.kind === 'player') {
|
|
207
|
+
const player = playerRef(killer.player);
|
|
208
|
+
return player?.name;
|
|
209
|
+
}
|
|
210
|
+
if (killer?.kind === 'system') {
|
|
211
|
+
return typeof killer.name === 'string' && killer.name.length > 0
|
|
212
|
+
? killer.name
|
|
213
|
+
: undefined;
|
|
214
|
+
}
|
|
215
|
+
return playerRef(value)?.name;
|
|
216
|
+
}
|
|
217
|
+
|
|
203
218
|
function applyEvent(
|
|
204
219
|
players: Map<string, MutablePlayerProjection>,
|
|
205
220
|
event: Record<string, any>,
|
|
@@ -225,7 +240,7 @@ function applyEvent(
|
|
|
225
240
|
// optional actor ref is absent. Never mistake another ref for the victim.
|
|
226
241
|
enrichKnownDeath(players, youRef ?? event.actor, {
|
|
227
242
|
cause: 'killed',
|
|
228
|
-
killer:
|
|
243
|
+
killer: killerName(event.killer) ?? null,
|
|
229
244
|
revealed: true,
|
|
230
245
|
source: 'event_log',
|
|
231
246
|
});
|
|
@@ -569,6 +569,14 @@ export async function runClawclawOwner(
|
|
|
569
569
|
strategy: assembly.strategy.activeResourceDescriptor(DESKTOP_RESOURCE_LOCALE),
|
|
570
570
|
perceptions: assembly.perception.localizedModuleDescriptors(DESKTOP_RESOURCE_LOCALE),
|
|
571
571
|
}),
|
|
572
|
+
eventDescriptors: () => assembly.perception
|
|
573
|
+
.localizedEventDescriptors(DESKTOP_RESOURCE_LOCALE)
|
|
574
|
+
.map((descriptor) => ({
|
|
575
|
+
type: descriptor.type,
|
|
576
|
+
perception_id: descriptor.perceptionId,
|
|
577
|
+
name: descriptor.name,
|
|
578
|
+
description: descriptor.description,
|
|
579
|
+
})),
|
|
572
580
|
onConnected: () => desktopEventPump?.retryNow(),
|
|
573
581
|
diagnostic: (name, attributes) => runtime?.diagnostic(name, attributes),
|
|
574
582
|
});
|
|
@@ -78,4 +78,17 @@ describe('ClawClaw plugin assembly', () => {
|
|
|
78
78
|
expect(assembled.plugins.filter((plugin) => plugin.id === CLAWCLAW_PERCEPTION_PLUGIN_ID))
|
|
79
79
|
.toEqual([perception]);
|
|
80
80
|
});
|
|
81
|
+
|
|
82
|
+
it('rejects terminate policy for plugins loaded into the ClawClaw graph', () => {
|
|
83
|
+
const plugin: RuntimeEpochPlugin<Record<string, any>> = {
|
|
84
|
+
kind: 'epoch',
|
|
85
|
+
id: 'user.plugin',
|
|
86
|
+
version: '1',
|
|
87
|
+
failurePolicy: 'terminate',
|
|
88
|
+
update: () => ({ outcome: 'noop' }),
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
expect(() => assembleClawclawPlugins(client, { epochPlugins: [plugin] }))
|
|
92
|
+
.toThrow('Runtime Plugin user.plugin cannot use the terminate failure policy');
|
|
93
|
+
});
|
|
81
94
|
});
|
|
@@ -48,6 +48,16 @@ export function assembleClawclawPlugins(
|
|
|
48
48
|
options: ClawclawPluginAssemblyOptions = {},
|
|
49
49
|
): ClawclawPluginAssembly {
|
|
50
50
|
const plugins = [...(options.epochPlugins ?? [])];
|
|
51
|
+
for (const plugin of plugins) {
|
|
52
|
+
const failureMode = typeof plugin.failurePolicy === 'string'
|
|
53
|
+
? plugin.failurePolicy
|
|
54
|
+
: plugin.failurePolicy?.mode;
|
|
55
|
+
if (failureMode === 'terminate') {
|
|
56
|
+
throw new Error(
|
|
57
|
+
`Runtime Plugin ${plugin.id} cannot use the terminate failure policy in the ClawClaw plugin graph.`,
|
|
58
|
+
);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
51
61
|
|
|
52
62
|
const configuredAction = plugins.find((plugin) => plugin.id === CLAWCLAW_ACTION_PLUGIN_ID);
|
|
53
63
|
if (configuredAction && !(configuredAction instanceof ClawclawActionPlugin)) {
|
|
@@ -204,11 +204,17 @@ describe('Desktop Agent event push integration', () => {
|
|
|
204
204
|
description: '完成任务并保持警觉。',
|
|
205
205
|
},
|
|
206
206
|
perceptions: [{
|
|
207
|
-
id: 'visual.
|
|
208
|
-
name: '
|
|
209
|
-
description: '
|
|
207
|
+
id: 'visual.motion',
|
|
208
|
+
name: '玩家移动',
|
|
209
|
+
description: '感知自己和可见玩家的连续移动片段及显著方向变化。',
|
|
210
210
|
}],
|
|
211
211
|
}),
|
|
212
|
+
eventDescriptors: () => [{
|
|
213
|
+
type: 'visual.player_moved',
|
|
214
|
+
perception_id: 'visual.motion',
|
|
215
|
+
name: '玩家移动',
|
|
216
|
+
description: '玩家持续移动形成一段可观察的移动轨迹。',
|
|
217
|
+
}],
|
|
212
218
|
});
|
|
213
219
|
pump = new MailboxEventBatchPump({
|
|
214
220
|
source: {
|
|
@@ -234,7 +240,7 @@ describe('Desktop Agent event push integration', () => {
|
|
|
234
240
|
.toMatchObject({
|
|
235
241
|
locale: 'zh-CN',
|
|
236
242
|
strategy: { id: 'normal-shrimp', name: '普通虾' },
|
|
237
|
-
perceptions: [{ id: 'visual.
|
|
243
|
+
perceptions: [{ id: 'visual.motion', name: '玩家移动' }],
|
|
238
244
|
});
|
|
239
245
|
expect(await mailbox.update({ pendingEvents: [] } as any)).toMatchObject({
|
|
240
246
|
outcome: 'noop',
|
|
@@ -290,8 +296,14 @@ describe('Desktop Agent event push integration', () => {
|
|
|
290
296
|
expect(firstBatch.frame.active_resources).toMatchObject({
|
|
291
297
|
locale: 'zh-CN',
|
|
292
298
|
strategy: { id: 'normal-shrimp', name: '普通虾' },
|
|
293
|
-
perceptions: [{ id: 'visual.
|
|
299
|
+
perceptions: [{ id: 'visual.motion', name: '玩家移动' }],
|
|
294
300
|
});
|
|
301
|
+
expect(firstBatch.frame.event_descriptors).toEqual([{
|
|
302
|
+
type: 'visual.player_moved',
|
|
303
|
+
perception_id: 'visual.motion',
|
|
304
|
+
name: '玩家移动',
|
|
305
|
+
description: '玩家持续移动形成一段可观察的移动轨迹。',
|
|
306
|
+
}]);
|
|
295
307
|
expect(firstBatch.frame.payload.events).toEqual([
|
|
296
308
|
'visual.player_moved | player-2 moved through engine',
|
|
297
309
|
expect.objectContaining({ type: 'speech', text: longText }),
|