@myclaw163/clawclaw-cli 0.7.5 → 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 +154 -0
- package/docs/runtime/README.md +1 -0
- package/docs/runtime/official-perception-modules.md +346 -0
- package/package.json +2 -1
- package/src/commands/game/index.test.ts +167 -1
- package/src/commands/game/index.ts +125 -36
- package/src/lib/game-client.test.ts +15 -0
- package/src/lib/game-client.ts +4 -0
- package/src/lib/participation-status.ts +113 -0
- package/src/lib/service-status.test.ts +56 -0
- package/src/lib/service-status.ts +111 -0
- package/src/pipeline/event-format.test.ts +30 -0
- package/src/pipeline/event-format.ts +26 -1
- package/src/pipeline/event-hints.test.ts +18 -3
- package/src/pipeline/event-hints.ts +11 -0
- package/src/pipeline/game-sync-event-normalization.test.ts +58 -1
- package/src/pipeline/game-sync-event-normalization.ts +51 -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 +62 -3
- package/src/runtime/clawclaw/plugins/mailbox/agent-mailbox-coordinator.test.ts +189 -0
- package/src/runtime/clawclaw/plugins/mailbox/agent-mailbox-coordinator.ts +532 -0
- package/src/runtime/clawclaw/plugins/mailbox/desktop-event-push.integration.test.ts +363 -0
- package/src/runtime/clawclaw/plugins/mailbox/desktop-event-socket.test.ts +236 -0
- package/src/runtime/clawclaw/plugins/mailbox/desktop-event-socket.ts +411 -0
- package/src/runtime/clawclaw/plugins/mailbox/index.ts +3 -0
- package/src/runtime/clawclaw/plugins/mailbox/mailbox-agent-event-batch.test.ts +166 -0
- package/src/runtime/clawclaw/plugins/mailbox/mailbox-event-batch-delivery.test.ts +194 -0
- package/src/runtime/clawclaw/plugins/mailbox/mailbox-event-batch-delivery.ts +262 -0
- package/src/runtime/clawclaw/plugins/mailbox/mailbox-plugin.ts +28 -0
- package/src/runtime/clawclaw/plugins/mailbox/mailbox-service.test.ts +49 -0
- package/src/runtime/clawclaw/plugins/mailbox/mailbox-service.ts +77 -259
- 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/runtime-plugins.test.ts +5 -0
- package/src/runtime/clawclaw/plugins/source/room-transport.ts +2 -1
- package/src/runtime/clawclaw/plugins/source/source-plugin.test.ts +201 -1
- package/src/runtime/clawclaw/plugins/source/source-plugin.ts +113 -24
- 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
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
import { createClawclawEventCatalog } from '../../../clawclaw-event-catalog.js';
|
|
3
|
+
import {
|
|
4
|
+
EventIngress,
|
|
5
|
+
MemoryEventRepository,
|
|
6
|
+
type CanonicalEvent,
|
|
7
|
+
} from '../../../framework/events/index.js';
|
|
8
|
+
import type { RuntimeReadyView } from '../../../framework/runtime.js';
|
|
9
|
+
import {
|
|
10
|
+
AGENT_MAILBOX_COALESCE_MS,
|
|
11
|
+
AgentMailboxCoordinator,
|
|
12
|
+
} from './agent-mailbox-coordinator.js';
|
|
13
|
+
|
|
14
|
+
const START_MS = Date.parse('2026-08-04T00:00:00.000Z');
|
|
15
|
+
|
|
16
|
+
function readyView(epochSeq: number, eventWatermark: number): RuntimeReadyView {
|
|
17
|
+
const scope = {
|
|
18
|
+
adapterId: 'clawclaw',
|
|
19
|
+
accountId: 'account-1',
|
|
20
|
+
sessionId: 'session-1',
|
|
21
|
+
segmentId: 'segment-1',
|
|
22
|
+
segmentSeq: 1,
|
|
23
|
+
};
|
|
24
|
+
return {
|
|
25
|
+
scope,
|
|
26
|
+
state: {
|
|
27
|
+
state: { phase: 'wandering', tick: epochSeq },
|
|
28
|
+
stateStatus: {
|
|
29
|
+
status: 'fresh',
|
|
30
|
+
semantics: 'latest_received',
|
|
31
|
+
source: 'owner_memory',
|
|
32
|
+
scope,
|
|
33
|
+
connectionId: 'connection-1',
|
|
34
|
+
connectionState: 'connected',
|
|
35
|
+
receivedAtMs: START_MS,
|
|
36
|
+
ageMs: 0,
|
|
37
|
+
backendTick: epochSeq,
|
|
38
|
+
reason: null,
|
|
39
|
+
},
|
|
40
|
+
},
|
|
41
|
+
pluginStates: {},
|
|
42
|
+
pluginOutcomes: {},
|
|
43
|
+
events: [],
|
|
44
|
+
throughCommitSeq: eventWatermark,
|
|
45
|
+
frameSeq: epochSeq,
|
|
46
|
+
eventWatermark,
|
|
47
|
+
epochSeq,
|
|
48
|
+
hasMore: false,
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function fixture() {
|
|
53
|
+
const repository = new MemoryEventRepository();
|
|
54
|
+
repository.saveSession({
|
|
55
|
+
sessionId: 'session-1',
|
|
56
|
+
adapterId: 'clawclaw',
|
|
57
|
+
accountId: 'account-1',
|
|
58
|
+
status: 'open',
|
|
59
|
+
isCurrent: true,
|
|
60
|
+
openedAt: new Date(START_MS).toISOString(),
|
|
61
|
+
});
|
|
62
|
+
repository.saveSegment({
|
|
63
|
+
segmentId: 'segment-1',
|
|
64
|
+
sessionId: 'session-1',
|
|
65
|
+
sequence: 1,
|
|
66
|
+
kind: 'game',
|
|
67
|
+
status: 'open',
|
|
68
|
+
isCurrent: true,
|
|
69
|
+
openedAt: new Date(START_MS).toISOString(),
|
|
70
|
+
});
|
|
71
|
+
const ingress = new EventIngress(repository, createClawclawEventCatalog());
|
|
72
|
+
let nowMs = START_MS;
|
|
73
|
+
let ready = readyView(1, 0);
|
|
74
|
+
const coordinator = new AgentMailboxCoordinator({
|
|
75
|
+
repository,
|
|
76
|
+
readyView: () => structuredClone(ready),
|
|
77
|
+
presentEvent: (event) => ({
|
|
78
|
+
type: event.type,
|
|
79
|
+
...(typeof event.payload.text === 'string' ? { text: event.payload.text } : {}),
|
|
80
|
+
}),
|
|
81
|
+
compactState: (state) => state
|
|
82
|
+
? { phase: state.phase, tick: state.tick }
|
|
83
|
+
: null,
|
|
84
|
+
now: () => nowMs,
|
|
85
|
+
});
|
|
86
|
+
return {
|
|
87
|
+
repository,
|
|
88
|
+
ingress,
|
|
89
|
+
coordinator,
|
|
90
|
+
advance: (milliseconds: number) => { nowMs += milliseconds; },
|
|
91
|
+
setReady: (epochSeq: number, watermark: number) => {
|
|
92
|
+
ready = readyView(epochSeq, watermark);
|
|
93
|
+
},
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
async function publish(
|
|
98
|
+
ingress: EventIngress,
|
|
99
|
+
eventId: string,
|
|
100
|
+
type: string,
|
|
101
|
+
epochSeq: number,
|
|
102
|
+
payload: Record<string, unknown> = {},
|
|
103
|
+
): Promise<CanonicalEvent> {
|
|
104
|
+
return (await ingress.publish({
|
|
105
|
+
eventId,
|
|
106
|
+
epochSeq,
|
|
107
|
+
type,
|
|
108
|
+
producer: 'backend_push',
|
|
109
|
+
sessionId: 'session-1',
|
|
110
|
+
segmentId: 'segment-1',
|
|
111
|
+
payload,
|
|
112
|
+
source: { sourceId: 'game-ws', eventId: `remote:${eventId}` },
|
|
113
|
+
})).event;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
describe('AgentMailboxCoordinator', () => {
|
|
117
|
+
it('uses one fixed coalescing window without extending it for later Events', async () => {
|
|
118
|
+
const { ingress, coordinator, advance, setReady } = fixture();
|
|
119
|
+
const first = await publish(ingress, 'speech-1', 'speech', 1, { text: 'first' });
|
|
120
|
+
coordinator.observeEvents([first]);
|
|
121
|
+
setReady(1, first.commitSeq);
|
|
122
|
+
|
|
123
|
+
advance(100);
|
|
124
|
+
const second = await publish(ingress, 'speech-2', 'speech', 2, { text: 'second' });
|
|
125
|
+
coordinator.observeEvents([second]);
|
|
126
|
+
setReady(2, second.commitSeq);
|
|
127
|
+
|
|
128
|
+
advance(AGENT_MAILBOX_COALESCE_MS - 101);
|
|
129
|
+
const waiting = coordinator.prepareEvents();
|
|
130
|
+
expect(waiting.deliveryToken).toBeUndefined();
|
|
131
|
+
expect(waiting.nextAttemptAtMs).toBe(START_MS + AGENT_MAILBOX_COALESCE_MS);
|
|
132
|
+
|
|
133
|
+
advance(1);
|
|
134
|
+
const prepared = coordinator.prepareEvents();
|
|
135
|
+
expect(prepared.deliveryToken).toBeTypeOf('string');
|
|
136
|
+
expect(prepared.batch.events).toEqual([
|
|
137
|
+
{ type: 'speech', text: 'second' },
|
|
138
|
+
{ type: 'speech', text: 'first' },
|
|
139
|
+
]);
|
|
140
|
+
expect(coordinator.ack(prepared.deliveryToken!)).toBe(true);
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
it('excludes internal facts and preserves Agent payloads larger than 64 KiB', async () => {
|
|
144
|
+
const { repository, ingress, coordinator, advance, setReady } = fixture();
|
|
145
|
+
const internal = await publish(ingress, 'task-1', 'task_assigned', 1, {
|
|
146
|
+
task_name: 'wires',
|
|
147
|
+
});
|
|
148
|
+
const text = `BEGIN-${'x'.repeat(64 * 1024)}-END`;
|
|
149
|
+
const visible = await publish(ingress, 'speech-long', 'speech', 1, { text });
|
|
150
|
+
coordinator.observeEvents([internal, visible]);
|
|
151
|
+
setReady(1, visible.commitSeq);
|
|
152
|
+
advance(AGENT_MAILBOX_COALESCE_MS);
|
|
153
|
+
|
|
154
|
+
const prepared = coordinator.prepareEvents();
|
|
155
|
+
expect(prepared.batch.events).toEqual([{ type: 'speech', text }]);
|
|
156
|
+
expect(Buffer.byteLength(JSON.stringify(prepared.batch), 'utf8')).toBeGreaterThan(64 * 1024);
|
|
157
|
+
expect(repository.delivery(internal.eventId, 'local-agent')?.detailState)
|
|
158
|
+
.toBe('not_applicable');
|
|
159
|
+
expect(coordinator.ack(prepared.deliveryToken!)).toBe(true);
|
|
160
|
+
});
|
|
161
|
+
|
|
162
|
+
it('owns one details lease and only advances delivery after ACK', async () => {
|
|
163
|
+
const { repository, ingress, coordinator, advance, setReady } = fixture();
|
|
164
|
+
const event = await publish(ingress, 'speech-1', 'speech', 1, { text: 'lease me' });
|
|
165
|
+
coordinator.observeEvents([event]);
|
|
166
|
+
setReady(1, event.commitSeq);
|
|
167
|
+
advance(AGENT_MAILBOX_COALESCE_MS);
|
|
168
|
+
|
|
169
|
+
const first = coordinator.prepareEvents();
|
|
170
|
+
expect(first.deliveryToken).toBeTypeOf('string');
|
|
171
|
+
expect(coordinator.renew(first.deliveryToken!)).toBe(true);
|
|
172
|
+
expect(() => coordinator.prepareEvents()).toThrow('agent_mailbox_delivery_busy');
|
|
173
|
+
expect(repository.delivery(event.eventId, 'local-agent')?.detailState).toBe('pending');
|
|
174
|
+
expect(repository.acquireLease({
|
|
175
|
+
consumerId: 'local-agent',
|
|
176
|
+
channel: 'details',
|
|
177
|
+
ownerId: 'competing-adapter',
|
|
178
|
+
ttlMs: 1_000,
|
|
179
|
+
nowMs: START_MS + AGENT_MAILBOX_COALESCE_MS,
|
|
180
|
+
})).toBeNull();
|
|
181
|
+
|
|
182
|
+
expect(coordinator.release(first.deliveryToken!)).toBe(true);
|
|
183
|
+
expect(repository.delivery(event.eventId, 'local-agent')?.detailState).toBe('pending');
|
|
184
|
+
|
|
185
|
+
const retried = coordinator.prepareEvents();
|
|
186
|
+
expect(coordinator.ack(retried.deliveryToken!)).toBe(true);
|
|
187
|
+
expect(repository.delivery(event.eventId, 'local-agent')?.detailState).toBe('delivered');
|
|
188
|
+
});
|
|
189
|
+
});
|