@clawzone/clawzone 1.4.10 → 1.4.12

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 CHANGED
@@ -152,10 +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" — do a single short wait (10s) in case your_turn is about to arrive.
155
+ // Status is "waiting" — do a single short wait (5s) in case your_turn is about to arrive.
156
156
  // If nothing arrives, return waiting immediately so the agent stays responsive.
157
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);
158
+ const resolution = await state.waitForTurnResolution(matchId, 5_000);
159
159
 
160
160
  if (resolution.type === "your_turn") {
161
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 }) }] };
@@ -168,12 +168,14 @@ export default {
168
168
  }
169
169
 
170
170
  // Still waiting after 10s — opponent hasn't moved yet. Use cron to poll.
171
+ // Include match context so the agent can build an enriched cron summary.
171
172
  return { content: [{ type: "text", text: JSON.stringify({
172
173
  status: "waiting",
173
174
  match_id: matchId,
174
175
  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."`,
176
+ state: matchState.agentView,
177
+ message: "Opponent hasn't moved yet. Before creating the cron, write a brief summary of the match state and your strategy. Replace {AGENT_SUMMARY} in cron_hint with your summary.",
178
+ cron_hint: `openclaw cron add --name "clawzone-turn-${matchId}" --every "5s" --session main --wake now --system-event "CLAWZONE_TURN_POLL match_id=${matchId}\n\n## Match Context\n{AGENT_SUMMARY}\n\n## Instructions\nCall clawzone_status(). If your_turn: delete this cron (openclaw cron remove JOB_ID), play your move with clawzone_action. If finished/cancelled: delete cron, report result. If waiting: go idle."`,
177
179
  }) }] };
178
180
  },
179
181
  });
@@ -218,7 +220,7 @@ export default {
218
220
  }
219
221
 
220
222
  // Start waiting BEFORE sending so we don't miss fast responses
221
- const resolutionPromise = state.waitForTurnResolution(matchId, 30_000);
223
+ const resolutionPromise = state.waitForTurnResolution(matchId, 15_000);
222
224
 
223
225
  // Send via WebSocket for lowest latency
224
226
  if (wsClient?.isConnected()) {
@@ -250,10 +252,10 @@ export default {
250
252
  }
251
253
  }
252
254
 
253
- // Hybrid wait: try WebSocket for 60s (fast path), then bail to cron.
254
- // Two 30s intervals with a race-condition check between them.
255
- const WAIT_INTERVAL = 30_000;
256
- const MAX_TOTAL_WAIT = 60_000;
255
+ // Hybrid wait: try WebSocket for 30s (fast path), then bail to cron.
256
+ // Two 15s intervals with a race-condition check between them.
257
+ const WAIT_INTERVAL = 15_000;
258
+ const MAX_TOTAL_WAIT = 30_000;
257
259
  let totalWaited = 0;
258
260
 
259
261
  // First wait uses the promise we set up before sending
@@ -356,14 +358,19 @@ export default {
356
358
  };
357
359
  }
358
360
 
359
- // Opponent didn't respond within 60s — instruct agent to set up cron polling.
361
+ // Opponent didn't respond within 30s — instruct agent to set up cron polling.
362
+ // Return current state so the agent can write a summary for the cron.
363
+ const currentMatchForCron = state.getMatch(matchId);
360
364
  return {
361
365
  content: [{
362
366
  type: "text",
363
367
  text: JSON.stringify({
364
368
  status: "waiting_for_opponent",
365
369
  match_id: matchId,
366
- cron_hint: `openclaw cron add --name "clawzone-turn-${matchId}" --every "15s" --session main --wake now --system-event "CLAWZONE_TURN_POLL match_id=${matchId}"`,
370
+ turn: currentMatchForCron?.turn,
371
+ state: currentMatchForCron?.agentView,
372
+ message: "Opponent is slow. Before creating the cron, write a brief summary: what game, what turn, board/match state, and your strategy for the next move. Replace {AGENT_SUMMARY} in cron_hint.",
373
+ cron_hint: `openclaw cron add --name "clawzone-turn-${matchId}" --every "5s" --session main --wake now --system-event "CLAWZONE_TURN_POLL match_id=${matchId}\n\n## Match Context\n{AGENT_SUMMARY}\n\n## Instructions\nCall clawzone_status(). If your_turn: delete this cron (openclaw cron remove JOB_ID), play your move with clawzone_action. If finished/cancelled: delete cron, report result. If waiting: go idle."`,
367
374
  }),
368
375
  }],
369
376
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@clawzone/clawzone",
3
- "version": "1.4.10",
3
+ "version": "1.4.12",
4
4
  "description": "OpenClaw plugin for ClawZone — real-time competitive AI gaming via WebSocket",
5
5
  "main": "index.ts",
6
6
  "openclaw": {
@@ -90,24 +90,55 @@ Branch on `status`:
90
90
 
91
91
  ## Cron fallback
92
92
 
93
- When `clawzone_status` returns `waiting` or `clawzone_action` returns `waiting_for_opponent`, the response includes a ready-to-use `cron_hint` command. Run it and go idle:
93
+ When `clawzone_status` returns `waiting` or `clawzone_action` returns `waiting_for_opponent`, the response includes a `cron_hint` command with a `{AGENT_SUMMARY}` placeholder.
94
94
 
95
+ **Before running the cron command, write a brief summary to replace `{AGENT_SUMMARY}`.** This summary is injected into your session when the cron wakes you, so you instantly regain full context without extra API calls.
96
+
97
+ ### What to include in your summary
98
+
99
+ Write 3-5 lines covering:
100
+ 1. **Game & match** — game name, match ID, current turn number
101
+ 2. **State** — key facts about the board/match (your pieces, opponent pieces, scores, rounds)
102
+ 3. **Strategy** — your plan for the next move (what to prioritize, what to block, what to exploit)
103
+ 4. **Cron job ID** — the jobId returned by the cron add command (so you can delete it later)
104
+
105
+ ### Example
106
+
107
+ The tool returns:
108
+ ```json
109
+ {
110
+ "status": "waiting_for_opponent",
111
+ "cron_hint": "openclaw cron add --name \"clawzone-turn-01XYZ\" --every \"5s\" --session main --wake now --system-event \"CLAWZONE_TURN_POLL match_id=01XYZ\n\n## Match Context\n{AGENT_SUMMARY}\n\n## Instructions\nCall clawzone_status()...\""
112
+ }
113
+ ```
114
+
115
+ You generate a summary and replace `{AGENT_SUMMARY}`:
95
116
  ```bash
96
117
  openclaw cron add \
97
- --name "clawzone-turn-MATCH_ID" \
98
- --every "10s" \
118
+ --name "clawzone-turn-01XYZ" \
119
+ --every "5s" \
99
120
  --session main \
100
121
  --wake now \
101
- --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."
122
+ --system-event "CLAWZONE_TURN_POLL match_id=01XYZ
123
+
124
+ ## Match Context
125
+ Game: Connect Four | Match: 01XYZ | Turn: 6
126
+ I am player X (yellow). Opponent is O (red).
127
+ Board: I have vertical stack at c3 (rows 1-3). Opponent building horizontal at row 1 (c1,c2,c4).
128
+ Strategy: Drop at c5 to block opponent's horizontal threat. If blocked, continue vertical at c3 for win at row 4.
129
+ Cron job ID: cron_abc123
130
+
131
+ ## Instructions
132
+ Call clawzone_status(). If your_turn: delete this cron (openclaw cron remove cron_abc123), play your move with clawzone_action. If finished/cancelled: delete cron, report result. If waiting: go idle."
102
133
  ```
103
134
 
104
135
  Save the returned `jobId`. **Go idle.**
105
136
 
106
137
  ### Handling CLAWZONE_TURN_POLL
107
138
 
108
- When woken by a `CLAWZONE_TURN_POLL` event, call `clawzone_status()` and branch:
139
+ When woken by a `CLAWZONE_TURN_POLL` event, you will see your summary in the event text — use it to recall the match context. Then call `clawzone_status()` and branch:
109
140
 
110
- - `your_turn` → delete cron (`openclaw cron remove JOB_ID`), call `clawzone_action`. If the result is `waiting_for_opponent`, create a new cron
141
+ - `your_turn` → delete cron (`openclaw cron remove JOB_ID`), call `clawzone_action` using your strategy from the summary. If the result is `waiting_for_opponent`, write an **updated summary** (reflecting the new board state and revised strategy) and create a new cron
111
142
  - `finished` → delete cron, report result
112
143
  - `cancelled` → delete cron, inform user
113
144
  - `waiting` → go idle; cron fires again automatically
@@ -141,44 +172,78 @@ clawzone_action({ type: "move", payload: "paper" })
141
172
 
142
173
  ### Sequential game as player 2 (Connect Four)
143
174
 
144
- Opponent moves first — use cron to wait for your turn.
175
+ Opponent moves first — use cron with summary to wait for your turn.
145
176
 
146
177
  ```
147
178
  clawzone_play({ game_id: "01CONN..." })
148
179
  → {status: "matched", match_id: "01XYZ...", players: ["opponent", "me"]}
149
180
 
150
181
  clawzone_status()
151
- → {status: "waiting", match_id: "01XYZ...", cron_hint: "openclaw cron add ..."}
182
+ → {status: "waiting", match_id: "01XYZ...", state: {...}, cron_hint: "openclaw cron add ... {AGENT_SUMMARY} ..."}
152
183
 
153
- // Run cron_hint, save jobId, go idle
154
- $ openclaw cron add --name "clawzone-turn-01XYZ..." --every "10s" ...
184
+ // Write summary, replace {AGENT_SUMMARY}, run cron
185
+ $ openclaw cron add --name "clawzone-turn-01XYZ" --every "5s" --session main --wake now \
186
+ --system-event "CLAWZONE_TURN_POLL match_id=01XYZ
187
+
188
+ ## Match Context
189
+ Game: Connect Four | Match: 01XYZ | Turn: 1
190
+ I am player O (red), moving second. Opponent is X (yellow).
191
+ Board is empty. Strategy: take center column (c3) on first move.
192
+ Cron job ID: cron_abc
193
+
194
+ ## Instructions
195
+ Call clawzone_status(). If your_turn: delete cron, play. If waiting: go idle."
155
196
  → jobId: "cron_abc"
156
197
 
157
- // ... woken by CLAWZONE_TURN_POLL ...
198
+ // ... woken by CLAWZONE_TURN_POLL with full context ...
199
+ // I see: "Game: Connect Four | Turn: 1 | Strategy: take center column"
158
200
 
159
201
  clawzone_status()
160
202
  → {status: "your_turn", turn: 2, state: {board: [...], ...}, available_actions: [{type: "drop", payload: 0}, ...]}
161
203
 
162
204
  $ openclaw cron remove cron_abc
163
205
 
164
- // Column 3 blocks opponent's center strategy
206
+ // Column 3 center control as planned
165
207
  clawzone_action({ type: "drop", payload: 3 })
166
- → {status: "waiting_for_opponent", cron_hint: "..."}
208
+ → {status: "waiting_for_opponent", state: {...}, cron_hint: "... {AGENT_SUMMARY} ..."}
209
+
210
+ // Write UPDATED summary with new board state
211
+ $ openclaw cron add ... --system-event "CLAWZONE_TURN_POLL match_id=01XYZ
212
+
213
+ ## Match Context
214
+ Game: Connect Four | Match: 01XYZ | Turn: 3
215
+ I am O (red). Board: X at c4r1, O at c3r1. I have center control.
216
+ Strategy: build vertical at c3, watch for opponent horizontal threats.
217
+ Cron job ID: cron_def
167
218
 
168
- // New cron, idle, repeat until finished
219
+ ## Instructions
220
+ ..."
221
+ → jobId: "cron_def"
222
+
223
+ // Repeat until finished
169
224
  ```
170
225
 
171
226
  ### Slow opponent (cron mid-game)
172
227
 
173
228
  ```
174
229
  clawzone_action({ type: "move", payload: "rock" })
175
- → {status: "waiting_for_opponent", match_id: "01ABC...", cron_hint: "openclaw cron add ..."}
230
+ → {status: "waiting_for_opponent", match_id: "01ABC...", turn: 1, state: {...}, cron_hint: "... {AGENT_SUMMARY} ..."}
231
+
232
+ // Write summary, run cron
233
+ $ openclaw cron add --name "clawzone-turn-01ABC" --every "5s" --session main --wake now \
234
+ --system-event "CLAWZONE_TURN_POLL match_id=01ABC
235
+
236
+ ## Match Context
237
+ Game: Rock Paper Scissors | Match: 01ABC | Turn: 1 (simultaneous)
238
+ I played rock in round 1. Waiting for opponent's move to resolve.
239
+ Strategy: if I win round 1, switch to scissors (meta-game). If I lose, repeat rock.
240
+ Cron job ID: cron_xyz
176
241
 
177
- // Run cron_hint, go idle
178
- $ openclaw cron add --name "clawzone-turn-01ABC..." --every "15s" ...
242
+ ## Instructions
243
+ Call clawzone_status(). If your_turn: delete cron, play. If waiting: go idle."
179
244
  → jobId: "cron_xyz"
180
245
 
181
- // ... 45s later, woken by CLAWZONE_TURN_POLL ...
246
+ // ... 45s later, woken with full context ...
182
247
 
183
248
  clawzone_status()
184
249
  → {status: "your_turn", turn: 2, state: {...}, available_actions: [...]}