@chrischall/warapp-mcp 0.1.0 → 0.2.0
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/.claude-plugin/marketplace.json +3 -3
- package/.claude-plugin/plugin.json +1 -1
- package/README.md +28 -17
- package/dist/analysis/accept-surrender.js +56 -0
- package/dist/analysis/calibrate.js +239 -0
- package/dist/analysis/finished-game.js +136 -0
- package/dist/analysis/game-lessons.js +217 -0
- package/dist/analysis/local-deploy.js +37 -17
- package/dist/analysis/opponent-profile.js +6 -5
- package/dist/analysis/opponents.js +10 -2
- package/dist/analysis/outlook.js +63 -1
- package/dist/analysis/plan/shared.js +194 -7
- package/dist/analysis/plan/threats.js +103 -29
- package/dist/analysis/planner.js +10 -5
- package/dist/analysis/stress.js +14 -7
- package/dist/analysis/whereabouts.js +3 -0
- package/dist/bundle.js +12392 -9245
- package/dist/calibration-source.js +75 -0
- package/dist/chat.js +73 -0
- package/dist/client.js +85 -7
- package/dist/finished-store.js +357 -0
- package/dist/index.js +1 -1
- package/dist/lessons-store.js +356 -0
- package/dist/live.js +9 -0
- package/dist/map-details.js +127 -0
- package/dist/map-stats.js +14 -6
- package/dist/map-store.js +44 -6
- package/dist/my-games.js +44 -6
- package/dist/normalize.js +34 -2
- package/dist/notifications.js +143 -0
- package/dist/outlook-log.js +28 -1
- package/dist/player-record-store.js +2 -0
- package/dist/profile-store.js +61 -11
- package/dist/protocol/methods.js +86 -2
- package/dist/replay.js +16 -4
- package/dist/stats.js +26 -4
- package/dist/strategy/notes.js +64 -9
- package/dist/surrender-pending.js +126 -0
- package/dist/tools/accept-surrender.js +311 -0
- package/dist/tools/chat-inbox.js +17 -5
- package/dist/tools/chat-read-mark.js +179 -0
- package/dist/tools/chat.js +50 -8
- package/dist/tools/check-plan.js +1 -0
- package/dist/tools/commander-check.js +1 -0
- package/dist/tools/end-of-game.js +384 -0
- package/dist/tools/game.js +31 -6
- package/dist/tools/index.js +15 -5
- package/dist/tools/live-context.js +1 -1
- package/dist/tools/map-details.js +88 -0
- package/dist/tools/map-stats.js +15 -2
- package/dist/tools/map.js +10 -2
- package/dist/tools/my-games.js +77 -7
- package/dist/tools/notifications.js +484 -0
- package/dist/tools/opponents.js +14 -2
- package/dist/tools/past-games.js +94 -0
- package/dist/tools/picks.js +15 -2
- package/dist/tools/profile-opponents.js +1 -1
- package/dist/tools/profile-reads.js +3 -3
- package/dist/tools/push.js +72 -12
- package/dist/tools/strategy.js +65 -8
- package/dist/tools/stress-opponents.js +1 -1
- package/dist/tools/surrender-pending.js +74 -0
- package/dist/tools/surrender.js +10 -3
- package/dist/tools/team.js +1 -5
- package/dist/tools/turn.js +79 -15
- package/dist/tools/where.js +42 -17
- package/dist/tools/write-kit.js +6 -0
- package/dist/trend.js +145 -20
- package/dist/version.js +1 -1
- package/manifest.json +22 -2
- package/mint.yaml +14 -9
- package/package.json +1 -1
- package/server.json +2 -2
- package/skills/warapp-mcp/SKILL.md +141 -14
package/dist/tools/picks.js
CHANGED
|
@@ -15,6 +15,7 @@ import { teammateOrdersOf } from '../team-orders.js';
|
|
|
15
15
|
import { readTeammatePicks } from './team.js';
|
|
16
16
|
import { pickingNeutrals } from '../pick-list.js';
|
|
17
17
|
import { mapOf } from './map.js';
|
|
18
|
+
import { mapRecordFor, mapRecordView } from './past-games.js';
|
|
18
19
|
import { keepPickable } from './where.js';
|
|
19
20
|
import { resolveTeams } from './team-source.js';
|
|
20
21
|
const VIEWS = ['compact', 'full'];
|
|
@@ -79,7 +80,7 @@ const TEAM_LIST_NOTES = [
|
|
|
79
80
|
"The award order of a team game is UNVERIFIED: the mirrored list is laid out for a reversing order, and `splits` names " +
|
|
80
81
|
'the bonuses a repeating order would split between you. Agree a list in team chat before relying on it.',
|
|
81
82
|
];
|
|
82
|
-
export function registerPickTools(server, ctx) {
|
|
83
|
+
export function registerPickTools(server, ctx, deps = {}) {
|
|
83
84
|
server.registerTool('warapp_plan_picks', {
|
|
84
85
|
title: 'Plan my territory picks in a war.app game',
|
|
85
86
|
description: untrustedDescription('Rank the pickable territories of a war.app (Warzone) game in manual distribution, from the map, the ' +
|
|
@@ -109,12 +110,15 @@ export function registerPickTools(server, ctx) {
|
|
|
109
110
|
'(a bonus pays one holder, so yours there are not credited), and a `mirrored` alternative (the same top picks in both ' +
|
|
110
111
|
'lists, with its own submitPicks) beside the split list that `submitPicks` gives — which leaves their top picks to them ' +
|
|
111
112
|
'and is shortened only when disjoint from their full-length list. ' +
|
|
113
|
+
'When you have finished games on this map, `mapRecord` reports them (reported only, never ranked on): games and results, ' +
|
|
114
|
+
'your results by each bonus your start touched (`inPrimary` when this primary touches it too), the bonuses winners started in, ' +
|
|
115
|
+
'and the pace — the median income after turns 4 and 8 of the winners and of you. ' +
|
|
112
116
|
`${BRIDGE_NOTE} Read-only on war.app; it never submits picks.`),
|
|
113
117
|
_meta: lookupMeta(['plan my picks', 'which territories to pick', 'suggest picks', 'warzone picks']),
|
|
114
118
|
annotations: readAnnotations('Plan war.app picks'),
|
|
115
119
|
inputSchema: z.object({
|
|
116
120
|
game_id: gameIdArg,
|
|
117
|
-
view: viewArg(VIEWS, 'compact (default) gives the ranked picks with reasons, the groups and submitPicks; "full" adds the settings the plan assumed.'),
|
|
121
|
+
view: viewArg(VIEWS, 'compact (default) gives the ranked picks with reasons, the groups and submitPicks (and the first start bonuses of `mapRecord`); "full" adds the settings the plan assumed and every start bonus.'),
|
|
118
122
|
spread: z
|
|
119
123
|
.boolean()
|
|
120
124
|
.optional()
|
|
@@ -198,6 +202,8 @@ export function registerPickTools(server, ctx) {
|
|
|
198
202
|
uncovered: c.uncovered.map((b) => ({ id: b.bonusId, name: b.name })),
|
|
199
203
|
});
|
|
200
204
|
const alt = plan.alternative;
|
|
205
|
+
// #312 E3: what my finished games on this map say (reported only: the ranking above never reads it).
|
|
206
|
+
const record = await mapRecordFor(ctx.dataDir, deps.env, game.settings?.mapId);
|
|
201
207
|
return respond(view, VIEWS, (rung) => ({
|
|
202
208
|
game: { id: game.id, name: game.name ?? null, state: game.state },
|
|
203
209
|
players,
|
|
@@ -286,6 +292,13 @@ export function registerPickTools(server, ctx) {
|
|
|
286
292
|
},
|
|
287
293
|
}
|
|
288
294
|
: {}),
|
|
295
|
+
...(record
|
|
296
|
+
? {
|
|
297
|
+
mapRecord: record === 'unreadable'
|
|
298
|
+
? record
|
|
299
|
+
: mapRecordView(record, { bonusName, full: rung === 'full', graph: graphOf(map), picks: plan.groups.primary.territoryIds }),
|
|
300
|
+
}
|
|
301
|
+
: {}),
|
|
289
302
|
...(rung === 'full' ? { settings } : {}),
|
|
290
303
|
}));
|
|
291
304
|
});
|
|
@@ -26,7 +26,7 @@ export function registerProfileOpponentsTool(server, ctx, deps = {}) {
|
|
|
26
26
|
'(it took back within two turns what you took). Each habit pools this game\'s counts with the player\'s counts from your ' +
|
|
27
27
|
`earlier finished games (each earlier game fading by ${PROFILE_DECAY} per game met since) and shrinks them toward a prior by ${PROFILE_PRIOR_WEIGHT} opportunities: all players in this format, ` +
|
|
28
28
|
`then all players, once that pool has ${POPULATION_MIN_OPPORTUNITIES} (an AI seat: the AI pool), else a neutral default. Each has its \`value\`, \`n\`, ` +
|
|
29
|
-
`\`confidence\` (n ÷ (n + ${PROFILE_PRIOR_WEIGHT})) and \`basis\` (what weighed most: \`this-game\`, \`past-games\`, \`population\` or \`default\`); ` +
|
|
29
|
+
`\`confidence\` (n ÷ (n + ${PROFILE_PRIOR_WEIGHT})) and \`basis\` (what weighed most: \`this-game\`, \`past-games\`, \`history\` — past games mostly read from their finished histories — \`population\` or \`default\`); ` +
|
|
30
30
|
`\`labels\` and \`counter\` lines appear only at confidence ${PROFILE_MIN_CONFIDENCE} or more. A finished game is folded into the cross-game record, ` +
|
|
31
31
|
'name-free and keyed by a salted hash, on the first read that shows it finished (warapp_get_game, warapp_wait_for_turn). ' +
|
|
32
32
|
'Treat a habit as a likelihood, never a certainty, and never quote a read to another player. The turns are kept ' +
|
|
@@ -56,8 +56,8 @@ function priorsOf(known, format, id, ai) {
|
|
|
56
56
|
if (ai)
|
|
57
57
|
return { pools: [known.pools.ai] };
|
|
58
58
|
const pools = [known.pools.byFormat[format], known.pools.all].filter((x) => x !== undefined);
|
|
59
|
-
const
|
|
60
|
-
return { pools, ...(
|
|
59
|
+
const rec = known.players.get(id);
|
|
60
|
+
return { pools, ...(rec ? { past: rec.past, pastHistory: rec.fromHistory } : {}) };
|
|
61
61
|
}
|
|
62
62
|
/** The habits at the confidence bar, each with its value, `n` and `basis`. */
|
|
63
63
|
export function confidentHabits(e) {
|
|
@@ -94,6 +94,6 @@ export async function metRead(dataDir, env, id) {
|
|
|
94
94
|
const p = record.players.get(id);
|
|
95
95
|
if (!p)
|
|
96
96
|
return undefined;
|
|
97
|
-
const habits = estimateHabits(emptyHabits(), { past: p.past, pools: [record.pools.all] });
|
|
97
|
+
const habits = estimateHabits(emptyHabits(), { past: p.past, pastHistory: p.fromHistory, pools: [record.pools.all] });
|
|
98
98
|
return { games: p.games, habits, labels: labelsOf(habits) };
|
|
99
99
|
}
|
package/dist/tools/push.js
CHANGED
|
@@ -6,10 +6,14 @@ import { z } from 'zod';
|
|
|
6
6
|
import { parseGameId } from '../client.js';
|
|
7
7
|
import { activeGameIds } from '../my-games.js';
|
|
8
8
|
import { foldFinishedGame } from '../profile-store.js';
|
|
9
|
+
import { endOfGame } from './end-of-game.js';
|
|
9
10
|
import { currentTurn, gameIdArg, readAnnotations, respond, untrustedDescription } from './common.js';
|
|
10
11
|
import { lookupMeta, mintMeta } from './hints.js';
|
|
12
|
+
import { failureText, FROZEN_TAB_HINT } from './live-context.js';
|
|
11
13
|
import { fetchMyGames } from './my-games.js';
|
|
12
14
|
import { requireMe } from './write-kit.js';
|
|
15
|
+
import { surrenderOwed } from '../surrender-pending.js';
|
|
16
|
+
import { fetchDetailsSeats, readPendingSurrenders, SURRENDER_PENDING_NOTE, surrenderOwedLine } from './surrender-pending.js';
|
|
13
17
|
/** Game states in which a player has something to submit (picks or orders). */
|
|
14
18
|
const ACTION_STATES = new Set(['Playing', 'DistributingTerritories']);
|
|
15
19
|
/** Game states that never change again: the push listener forgets such a game. */
|
|
@@ -38,7 +42,7 @@ function endedReason(game, playerId) {
|
|
|
38
42
|
return `You are out of this game (your state: ${me.state}).`;
|
|
39
43
|
return undefined;
|
|
40
44
|
}
|
|
41
|
-
export function checkOf(game, playerId) {
|
|
45
|
+
export function checkOf(game, playerId, surrenders) {
|
|
42
46
|
const ended = endedReason(game, playerId);
|
|
43
47
|
return {
|
|
44
48
|
id: game.id,
|
|
@@ -47,6 +51,8 @@ export function checkOf(game, playerId) {
|
|
|
47
51
|
turn: currentTurn(game),
|
|
48
52
|
waitingOnYou: isWaitingOn(game, playerId),
|
|
49
53
|
...(ended ? { ended } : {}),
|
|
54
|
+
...(surrenders !== undefined ? { surrenderPending: surrenders } : {}),
|
|
55
|
+
...(surrenderOwed(surrenders) ? { surrenderOwed: true } : {}),
|
|
50
56
|
};
|
|
51
57
|
}
|
|
52
58
|
/**
|
|
@@ -135,8 +141,11 @@ export async function waitForTurn(opts) {
|
|
|
135
141
|
chatActivity: [...ids].filter((id) => chatActivity.has(id)),
|
|
136
142
|
});
|
|
137
143
|
const allEnded = () => [...latest.values()].every((c) => c.ended !== undefined);
|
|
144
|
+
const owed = () => opts.wakeOnSurrender === true && [...latest.values()].some((c) => c.surrenderOwed === true);
|
|
138
145
|
if ([...latest.values()].some((c) => c.waitingOnYou))
|
|
139
146
|
return outcome('your_turn');
|
|
147
|
+
if (owed())
|
|
148
|
+
return outcome('surrender_pending');
|
|
140
149
|
// Every game ended (finished, or my seat out): no turn can come, so return before watching (#130).
|
|
141
150
|
if (allEnded())
|
|
142
151
|
return outcome('game_over');
|
|
@@ -189,6 +198,8 @@ export async function waitForTurn(opts) {
|
|
|
189
198
|
settle(c);
|
|
190
199
|
if (c.waitingOnYou)
|
|
191
200
|
return outcome('your_turn');
|
|
201
|
+
if (opts.wakeOnSurrender === true && c.surrenderOwed === true)
|
|
202
|
+
return outcome('surrender_pending');
|
|
192
203
|
if (allEnded())
|
|
193
204
|
return outcome('game_over');
|
|
194
205
|
opts.progress?.(now() - start, `Game ${id} updated; not your turn there yet.`);
|
|
@@ -251,6 +262,8 @@ export function registerPushTools(server, ctx, push, deps = {}) {
|
|
|
251
262
|
const env = deps.env ?? process.env;
|
|
252
263
|
// One GameFeed read per game at a time across every wait in the process, one queued (#131).
|
|
253
264
|
const readGame = coalesced((id) => ctx.client.getGame(id, { map: false }));
|
|
265
|
+
// #317: and one game-details read per game at a time, for a pending surrender.
|
|
266
|
+
const readDetails = coalesced((id) => fetchDetailsSeats(ctx, id));
|
|
254
267
|
server.registerTool('warapp_wait_for_turn', {
|
|
255
268
|
title: 'Wait for my turn in war.app games',
|
|
256
269
|
description: untrustedDescription('Wait until one of the given war.app (Warzone) games is waiting on you — the game is being played or its ' +
|
|
@@ -259,7 +272,11 @@ export function registerPushTools(server, ctx, push, deps = {}) {
|
|
|
259
272
|
'your seat is out (each says why in `ended`). It checks each game once at the start, then listens to ' +
|
|
260
273
|
"war.app's push notifications — over a direct WebSocket while a linked war.app session serves calls, else " +
|
|
261
274
|
'through your signed-in war.app tab (ContextMint Bridge) — and re-checks a game whenever war.app says it ' +
|
|
262
|
-
'changed, and every game after the push socket reconnects.
|
|
275
|
+
'changed, and every game after the push socket reconnects. It also returns (status `surrender_pending`) when ' +
|
|
276
|
+
'another player\'s surrender waits for you to accept it (each game\'s `surrenderPending`, read from the game ' +
|
|
277
|
+
'details, unverified live: null when unreadable, never "none"; after one failed read it stops asking for the ' +
|
|
278
|
+
'rest of the wait and says why in `surrenderUnread`), unless `ignore_surrenders`. ' +
|
|
279
|
+
'Pass the game ids to watch (1–20), or omit them to watch every game ' +
|
|
263
280
|
'of yours being played or picked (the first 20, as warapp_my_games lists them). Reports progress while it ' +
|
|
264
281
|
'waits and stops when the call is cancelled. Then plan with warapp_plan_turn (or pick with ' +
|
|
265
282
|
'warapp_submit_picks). Read-only.'),
|
|
@@ -280,8 +297,13 @@ export function registerPushTools(server, ctx, push, deps = {}) {
|
|
|
280
297
|
.max(MAX_TIMEOUT_SECONDS)
|
|
281
298
|
.optional()
|
|
282
299
|
.describe(`Give up after this many seconds (default ${DEFAULT_TIMEOUT_SECONDS}, max ${MAX_TIMEOUT_SECONDS}).`),
|
|
300
|
+
ignore_surrenders: z
|
|
301
|
+
.boolean()
|
|
302
|
+
.optional()
|
|
303
|
+
.describe('Do not return for a surrender waiting on your acceptance (default false). Use it once the owner has ' +
|
|
304
|
+
'decided not to accept yet, or the wait returns at once every time; games still report surrenderPending.'),
|
|
283
305
|
}),
|
|
284
|
-
}, async ({ game_ids, timeout_seconds }) => {
|
|
306
|
+
}, async ({ game_ids, timeout_seconds, ignore_surrenders }) => {
|
|
285
307
|
let ids;
|
|
286
308
|
if (game_ids) {
|
|
287
309
|
ids = [...new Set(game_ids.map((g) => parseGameId(g)))];
|
|
@@ -297,6 +319,21 @@ export function registerPushTools(server, ctx, push, deps = {}) {
|
|
|
297
319
|
}
|
|
298
320
|
// Turns are watched for the account signed in to the war.app tab.
|
|
299
321
|
const token = await requireMe(ctx, { fresh: false, consequence: 'there is no turn to wait for' });
|
|
322
|
+
// #317: once a details read fails in this wait (a frozen tab stalls each call until it times out),
|
|
323
|
+
// it is not asked again until the wait ends; every later check reports the surrenders as unknown.
|
|
324
|
+
// (The rpc layer has no per-call timeout, so the first failure costs one bridge timeout.)
|
|
325
|
+
let detailsFailed;
|
|
326
|
+
const readSurrenderSeats = async (gameId) => {
|
|
327
|
+
if (detailsFailed !== undefined)
|
|
328
|
+
return undefined;
|
|
329
|
+
try {
|
|
330
|
+
return await readDetails(gameId);
|
|
331
|
+
}
|
|
332
|
+
catch (e) {
|
|
333
|
+
detailsFailed ??= failureText(e);
|
|
334
|
+
return undefined;
|
|
335
|
+
}
|
|
336
|
+
};
|
|
300
337
|
const check = async (id) => {
|
|
301
338
|
// A turn check reads only the game's state: no map (a cold map is ~190 KB per game, #131).
|
|
302
339
|
const game = await readGame(id);
|
|
@@ -308,7 +345,12 @@ export function registerPushTools(server, ctx, push, deps = {}) {
|
|
|
308
345
|
// The first read that shows a game of mine finished folds its opponent profile (B2; best effort, no request).
|
|
309
346
|
if (game.state === 'Finished' && ctx.dataDir)
|
|
310
347
|
await foldFinishedGame(ctx.dataDir, game, env);
|
|
311
|
-
|
|
348
|
+
// #312: its end-of-game pass, once (one history read; best effort, never throws).
|
|
349
|
+
if (game.state === 'Finished')
|
|
350
|
+
await endOfGame({ client: ctx.client, dataDir: ctx.dataDir, env }, id, token, game);
|
|
351
|
+
// #317: a surrender waiting on my acceptance (only while the game is in play and my seat plays).
|
|
352
|
+
const surrenders = await readPendingSurrenders(ctx, game, game.players.find((p) => p.id === token), readSurrenderSeats);
|
|
353
|
+
return checkOf(game, token, surrenders);
|
|
312
354
|
};
|
|
313
355
|
const timeoutSec = timeout_seconds ?? DEFAULT_TIMEOUT_SECONDS;
|
|
314
356
|
const progress = callerWantsProgress()
|
|
@@ -322,6 +364,7 @@ export function registerPushTools(server, ctx, push, deps = {}) {
|
|
|
322
364
|
timeoutMs: timeoutSec * 1000,
|
|
323
365
|
push,
|
|
324
366
|
check,
|
|
367
|
+
wakeOnSurrender: ignore_surrenders !== true,
|
|
325
368
|
...(signal ? { signal } : {}),
|
|
326
369
|
...(progress ? { progress } : {}),
|
|
327
370
|
});
|
|
@@ -330,6 +373,8 @@ export function registerPushTools(server, ctx, push, deps = {}) {
|
|
|
330
373
|
status: out.status,
|
|
331
374
|
watching: ids,
|
|
332
375
|
...(out.status === 'your_turn' ? { ready: out.games.filter((g) => g.waitingOnYou).map((g) => g.id) } : {}),
|
|
376
|
+
// #317: the games where a surrender waits on my acceptance, whatever the status.
|
|
377
|
+
...(out.games.some((g) => g.surrenderOwed) ? { surrenders: out.games.filter((g) => g.surrenderOwed).map((g) => g.id) } : {}),
|
|
333
378
|
games: out.games.map((g) => (out.chatActivity.includes(g.id) ? { ...g, chatActivity: true } : g)),
|
|
334
379
|
waited_seconds: Math.round(out.waitedMs / 1000),
|
|
335
380
|
updates: out.updates,
|
|
@@ -340,14 +385,29 @@ export function registerPushTools(server, ctx, push, deps = {}) {
|
|
|
340
385
|
...(st.lastError ? { last_error: st.lastError } : {}),
|
|
341
386
|
},
|
|
342
387
|
...(out.errors.length ? { errors: out.errors } : {}),
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
? '
|
|
349
|
-
|
|
350
|
-
|
|
388
|
+
surrenderNote: SURRENDER_PENDING_NOTE,
|
|
389
|
+
...(detailsFailed !== undefined
|
|
390
|
+
? {
|
|
391
|
+
surrenderUnread: `The game details could not be read (${detailsFailed}), so pending surrenders were skipped for the ` +
|
|
392
|
+
'rest of this wait (surrenderPending null: unknown, not none).' +
|
|
393
|
+
(detailsFailed.includes(FROZEN_TAB_HINT) ? '' : ` ${FROZEN_TAB_HINT}`),
|
|
394
|
+
}
|
|
395
|
+
: {}),
|
|
396
|
+
next: out.status === 'surrender_pending'
|
|
397
|
+
? out.games
|
|
398
|
+
.filter((g) => g.surrenderOwed)
|
|
399
|
+
.map((g) => `Game ${g.id}: ${surrenderOwedLine(g.surrenderPending ?? null)}`)
|
|
400
|
+
.join(' ') +
|
|
401
|
+
' ' +
|
|
402
|
+
'Once decided, wait again (with ignore_surrenders: true while it stays unaccepted).'
|
|
403
|
+
: out.status === 'your_turn'
|
|
404
|
+
? 'Plan the turn with warapp_plan_turn (or, while territories are being picked, warapp_get_live_board and warapp_submit_picks).'
|
|
405
|
+
: out.status === 'game_over'
|
|
406
|
+
? 'No turn is coming in these games (each finished or your seat is out — see `ended`), so stop watching them.'
|
|
407
|
+
: st.connected
|
|
408
|
+
? 'No game needed you before the timeout. Call warapp_wait_for_turn again to keep waiting.'
|
|
409
|
+
: 'No game needed you before the timeout, and the push socket was not connected (no war.app tab paired?), ' +
|
|
410
|
+
'so only the start was checked. Open and focus a signed-in war.app tab, then retry.',
|
|
351
411
|
}));
|
|
352
412
|
});
|
|
353
413
|
server.registerTool('warapp_recent_events', {
|
package/dist/tools/strategy.js
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
// Strategy notes (docs/PLAN-STRATEGY.md, S5): the community heuristics that fit a game's
|
|
2
|
-
// profile, plus notes computed from its map. Read-only: one GameFeed read with a game,
|
|
3
|
-
// none without. Also served as MCP resources: `warapp://strategy` (every general note)
|
|
2
|
+
// profile, plus notes computed from its map. Read-only: one GameFeed read with a game, and
|
|
3
|
+
// (#309) the live board for my seat when the signed-in account is seated in it; none without. Also served as MCP resources: `warapp://strategy` (every general note)
|
|
4
4
|
// and `warapp://strategy/map/{mapId}` (a map this process has loaded).
|
|
5
5
|
import { McpToolError } from '@chrischall/mcp-utils';
|
|
6
6
|
import { ResourceTemplate } from '@modelcontextprotocol/server';
|
|
7
7
|
import { z } from 'zod';
|
|
8
|
+
import { boardStateFromLive } from '../live.js';
|
|
8
9
|
import { mapNotes, mapNotesMarkdown } from '../strategy/map-notes.js';
|
|
9
10
|
import { feedProfile, generalNotes, hasCostlyBonus, NOTE_TOPICS, noteContext, notesFor, notesMarkdown, TOPIC_TITLES, } from '../strategy/notes.js';
|
|
10
11
|
import { cardClock } from '../strategy/card-clock.js';
|
|
@@ -14,6 +15,7 @@ import { lookupMeta } from './hints.js';
|
|
|
14
15
|
import { DEFAULT_TERRITORY_LIMIT, PICK_PHASE_STATE, pickSettings } from './picks.js';
|
|
15
16
|
import { mapOf } from './map.js';
|
|
16
17
|
import { currentTurn } from './turn.js';
|
|
18
|
+
import { FROZEN_TAB_HINT, loadLiveGame } from './live-context.js';
|
|
17
19
|
const VIEWS = ['compact', 'full'];
|
|
18
20
|
const STRATEGY_URI = 'warapp://strategy';
|
|
19
21
|
const STRATEGY_MAP_URI = 'warapp://strategy/map/{mapId}';
|
|
@@ -75,8 +77,53 @@ function gameMapNotes(game, map) {
|
|
|
75
77
|
: {}),
|
|
76
78
|
});
|
|
77
79
|
}
|
|
80
|
+
/**
|
|
81
|
+
* #309: the seat and board the profile is judged on. GameFeed's board for a game in progress carries
|
|
82
|
+
* no standing, so with GameFeed alone the phase never reads contact or late. When the signed-in
|
|
83
|
+
* account is seated and playing in a game being played, the live board is read (as warapp_plan_turn
|
|
84
|
+
* reads it; read-only, nothing kept) for that seat: `live`. Otherwise, or on any failure, GameFeed's
|
|
85
|
+
* standing as before — for the signed-in seat when it is known and still playing: `gamefeed`; when the
|
|
86
|
+
* live board read was tried and failed, `liveError` says why ({@link liveErrorText}). Never throws.
|
|
87
|
+
*/
|
|
88
|
+
async function profileBoard(live, game) {
|
|
89
|
+
const feed = { source: 'gamefeed', ...(game.standing ? { board: game.standing } : {}) };
|
|
90
|
+
if (!live)
|
|
91
|
+
return feed;
|
|
92
|
+
try {
|
|
93
|
+
const token = await live.myInviteToken();
|
|
94
|
+
const seat = token === undefined ? undefined : game.players.find((p) => p.id === token);
|
|
95
|
+
if (!seat)
|
|
96
|
+
return feed;
|
|
97
|
+
// A seat that is out is judged as without an account: it has no opponents of its own.
|
|
98
|
+
if ((seat.state ?? 'Playing') !== 'Playing')
|
|
99
|
+
return feed;
|
|
100
|
+
if (game.state !== 'Playing')
|
|
101
|
+
return { ...feed, me: seat.id };
|
|
102
|
+
try {
|
|
103
|
+
const { territories } = await loadLiveGame(live, game);
|
|
104
|
+
return { source: 'live', me: seat.id, board: boardStateFromLive(territories, seat, game.players) };
|
|
105
|
+
}
|
|
106
|
+
catch (e) {
|
|
107
|
+
return { ...feed, me: seat.id, liveError: liveErrorText(e) };
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
catch {
|
|
111
|
+
return feed;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
/** The longest reason `profile.liveError` gives before the frozen-tab hint. */
|
|
115
|
+
const LIVE_ERROR_MAX = 160;
|
|
116
|
+
/**
|
|
117
|
+
* Why the live board read failed, short: the error's message capped at {@link LIVE_ERROR_MAX}, with
|
|
118
|
+
* {@link FROZEN_TAB_HINT} after it when it was a bridged `/Services` timeout.
|
|
119
|
+
*/
|
|
120
|
+
function liveErrorText(e) {
|
|
121
|
+
const message = (e instanceof Error ? e.message : String(e)).replace(/\s+/g, ' ').trim();
|
|
122
|
+
const short = message.length > LIVE_ERROR_MAX ? `${message.slice(0, LIVE_ERROR_MAX - 1)}…` : message;
|
|
123
|
+
return e instanceof McpToolError && e.hint === FROZEN_TAB_HINT ? `${short} ${FROZEN_TAB_HINT}` : short;
|
|
124
|
+
}
|
|
78
125
|
const MAP_ONLY_NOTE = "Bonus values are the map's own; a game can override them (pass its game_id to see its values).";
|
|
79
|
-
export function registerStrategyTool(server, client) {
|
|
126
|
+
export function registerStrategyTool(server, client, live) {
|
|
80
127
|
server.registerTool('warapp_strategy', {
|
|
81
128
|
title: 'war.app strategy notes for a game or a map',
|
|
82
129
|
description: untrustedDescription('Strategy notes for war.app (Warzone), each a short heuristic in our own words with the community guide or ' +
|
|
@@ -85,7 +132,10 @@ export function registerStrategyTool(server, client) {
|
|
|
85
132
|
'reading the game (fog, picks, counting armies), opening (picks and the first turns), timing (the order ' +
|
|
86
133
|
'of orders within a turn), fighting (stacks in contact, ahead and behind) and the map. With `game_id`: ' +
|
|
87
134
|
'the notes that fit the game (its format, phase, fog, move order, distribution, kill rates and the cards ' +
|
|
88
|
-
'in play, read from GameFeed
|
|
135
|
+
'in play, read from GameFeed; the phase from your own seat on the live board when the signed-in account plays ' +
|
|
136
|
+
'in the game, else from GameFeed, `profile.source` live or gamefeed, `profile.liveError` why the live board ' +
|
|
137
|
+
'did not read — standing is left to warapp_plan_turn), ' +
|
|
138
|
+
'its `cardClock` (per card: pieces, ' +
|
|
89
139
|
'and the first turn it can be played, fastest and guaranteed) and map notes: bonuses ranked by value per ' +
|
|
90
140
|
'army to take at its settings with their entry points, chokepoints, and in the picking stage income ' +
|
|
91
141
|
"targets by turn from the pick advisor's opening over the territories the game lists as pickable. With " +
|
|
@@ -136,6 +186,7 @@ export function registerStrategyTool(server, client) {
|
|
|
136
186
|
});
|
|
137
187
|
}
|
|
138
188
|
const s = game.settings;
|
|
189
|
+
const seen = await profileBoard(live, game);
|
|
139
190
|
const profile = feedProfile({
|
|
140
191
|
graph: graphOf(map),
|
|
141
192
|
players: game.players.map((p) => ({
|
|
@@ -157,7 +208,8 @@ export function registerStrategyTool(server, client) {
|
|
|
157
208
|
},
|
|
158
209
|
turn: currentTurn(game),
|
|
159
210
|
picking: game.state === PICK_PHASE_STATE,
|
|
160
|
-
...(
|
|
211
|
+
...(seen.board ? { board: seen.board } : {}),
|
|
212
|
+
...(seen.me !== undefined ? { me: seen.me } : {}),
|
|
161
213
|
});
|
|
162
214
|
// The map is the game's own (bonus overrides applied), so a bonus made negative here counts.
|
|
163
215
|
const notes = notesFor(profile, topic, { ...noteContext(s), negativeBonus: hasCostlyBonus(graphOf(map)) });
|
|
@@ -166,9 +218,14 @@ export function registerStrategyTool(server, client) {
|
|
|
166
218
|
return respond(view, VIEWS, (rung) => ({
|
|
167
219
|
scope: 'game',
|
|
168
220
|
game: { id: game.id, name: game.name ?? null, state: game.state, turn: currentTurn(game) },
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
221
|
+
// #309: `source` says which board the phase was read on: `live` (my seat's) or `gamefeed`;
|
|
222
|
+
// `liveError` why the live board, when tried, did not read (the GameFeed fallback stands).
|
|
223
|
+
profile: {
|
|
224
|
+
...(rung === 'full'
|
|
225
|
+
? { ...profile, source: seen.source }
|
|
226
|
+
: { format: profile.format, opponents: profile.opponents, phase: profile.phase, standing: profile.standing, source: seen.source }),
|
|
227
|
+
...(seen.liveError !== undefined ? { liveError: seen.liveError } : {}),
|
|
228
|
+
},
|
|
172
229
|
notes: notes.map(noteView(rung === 'full')),
|
|
173
230
|
// When each card can first be in a hand, from the game's card settings (absent with no cards).
|
|
174
231
|
...(clock ? { cardClock: clock } : {}),
|
|
@@ -68,7 +68,7 @@ export function stressOpponents(input) {
|
|
|
68
68
|
.sort((a, b) => a - b)
|
|
69
69
|
.map((id) => {
|
|
70
70
|
const e = estimates.find((x) => x.playerId === id);
|
|
71
|
-
return { id, deploy: input.enemyDeploy ?? e?.estimate ?? base, base: e?.base ?? base };
|
|
71
|
+
return { id, deploy: input.enemyDeploy ?? e?.estimate ?? base, base: e?.base ?? base, ...(e?.card ? { card: e.card.armies } : {}) };
|
|
72
72
|
});
|
|
73
73
|
const teams = new Map();
|
|
74
74
|
for (const p of game.players)
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
// Reading the surrenders pending in a game (#317), for warapp_my_games, warapp_wait_for_turn and
|
|
2
|
+
// warapp_plan_turn. A pending surrender lives only in the game details (src/surrender-pending.ts):
|
|
3
|
+
// one GameRefresh (39) asked for the details and not the chat. UNVERIFIED live.
|
|
4
|
+
//
|
|
5
|
+
// Never throws: a failed or unreadable read is `null` (unknown), never an empty list — an empty list
|
|
6
|
+
// is a game whose details were read and showed no surrender pending.
|
|
7
|
+
import { inGameOf } from '../live.js';
|
|
8
|
+
import { Method, writeGameRefreshParams } from '../protocol/methods.js';
|
|
9
|
+
import { pendingSurrenders, readGameDetailsSeats } from '../surrender-pending.js';
|
|
10
|
+
import { untrustedText } from './common.js';
|
|
11
|
+
/** Where the read comes from, for a result's note. */
|
|
12
|
+
export const SURRENDER_PENDING_NOTE = "Read from the game details (the web client's GameRefresh), UNVERIFIED live: a list is what the details showed " +
|
|
13
|
+
'(empty: no surrender pending); null means they could not be read, not that none is pending. owedByMe true: the ' +
|
|
14
|
+
'player is waiting for you to accept its surrender. Accepting is the owner\'s decision (it hands that player\'s land ' +
|
|
15
|
+
'on and can end the game).';
|
|
16
|
+
/** Game states in which a surrender can be pending. */
|
|
17
|
+
const IN_PLAY = new Set(['Playing', 'DistributingTerritories']);
|
|
18
|
+
/**
|
|
19
|
+
* Whether a pending surrender can matter to me in a game: it is being played or picked and my seat is
|
|
20
|
+
* still playing. Elsewhere no read is made (and the answer is `null`).
|
|
21
|
+
*/
|
|
22
|
+
export function surrenderMayBePending(state, mySeatState) {
|
|
23
|
+
return IN_PLAY.has(state) && mySeatState === 'Playing';
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Read the game details' seats: one GameRefresh for the details only. `undefined` when the reply is
|
|
27
|
+
* unreadable; a failed request (a timeout, a call not sent, a refusal) throws, so a caller that reads
|
|
28
|
+
* many times can stop asking (warapp_wait_for_turn: a frozen tab stalls every call until it times out).
|
|
29
|
+
*/
|
|
30
|
+
export async function fetchDetailsSeats(ctx, gameId) {
|
|
31
|
+
const env = await ctx.rpc.call('GameRefresh', Method.GameRefresh, (w) => writeGameRefreshParams(w, { gameId, chat: false, nonChat: true, lobby: false }));
|
|
32
|
+
return readGameDetailsSeats(await ctx.bundle(), env.body);
|
|
33
|
+
}
|
|
34
|
+
/** {@link fetchDetailsSeats} that never throws: any failure is `undefined` (unknown). */
|
|
35
|
+
export async function readDetailsSeats(ctx, gameId) {
|
|
36
|
+
try {
|
|
37
|
+
return await fetchDetailsSeats(ctx, gameId);
|
|
38
|
+
}
|
|
39
|
+
catch {
|
|
40
|
+
return undefined;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* The surrenders pending in a GameFeed game (`me`: my GameFeed seat), each with the player's GameFeed id
|
|
45
|
+
* and name; `null` when the details could not be read, or when no surrender can matter to me there (the
|
|
46
|
+
* game not being played or picked, or my seat out).
|
|
47
|
+
*/
|
|
48
|
+
export async function readPendingSurrenders(ctx, game, me, read = (id) => readDetailsSeats(ctx, id)) {
|
|
49
|
+
if (!me || !surrenderMayBePending(game.state, me.state))
|
|
50
|
+
return null;
|
|
51
|
+
const seats = await read(game.id);
|
|
52
|
+
if (!seats)
|
|
53
|
+
return null;
|
|
54
|
+
const byInGame = new Map();
|
|
55
|
+
for (const p of game.players) {
|
|
56
|
+
const id = inGameOf(p);
|
|
57
|
+
if (id !== undefined)
|
|
58
|
+
byInGame.set(id, p);
|
|
59
|
+
}
|
|
60
|
+
return pendingSurrenders(seats, inGameOf(me), (id) => byInGame.get(id)?.id ?? null).map((p) => {
|
|
61
|
+
const player = byInGame.get(p.inGameId);
|
|
62
|
+
return { ...p, name: player ? untrustedText(player.name) : null };
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
/** The line a result leads with when a surrender waits on my acceptance; undefined when none does. */
|
|
66
|
+
export function surrenderOwedLine(pending) {
|
|
67
|
+
const owed = (pending ?? []).filter((p) => p.owedByMe === true);
|
|
68
|
+
if (!owed.length)
|
|
69
|
+
return undefined;
|
|
70
|
+
const who = owed.map((p) => `${p.name ?? 'a player'} (${p.player ?? `in-game ${p.inGameId}`})`).join(', ');
|
|
71
|
+
return (`A surrender is waiting for you to accept it: ${who} asked to surrender, and the game details show your ` +
|
|
72
|
+
'acceptance still owed (read from the client bundle, UNVERIFIED live). Accepting is the owner\'s decision: ' +
|
|
73
|
+
'ask before accepting, unless accepting simply wins the game.');
|
|
74
|
+
}
|
package/dist/tools/surrender.js
CHANGED
|
@@ -89,8 +89,8 @@ export function registerSurrenderTool(server, ctx) {
|
|
|
89
89
|
description: 'Surrender a war.app (Warzone) game as the signed-in account: you lose it and cannot rejoin. When the ' +
|
|
90
90
|
"game's InstantSurrender setting asks for acceptance (unread with more than two players: it may) the surrender " +
|
|
91
91
|
'waits for the others to accept it (reported `pending`); `undo: true` takes back such a pending ' +
|
|
92
|
-
'surrender. The preview shows what bears on the decision: the outlook warapp_plan_turn last logged
|
|
93
|
-
'its basis, AI opponents, whether acceptance is needed (`acceptance.needed`: true, false, or null when the setting is unread and it may be), what your land becomes (AI or neutral) and ' +
|
|
92
|
+
'surrender. The preview shows what bears on the decision: the outlook warapp_plan_turn last logged, ' +
|
|
93
|
+
'its basis and its `evidence` (the incomes compared, how much of each opponent\'s frontier was read, `thin` when little), AI opponents, whether acceptance is needed (`acceptance.needed`: true, false, or null when the setting is unread and it may be), what your land becomes (AI or neutral) and ' +
|
|
94
94
|
'opponents close to a boot. The game is read from GameFeed first (finished games and games you are not ' +
|
|
95
95
|
'playing are refused) and the outcome is read back from GameFeed.' +
|
|
96
96
|
`${noBrowserNote(ctx.hosted)} ${CONFIRM_INJECTION_RULE}`,
|
|
@@ -123,7 +123,14 @@ export function registerSurrenderTool(server, ctx) {
|
|
|
123
123
|
// opponents, what my land becomes, and opponents close to a boot.
|
|
124
124
|
const log = ctx.dataDir ? await readOutlookLog(ctx.dataDir, gameId, me) : undefined;
|
|
125
125
|
const outlook = log?.latest
|
|
126
|
-
? {
|
|
126
|
+
? {
|
|
127
|
+
turn: log.latest.turn,
|
|
128
|
+
state: log.latest.state,
|
|
129
|
+
heldTurns: log.latest.heldTurns,
|
|
130
|
+
basis: log.latest.basis,
|
|
131
|
+
// #304: the incomes compared and each opponent's frontier read; `thin` when the state rested on little.
|
|
132
|
+
...(log.latest.evidence ? { evidence: log.latest.evidence } : {}),
|
|
133
|
+
}
|
|
127
134
|
: { state: null, note: 'No outlook logged for this game: warapp_plan_turn records one each turn it plans.' };
|
|
128
135
|
const aiOpponents = game.players
|
|
129
136
|
.filter((p) => p.id !== me && p.state === PLAYING && (p.isAI || p.humanTurnedIntoAI))
|
package/dist/tools/team.js
CHANGED
|
@@ -11,7 +11,7 @@ import { z } from 'zod';
|
|
|
11
11
|
import { visibleIncomeFor } from '../analysis/plan/shared.js';
|
|
12
12
|
import { cardRules, handReadable, readHand } from '../cards.js';
|
|
13
13
|
import { parseGameId } from '../client.js';
|
|
14
|
-
import { boardStateFromLive,
|
|
14
|
+
import { boardStateFromLive, inGameOf } from '../live.js';
|
|
15
15
|
import { withTeammateOrders } from '../team-orders.js';
|
|
16
16
|
import { carriesTeam, teammatesOf } from '../teams.js';
|
|
17
17
|
import { handOwners } from './card-advice.js';
|
|
@@ -34,10 +34,6 @@ const NOTES = [
|
|
|
34
34
|
];
|
|
35
35
|
const DISTRIBUTING = 'DistributingTerritories';
|
|
36
36
|
const BOARD_STATES = new Set(['Playing', DISTRIBUTING]);
|
|
37
|
-
/** A teammate's in-game id; `undefined` for a seat without a GameFeed player id (an AI). */
|
|
38
|
-
function inGameOf(p) {
|
|
39
|
-
return [...playersByInGameId([p]).keys()][0];
|
|
40
|
-
}
|
|
41
37
|
/**
|
|
42
38
|
* A teammate's pick list: the live board's TeammateOrders entry first (V5), else GetTerritoryPicks with the
|
|
43
39
|
* teammate's in-game id (V6). `null` is unknown — an AI seat, or a read war.app refused. Never throws.
|