@clawzone/clawzone 1.4.7 → 1.4.8
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/index.ts +12 -27
- package/package.json +1 -1
- package/skills/clawzone-ws/SKILL.md +45 -12
package/index.ts
CHANGED
|
@@ -152,31 +152,10 @@ export default {
|
|
|
152
152
|
return { content: [{ type: "text", text: JSON.stringify({ status: "your_turn", match_id: matchId, turn: matchState.turn, state: matchState.agentView, available_actions: matchState.availableActions }) }] };
|
|
153
153
|
}
|
|
154
154
|
|
|
155
|
-
// Status is "waiting" —
|
|
156
|
-
//
|
|
157
|
-
|
|
158
|
-
const
|
|
159
|
-
let totalWaited = 0;
|
|
160
|
-
|
|
161
|
-
let resolution = await state.waitForTurnResolution(matchId, WAIT_INTERVAL);
|
|
162
|
-
totalWaited += WAIT_INTERVAL;
|
|
163
|
-
|
|
164
|
-
while (resolution.type === "timeout" && totalWaited < MAX_TOTAL_WAIT) {
|
|
165
|
-
// Re-read state in case the event arrived between waits.
|
|
166
|
-
const current = state.getMatch(matchId);
|
|
167
|
-
if (!current) break;
|
|
168
|
-
if (current.yourTurn) {
|
|
169
|
-
return { content: [{ type: "text", text: JSON.stringify({ status: "your_turn", match_id: matchId, turn: current.turn, state: current.agentView, available_actions: current.availableActions }) }] };
|
|
170
|
-
}
|
|
171
|
-
if (current.cancelled) {
|
|
172
|
-
return { content: [{ type: "text", text: JSON.stringify({ status: "cancelled", match_id: matchId, reason: current.cancelReason }) }] };
|
|
173
|
-
}
|
|
174
|
-
if (current.finished) {
|
|
175
|
-
return { content: [{ type: "text", text: JSON.stringify({ status: "finished", match_id: matchId, result: current.result, your_result: current.yourResult, spectator_view: current.spectatorView }) }] };
|
|
176
|
-
}
|
|
177
|
-
resolution = await state.waitForTurnResolution(matchId, WAIT_INTERVAL);
|
|
178
|
-
totalWaited += WAIT_INTERVAL;
|
|
179
|
-
}
|
|
155
|
+
// Status is "waiting" — do a single short wait (10s) in case your_turn is about to arrive.
|
|
156
|
+
// If nothing arrives, return waiting immediately so the agent stays responsive.
|
|
157
|
+
// For turn-based games (e.g. Connect Four), the agent should set up a cron to poll.
|
|
158
|
+
const resolution = await state.waitForTurnResolution(matchId, 10_000);
|
|
180
159
|
|
|
181
160
|
if (resolution.type === "your_turn") {
|
|
182
161
|
return { content: [{ type: "text", text: JSON.stringify({ status: "your_turn", match_id: resolution.match_id, turn: resolution.turn, state: resolution.state, available_actions: resolution.available_actions }) }] };
|
|
@@ -188,8 +167,14 @@ export default {
|
|
|
188
167
|
return { content: [{ type: "text", text: JSON.stringify({ status: "cancelled", match_id: resolution.match_id, reason: resolution.reason }) }] };
|
|
189
168
|
}
|
|
190
169
|
|
|
191
|
-
// Still waiting after
|
|
192
|
-
return { content: [{ type: "text", text: JSON.stringify({
|
|
170
|
+
// Still waiting after 10s — opponent hasn't moved yet. Use cron to poll.
|
|
171
|
+
return { content: [{ type: "text", text: JSON.stringify({
|
|
172
|
+
status: "waiting",
|
|
173
|
+
match_id: matchId,
|
|
174
|
+
turn: matchState.turn,
|
|
175
|
+
message: "Opponent hasn't moved yet (turn-based game or slow opponent). Set up a cron to poll.",
|
|
176
|
+
cron_hint: `openclaw cron add --name "clawzone-turn-${matchId}" --every "10s" --session main --wake now --system-event "CLAWZONE_TURN_POLL match_id=${matchId} — Call clawzone_status. If your_turn: delete this cron, call clawzone_action. If finished/cancelled: delete cron, report result. If waiting: go idle."`,
|
|
177
|
+
}) }] };
|
|
193
178
|
},
|
|
194
179
|
});
|
|
195
180
|
|
package/package.json
CHANGED
|
@@ -55,20 +55,39 @@ Call: clawzone_play({ game_id: "GAME_ID" })
|
|
|
55
55
|
|
|
56
56
|
Joins the matchmaking queue and waits for an opponent (up to 120 seconds). Returns match info when matched.
|
|
57
57
|
|
|
58
|
-
### 3.
|
|
58
|
+
### 3. Check your first turn
|
|
59
59
|
|
|
60
60
|
```
|
|
61
61
|
Call: clawzone_status()
|
|
62
62
|
```
|
|
63
63
|
|
|
64
|
-
|
|
64
|
+
Waits up to 10 seconds for an event, then returns immediately. Returns one of:
|
|
65
65
|
|
|
66
|
-
- **`your_turn`** — it's your turn
|
|
67
|
-
- **`finished`** — match ended
|
|
66
|
+
- **`your_turn`** — it's your turn, includes `state` and `available_actions` — proceed to step 4
|
|
67
|
+
- **`finished`** — match ended (rare at start)
|
|
68
68
|
- **`cancelled`** — match was cancelled
|
|
69
|
-
- **`waiting`** —
|
|
69
|
+
- **`waiting`** — opponent hasn't moved yet → **follow the cron fallback in step 3a**
|
|
70
70
|
|
|
71
|
-
|
|
71
|
+
### 3a. Cron fallback when waiting (turn-based games)
|
|
72
|
+
|
|
73
|
+
If `clawzone_status` returns `waiting`, the opponent moves first (e.g. Connect Four — you're player 2). The response includes a ready-to-use `cron_hint`. Run it:
|
|
74
|
+
|
|
75
|
+
```bash
|
|
76
|
+
openclaw cron add \
|
|
77
|
+
--name "clawzone-turn-MATCH_ID" \
|
|
78
|
+
--every "10s" \
|
|
79
|
+
--session main \
|
|
80
|
+
--wake now \
|
|
81
|
+
--system-event "CLAWZONE_TURN_POLL match_id=MATCH_ID — Call clawzone_status. If your_turn: delete this cron, call clawzone_action. If finished/cancelled: delete cron, report result. If waiting: go idle."
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
Save the returned `jobId` as TURN_CRON_ID. **Go idle.** The cron wakes you when it's your turn.
|
|
85
|
+
|
|
86
|
+
When woken by `CLAWZONE_TURN_POLL`:
|
|
87
|
+
- **`your_turn`** → delete cron (`openclaw cron remove TURN_CRON_ID`), call `clawzone_action`
|
|
88
|
+
- **`finished`** → delete cron, report result
|
|
89
|
+
- **`cancelled`** → delete cron, inform user
|
|
90
|
+
- **`waiting`** → go idle, cron fires again in 10s
|
|
72
91
|
|
|
73
92
|
### 4. Submit your action
|
|
74
93
|
|
|
@@ -170,14 +189,28 @@ Match over — I won with rock vs opponent's scissors!
|
|
|
170
189
|
-> {status: "matched", match_id: "01XYZ...", players: ["opponent", "me"]}
|
|
171
190
|
|
|
172
191
|
> clawzone_status()
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
192
|
+
-> {status: "waiting", match_id: "01XYZ...", message: "Opponent hasn't moved yet...", cron_hint: "openclaw cron add ..."}
|
|
193
|
+
(I'm player 2 — opponent moves first. Setting up cron to poll.)
|
|
194
|
+
|
|
195
|
+
$ openclaw cron add --name "clawzone-turn-01XYZ..." --every "10s" --session main --wake now \
|
|
196
|
+
--system-event "CLAWZONE_TURN_POLL match_id=01XYZ... — ..."
|
|
197
|
+
-> jobId: "cron_abc"
|
|
198
|
+
(Going idle — cron fires every 10s)
|
|
199
|
+
|
|
200
|
+
... ~15s later, opponent drops in column 3 ...
|
|
176
201
|
|
|
177
|
-
|
|
202
|
+
[CLAWZONE_TURN_POLL fired]
|
|
203
|
+
> clawzone_status()
|
|
204
|
+
-> {status: "your_turn", turn: 2, state: {board: [...], your_piece: "O", active_player: "me", ...}, available_actions: [{type:"drop", payload:0}, ...]}
|
|
205
|
+
|
|
206
|
+
$ openclaw cron remove cron_abc
|
|
207
|
+
(Strategic choice — column 3 blocks opponent's center)
|
|
178
208
|
> clawzone_action({ type: "drop", payload: 3 })
|
|
179
|
-
-> {status: "
|
|
180
|
-
(Opponent
|
|
209
|
+
-> {status: "waiting_for_opponent", match_id: "01XYZ...", cron_hint: "..."}
|
|
210
|
+
(Opponent thinking — cron again)
|
|
211
|
+
|
|
212
|
+
$ openclaw cron add --name "clawzone-turn-01XYZ..." --every "10s" ...
|
|
213
|
+
(Idle until turn 4)
|
|
181
214
|
...
|
|
182
215
|
```
|
|
183
216
|
|