@myclaw163/clawclaw-cli 0.7.6 → 0.7.7
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 +37 -3
- package/docs/runtime/README.md +1 -0
- package/docs/runtime/official-perception-modules.md +346 -0
- package/package.json +1 -1
- package/src/commands/game/index.ts +1 -1
- package/src/lib/service-status.test.ts +56 -0
- package/src/lib/service-status.ts +111 -0
- package/src/pipeline/event-format.test.ts +13 -0
- package/src/pipeline/event-format.ts +11 -0
- package/src/pipeline/event-hints.test.ts +18 -3
- package/src/pipeline/event-hints.ts +11 -0
- package/src/runtime/clawclaw/agent-event-policy.test.ts +4 -0
- package/src/runtime/clawclaw/agent-event-policy.ts +1 -0
- package/src/runtime/clawclaw/owner.ts +6 -0
- package/src/runtime/clawclaw/plugins/mailbox/desktop-event-push.integration.test.ts +24 -0
- package/src/runtime/clawclaw/plugins/mailbox/desktop-event-socket.test.ts +29 -0
- package/src/runtime/clawclaw/plugins/mailbox/desktop-event-socket.ts +39 -0
- package/src/runtime/clawclaw/plugins/perception/contracts.ts +4 -0
- package/src/runtime/clawclaw/plugins/perception/modules/co-movement-module.ts +6 -0
- package/src/runtime/clawclaw/plugins/perception/modules/follow-module.ts +6 -0
- package/src/runtime/clawclaw/plugins/perception/modules/motion-module.ts +6 -0
- package/src/runtime/clawclaw/plugins/perception/modules/route-module.ts +6 -0
- package/src/runtime/clawclaw/plugins/perception/modules/spatial-module.ts +6 -0
- package/src/runtime/clawclaw/plugins/perception/modules/stop-module.ts +6 -0
- package/src/runtime/clawclaw/plugins/perception/modules/visibility-module.ts +6 -0
- package/src/runtime/clawclaw/plugins/perception/perception-plugin.test.ts +11 -0
- package/src/runtime/clawclaw/plugins/perception/perception-plugin.ts +8 -0
- package/src/runtime/clawclaw/plugins/perception/perception-source.test.ts +12 -0
- package/src/runtime/clawclaw/plugins/perception/perception-source.ts +37 -1
- package/src/runtime/clawclaw/plugins/source/room-transport.ts +2 -1
- package/src/runtime/clawclaw/plugins/source/source-plugin.test.ts +149 -1
- package/src/runtime/clawclaw/plugins/source/source-plugin.ts +109 -21
- package/src/runtime/clawclaw/plugins/source/types.ts +1 -0
- package/src/runtime/clawclaw/plugins/strategy/examples/task-only-strategy.ts +6 -0
- package/src/runtime/clawclaw/plugins/strategy/strategy-executor-types.ts +4 -0
- package/src/runtime/clawclaw/plugins/strategy/strategy-module-loader.ts +4 -0
- package/src/runtime/clawclaw/plugins/strategy/strategy-plugin.test.ts +36 -0
- package/src/runtime/clawclaw/plugins/strategy/strategy-plugin.ts +13 -0
- package/src/runtime/clawclaw/plugins/strategy/strategy-source.test.ts +22 -0
- package/src/runtime/clawclaw/plugins/strategy/strategy-source.ts +46 -16
- package/src/runtime/clawclaw-event-catalog.test.ts +2 -0
- package/src/runtime/clawclaw-event-catalog.ts +1 -0
- package/src/sdk/perception-plugin/index.ts +14 -0
- package/src/sdk/resource-metadata.test.ts +40 -0
- package/src/sdk/resource-metadata.ts +63 -0
- package/src/sdk/strategy-plugin/index.ts +14 -0
|
@@ -11,12 +11,12 @@ import {
|
|
|
11
11
|
} from './event-hints.js';
|
|
12
12
|
|
|
13
13
|
describe('Mailbox-owned Event hint registries', () => {
|
|
14
|
-
it('keeps
|
|
14
|
+
it('keeps 31 backend hint formatters and classifies 14 Agent Events as unregistered', () => {
|
|
15
15
|
const unregistered = CLAWCLAW_BACKEND_AGENT_EVENT_TYPES.filter((type) => (
|
|
16
16
|
BACKEND_EVENT_HINT_FORMATTERS[type] === undefined
|
|
17
17
|
));
|
|
18
18
|
|
|
19
|
-
expect(Object.keys(BACKEND_EVENT_HINT_FORMATTERS)).toHaveLength(
|
|
19
|
+
expect(Object.keys(BACKEND_EVENT_HINT_FORMATTERS)).toHaveLength(31);
|
|
20
20
|
expect(unregistered).toEqual([
|
|
21
21
|
'task_completed',
|
|
22
22
|
'task_sabotaged',
|
|
@@ -35,6 +35,21 @@ describe('Mailbox-owned Event hint registries', () => {
|
|
|
35
35
|
]);
|
|
36
36
|
});
|
|
37
37
|
|
|
38
|
+
it('tells the Agent when maintenance permits or blocks Lobby operations', () => {
|
|
39
|
+
const maintenance = {
|
|
40
|
+
starts_at: '2026-08-05T01:00:00+00:00',
|
|
41
|
+
ends_at: '2026-08-05T03:00:00+00:00',
|
|
42
|
+
};
|
|
43
|
+
expect(formatCanonicalEventHint(
|
|
44
|
+
{ producer: 'backend_push' },
|
|
45
|
+
{ type: 'service_status', service_status: 'maintenance_upcoming', maintenance },
|
|
46
|
+
)).toContain('current request succeeded');
|
|
47
|
+
expect(formatCanonicalEventHint(
|
|
48
|
+
{ producer: 'backend_push' },
|
|
49
|
+
{ type: 'service_status', service_status: 'maintenance_active', maintenance },
|
|
50
|
+
)).toContain('Do not retry matchmaking');
|
|
51
|
+
});
|
|
52
|
+
|
|
38
53
|
it('classifies Source and Derived lifecycle Events with players_changed factual-only', () => {
|
|
39
54
|
const excluded = new Set(['robot_speak_rule', 'strategy_alert']);
|
|
40
55
|
const sourceTypes = CLAWCLAW_LOCAL_AGENT_EVENT_TYPES.filter((type) => (
|
|
@@ -235,7 +250,7 @@ describe('Mailbox-owned Event hint registries', () => {
|
|
|
235
250
|
...Object.values(DERIVED_EVENT_HINT_FORMATTERS).map((formatter) => formatter(sample, {})),
|
|
236
251
|
].filter((hint): hint is string => typeof hint === 'string');
|
|
237
252
|
|
|
238
|
-
expect(hints).toHaveLength(
|
|
253
|
+
expect(hints).toHaveLength(51);
|
|
239
254
|
for (const hint of hints) expect(hint).not.toMatch(/[一-鿿]/);
|
|
240
255
|
});
|
|
241
256
|
});
|
|
@@ -110,6 +110,17 @@ function meetingBriefingHint(event: Record<string, any>): string | undefined {
|
|
|
110
110
|
}
|
|
111
111
|
|
|
112
112
|
export const BACKEND_EVENT_HINT_FORMATTERS: Readonly<Record<string, EventHintFormatter>> = Object.freeze({
|
|
113
|
+
service_status: (event) => {
|
|
114
|
+
const startsAt = text(event.maintenance?.starts_at, 'the scheduled start time');
|
|
115
|
+
const endsAt = text(event.maintenance?.ends_at, 'the scheduled end time');
|
|
116
|
+
if (event.service_status === 'maintenance_upcoming') {
|
|
117
|
+
return `Tell the user that maintenance is scheduled from ${startsAt} to ${endsAt}. The current request succeeded and may continue; do not start an extra runtime.`;
|
|
118
|
+
}
|
|
119
|
+
if (event.service_status === 'maintenance_active') {
|
|
120
|
+
return `Tell the user that the service is under maintenance until ${endsAt}. Do not retry matchmaking, room creation, room joining, or room start before then; query server status before trying again.`;
|
|
121
|
+
}
|
|
122
|
+
return 'The service is available again. Tell the user if they were waiting, but do not replay a previously blocked request unless they still want it.';
|
|
123
|
+
},
|
|
113
124
|
move_interrupted: (event) => {
|
|
114
125
|
const nearby = Array.isArray(event.nearby_players)
|
|
115
126
|
? event.nearby_players.map((player: any) => text(player?.name, '')).filter(Boolean).slice(0, 3)
|
|
@@ -10,6 +10,10 @@ describe('ClawClaw Monitor Event policy', () => {
|
|
|
10
10
|
.toBeGreaterThan(clawclawMonitorPriority('speech'));
|
|
11
11
|
});
|
|
12
12
|
|
|
13
|
+
it('prioritizes service availability changes', () => {
|
|
14
|
+
expect(clawclawMonitorPriority('service_status')).toBe(95);
|
|
15
|
+
});
|
|
16
|
+
|
|
13
17
|
it('uses the default priority for unlisted Events', () => {
|
|
14
18
|
expect(clawclawMonitorPriority('speech')).toBe(50);
|
|
15
19
|
});
|
|
@@ -164,6 +164,7 @@ interface OwnerRuntimePointer {
|
|
|
164
164
|
}
|
|
165
165
|
|
|
166
166
|
const MAILBOX_DRAIN_TIMEOUT_MS = 2_000;
|
|
167
|
+
const DESKTOP_RESOURCE_LOCALE = 'zh-CN';
|
|
167
168
|
const EVENTS_QUERY_BARRIER_TIMEOUT_MS = 10_000;
|
|
168
169
|
const LOCAL_STOP_FORCE_EXIT_MS = 10_000;
|
|
169
170
|
const FORCE_STOP_GRACE_MS = 1_500;
|
|
@@ -563,6 +564,11 @@ export async function runClawclawOwner(
|
|
|
563
564
|
if (options.desktopEvents) {
|
|
564
565
|
const desktopSink = new DesktopEventSocketSink({
|
|
565
566
|
...options.desktopEvents,
|
|
567
|
+
activeResources: () => ({
|
|
568
|
+
locale: DESKTOP_RESOURCE_LOCALE,
|
|
569
|
+
strategy: assembly.strategy.activeResourceDescriptor(DESKTOP_RESOURCE_LOCALE),
|
|
570
|
+
perceptions: assembly.perception.localizedModuleDescriptors(DESKTOP_RESOURCE_LOCALE),
|
|
571
|
+
}),
|
|
566
572
|
onConnected: () => desktopEventPump?.retryNow(),
|
|
567
573
|
diagnostic: (name, attributes) => runtime?.diagnostic(name, attributes),
|
|
568
574
|
});
|
|
@@ -196,6 +196,19 @@ describe('Desktop Agent event push integration', () => {
|
|
|
196
196
|
reconnectBaseMs: 10,
|
|
197
197
|
reconnectMaxMs: 20,
|
|
198
198
|
onConnected: () => pump?.retryNow(),
|
|
199
|
+
activeResources: () => ({
|
|
200
|
+
locale: 'zh-CN',
|
|
201
|
+
strategy: {
|
|
202
|
+
id: 'normal-shrimp',
|
|
203
|
+
name: '普通虾',
|
|
204
|
+
description: '完成任务并保持警觉。',
|
|
205
|
+
},
|
|
206
|
+
perceptions: [{
|
|
207
|
+
id: 'visual.visibility',
|
|
208
|
+
name: '视野变化',
|
|
209
|
+
description: '感知其他玩家进入、离开或重新出现在视野中。',
|
|
210
|
+
}],
|
|
211
|
+
}),
|
|
199
212
|
});
|
|
200
213
|
pump = new MailboxEventBatchPump({
|
|
201
214
|
source: {
|
|
@@ -217,6 +230,12 @@ describe('Desktop Agent event push integration', () => {
|
|
|
217
230
|
await vi.waitFor(() => {
|
|
218
231
|
expect(received.filter(({ frame }) => frame.type === 'hello')).toHaveLength(1);
|
|
219
232
|
});
|
|
233
|
+
expect(received.find(({ frame }) => frame.type === 'hello')?.frame.active_resources)
|
|
234
|
+
.toMatchObject({
|
|
235
|
+
locale: 'zh-CN',
|
|
236
|
+
strategy: { id: 'normal-shrimp', name: '普通虾' },
|
|
237
|
+
perceptions: [{ id: 'visual.visibility', name: '视野变化' }],
|
|
238
|
+
});
|
|
220
239
|
expect(await mailbox.update({ pendingEvents: [] } as any)).toMatchObject({
|
|
221
240
|
outcome: 'noop',
|
|
222
241
|
reason: 'no_pending_events',
|
|
@@ -268,6 +287,11 @@ describe('Desktop Agent event push integration', () => {
|
|
|
268
287
|
schema: 'clawclaw.channel-events.v1',
|
|
269
288
|
state: { phase: 'wandering', tick: 3 },
|
|
270
289
|
});
|
|
290
|
+
expect(firstBatch.frame.active_resources).toMatchObject({
|
|
291
|
+
locale: 'zh-CN',
|
|
292
|
+
strategy: { id: 'normal-shrimp', name: '普通虾' },
|
|
293
|
+
perceptions: [{ id: 'visual.visibility', name: '视野变化' }],
|
|
294
|
+
});
|
|
271
295
|
expect(firstBatch.frame.payload.events).toEqual([
|
|
272
296
|
'visual.player_moved | player-2 moved through engine',
|
|
273
297
|
expect.objectContaining({ type: 'speech', text: longText }),
|
|
@@ -85,11 +85,21 @@ describe('DesktopEventSocketSink', () => {
|
|
|
85
85
|
server.listen(socketPath, resolve);
|
|
86
86
|
});
|
|
87
87
|
|
|
88
|
+
const activeResources = {
|
|
89
|
+
locale: 'zh-CN',
|
|
90
|
+
strategy: null,
|
|
91
|
+
perceptions: [{
|
|
92
|
+
id: 'visual.motion',
|
|
93
|
+
name: '玩家移动',
|
|
94
|
+
description: '感知自己和可见玩家的连续移动片段及显著方向变化。',
|
|
95
|
+
}],
|
|
96
|
+
} as const;
|
|
88
97
|
const sink = new DesktopEventSocketSink({
|
|
89
98
|
socketPath,
|
|
90
99
|
token: '0123456789abcdef0123456789abcdef',
|
|
91
100
|
reconnectBaseMs: 10,
|
|
92
101
|
reconnectMaxMs: 20,
|
|
102
|
+
activeResources: () => activeResources,
|
|
93
103
|
});
|
|
94
104
|
sink.start();
|
|
95
105
|
await vi.waitFor(() => expect(frames[0]).toMatchObject({
|
|
@@ -97,6 +107,7 @@ describe('DesktopEventSocketSink', () => {
|
|
|
97
107
|
type: 'hello',
|
|
98
108
|
token: '0123456789abcdef0123456789abcdef',
|
|
99
109
|
pid: process.pid,
|
|
110
|
+
active_resources: activeResources,
|
|
100
111
|
}));
|
|
101
112
|
|
|
102
113
|
const largeText = 'z'.repeat(70 * 1024);
|
|
@@ -122,6 +133,7 @@ describe('DesktopEventSocketSink', () => {
|
|
|
122
133
|
expect.objectContaining({
|
|
123
134
|
seq: 1,
|
|
124
135
|
delivery_id: 'delivery-1',
|
|
136
|
+
active_resources: activeResources,
|
|
125
137
|
payload: expect.objectContaining({
|
|
126
138
|
schema: 'clawclaw.channel-events.v1',
|
|
127
139
|
events: [expect.objectContaining({ text: largeText })],
|
|
@@ -139,6 +151,7 @@ describe('DesktopEventSocketSink', () => {
|
|
|
139
151
|
? `\\\\.\\pipe\\${pipeName}`
|
|
140
152
|
: `/tmp/${pipeName}.sock`;
|
|
141
153
|
const hellos: Array<Record<string, any>> = [];
|
|
154
|
+
const batches: Array<Record<string, any>> = [];
|
|
142
155
|
let connectionNumber = 0;
|
|
143
156
|
const server = createServer((socket) => {
|
|
144
157
|
connectionNumber += 1;
|
|
@@ -156,6 +169,7 @@ describe('DesktopEventSocketSink', () => {
|
|
|
156
169
|
const frame = JSON.parse(line) as Record<string, any>;
|
|
157
170
|
if (frame.type === 'hello') hellos.push(frame);
|
|
158
171
|
if (frame.type !== 'mailbox_batch') continue;
|
|
172
|
+
batches.push(frame);
|
|
159
173
|
if (currentConnection === 1) {
|
|
160
174
|
socket.destroy();
|
|
161
175
|
continue;
|
|
@@ -176,11 +190,17 @@ describe('DesktopEventSocketSink', () => {
|
|
|
176
190
|
server.listen(socketPath, resolve);
|
|
177
191
|
});
|
|
178
192
|
|
|
193
|
+
let strategy = {
|
|
194
|
+
id: 'strategy-a',
|
|
195
|
+
name: '策略甲',
|
|
196
|
+
description: '策略甲描述。',
|
|
197
|
+
};
|
|
179
198
|
const sink = new DesktopEventSocketSink({
|
|
180
199
|
socketPath,
|
|
181
200
|
token: '0123456789abcdef0123456789abcdef',
|
|
182
201
|
reconnectBaseMs: 10,
|
|
183
202
|
reconnectMaxMs: 20,
|
|
203
|
+
activeResources: () => ({ locale: 'zh-CN', strategy, perceptions: [] }),
|
|
184
204
|
});
|
|
185
205
|
sink.start();
|
|
186
206
|
await vi.waitFor(() => expect(hellos).toHaveLength(1));
|
|
@@ -196,11 +216,20 @@ describe('DesktopEventSocketSink', () => {
|
|
|
196
216
|
code: 'desktop_event_socket_disconnected',
|
|
197
217
|
retryable: true,
|
|
198
218
|
});
|
|
219
|
+
strategy = {
|
|
220
|
+
id: 'strategy-b',
|
|
221
|
+
name: '策略乙',
|
|
222
|
+
description: '策略乙描述。',
|
|
223
|
+
};
|
|
199
224
|
await vi.waitFor(() => expect(hellos).toHaveLength(2));
|
|
200
225
|
await expect(sink.deliver(envelope, new AbortController().signal)).resolves.toMatchObject({
|
|
201
226
|
acceptedAt: expect.any(String),
|
|
202
227
|
});
|
|
203
228
|
expect(hellos[1].connection_id).not.toBe(hellos[0].connection_id);
|
|
229
|
+
expect(hellos[1].active_resources.strategy.id).toBe('strategy-b');
|
|
230
|
+
expect(batches).toHaveLength(2);
|
|
231
|
+
expect(batches[0].active_resources.strategy.id).toBe('strategy-a');
|
|
232
|
+
expect(batches[1].active_resources.strategy.id).toBe('strategy-a');
|
|
204
233
|
|
|
205
234
|
await sink.close();
|
|
206
235
|
});
|
|
@@ -19,6 +19,18 @@ export interface DesktopEventSocketConfig {
|
|
|
19
19
|
token: string;
|
|
20
20
|
}
|
|
21
21
|
|
|
22
|
+
export interface DesktopActiveResource {
|
|
23
|
+
readonly id: string;
|
|
24
|
+
readonly name: string;
|
|
25
|
+
readonly description: string;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export interface DesktopActiveResources {
|
|
29
|
+
readonly locale: string;
|
|
30
|
+
readonly strategy: DesktopActiveResource | null;
|
|
31
|
+
readonly perceptions: readonly DesktopActiveResource[];
|
|
32
|
+
}
|
|
33
|
+
|
|
22
34
|
export interface DesktopEventSocketOptions extends DesktopEventSocketConfig {
|
|
23
35
|
ackTimeoutMs?: number;
|
|
24
36
|
reconnectBaseMs?: number;
|
|
@@ -26,6 +38,7 @@ export interface DesktopEventSocketOptions extends DesktopEventSocketConfig {
|
|
|
26
38
|
now?: () => number;
|
|
27
39
|
platform?: NodeJS.Platform;
|
|
28
40
|
onConnected?: () => void;
|
|
41
|
+
activeResources?: () => DesktopActiveResources;
|
|
29
42
|
diagnostic?: (name: string, attributes?: Record<string, unknown>) => void;
|
|
30
43
|
}
|
|
31
44
|
|
|
@@ -99,6 +112,7 @@ export class DesktopEventSocketSink implements MailboxEventBatchSink {
|
|
|
99
112
|
private readonly reconnectMaxMs: number;
|
|
100
113
|
private readonly now: () => number;
|
|
101
114
|
private readonly onConnected?: DesktopEventSocketOptions['onConnected'];
|
|
115
|
+
private readonly activeResources?: DesktopEventSocketOptions['activeResources'];
|
|
102
116
|
private readonly diagnostic?: DesktopEventSocketOptions['diagnostic'];
|
|
103
117
|
|
|
104
118
|
private socket: Socket | undefined;
|
|
@@ -110,6 +124,10 @@ export class DesktopEventSocketSink implements MailboxEventBatchSink {
|
|
|
110
124
|
private reconnectTimer: ReturnType<typeof setTimeout> | undefined;
|
|
111
125
|
private inputBuffer = '';
|
|
112
126
|
private pendingAck: PendingDesktopAck | undefined;
|
|
127
|
+
private deliveryResources: {
|
|
128
|
+
deliveryId: string;
|
|
129
|
+
value: DesktopActiveResources | undefined;
|
|
130
|
+
} | undefined;
|
|
113
131
|
|
|
114
132
|
constructor(options: DesktopEventSocketOptions) {
|
|
115
133
|
this.path = normalizeDesktopEventSocketPath(options.socketPath, options.platform);
|
|
@@ -119,6 +137,7 @@ export class DesktopEventSocketSink implements MailboxEventBatchSink {
|
|
|
119
137
|
this.reconnectMaxMs = options.reconnectMaxMs ?? DEFAULT_RECONNECT_MAX_MS;
|
|
120
138
|
this.now = options.now ?? Date.now;
|
|
121
139
|
this.onConnected = options.onConnected;
|
|
140
|
+
this.activeResources = options.activeResources;
|
|
122
141
|
this.diagnostic = options.diagnostic;
|
|
123
142
|
if (!Number.isFinite(this.ackTimeoutMs) || this.ackTimeoutMs <= 0) {
|
|
124
143
|
throw new Error('Desktop event ACK timeout must be positive.');
|
|
@@ -167,12 +186,14 @@ export class DesktopEventSocketSink implements MailboxEventBatchSink {
|
|
|
167
186
|
}
|
|
168
187
|
|
|
169
188
|
const seq = ++this.sequence;
|
|
189
|
+
const activeResources = this.resourcesForDelivery(envelope.deliveryId);
|
|
170
190
|
const frame = {
|
|
171
191
|
schema: DESKTOP_EVENT_PROTOCOL_SCHEMA,
|
|
172
192
|
type: 'mailbox_batch',
|
|
173
193
|
connection_id: connectionId,
|
|
174
194
|
seq,
|
|
175
195
|
delivery_id: envelope.deliveryId,
|
|
196
|
+
...(activeResources ? { active_resources: activeResources } : {}),
|
|
176
197
|
payload: {
|
|
177
198
|
schema: 'clawclaw.channel-events.v1',
|
|
178
199
|
...envelope.batch,
|
|
@@ -232,6 +253,7 @@ export class DesktopEventSocketSink implements MailboxEventBatchSink {
|
|
|
232
253
|
this.socket = undefined;
|
|
233
254
|
this.connected = false;
|
|
234
255
|
this.connectionId = undefined;
|
|
256
|
+
this.deliveryResources = undefined;
|
|
235
257
|
if (!socket || socket.destroyed) return;
|
|
236
258
|
await new Promise<void>((resolve) => {
|
|
237
259
|
socket.once('close', () => resolve());
|
|
@@ -253,12 +275,14 @@ export class DesktopEventSocketSink implements MailboxEventBatchSink {
|
|
|
253
275
|
if (this.socket !== socket || this.stopped) return;
|
|
254
276
|
this.connected = true;
|
|
255
277
|
this.reconnectAttempt = 0;
|
|
278
|
+
const activeResources = this.readActiveResources();
|
|
256
279
|
socket.write(`${JSON.stringify({
|
|
257
280
|
schema: DESKTOP_EVENT_PROTOCOL_SCHEMA,
|
|
258
281
|
type: 'hello',
|
|
259
282
|
connection_id: connectionId,
|
|
260
283
|
token: this.token,
|
|
261
284
|
pid: process.pid,
|
|
285
|
+
...(activeResources ? { active_resources: activeResources } : {}),
|
|
262
286
|
})}\n`);
|
|
263
287
|
this.diagnostic?.('runtime.desktop_event_socket.connected', {
|
|
264
288
|
connection_id: connectionId,
|
|
@@ -321,6 +345,9 @@ export class DesktopEventSocketSink implements MailboxEventBatchSink {
|
|
|
321
345
|
this.pendingAck = undefined;
|
|
322
346
|
clearTimeout(pending.timer);
|
|
323
347
|
pending.signal.removeEventListener('abort', pending.onAbort);
|
|
348
|
+
if (this.deliveryResources?.deliveryId === pending.deliveryId) {
|
|
349
|
+
this.deliveryResources = undefined;
|
|
350
|
+
}
|
|
324
351
|
pending.resolve({
|
|
325
352
|
acceptedAt: new Date(this.now()).toISOString(),
|
|
326
353
|
...(receiptId ? { receiptId } : {}),
|
|
@@ -369,4 +396,16 @@ export class DesktopEventSocketSink implements MailboxEventBatchSink {
|
|
|
369
396
|
signal.reason instanceof Error ? signal.reason.message : 'Desktop event delivery aborted.',
|
|
370
397
|
);
|
|
371
398
|
}
|
|
399
|
+
|
|
400
|
+
private readActiveResources(): DesktopActiveResources | undefined {
|
|
401
|
+
if (!this.activeResources) return undefined;
|
|
402
|
+
return structuredClone(this.activeResources());
|
|
403
|
+
}
|
|
404
|
+
|
|
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;
|
|
410
|
+
}
|
|
372
411
|
}
|
|
@@ -2,8 +2,12 @@ export {
|
|
|
2
2
|
ClawclawPerception,
|
|
3
3
|
ClawclawParallelPerception,
|
|
4
4
|
PERCEPTION_PLUGIN_API_VERSION,
|
|
5
|
+
hasValidClawclawResourceLocalizations,
|
|
6
|
+
resolveClawclawResourceMetadata,
|
|
5
7
|
} from '../../../../sdk/perception-plugin/index.js';
|
|
6
8
|
export type {
|
|
9
|
+
ClawclawResolvedResourceMetadata,
|
|
10
|
+
ClawclawResourceLocalizations,
|
|
7
11
|
ClawclawPerceptionClass,
|
|
8
12
|
ClawclawPerceptionManifest,
|
|
9
13
|
PerceptionApi,
|
|
@@ -57,6 +57,12 @@ export class CoMovementModule extends ClawclawParallelPerception<CoMovementAnaly
|
|
|
57
57
|
id: 'visual.co_movement',
|
|
58
58
|
name: 'Co-movement',
|
|
59
59
|
description: 'Reports visible player pairs moving close together in the same direction.',
|
|
60
|
+
localizations: {
|
|
61
|
+
'zh-CN': {
|
|
62
|
+
name: '共同移动',
|
|
63
|
+
description: '感知同时可见的玩家对近距离同方向稳定移动。',
|
|
64
|
+
},
|
|
65
|
+
},
|
|
60
66
|
subjectScope: 'visible_pairs',
|
|
61
67
|
produces: [
|
|
62
68
|
'visual.players_moving_together',
|
|
@@ -64,6 +64,12 @@ export class FollowModule extends ClawclawParallelPerception<FollowAnalysis> {
|
|
|
64
64
|
id: 'visual.follow',
|
|
65
65
|
name: 'Following',
|
|
66
66
|
description: 'Reports a stable front/back following relation between visible players.',
|
|
67
|
+
localizations: {
|
|
68
|
+
'zh-CN': {
|
|
69
|
+
name: '跟随关系',
|
|
70
|
+
description: '感知同时可见玩家之间稳定的前后跟随关系。',
|
|
71
|
+
},
|
|
72
|
+
},
|
|
67
73
|
subjectScope: 'visible_pairs',
|
|
68
74
|
produces: ['visual.following', 'visual.following_ended'],
|
|
69
75
|
execution: 'parallel_analysis',
|
|
@@ -80,6 +80,12 @@ export class MotionModule extends ClawclawParallelPerception<MotionAnalysis> {
|
|
|
80
80
|
id: 'visual.motion',
|
|
81
81
|
name: 'Player movement',
|
|
82
82
|
description: 'Reports movement slices and meaningful direction changes for self and visible players.',
|
|
83
|
+
localizations: {
|
|
84
|
+
'zh-CN': {
|
|
85
|
+
name: '玩家移动',
|
|
86
|
+
description: '感知自己和可见玩家的连续移动片段及显著方向变化。',
|
|
87
|
+
},
|
|
88
|
+
},
|
|
83
89
|
subjectScope: 'self_and_others',
|
|
84
90
|
produces: ['visual.player_moved', 'visual.player_motion_changed'],
|
|
85
91
|
execution: 'parallel_analysis',
|
|
@@ -60,6 +60,12 @@ export class RouteModule extends ClawclawParallelPerception<RouteAnalysis> {
|
|
|
60
60
|
id: 'visual.route',
|
|
61
61
|
name: 'Route shape',
|
|
62
62
|
description: 'Reports turns, reversals, and repeated local direction changes.',
|
|
63
|
+
localizations: {
|
|
64
|
+
'zh-CN': {
|
|
65
|
+
name: '路线形态',
|
|
66
|
+
description: '感知转弯、折返和连续多次局部方向变化。',
|
|
67
|
+
},
|
|
68
|
+
},
|
|
63
69
|
subjectScope: 'self_and_others',
|
|
64
70
|
produces: [
|
|
65
71
|
'visual.player_turned',
|
|
@@ -28,6 +28,12 @@ export class SpatialModule extends ClawclawParallelPerception<SpatialAnalysis> {
|
|
|
28
28
|
id: 'visual.spatial',
|
|
29
29
|
name: 'Spatial changes',
|
|
30
30
|
description: 'Reports verified room transitions and movement between coarse room regions.',
|
|
31
|
+
localizations: {
|
|
32
|
+
'zh-CN': {
|
|
33
|
+
name: '空间变化',
|
|
34
|
+
description: '感知已验证的房间切换和房间内粗粒度方位变化。',
|
|
35
|
+
},
|
|
36
|
+
},
|
|
31
37
|
subjectScope: 'self_and_others',
|
|
32
38
|
produces: ['visual.player_area_changed', 'visual.player_position_changed'],
|
|
33
39
|
execution: 'parallel_analysis',
|
|
@@ -46,6 +46,12 @@ export class StopModule extends ClawclawParallelPerception<StopAnalysis> {
|
|
|
46
46
|
id: 'visual.stop',
|
|
47
47
|
name: 'Player stops',
|
|
48
48
|
description: 'Reports stable stops and confirmed movement resumption.',
|
|
49
|
+
localizations: {
|
|
50
|
+
'zh-CN': {
|
|
51
|
+
name: '玩家停留',
|
|
52
|
+
description: '感知自己和可见玩家的稳定停留及确认恢复移动。',
|
|
53
|
+
},
|
|
54
|
+
},
|
|
49
55
|
subjectScope: 'self_and_others',
|
|
50
56
|
produces: [
|
|
51
57
|
'visual.player_stopped',
|
|
@@ -25,6 +25,12 @@ export class VisibilityModule extends ClawclawParallelPerception<VisibilityAnaly
|
|
|
25
25
|
id: 'visual.visibility',
|
|
26
26
|
name: 'Visibility changes',
|
|
27
27
|
description: 'Reports other players entering, leaving, or quickly reappearing in view.',
|
|
28
|
+
localizations: {
|
|
29
|
+
'zh-CN': {
|
|
30
|
+
name: '视野变化',
|
|
31
|
+
description: '感知其他玩家进入、离开或短暂离开后重新出现在视野中。',
|
|
32
|
+
},
|
|
33
|
+
},
|
|
28
34
|
subjectScope: 'others',
|
|
29
35
|
produces: [
|
|
30
36
|
'visual.player_entered',
|
|
@@ -344,6 +344,17 @@ describe('ClawClaw Perception plugin', () => {
|
|
|
344
344
|
expect.objectContaining({ id: 'visual.motion', subjectScope: 'self_and_others' }),
|
|
345
345
|
expect.objectContaining({ id: 'visual.follow', subjectScope: 'visible_pairs' }),
|
|
346
346
|
]));
|
|
347
|
+
expect(plugin.localizedModuleDescriptors('zh-CN')).toEqual(expect.arrayContaining([
|
|
348
|
+
{
|
|
349
|
+
id: 'visual.visibility',
|
|
350
|
+
name: '视野变化',
|
|
351
|
+
description: '感知其他玩家进入、离开或短暂离开后重新出现在视野中。',
|
|
352
|
+
},
|
|
353
|
+
expect.objectContaining({ id: 'visual.motion', name: '玩家移动' }),
|
|
354
|
+
]));
|
|
355
|
+
expect(plugin.localizedModuleDescriptors('en-US')).toEqual(expect.arrayContaining([
|
|
356
|
+
expect.objectContaining({ id: 'visual.visibility', name: 'Visibility changes' }),
|
|
357
|
+
]));
|
|
347
358
|
});
|
|
348
359
|
|
|
349
360
|
it('starts, analyzes, commits, and stops all seven official Worker modules together', async () => {
|
|
@@ -13,6 +13,9 @@ import { isClawclawRuntimeState } from '../../runtime-state.js';
|
|
|
13
13
|
import {
|
|
14
14
|
PERCEPTION_PLUGIN_API_VERSION,
|
|
15
15
|
ClawclawPerception,
|
|
16
|
+
hasValidClawclawResourceLocalizations,
|
|
17
|
+
resolveClawclawResourceMetadata,
|
|
18
|
+
type ClawclawResolvedResourceMetadata,
|
|
16
19
|
type ClawclawPerceptionClass,
|
|
17
20
|
type ClawclawPerceptionManifest,
|
|
18
21
|
type PerceptionApi,
|
|
@@ -205,6 +208,7 @@ export function validatePerceptionManifest(
|
|
|
205
208
|
|| !/^[a-z0-9][a-z0-9._-]*$/.test(manifest.id)
|
|
206
209
|
|| !nonEmpty(manifest.name)
|
|
207
210
|
|| !nonEmpty(manifest.description)
|
|
211
|
+
|| !hasValidClawclawResourceLocalizations(manifest.localizations)
|
|
208
212
|
|| !['others', 'self_and_others', 'visible_pairs', 'corpses'].includes(manifest.subjectScope)
|
|
209
213
|
|| !Array.isArray(manifest.produces)
|
|
210
214
|
|| manifest.produces.length === 0
|
|
@@ -772,6 +776,10 @@ export class ClawclawPerceptionPlugin implements RuntimeEpochPlugin<Record<strin
|
|
|
772
776
|
}));
|
|
773
777
|
}
|
|
774
778
|
|
|
779
|
+
localizedModuleDescriptors(locale: string): ClawclawResolvedResourceMetadata[] {
|
|
780
|
+
return this.modules.map(({ manifest }) => resolveClawclawResourceMetadata(manifest, locale));
|
|
781
|
+
}
|
|
782
|
+
|
|
775
783
|
moduleStateSnapshot(): Record<string, unknown> {
|
|
776
784
|
return Object.fromEntries(this.modules.map(({ manifest, runner }) => [
|
|
777
785
|
manifest.id,
|
|
@@ -37,6 +37,12 @@ describe('ClawClaw perception source discovery', () => {
|
|
|
37
37
|
id: 'visual.custom_linger',
|
|
38
38
|
name: 'Custom linger',
|
|
39
39
|
description: 'Reports a long stay.',
|
|
40
|
+
localizations: {
|
|
41
|
+
'zh-CN': {
|
|
42
|
+
name: '长时间停留',
|
|
43
|
+
description: '感知玩家长时间停留。',
|
|
44
|
+
},
|
|
45
|
+
},
|
|
40
46
|
subjectScope: 'others',
|
|
41
47
|
produces: ['visual.custom_linger'],
|
|
42
48
|
} as const;
|
|
@@ -51,6 +57,12 @@ describe('ClawClaw perception source discovery', () => {
|
|
|
51
57
|
id: 'visual.custom_linger',
|
|
52
58
|
name: 'Custom linger',
|
|
53
59
|
description: 'Reports a long stay.',
|
|
60
|
+
localizations: {
|
|
61
|
+
'zh-CN': {
|
|
62
|
+
name: '长时间停留',
|
|
63
|
+
description: '感知玩家长时间停留。',
|
|
64
|
+
},
|
|
65
|
+
},
|
|
54
66
|
subjectScope: 'others',
|
|
55
67
|
produces: ['visual.custom_linger'],
|
|
56
68
|
},
|
|
@@ -15,7 +15,10 @@ import {
|
|
|
15
15
|
ensureUserDataLayout,
|
|
16
16
|
getUserDataPerceptionsDir,
|
|
17
17
|
} from '../../../../lib/user-data.js';
|
|
18
|
-
import type {
|
|
18
|
+
import type {
|
|
19
|
+
ClawclawPerceptionManifest,
|
|
20
|
+
ClawclawResourceLocalizations,
|
|
21
|
+
} from './contracts.js';
|
|
19
22
|
|
|
20
23
|
export const MAX_PERCEPTION_FILES = 512;
|
|
21
24
|
const MAX_PERCEPTION_SOURCE_BYTES = 2 * 1024 * 1024;
|
|
@@ -137,6 +140,36 @@ function literalStringArray(source: string, property: string): string[] | null {
|
|
|
137
140
|
return residue.length === 0 ? values : null;
|
|
138
141
|
}
|
|
139
142
|
|
|
143
|
+
function literalLocalizations(
|
|
144
|
+
source: string,
|
|
145
|
+
): ClawclawResourceLocalizations | null | undefined {
|
|
146
|
+
const property = /\blocalizations\s*:\s*\{/m.exec(source);
|
|
147
|
+
if (!property) return undefined;
|
|
148
|
+
const open = property.index + property[0].lastIndexOf('{');
|
|
149
|
+
const block = balancedBlock(source, open, '{', '}');
|
|
150
|
+
if (!block) return null;
|
|
151
|
+
const values: Record<string, { name: string; description: string }> = {};
|
|
152
|
+
const entry = /(["'\x60])((?:\\.|(?!\1)[\s\S])*)\1\s*:\s*\{/g;
|
|
153
|
+
let cursor = 1;
|
|
154
|
+
let match: RegExpExecArray | null;
|
|
155
|
+
while ((match = entry.exec(block)) !== null) {
|
|
156
|
+
if (block.slice(cursor, match.index).replace(/[\s,]/g, '')) return null;
|
|
157
|
+
if (match[1] === '`' && match[2].includes('${')) return null;
|
|
158
|
+
const locale = decodeString(match[2])?.trim();
|
|
159
|
+
const entryOpen = match.index + match[0].lastIndexOf('{');
|
|
160
|
+
const entryBlock = balancedBlock(block, entryOpen, '{', '}');
|
|
161
|
+
if (!locale || !entryBlock || values[locale]) return null;
|
|
162
|
+
const name = literalProperty(entryBlock, 'name')?.trim();
|
|
163
|
+
const description = literalProperty(entryBlock, 'description')?.trim();
|
|
164
|
+
if (!name || !description) return null;
|
|
165
|
+
values[locale] = { name, description };
|
|
166
|
+
cursor = entryOpen + entryBlock.length;
|
|
167
|
+
entry.lastIndex = cursor;
|
|
168
|
+
}
|
|
169
|
+
if (block.slice(cursor, -1).replace(/[\s,]/g, '')) return null;
|
|
170
|
+
return values;
|
|
171
|
+
}
|
|
172
|
+
|
|
140
173
|
function parseSource(sourcePath: string, sourceRoot: string): ResolvedClawclawPerceptionSource | null {
|
|
141
174
|
let source: string;
|
|
142
175
|
try {
|
|
@@ -163,6 +196,7 @@ function parseSource(sourcePath: string, sourceRoot: string): ResolvedClawclawPe
|
|
|
163
196
|
const produces = literalStringArray(manifestBlock, 'produces');
|
|
164
197
|
const execution = literalProperty(manifestBlock, 'execution')?.trim();
|
|
165
198
|
const boundaryBaseline = literalProperty(manifestBlock, 'boundaryBaseline')?.trim();
|
|
199
|
+
const localizations = literalLocalizations(manifestBlock);
|
|
166
200
|
const parallelClass = classMatch[1] === 'ClawclawParallelPerception';
|
|
167
201
|
if (
|
|
168
202
|
!id
|
|
@@ -180,12 +214,14 @@ function parseSource(sourcePath: string, sourceRoot: string): ResolvedClawclawPe
|
|
|
180
214
|
&& (execution !== 'parallel_analysis' || boundaryBaseline !== 'current_only')
|
|
181
215
|
)
|
|
182
216
|
|| parallelClass !== (execution === 'parallel_analysis')
|
|
217
|
+
|| localizations === null
|
|
183
218
|
) return null;
|
|
184
219
|
|
|
185
220
|
const manifest: ClawclawPerceptionManifest = {
|
|
186
221
|
id,
|
|
187
222
|
name,
|
|
188
223
|
description,
|
|
224
|
+
...(localizations === undefined ? {} : { localizations }),
|
|
189
225
|
subjectScope: subjectScope as ClawclawPerceptionManifest['subjectScope'],
|
|
190
226
|
produces,
|
|
191
227
|
...(execution ? { execution: 'parallel_analysis' as const } : {}),
|
|
@@ -16,6 +16,7 @@ export type ClawclawRoomTransportStopReason =
|
|
|
16
16
|
| 'game_started'
|
|
17
17
|
| 'self_left'
|
|
18
18
|
| 'room_destroyed'
|
|
19
|
+
| 'maintenance'
|
|
19
20
|
| 'reconcile'
|
|
20
21
|
| 'replaced'
|
|
21
22
|
| 'fatal'
|
|
@@ -31,7 +32,7 @@ export interface ClawclawRoomCloseInfo {
|
|
|
31
32
|
reason: string;
|
|
32
33
|
}
|
|
33
34
|
|
|
34
|
-
export type ClawclawRoomCloseDecision = 'retry' | 'room_destroyed' | 'reconcile' | 'replaced' | 'fatal';
|
|
35
|
+
export type ClawclawRoomCloseDecision = 'retry' | 'room_destroyed' | 'maintenance' | 'reconcile' | 'replaced' | 'fatal';
|
|
35
36
|
|
|
36
37
|
export interface ClawclawRoomTransportFrameMeta {
|
|
37
38
|
connectionId: string;
|