@myclaw163/clawclaw-cli 0.6.96 → 0.6.101

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 (37) hide show
  1. package/bin/clawclaw-cli.mjs +3 -3
  2. package/package.json +1 -1
  3. package/skills/clawclaw/SKILL.md +26 -10
  4. package/skills/clawclaw/references/CLAUDE-CODE-MONITOR.md +1 -1
  5. package/skills/clawclaw/references/COMMANDS.md +17 -5
  6. package/skills/clawclaw/references/STREAM.md +15 -12
  7. package/src/commands/config.ts +30 -30
  8. package/src/commands/do.test.ts +27 -1
  9. package/src/commands/do.ts +61 -0
  10. package/src/commands/events.test.ts +21 -3
  11. package/src/commands/events.ts +8 -2
  12. package/src/commands/game-start-plan.test.ts +158 -0
  13. package/src/commands/game.ts +670 -64
  14. package/src/commands/history-player.test.ts +3 -0
  15. package/src/commands/setup/hermes.test.ts +96 -96
  16. package/src/commands/setup/hermes.ts +76 -76
  17. package/src/commands/setup/index.ts +13 -13
  18. package/src/commands/setup/openclaw.test.ts +124 -114
  19. package/src/commands/setup/openclaw.ts +162 -147
  20. package/src/commands/watch.test.ts +272 -0
  21. package/src/commands/watch.ts +185 -25
  22. package/src/lib/game-client.ts +34 -0
  23. package/src/lib/host-config-patcher.test.ts +130 -130
  24. package/src/lib/host-config-patcher.ts +151 -151
  25. package/src/lib/room.test.ts +74 -0
  26. package/src/lib/room.ts +129 -0
  27. package/src/lib/server-registry.test.ts +54 -0
  28. package/src/lib/server-registry.ts +35 -2
  29. package/src/perception/player-history-store.test.ts +92 -2
  30. package/src/perception/player-history-store.ts +68 -0
  31. package/src/pipeline/event-format.test.ts +61 -1
  32. package/src/pipeline/event-format.ts +88 -0
  33. package/src/pipeline/event-hints.ts +10 -1
  34. package/src/runtime/event-daemon.test.ts +43 -0
  35. package/src/runtime/event-daemon.ts +8 -4
  36. package/src/runtime/room-lobby-runtime.test.ts +95 -0
  37. package/src/runtime/room-lobby-runtime.ts +367 -0
@@ -2,8 +2,14 @@ import { describe, expect, it } from 'vitest';
2
2
  import {
3
3
  createGameCommand,
4
4
  gameStrategyIdentity,
5
+ leaveGameFailureFromResult,
6
+ lobbyWatchUrl,
5
7
  planGameStartAction,
8
+ planRoomEntryStreamGuard,
9
+ planRoomJoinAction,
10
+ roomStartFailureFromError,
6
11
  } from './game.js';
12
+ import { ApiError } from '../lib/http-transport.js';
7
13
 
8
14
  describe('planGameStartAction', () => {
9
15
  it('returns the running game start pid when a stream is already alive', () => {
@@ -42,6 +48,21 @@ describe('planGameStartAction', () => {
42
48
  })).toEqual({ kind: 'resume_allocated' });
43
49
  });
44
50
 
51
+ it('resumes an allocated room match with room return context', () => {
52
+ expect(planGameStartAction({
53
+ hasMatchState: false,
54
+ queueStatus: 'allocated',
55
+ queueMode: 'room',
56
+ })).toEqual({ kind: 'resume_room_allocated' });
57
+ });
58
+
59
+ it('resumes the room lobby stream from backend room state', () => {
60
+ expect(planGameStartAction({
61
+ hasMatchState: false,
62
+ queueStatus: 'in_room',
63
+ })).toEqual({ kind: 'resume_room' });
64
+ });
65
+
45
66
  it('resumes queue polling for queued and already_in_queue states without an owner runtime', () => {
46
67
  for (const queueStatus of ['queued', 'already_in_queue']) {
47
68
  expect(planGameStartAction({
@@ -84,6 +105,124 @@ describe('game strategy identity', () => {
84
105
 
85
106
  });
86
107
 
108
+ describe('planRoomJoinAction', () => {
109
+ it('resumes the current room when joining the same room', () => {
110
+ expect(planRoomJoinAction({
111
+ targetRoomCode: '123456',
112
+ queueStatus: 'in_room',
113
+ currentRoomCode: '123456',
114
+ })).toEqual({ kind: 'resume_current_room', roomCode: '123456' });
115
+ });
116
+
117
+ it('leaves the current room before joining a different room', () => {
118
+ expect(planRoomJoinAction({
119
+ targetRoomCode: '654321',
120
+ queueStatus: 'in_room',
121
+ currentRoomCode: '123456',
122
+ })).toEqual({ kind: 'leave_then_join', roomCode: '123456' });
123
+ });
124
+
125
+ it('joins directly when the current room code is unavailable', () => {
126
+ expect(planRoomJoinAction({
127
+ targetRoomCode: '654321',
128
+ queueStatus: 'in_room',
129
+ })).toEqual({ kind: 'join' });
130
+ });
131
+
132
+ it('joins directly when queue status is unavailable', () => {
133
+ expect(planRoomJoinAction({
134
+ targetRoomCode: '654321',
135
+ queueStatus: undefined,
136
+ })).toEqual({ kind: 'join' });
137
+ });
138
+
139
+ it('refuses to switch while a room match allocation is active', () => {
140
+ expect(planRoomJoinAction({
141
+ targetRoomCode: '654321',
142
+ queueStatus: 'allocated',
143
+ queueMode: 'room',
144
+ })).toEqual({ kind: 'refuse_room_allocated', roomCode: undefined });
145
+ });
146
+ });
147
+
148
+ describe('planRoomEntryStreamGuard', () => {
149
+ it('blocks switching rooms before any leave/join side effect when a stream is running', () => {
150
+ expect(planRoomEntryStreamGuard({
151
+ runningPid: 1234,
152
+ source: 'room_join',
153
+ })).toEqual({
154
+ kind: 'already_running',
155
+ pid: 1234,
156
+ nextStep: 'A room/game stream is already running (pid 1234). To enter another room, run ccl game quit first, wait for the current stream to exit, then start ccl game join-room <room_code> with Monitor.',
157
+ });
158
+ });
159
+
160
+ it('allows room entry with --force even when a stream is running', () => {
161
+ expect(planRoomEntryStreamGuard({
162
+ runningPid: 1234,
163
+ force: true,
164
+ source: 'room_join',
165
+ })).toEqual({ kind: 'continue' });
166
+ });
167
+ });
168
+
169
+ describe('leave game result classification', () => {
170
+ it('treats HTTP-success STILL_ALIVE responses as leave failures', () => {
171
+ expect(leaveGameFailureFromResult({
172
+ success: false,
173
+ error: {
174
+ code: 'STILL_ALIVE',
175
+ message: 'You can only leave when dead',
176
+ },
177
+ })).toEqual({
178
+ code: 'STILL_ALIVE',
179
+ message: 'You can only leave when dead',
180
+ still_alive: true,
181
+ });
182
+ });
183
+
184
+ it('does not classify successful leave responses as failures', () => {
185
+ expect(leaveGameFailureFromResult({
186
+ success: true,
187
+ data: { left: true },
188
+ })).toBeUndefined();
189
+ });
190
+ });
191
+
192
+ describe('room start error classification', () => {
193
+ it('formats NOT_ENOUGH_PLAYERS as structured output for agents', () => {
194
+ const err = new ApiError(400, JSON.stringify({
195
+ success: false,
196
+ error: {
197
+ code: 'NOT_ENOUGH_PLAYERS',
198
+ message: 'Need 10 players to start the room match.',
199
+ shortage: 9,
200
+ },
201
+ }), 'POST', '/api/v1/room/start');
202
+
203
+ expect(roomStartFailureFromError(err, {
204
+ success: true,
205
+ data: {
206
+ status: 'in_room',
207
+ room_code: '123456',
208
+ mode: 'room',
209
+ },
210
+ })).toEqual({
211
+ ok: false,
212
+ command: 'game start-room',
213
+ error: 'NOT_ENOUGH_PLAYERS',
214
+ message: 'Need 10 players to start the room match.',
215
+ shortage: 9,
216
+ queue_status: {
217
+ status: 'in_room',
218
+ room_code: '123456',
219
+ mode: 'room',
220
+ },
221
+ next_step: 'The room is not full yet. Tell the user how many players are missing; do not leave the room or start normal matchmaking.',
222
+ });
223
+ });
224
+ });
225
+
87
226
  describe('game command help', () => {
88
227
  it('hides the competition option from game start help', () => {
89
228
  const game = createGameCommand();
@@ -91,4 +230,23 @@ describe('game command help', () => {
91
230
 
92
231
  expect(start?.helpInformation()).not.toContain('--competition');
93
232
  });
233
+
234
+ it('exposes familiar room entry and manual start commands', () => {
235
+ const game = createGameCommand();
236
+
237
+ expect(game.commands.map((command) => command.name())).toEqual(expect.arrayContaining([
238
+ 'create-room',
239
+ 'join-room',
240
+ 'start-room',
241
+ ]));
242
+ });
243
+ });
244
+
245
+ describe('lobbyWatchUrl', () => {
246
+ it('preserves http for test server lobby links', () => {
247
+ expect(lobbyWatchUrl({
248
+ serverUrl: 'http://10.1.9.59:30900/claw',
249
+ apiKey: 'claw_test key',
250
+ })).toBe('http://10.1.9.59:30900/lobby?token=claw_test%20key');
251
+ });
94
252
  });