@myclaw163/clawclaw-cli 0.7.8 → 0.7.10

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.
Files changed (52) hide show
  1. package/docs/desktop-event-push.md +14 -2
  2. package/docs//350/207/252/345/256/232/344/271/211/346/204/237/347/237/245.md +15 -1
  3. package/package.json +1 -1
  4. package/skills/clawclaw/SKILL.md +5 -5
  5. package/skills/clawclaw/references/COMMANDS.md +4 -4
  6. package/skills/clawclaw/references/GAME-MECHANICS.md +1 -1
  7. package/src/commands/communication.test.ts +14 -3
  8. package/src/commands/communication.ts +12 -4
  9. package/src/pipeline/event-format.test.ts +0 -21
  10. package/src/pipeline/event-format.ts +0 -33
  11. package/src/pipeline/event-hints.test.ts +2 -5
  12. package/src/pipeline/event-hints.ts +0 -17
  13. package/src/pipeline/game-sync-event-normalization.test.ts +34 -12
  14. package/src/pipeline/game-sync-event-normalization.ts +52 -22
  15. package/src/runtime/clawclaw/owner.ts +8 -0
  16. package/src/runtime/clawclaw/plugins/assembly.test.ts +13 -0
  17. package/src/runtime/clawclaw/plugins/assembly.ts +10 -0
  18. package/src/runtime/clawclaw/plugins/mailbox/desktop-event-push.integration.test.ts +17 -5
  19. package/src/runtime/clawclaw/plugins/mailbox/desktop-event-socket.test.ts +37 -3
  20. package/src/runtime/clawclaw/plugins/mailbox/desktop-event-socket.ts +49 -14
  21. package/src/runtime/clawclaw/plugins/perception/contracts.ts +1 -0
  22. package/src/runtime/clawclaw/plugins/perception/modules/co-movement-module.ts +16 -0
  23. package/src/runtime/clawclaw/plugins/perception/modules/follow-module.ts +16 -0
  24. package/src/runtime/clawclaw/plugins/perception/modules/motion-module.ts +16 -0
  25. package/src/runtime/clawclaw/plugins/perception/modules/route-module.ts +23 -0
  26. package/src/runtime/clawclaw/plugins/perception/modules/spatial-module.ts +16 -0
  27. package/src/runtime/clawclaw/plugins/perception/modules/stop-module.ts +16 -0
  28. package/src/runtime/clawclaw/plugins/perception/modules/visibility-module.ts +23 -0
  29. package/src/runtime/clawclaw/plugins/perception/perception-plugin.test.ts +19 -0
  30. package/src/runtime/clawclaw/plugins/perception/perception-plugin.ts +41 -0
  31. package/src/runtime/clawclaw/plugins/perception/perception-source.test.ts +49 -0
  32. package/src/runtime/clawclaw/plugins/perception/perception-source.ts +105 -5
  33. package/src/runtime/clawclaw/plugins/source/source-plugin.test.ts +174 -0
  34. package/src/runtime/clawclaw/plugins/source/source-plugin.ts +146 -66
  35. package/src/runtime/clawclaw/plugins/strategy/strategy-action.ts +11 -4
  36. package/src/runtime/clawclaw-event-catalog.ts +0 -2
  37. package/src/runtime/framework/plugins/runtime-plugin-scheduler.test.ts +36 -0
  38. package/src/runtime/framework/plugins/runtime-plugin-scheduler.ts +0 -5
  39. package/src/sdk/action.ts +9 -8
  40. package/src/sdk/perception-plugin/index.ts +8 -0
  41. package/src/sdk/strategy-plugin/index.test.ts +3 -3
  42. package/src/sdk/strategy-plugin/index.ts +25 -24
  43. package/src/strategies/custom-module.test.ts +1 -1
  44. package/src/strategies/game-utils.test.ts +8 -8
  45. package/src/strategies/game-utils.ts +39 -28
  46. package/src/strategies/goals/crab-octopus-reflexes.ts +11 -7
  47. package/src/strategies/goals/hide-top.ts +2 -1
  48. package/src/strategies/goals/kill-target-goal.ts +2 -1
  49. package/src/strategies/goals/kill-target-top.ts +3 -3
  50. package/src/strategies/goals/lone-kill-core.ts +3 -1
  51. package/src/strategies/goals/task-kill-report-top.ts +2 -1
  52. package/src/strategies/goals/warrior-shrimp-top.ts +2 -1
@@ -204,11 +204,17 @@ describe('Desktop Agent event push integration', () => {
204
204
  description: '完成任务并保持警觉。',
205
205
  },
206
206
  perceptions: [{
207
- id: 'visual.visibility',
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.visibility', name: '视野变化' }],
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.visibility', name: '视野变化' }],
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 }),
@@ -94,12 +94,19 @@ describe('DesktopEventSocketSink', () => {
94
94
  description: '感知自己和可见玩家的连续移动片段及显著方向变化。',
95
95
  }],
96
96
  } as const;
97
+ const eventDescriptors = [{
98
+ type: 'visual.player_moved',
99
+ perception_id: 'visual.motion',
100
+ name: '玩家移动',
101
+ description: '玩家持续移动形成一段可观察的移动轨迹。',
102
+ }] as const;
97
103
  const sink = new DesktopEventSocketSink({
98
104
  socketPath,
99
105
  token: '0123456789abcdef0123456789abcdef',
100
106
  reconnectBaseMs: 10,
101
107
  reconnectMaxMs: 20,
102
108
  activeResources: () => activeResources,
109
+ eventDescriptors: () => eventDescriptors,
103
110
  });
104
111
  sink.start();
105
112
  await vi.waitFor(() => expect(frames[0]).toMatchObject({
@@ -122,7 +129,11 @@ describe('DesktopEventSocketSink', () => {
122
129
  deliveryId: 'delivery-2',
123
130
  batch: {
124
131
  state: { phase: 'wandering' },
125
- events: [{ type: 'speech_your_turn' }],
132
+ events: [
133
+ 'visual.player_moved | 1:2,你向右移动。',
134
+ 'visual.following | 1:2,玩家2跟随玩家3。',
135
+ { type: 'speech_your_turn' },
136
+ ],
126
137
  },
127
138
  }, new AbortController().signal);
128
139
 
@@ -139,8 +150,21 @@ describe('DesktopEventSocketSink', () => {
139
150
  events: [expect.objectContaining({ text: largeText })],
140
151
  }),
141
152
  }),
142
- expect.objectContaining({ seq: 2, delivery_id: 'delivery-2' }),
153
+ expect.objectContaining({
154
+ seq: 2,
155
+ delivery_id: 'delivery-2',
156
+ event_descriptors: eventDescriptors,
157
+ payload: expect.objectContaining({
158
+ events: [
159
+ 'visual.player_moved | 1:2,你向右移动。',
160
+ 'visual.following | 1:2,玩家2跟随玩家3。',
161
+ { type: 'speech_your_turn' },
162
+ ],
163
+ }),
164
+ }),
143
165
  ]);
166
+ expect(frames.find((frame) => frame.delivery_id === 'delivery-1'))
167
+ .not.toHaveProperty('event_descriptors');
144
168
 
145
169
  await sink.close();
146
170
  });
@@ -195,12 +219,19 @@ describe('DesktopEventSocketSink', () => {
195
219
  name: '策略甲',
196
220
  description: '策略甲描述。',
197
221
  };
222
+ let eventName = '旧玩家移动';
198
223
  const sink = new DesktopEventSocketSink({
199
224
  socketPath,
200
225
  token: '0123456789abcdef0123456789abcdef',
201
226
  reconnectBaseMs: 10,
202
227
  reconnectMaxMs: 20,
203
228
  activeResources: () => ({ locale: 'zh-CN', strategy, perceptions: [] }),
229
+ eventDescriptors: () => [{
230
+ type: 'visual.player_moved',
231
+ perception_id: 'visual.motion',
232
+ name: eventName,
233
+ description: '重试快照测试。',
234
+ }],
204
235
  });
205
236
  sink.start();
206
237
  await vi.waitFor(() => expect(hellos).toHaveLength(1));
@@ -208,7 +239,7 @@ describe('DesktopEventSocketSink', () => {
208
239
  deliveryId: 'durable-delivery',
209
240
  batch: {
210
241
  state: null,
211
- events: [{ type: 'game_over' }],
242
+ events: ['visual.player_moved | 测试移动。'],
212
243
  },
213
244
  };
214
245
 
@@ -221,6 +252,7 @@ describe('DesktopEventSocketSink', () => {
221
252
  name: '策略乙',
222
253
  description: '策略乙描述。',
223
254
  };
255
+ eventName = '新事件名称';
224
256
  await vi.waitFor(() => expect(hellos).toHaveLength(2));
225
257
  await expect(sink.deliver(envelope, new AbortController().signal)).resolves.toMatchObject({
226
258
  acceptedAt: expect.any(String),
@@ -230,6 +262,8 @@ describe('DesktopEventSocketSink', () => {
230
262
  expect(batches).toHaveLength(2);
231
263
  expect(batches[0].active_resources.strategy.id).toBe('strategy-a');
232
264
  expect(batches[1].active_resources.strategy.id).toBe('strategy-a');
265
+ expect(batches[0].event_descriptors[0].name).toBe('旧玩家移动');
266
+ expect(batches[1].event_descriptors[0].name).toBe('旧玩家移动');
233
267
 
234
268
  await sink.close();
235
269
  });
@@ -31,6 +31,13 @@ export interface DesktopActiveResources {
31
31
  readonly perceptions: readonly DesktopActiveResource[];
32
32
  }
33
33
 
34
+ export interface DesktopEventDescriptor {
35
+ readonly type: string;
36
+ readonly perception_id: string;
37
+ readonly name: string;
38
+ readonly description: string;
39
+ }
40
+
34
41
  export interface DesktopEventSocketOptions extends DesktopEventSocketConfig {
35
42
  ackTimeoutMs?: number;
36
43
  reconnectBaseMs?: number;
@@ -39,6 +46,7 @@ export interface DesktopEventSocketOptions extends DesktopEventSocketConfig {
39
46
  platform?: NodeJS.Platform;
40
47
  onConnected?: () => void;
41
48
  activeResources?: () => DesktopActiveResources;
49
+ eventDescriptors?: () => readonly DesktopEventDescriptor[];
42
50
  diagnostic?: (name: string, attributes?: Record<string, unknown>) => void;
43
51
  }
44
52
 
@@ -53,6 +61,12 @@ interface PendingDesktopAck {
53
61
  reject: (error: Error) => void;
54
62
  }
55
63
 
64
+ interface DesktopDeliveryMetadata {
65
+ readonly deliveryId: string;
66
+ readonly activeResources: DesktopActiveResources | undefined;
67
+ readonly eventDescriptors: readonly DesktopEventDescriptor[];
68
+ }
69
+
56
70
  export class DesktopEventSocketDeliveryError extends Error {
57
71
  readonly code: string;
58
72
  readonly retryable: boolean;
@@ -74,6 +88,16 @@ function controlledText(value: string, label: string, maxLength: number): string
74
88
  return text;
75
89
  }
76
90
 
91
+ function mailboxEventType(event: Record<string, unknown> | string): string | undefined {
92
+ if (typeof event === 'string') {
93
+ const separator = event.indexOf(' | ');
94
+ const type = (separator < 0 ? event : event.slice(0, separator)).trim();
95
+ return /^visual\.[a-z0-9_.-]+$/.test(type) ? type : undefined;
96
+ }
97
+ const type = typeof event.type === 'string' ? event.type.trim() : '';
98
+ return /^visual\.[a-z0-9_.-]+$/.test(type) ? type : undefined;
99
+ }
100
+
77
101
  export function normalizeDesktopEventSocketPath(
78
102
  value: string,
79
103
  platform: NodeJS.Platform = process.platform,
@@ -113,6 +137,7 @@ export class DesktopEventSocketSink implements MailboxEventBatchSink {
113
137
  private readonly now: () => number;
114
138
  private readonly onConnected?: DesktopEventSocketOptions['onConnected'];
115
139
  private readonly activeResources?: DesktopEventSocketOptions['activeResources'];
140
+ private readonly eventDescriptors?: DesktopEventSocketOptions['eventDescriptors'];
116
141
  private readonly diagnostic?: DesktopEventSocketOptions['diagnostic'];
117
142
 
118
143
  private socket: Socket | undefined;
@@ -124,10 +149,7 @@ export class DesktopEventSocketSink implements MailboxEventBatchSink {
124
149
  private reconnectTimer: ReturnType<typeof setTimeout> | undefined;
125
150
  private inputBuffer = '';
126
151
  private pendingAck: PendingDesktopAck | undefined;
127
- private deliveryResources: {
128
- deliveryId: string;
129
- value: DesktopActiveResources | undefined;
130
- } | undefined;
152
+ private deliveryMetadata: DesktopDeliveryMetadata | undefined;
131
153
 
132
154
  constructor(options: DesktopEventSocketOptions) {
133
155
  this.path = normalizeDesktopEventSocketPath(options.socketPath, options.platform);
@@ -138,6 +160,7 @@ export class DesktopEventSocketSink implements MailboxEventBatchSink {
138
160
  this.now = options.now ?? Date.now;
139
161
  this.onConnected = options.onConnected;
140
162
  this.activeResources = options.activeResources;
163
+ this.eventDescriptors = options.eventDescriptors;
141
164
  this.diagnostic = options.diagnostic;
142
165
  if (!Number.isFinite(this.ackTimeoutMs) || this.ackTimeoutMs <= 0) {
143
166
  throw new Error('Desktop event ACK timeout must be positive.');
@@ -186,14 +209,17 @@ export class DesktopEventSocketSink implements MailboxEventBatchSink {
186
209
  }
187
210
 
188
211
  const seq = ++this.sequence;
189
- const activeResources = this.resourcesForDelivery(envelope.deliveryId);
212
+ const metadata = this.metadataForDelivery(envelope.deliveryId, envelope.batch.events);
190
213
  const frame = {
191
214
  schema: DESKTOP_EVENT_PROTOCOL_SCHEMA,
192
215
  type: 'mailbox_batch',
193
216
  connection_id: connectionId,
194
217
  seq,
195
218
  delivery_id: envelope.deliveryId,
196
- ...(activeResources ? { active_resources: activeResources } : {}),
219
+ ...(metadata.activeResources ? { active_resources: metadata.activeResources } : {}),
220
+ ...(metadata.eventDescriptors.length > 0
221
+ ? { event_descriptors: metadata.eventDescriptors }
222
+ : {}),
197
223
  payload: {
198
224
  schema: 'clawclaw.channel-events.v1',
199
225
  ...envelope.batch,
@@ -253,7 +279,7 @@ export class DesktopEventSocketSink implements MailboxEventBatchSink {
253
279
  this.socket = undefined;
254
280
  this.connected = false;
255
281
  this.connectionId = undefined;
256
- this.deliveryResources = undefined;
282
+ this.deliveryMetadata = undefined;
257
283
  if (!socket || socket.destroyed) return;
258
284
  await new Promise<void>((resolve) => {
259
285
  socket.once('close', () => resolve());
@@ -345,8 +371,8 @@ export class DesktopEventSocketSink implements MailboxEventBatchSink {
345
371
  this.pendingAck = undefined;
346
372
  clearTimeout(pending.timer);
347
373
  pending.signal.removeEventListener('abort', pending.onAbort);
348
- if (this.deliveryResources?.deliveryId === pending.deliveryId) {
349
- this.deliveryResources = undefined;
374
+ if (this.deliveryMetadata?.deliveryId === pending.deliveryId) {
375
+ this.deliveryMetadata = undefined;
350
376
  }
351
377
  pending.resolve({
352
378
  acceptedAt: new Date(this.now()).toISOString(),
@@ -402,10 +428,19 @@ export class DesktopEventSocketSink implements MailboxEventBatchSink {
402
428
  return structuredClone(this.activeResources());
403
429
  }
404
430
 
405
- private resourcesForDelivery(deliveryId: string): DesktopActiveResources | undefined {
406
- if (this.deliveryResources?.deliveryId === deliveryId) return this.deliveryResources.value;
407
- const value = this.readActiveResources();
408
- this.deliveryResources = { deliveryId, value };
409
- return value;
431
+ private metadataForDelivery(
432
+ deliveryId: string,
433
+ events: readonly (Record<string, unknown> | string)[],
434
+ ): Omit<DesktopDeliveryMetadata, 'deliveryId'> {
435
+ if (this.deliveryMetadata?.deliveryId === deliveryId) return this.deliveryMetadata;
436
+ const activeEventTypes = new Set(events.map(mailboxEventType).filter((type) => type !== undefined));
437
+ const eventDescriptors = structuredClone(this.eventDescriptors?.() ?? [])
438
+ .filter((descriptor) => activeEventTypes.has(descriptor.type));
439
+ this.deliveryMetadata = {
440
+ deliveryId,
441
+ activeResources: this.readActiveResources(),
442
+ eventDescriptors,
443
+ };
444
+ return this.deliveryMetadata;
410
445
  }
411
446
  }
@@ -9,6 +9,7 @@ export type {
9
9
  ClawclawResolvedResourceMetadata,
10
10
  ClawclawResourceLocalizations,
11
11
  ClawclawPerceptionClass,
12
+ ClawclawPerceptionEventMetadata,
12
13
  ClawclawPerceptionManifest,
13
14
  PerceptionApi,
14
15
  PerceptionAnalysisInput,
@@ -68,6 +68,22 @@ export class CoMovementModule extends ClawclawParallelPerception<CoMovementAnaly
68
68
  'visual.players_moving_together',
69
69
  'visual.players_stopped_moving_together',
70
70
  ],
71
+ eventMetadata: {
72
+ 'visual.players_moving_together': {
73
+ name: 'Players moving together',
74
+ description: 'Reports two visible players moving close together in the same direction.',
75
+ localizations: {
76
+ 'zh-CN': { name: '共同移动', description: '两名同时可见的玩家近距离同方向稳定移动。' },
77
+ },
78
+ },
79
+ 'visual.players_stopped_moving_together': {
80
+ name: 'Players stopped moving together',
81
+ description: 'Reports when two players stop maintaining close same-direction movement.',
82
+ localizations: {
83
+ 'zh-CN': { name: '共同移动结束', description: '两名玩家不再保持近距离同方向移动。' },
84
+ },
85
+ },
86
+ },
71
87
  execution: 'parallel_analysis',
72
88
  boundaryBaseline: 'current_only',
73
89
  } as const;
@@ -72,6 +72,22 @@ export class FollowModule extends ClawclawParallelPerception<FollowAnalysis> {
72
72
  },
73
73
  subjectScope: 'visible_pairs',
74
74
  produces: ['visual.following', 'visual.following_ended'],
75
+ eventMetadata: {
76
+ 'visual.following': {
77
+ name: 'Following relation',
78
+ description: 'Reports one visible player moving steadily behind another in the same direction.',
79
+ localizations: {
80
+ 'zh-CN': { name: '跟随关系', description: '一名玩家稳定地跟在另一名玩家后方同方向移动。' },
81
+ },
82
+ },
83
+ 'visual.following_ended': {
84
+ name: 'Following relation ended',
85
+ description: 'Reports when two players stop maintaining a confirmed front/back relation.',
86
+ localizations: {
87
+ 'zh-CN': { name: '跟随关系结束', description: '两名玩家不再保持已确认的前后跟随关系。' },
88
+ },
89
+ },
90
+ },
75
91
  execution: 'parallel_analysis',
76
92
  boundaryBaseline: 'current_only',
77
93
  } as const;
@@ -88,6 +88,22 @@ export class MotionModule extends ClawclawParallelPerception<MotionAnalysis> {
88
88
  },
89
89
  subjectScope: 'self_and_others',
90
90
  produces: ['visual.player_moved', 'visual.player_motion_changed'],
91
+ eventMetadata: {
92
+ 'visual.player_moved': {
93
+ name: 'Player moved',
94
+ description: 'Reports a continuous observed movement segment for a player.',
95
+ localizations: {
96
+ 'zh-CN': { name: '玩家移动', description: '玩家持续移动形成一段可观察的移动轨迹。' },
97
+ },
98
+ },
99
+ 'visual.player_motion_changed': {
100
+ name: 'Movement direction changed',
101
+ description: 'Reports a confirmed meaningful change in a player\'s movement direction.',
102
+ localizations: {
103
+ 'zh-CN': { name: '移动方向变化', description: '玩家的移动方向发生经过确认的显著变化。' },
104
+ },
105
+ },
106
+ },
91
107
  execution: 'parallel_analysis',
92
108
  boundaryBaseline: 'current_only',
93
109
  } as const;
@@ -72,6 +72,29 @@ export class RouteModule extends ClawclawParallelPerception<RouteAnalysis> {
72
72
  'visual.player_reversed',
73
73
  'visual.player_wandering',
74
74
  ],
75
+ eventMetadata: {
76
+ 'visual.player_turned': {
77
+ name: 'Player turned',
78
+ description: 'Reports when a player changes direction and forms a turn.',
79
+ localizations: {
80
+ 'zh-CN': { name: '玩家转向', description: '玩家改变移动方向并形成一次转向。' },
81
+ },
82
+ },
83
+ 'visual.player_reversed': {
84
+ name: 'Player reversed direction',
85
+ description: 'Reports when a player changes to a roughly opposite movement direction.',
86
+ localizations: {
87
+ 'zh-CN': { name: '玩家折返', description: '玩家改变为大致相反方向移动。' },
88
+ },
89
+ },
90
+ 'visual.player_wandering': {
91
+ name: 'Player wandering',
92
+ description: 'Reports repeated nearby turns or reversals by a player.',
93
+ localizations: {
94
+ 'zh-CN': { name: '玩家徘徊', description: '玩家在附近连续多次转向或折返。' },
95
+ },
96
+ },
97
+ },
75
98
  execution: 'parallel_analysis',
76
99
  boundaryBaseline: 'current_only',
77
100
  } as const;
@@ -36,6 +36,22 @@ export class SpatialModule extends ClawclawParallelPerception<SpatialAnalysis> {
36
36
  },
37
37
  subjectScope: 'self_and_others',
38
38
  produces: ['visual.player_area_changed', 'visual.player_position_changed'],
39
+ eventMetadata: {
40
+ 'visual.player_area_changed': {
41
+ name: 'Player area changed',
42
+ description: 'Reports when a player enters another room or named area.',
43
+ localizations: {
44
+ 'zh-CN': { name: '区域变化', description: '玩家进入另一房间或位置区域。' },
45
+ },
46
+ },
47
+ 'visual.player_position_changed': {
48
+ name: 'Position within room changed',
49
+ description: 'Reports a coarse position change within the same room.',
50
+ localizations: {
51
+ 'zh-CN': { name: '房间内位置变化', description: '玩家在同一房间内的粗粒度方位发生变化。' },
52
+ },
53
+ },
54
+ },
39
55
  execution: 'parallel_analysis',
40
56
  boundaryBaseline: 'current_only',
41
57
  } as const;
@@ -57,6 +57,22 @@ export class StopModule extends ClawclawParallelPerception<StopAnalysis> {
57
57
  'visual.player_stopped',
58
58
  'visual.player_resumed',
59
59
  ],
60
+ eventMetadata: {
61
+ 'visual.player_stopped': {
62
+ name: 'Player stopped',
63
+ description: 'Reports when a player remains at one position long enough to confirm a stop.',
64
+ localizations: {
65
+ 'zh-CN': { name: '玩家停留', description: '玩家在同一位置持续停留达到确认阈值。' },
66
+ },
67
+ },
68
+ 'visual.player_resumed': {
69
+ name: 'Player resumed movement',
70
+ description: 'Reports when a player ends a confirmed stop and resumes moving.',
71
+ localizations: {
72
+ 'zh-CN': { name: '恢复移动', description: '玩家结束已确认的停留并恢复移动。' },
73
+ },
74
+ },
75
+ },
60
76
  execution: 'parallel_analysis',
61
77
  boundaryBaseline: 'current_only',
62
78
  } as const;
@@ -37,6 +37,29 @@ export class VisibilityModule extends ClawclawParallelPerception<VisibilityAnaly
37
37
  'visual.player_left',
38
38
  'visual.player_reappeared',
39
39
  ],
40
+ eventMetadata: {
41
+ 'visual.player_entered': {
42
+ name: 'Player entered view',
43
+ description: 'Reports when a player enters the observer\'s current field of view.',
44
+ localizations: {
45
+ 'zh-CN': { name: '进入视野', description: '玩家从不可见状态进入你的当前视野。' },
46
+ },
47
+ },
48
+ 'visual.player_left': {
49
+ name: 'Player left view',
50
+ description: 'Reports when a player disappears from the observer\'s current field of view.',
51
+ localizations: {
52
+ 'zh-CN': { name: '离开视野', description: '玩家从你的当前视野中消失。' },
53
+ },
54
+ },
55
+ 'visual.player_reappeared': {
56
+ name: 'Player reappeared',
57
+ description: 'Reports when a player returns shortly after leaving the observer\'s view.',
58
+ localizations: {
59
+ 'zh-CN': { name: '重新进入视野', description: '玩家短暂离开后重新出现在你的视野中。' },
60
+ },
61
+ },
62
+ },
40
63
  execution: 'parallel_analysis',
41
64
  boundaryBaseline: 'current_only',
42
65
  } as const;
@@ -355,6 +355,25 @@ describe('ClawClaw Perception plugin', () => {
355
355
  expect(plugin.localizedModuleDescriptors('en-US')).toEqual(expect.arrayContaining([
356
356
  expect.objectContaining({ id: 'visual.visibility', name: 'Visibility changes' }),
357
357
  ]));
358
+ expect(plugin.localizedEventDescriptors('zh-CN')).toHaveLength(16);
359
+ expect(plugin.localizedEventDescriptors('zh-CN')).toEqual(expect.arrayContaining([
360
+ {
361
+ type: 'visual.player_entered',
362
+ perceptionId: 'visual.visibility',
363
+ name: '进入视野',
364
+ description: '玩家从不可见状态进入你的当前视野。',
365
+ },
366
+ expect.objectContaining({
367
+ type: 'visual.player_moved',
368
+ perceptionId: 'visual.motion',
369
+ name: '玩家移动',
370
+ }),
371
+ ]));
372
+ expect(new ClawclawPerceptionPlugin({ modules: ['visual.motion'] })
373
+ .localizedEventDescriptors('zh-CN').map((event) => event.type)).toEqual([
374
+ 'visual.player_moved',
375
+ 'visual.player_motion_changed',
376
+ ]);
358
377
  });
359
378
 
360
379
  it('starts, analyzes, commits, and stops all seven official Worker modules together', async () => {
@@ -72,6 +72,13 @@ export interface PerceptionModuleDescriptor extends ClawclawPerceptionManifest {
72
72
  readonly pluginId: typeof CLAWCLAW_PERCEPTION_PLUGIN_ID;
73
73
  }
74
74
 
75
+ export interface LocalizedPerceptionEventDescriptor {
76
+ readonly type: string;
77
+ readonly perceptionId: string;
78
+ readonly name: string;
79
+ readonly description: string;
80
+ }
81
+
75
82
  export interface PerceptionFrameInspection {
76
83
  visual: VisualState | null;
77
84
  proposals: readonly RuntimeEventProposal[];
@@ -167,6 +174,25 @@ function nonEmpty(value: unknown): value is string {
167
174
  return typeof value === 'string' && value.trim().length > 0;
168
175
  }
169
176
 
177
+ function hasValidPerceptionEventMetadata(manifest: ClawclawPerceptionManifest): boolean {
178
+ const metadata = manifest.eventMetadata;
179
+ if (metadata === undefined) return true;
180
+ if (!metadata || typeof metadata !== 'object' || Array.isArray(metadata)) return false;
181
+ const entries = Object.entries(metadata);
182
+ return (
183
+ entries.length === manifest.produces.length
184
+ && entries.every(([type, value]) => (
185
+ manifest.produces.includes(type)
186
+ && !!value
187
+ && typeof value === 'object'
188
+ && !Array.isArray(value)
189
+ && nonEmpty(value.name)
190
+ && nonEmpty(value.description)
191
+ && hasValidClawclawResourceLocalizations(value.localizations)
192
+ ))
193
+ );
194
+ }
195
+
170
196
  function moduleClass(instance: ClawclawPerception): ClawclawPerceptionClass {
171
197
  return instance.constructor as ClawclawPerceptionClass;
172
198
  }
@@ -214,6 +240,7 @@ export function validatePerceptionManifest(
214
240
  || manifest.produces.length === 0
215
241
  || manifest.produces.some((type) => !/^visual\.[a-z0-9_.-]+$/.test(type))
216
242
  || new Set(manifest.produces).size !== manifest.produces.length
243
+ || !hasValidPerceptionEventMetadata(manifest)
217
244
  || (manifest.execution !== undefined && manifest.execution !== 'parallel_analysis')
218
245
  || (
219
246
  manifest.boundaryBaseline !== undefined
@@ -780,6 +807,20 @@ export class ClawclawPerceptionPlugin implements RuntimeEpochPlugin<Record<strin
780
807
  return this.modules.map(({ manifest }) => resolveClawclawResourceMetadata(manifest, locale));
781
808
  }
782
809
 
810
+ localizedEventDescriptors(locale: string): LocalizedPerceptionEventDescriptor[] {
811
+ return this.modules.flatMap(({ manifest }) => manifest.produces.flatMap((type) => {
812
+ const metadata = manifest.eventMetadata?.[type];
813
+ if (!metadata) return [];
814
+ const localized = resolveClawclawResourceMetadata({ id: type, ...metadata }, locale);
815
+ return [{
816
+ type,
817
+ perceptionId: manifest.id,
818
+ name: localized.name,
819
+ description: localized.description,
820
+ }];
821
+ }));
822
+ }
823
+
783
824
  moduleStateSnapshot(): Record<string, unknown> {
784
825
  return Object.fromEntries(this.modules.map(({ manifest, runner }) => [
785
826
  manifest.id,
@@ -45,6 +45,18 @@ describe('ClawClaw perception source discovery', () => {
45
45
  },
46
46
  subjectScope: 'others',
47
47
  produces: ['visual.custom_linger'],
48
+ eventMetadata: {
49
+ 'visual.custom_linger': {
50
+ name: 'Player lingered',
51
+ description: 'Reports one confirmed long stay.',
52
+ localizations: {
53
+ 'zh-CN': {
54
+ name: '玩家长时间停留',
55
+ description: '玩家在一个位置长时间停留。',
56
+ },
57
+ },
58
+ },
59
+ },
48
60
  } as const;
49
61
  update() {}
50
62
  }
@@ -65,6 +77,18 @@ describe('ClawClaw perception source discovery', () => {
65
77
  },
66
78
  subjectScope: 'others',
67
79
  produces: ['visual.custom_linger'],
80
+ eventMetadata: {
81
+ 'visual.custom_linger': {
82
+ name: 'Player lingered',
83
+ description: 'Reports one confirmed long stay.',
84
+ localizations: {
85
+ 'zh-CN': {
86
+ name: '玩家长时间停留',
87
+ description: '玩家在一个位置长时间停留。',
88
+ },
89
+ },
90
+ },
91
+ },
68
92
  },
69
93
  }),
70
94
  ]);
@@ -80,6 +104,31 @@ describe('ClawClaw perception source discovery', () => {
80
104
  expect(listClawclawPerceptionSources(fixture.root)).toEqual([]);
81
105
  });
82
106
 
107
+ it('rejects event metadata that does not cover every produced event type', () => {
108
+ const fixture = workspace();
109
+ writeFileSync(join(fixture.perceptions, 'incomplete-events.ts'), `
110
+ import { ClawclawPerception } from '@myclaw163/clawclaw-cli/perception-plugin';
111
+ export default class IncompleteEvents extends ClawclawPerception {
112
+ static readonly manifest = {
113
+ id: 'visual.incomplete_events',
114
+ name: 'Incomplete events',
115
+ description: 'Declares incomplete event metadata.',
116
+ subjectScope: 'others',
117
+ produces: ['visual.first', 'visual.second'],
118
+ eventMetadata: {
119
+ 'visual.first': {
120
+ name: 'First event',
121
+ description: 'Describes only the first event.',
122
+ },
123
+ },
124
+ } as const;
125
+ update() {}
126
+ }
127
+ `);
128
+
129
+ expect(listClawclawPerceptionSources(fixture.root)).toEqual([]);
130
+ });
131
+
83
132
  it('discovers an explicitly parallel analyzer without executing it', () => {
84
133
  const fixture = workspace();
85
134
  writeFileSync(join(fixture.perceptions, 'parallel.ts'), `