@chrischall/warapp-mcp 0.0.0 → 0.1.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 +4 -4
- package/.claude-plugin/plugin.json +2 -2
- package/README.md +199 -8
- package/dist/analysis/award.js +159 -0
- package/dist/analysis/bonuses.js +98 -0
- package/dist/analysis/breach.js +62 -0
- package/dist/analysis/card-support.js +329 -0
- package/dist/analysis/card-threats.js +234 -0
- package/dist/analysis/cards-in-effect.js +130 -0
- package/dist/analysis/chains.js +59 -0
- package/dist/analysis/chokepoints.js +140 -0
- package/dist/analysis/combat.js +231 -0
- package/dist/analysis/commander-safety.js +149 -0
- package/dist/analysis/commitments.js +338 -0
- package/dist/analysis/exchange.js +155 -0
- package/dist/analysis/graph.js +82 -0
- package/dist/analysis/guard-off.js +54 -0
- package/dist/analysis/guess.js +351 -0
- package/dist/analysis/headroom.js +241 -0
- package/dist/analysis/hold-diff.js +64 -0
- package/dist/analysis/how-lost.js +130 -0
- package/dist/analysis/index.js +14 -0
- package/dist/analysis/local-deploy.js +159 -0
- package/dist/analysis/lookahead.js +108 -0
- package/dist/analysis/opponent-profile.js +551 -0
- package/dist/analysis/opponents.js +1245 -0
- package/dist/analysis/outlook.js +633 -0
- package/dist/analysis/overrides.js +60 -0
- package/dist/analysis/picks.js +1879 -0
- package/dist/analysis/plan/after-leftover.js +140 -0
- package/dist/analysis/plan/cap-spend.js +242 -0
- package/dist/analysis/plan/captures.js +1195 -0
- package/dist/analysis/plan/commander.js +236 -0
- package/dist/analysis/plan/completed.js +29 -0
- package/dist/analysis/plan/conceded-out.js +131 -0
- package/dist/analysis/plan/estimates.js +715 -0
- package/dist/analysis/plan/guard-off.js +232 -0
- package/dist/analysis/plan/holds.js +1631 -0
- package/dist/analysis/plan/leftover.js +760 -0
- package/dist/analysis/plan/move-order.js +319 -0
- package/dist/analysis/plan/orders.js +317 -0
- package/dist/analysis/plan/relations.js +702 -0
- package/dist/analysis/plan/report.js +672 -0
- package/dist/analysis/plan/shared.js +1218 -0
- package/dist/analysis/plan/stand-still.js +823 -0
- package/dist/analysis/plan/state.js +44 -0
- package/dist/analysis/plan/strike.js +1416 -0
- package/dist/analysis/plan/targets.js +651 -0
- package/dist/analysis/plan/team.js +299 -0
- package/dist/analysis/plan/threats.js +927 -0
- package/dist/analysis/plan/transfers.js +328 -0
- package/dist/analysis/plan/util.js +5 -0
- package/dist/analysis/plan/vacated.js +285 -0
- package/dist/analysis/planner.js +2922 -0
- package/dist/analysis/player-record.js +144 -0
- package/dist/analysis/player.js +268 -0
- package/dist/analysis/profile.js +347 -0
- package/dist/analysis/relations.js +1030 -0
- package/dist/analysis/schedule.js +88 -0
- package/dist/analysis/since-last.js +50 -0
- package/dist/analysis/static-seats.js +71 -0
- package/dist/analysis/stress.js +577 -0
- package/dist/analysis/team-brief.js +151 -0
- package/dist/analysis/tripwire.js +644 -0
- package/dist/analysis/turn-sim.js +259 -0
- package/dist/analysis/whereabouts.js +1109 -0
- package/dist/board.js +105 -0
- package/dist/bundle.js +117959 -36172
- package/dist/cards.js +435 -0
- package/dist/chat-cursor.js +135 -0
- package/dist/chat.js +192 -0
- package/dist/client.js +361 -0
- package/dist/config.js +62 -0
- package/dist/direct/link.js +102 -0
- package/dist/direct/session.js +267 -0
- package/dist/direct/transport.js +424 -0
- package/dist/guess-salt.js +65 -0
- package/dist/hosted.js +24 -0
- package/dist/index.js +33 -0
- package/dist/join-color.js +140 -0
- package/dist/live.js +278 -0
- package/dist/map-stats.js +152 -0
- package/dist/map-store.js +204 -0
- package/dist/move-order.js +141 -0
- package/dist/my-games.js +180 -0
- package/dist/normalize.js +411 -0
- package/dist/open-games.js +537 -0
- package/dist/outlook-log.js +138 -0
- package/dist/path-lock.js +22 -0
- package/dist/pick-list.js +193 -0
- package/dist/player-record-store.js +229 -0
- package/dist/player-states.js +31 -0
- package/dist/profile-store.js +677 -0
- package/dist/protocol/bundle.js +375 -0
- package/dist/protocol/codec.js +556 -0
- package/dist/protocol/decoded.js +12 -0
- package/dist/protocol/interp.js +1904 -0
- package/dist/protocol/methods.js +531 -0
- package/dist/protocol/rpc.js +202 -0
- package/dist/push/listener.js +393 -0
- package/dist/push/packets.js +66 -0
- package/dist/push/socketio.js +333 -0
- package/dist/push/websocket.js +179 -0
- package/dist/redact.js +62 -0
- package/dist/relations-store.js +242 -0
- package/dist/replay.js +215 -0
- package/dist/scalars.js +28 -0
- package/dist/scout.js +346 -0
- package/dist/stats.js +269 -0
- package/dist/strategy/card-clock.js +185 -0
- package/dist/strategy/map-notes.js +128 -0
- package/dist/strategy/notes.js +2168 -0
- package/dist/team-cards.js +84 -0
- package/dist/team-orders.js +150 -0
- package/dist/teams.js +19 -0
- package/dist/tools/award.js +206 -0
- package/dist/tools/begin-turn.js +162 -0
- package/dist/tools/board.js +77 -0
- package/dist/tools/card-advice.js +256 -0
- package/dist/tools/card-effects.js +49 -0
- package/dist/tools/card-plays.js +434 -0
- package/dist/tools/card-support-advice.js +140 -0
- package/dist/tools/chat-inbox.js +146 -0
- package/dist/tools/chat.js +483 -0
- package/dist/tools/check-plan.js +688 -0
- package/dist/tools/commander-check.js +102 -0
- package/dist/tools/commitments.js +216 -0
- package/dist/tools/common.js +143 -0
- package/dist/tools/diplomacy.js +342 -0
- package/dist/tools/game.js +126 -0
- package/dist/tools/guess-view.js +56 -0
- package/dist/tools/healthcheck.js +90 -0
- package/dist/tools/hints.js +34 -0
- package/dist/tools/how-lost.js +154 -0
- package/dist/tools/index.js +142 -0
- package/dist/tools/join-game.js +327 -0
- package/dist/tools/leave-game.js +181 -0
- package/dist/tools/live-context.js +339 -0
- package/dist/tools/live.js +404 -0
- package/dist/tools/map-stats.js +117 -0
- package/dist/tools/map.js +133 -0
- package/dist/tools/my-games.js +123 -0
- package/dist/tools/open-games.js +104 -0
- package/dist/tools/opponents.js +151 -0
- package/dist/tools/order-options.js +135 -0
- package/dist/tools/picks.js +292 -0
- package/dist/tools/profile-hook.js +156 -0
- package/dist/tools/profile-opponents.js +121 -0
- package/dist/tools/profile-reads.js +99 -0
- package/dist/tools/push.js +385 -0
- package/dist/tools/relations.js +611 -0
- package/dist/tools/resolve.js +45 -0
- package/dist/tools/route.js +36 -0
- package/dist/tools/scout.js +87 -0
- package/dist/tools/session.js +163 -0
- package/dist/tools/strategy.js +200 -0
- package/dist/tools/stress-opponents.js +83 -0
- package/dist/tools/surrender.js +240 -0
- package/dist/tools/survival.js +189 -0
- package/dist/tools/team-brief.js +266 -0
- package/dist/tools/team-source.js +222 -0
- package/dist/tools/team.js +182 -0
- package/dist/tools/turn.js +2761 -0
- package/dist/tools/uncommit.js +160 -0
- package/dist/tools/where.js +275 -0
- package/dist/tools/write-kit.js +158 -0
- package/dist/transport-bridge.js +33 -0
- package/dist/trend.js +452 -0
- package/dist/version.js +4 -0
- package/manifest.json +174 -4
- package/mint.yaml +101 -14
- package/package.json +11 -6
- package/server.json +40 -3
- package/skills/warapp-api/SKILL.md +95 -4
- package/skills/warapp-api/references/scout.mjs +348 -0
- package/skills/warapp-api/scripts/warapp.sh +69 -8
- package/skills/warapp-mcp/SKILL.md +969 -21
|
@@ -0,0 +1,404 @@
|
|
|
1
|
+
// Live-game tools over the web-client protocol (through the user's signed-in
|
|
2
|
+
// war.app tab): the current board, the player's territory picks, and — gated
|
|
3
|
+
// on the user's confirmation — submitting picks.
|
|
4
|
+
import { CONFIRM_INJECTION_RULE, McpToolError, toolAnnotations } from '@chrischall/mcp-utils';
|
|
5
|
+
import { z } from 'zod';
|
|
6
|
+
import { clientPickLimits } from '../analysis/picks.js';
|
|
7
|
+
import { isTeamGame } from '../teams.js';
|
|
8
|
+
import { parseGameId } from '../client.js';
|
|
9
|
+
import { FOG_LEVEL_NAMES, inGameId, OWNER_NEUTRAL, OWNER_PICKABLE, playersByInGameId, } from '../live.js';
|
|
10
|
+
import { pickingNeutrals, writePickable, writePickList } from '../pick-list.js';
|
|
11
|
+
import { Method, writeSendTerritoryPicksParams } from '../protocol/methods.js';
|
|
12
|
+
import { currentTurn, gameIdArg, namer, readAnnotations, respond, shownAccount, turnsCompleted, UNTRUSTED_PREVIEW_NOTE, untrustedDescription, UNTRUSTED_LIST_MAX, untrustedList, untrustedText, viewArg, } from './common.js';
|
|
13
|
+
import { lookupMeta, mintMeta } from './hints.js';
|
|
14
|
+
import { loadLiveTerritories, loadPicks, requireApprovedAccount, writeAccount } from './live-context.js';
|
|
15
|
+
import { mapOf } from './map.js';
|
|
16
|
+
import { resolvePlayer, resolveTerritory } from './resolve.js';
|
|
17
|
+
import { defineGatedWrite, requireMySeat, sendAndVerify } from './write-kit.js';
|
|
18
|
+
import { resolveTeamsFor } from './team-source.js';
|
|
19
|
+
const VIEWS = ['compact', 'full'];
|
|
20
|
+
const MAX_PICK_ARGS = 200;
|
|
21
|
+
export const BRIDGE_NOTE = 'Reads through your signed-in war.app tab (ContextMint Bridge), so it sees exactly what you see — fog included.';
|
|
22
|
+
export const playerArg = z
|
|
23
|
+
.union([z.string(), z.number()])
|
|
24
|
+
.optional()
|
|
25
|
+
.describe('You in this game: your war.app name (or part of it) or GameFeed player id. Omit to use the signed-in account.');
|
|
26
|
+
/** `player` when given; else the signed-in account (its invite token is its GameFeed id). */
|
|
27
|
+
export async function resolveMe(ctx, players, input, opts = {}) {
|
|
28
|
+
if (input === undefined || String(input).trim() === '') {
|
|
29
|
+
const token = await ctx.myInviteToken(opts);
|
|
30
|
+
const me = token === undefined ? undefined : players.find((p) => p.id === token);
|
|
31
|
+
if (me)
|
|
32
|
+
return me;
|
|
33
|
+
}
|
|
34
|
+
return resolvePlayer(players, input);
|
|
35
|
+
}
|
|
36
|
+
/** A territory's owner as a person reads it. */
|
|
37
|
+
function ownerLabel(t, byInGame) {
|
|
38
|
+
if (t.fogged)
|
|
39
|
+
return 'fogged';
|
|
40
|
+
if (t.owner === OWNER_NEUTRAL)
|
|
41
|
+
return 'neutral';
|
|
42
|
+
if (t.owner === OWNER_PICKABLE)
|
|
43
|
+
return 'pickable';
|
|
44
|
+
if (t.owner > 0)
|
|
45
|
+
return byInGame.get(t.owner)?.name ?? `player ${t.owner}`;
|
|
46
|
+
return 'unknown';
|
|
47
|
+
}
|
|
48
|
+
/** A unit owner's name, as {@link ownerLabel} names a territory's player owner. */
|
|
49
|
+
function playerLabel(id, byInGame) {
|
|
50
|
+
return byInGame.get(id)?.name ?? `player ${id}`;
|
|
51
|
+
}
|
|
52
|
+
/** The commander(s) on a territory, by owner name; `undefined` when there is none. */
|
|
53
|
+
function commanderOn(t, byInGame) {
|
|
54
|
+
const owners = (t.specialUnits ?? []).filter((u) => u.kind === 'commander').map((u) => playerLabel(u.owner, byInGame));
|
|
55
|
+
return owners.length ? owners.join(', ') : undefined;
|
|
56
|
+
}
|
|
57
|
+
const nameIn = (map) => {
|
|
58
|
+
const name = namer(map);
|
|
59
|
+
return (id) => name(id).name;
|
|
60
|
+
};
|
|
61
|
+
/**
|
|
62
|
+
* The most territory picks war.app's client lets a player list (players × territories per
|
|
63
|
+
* player, #129), when the settings say; `pickable` (the live board's count) can lower it.
|
|
64
|
+
*/
|
|
65
|
+
export function maxPicks(game, pickable) {
|
|
66
|
+
return clientPickLimits({ territoryLimit: game.settings?.territoryLimit, players: game.players.length, pickable })?.max ?? null;
|
|
67
|
+
}
|
|
68
|
+
/** The selected territories of `list`, and the page block when paged. */
|
|
69
|
+
function select(list, sel) {
|
|
70
|
+
const matched = list.filter((t) => (sel.ids === undefined || sel.ids.has(t.territoryId)) && (sel.owner === undefined || (!t.fogged && t.owner === sel.owner)));
|
|
71
|
+
if (sel.limit === undefined && sel.offset === undefined)
|
|
72
|
+
return { shown: matched };
|
|
73
|
+
const offset = sel.offset ?? 0;
|
|
74
|
+
const limit = sel.limit ?? matched.length;
|
|
75
|
+
const shown = matched.slice(offset, offset + limit);
|
|
76
|
+
const next = offset + shown.length;
|
|
77
|
+
return { shown, page: { offset, limit, matched: matched.length, nextOffset: next < matched.length ? next : null } };
|
|
78
|
+
}
|
|
79
|
+
function liveBoardView(game, territories, rung, sel = {}) {
|
|
80
|
+
const map = mapOf(game);
|
|
81
|
+
const name = nameIn(map);
|
|
82
|
+
const byInGame = playersByInGameId(game.players);
|
|
83
|
+
const stats = new Map();
|
|
84
|
+
for (const t of territories) {
|
|
85
|
+
if (t.fogged || t.owner <= 0)
|
|
86
|
+
continue;
|
|
87
|
+
const s = stats.get(t.owner) ?? { territories: 0, armies: 0 };
|
|
88
|
+
s.territories++;
|
|
89
|
+
s.armies += t.armies ?? 0;
|
|
90
|
+
stats.set(t.owner, s);
|
|
91
|
+
}
|
|
92
|
+
const header = {
|
|
93
|
+
game: { id: game.id, name: game.name ?? null, state: game.state, turn: currentTurn(game), turnsCompleted: turnsCompleted(game) },
|
|
94
|
+
map: { id: map.id, name: map.name },
|
|
95
|
+
};
|
|
96
|
+
const players = game.players.map((p) => {
|
|
97
|
+
let id = null;
|
|
98
|
+
try {
|
|
99
|
+
id = inGameId(p);
|
|
100
|
+
}
|
|
101
|
+
catch {
|
|
102
|
+
// not a wrapped id
|
|
103
|
+
}
|
|
104
|
+
const s = id === null ? undefined : stats.get(id);
|
|
105
|
+
const row = {
|
|
106
|
+
id: p.id,
|
|
107
|
+
name: p.name,
|
|
108
|
+
visibleTerritories: s?.territories ?? 0,
|
|
109
|
+
visibleArmies: s?.armies ?? 0,
|
|
110
|
+
};
|
|
111
|
+
if (rung === 'full')
|
|
112
|
+
row.inGameId = id;
|
|
113
|
+
return row;
|
|
114
|
+
});
|
|
115
|
+
const pickable = territories.filter((t) => !t.fogged && t.owner === OWNER_PICKABLE).length;
|
|
116
|
+
if (rung === 'full') {
|
|
117
|
+
const { shown, page } = select(territories, sel);
|
|
118
|
+
return {
|
|
119
|
+
...header,
|
|
120
|
+
players,
|
|
121
|
+
...(page ? { page } : {}),
|
|
122
|
+
territories: shown.map((t) => ({
|
|
123
|
+
id: t.territoryId,
|
|
124
|
+
name: name(t.territoryId),
|
|
125
|
+
owner: ownerLabel(t, byInGame),
|
|
126
|
+
ownerId: t.owner,
|
|
127
|
+
armies: t.armies,
|
|
128
|
+
fogged: t.fogged,
|
|
129
|
+
fogLevel: FOG_LEVEL_NAMES[t.fogLevel] ?? t.fogLevel,
|
|
130
|
+
specialUnits: (t.specialUnits ?? []).map((u) => ({
|
|
131
|
+
kind: u.kind,
|
|
132
|
+
...(u.type ? { type: u.type } : {}),
|
|
133
|
+
id: u.id,
|
|
134
|
+
owner: playerLabel(u.owner, byInGame),
|
|
135
|
+
ownerId: u.owner,
|
|
136
|
+
})),
|
|
137
|
+
})),
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
const visible = territories.filter((t) => !t.fogged);
|
|
141
|
+
const { shown, page } = select(visible, sel);
|
|
142
|
+
return {
|
|
143
|
+
...header,
|
|
144
|
+
players,
|
|
145
|
+
...(page ? { page } : {}),
|
|
146
|
+
territories: shown.map((t) => {
|
|
147
|
+
const commander = commanderOn(t, byInGame);
|
|
148
|
+
return {
|
|
149
|
+
id: t.territoryId,
|
|
150
|
+
name: name(t.territoryId),
|
|
151
|
+
owner: ownerLabel(t, byInGame),
|
|
152
|
+
armies: t.armies,
|
|
153
|
+
...(commander ? { commander } : {}),
|
|
154
|
+
};
|
|
155
|
+
}),
|
|
156
|
+
counts: { territories: territories.length, visible: visible.length, fogged: territories.length - visible.length, pickable },
|
|
157
|
+
};
|
|
158
|
+
}
|
|
159
|
+
const FALLBACK_NOTE = "Decoded by a cached copy of war.app's client: the current version could not be looked up (a frozen or " +
|
|
160
|
+
'signed-out tab?). Reload or focus a war.app tab; warapp_session_status shows the decoder.';
|
|
161
|
+
export function registerLiveTools(server, ctx) {
|
|
162
|
+
server.registerTool('warapp_get_live_board', {
|
|
163
|
+
title: 'Get the live board of a war.app game',
|
|
164
|
+
description: untrustedDescription('The current board of a war.app (Warzone) game as the web client shows it: every territory by name with ' +
|
|
165
|
+
'its owner (a player name, "neutral", or "pickable" while territories are being picked), its armies, ' +
|
|
166
|
+
'whether it is fogged and, in a Commanders game, whose commander stands on it (losing your commander ' +
|
|
167
|
+
'eliminates you); plus each player\'s visible territory and army totals. Works in the pick ' +
|
|
168
|
+
'phase and mid-game, where GameFeed has no board. On a large map, narrow it with `owner`, `territories` or ' +
|
|
169
|
+
`\`limit\`/\`offset\` paging (the counts stay whole-board). ${BRIDGE_NOTE} Read-only.`),
|
|
170
|
+
_meta: lookupMeta(['warzone board', 'live board', 'who owns what', 'pickable territories', 'where is my commander']),
|
|
171
|
+
annotations: readAnnotations('Get a war.app live board'),
|
|
172
|
+
inputSchema: z.object({
|
|
173
|
+
game_id: gameIdArg,
|
|
174
|
+
view: viewArg(VIEWS, 'compact (default) lists the territories you can see (owner by name, armies, `commander` naming the owner of ' +
|
|
175
|
+
'a commander standing there) with counts of fogged and pickable ones; "full" lists every territory with raw ' +
|
|
176
|
+
'owner ids, fog flags and fog levels, its special units (commanders, bosses) with owners, and in-game player ids.'),
|
|
177
|
+
owner: z
|
|
178
|
+
.union([z.string(), z.number()])
|
|
179
|
+
.optional()
|
|
180
|
+
.describe('Only territories owned by: "me", "neutral", "pickable", or a player (name or GameFeed id).'),
|
|
181
|
+
territories: z
|
|
182
|
+
.array(z.union([z.string(), z.number()]))
|
|
183
|
+
.min(1)
|
|
184
|
+
.max(MAX_PICK_ARGS)
|
|
185
|
+
.optional()
|
|
186
|
+
.describe('Only these territories (ids or names).'),
|
|
187
|
+
limit: z.coerce.number().int().min(1).max(5000).optional().describe('Page size; omit for every match.'),
|
|
188
|
+
offset: z.coerce.number().int().min(0).optional().describe('Skip this many matches (from a previous `page.nextOffset`).'),
|
|
189
|
+
}),
|
|
190
|
+
}, async ({ game_id, view, owner, territories: only, limit, offset }) => {
|
|
191
|
+
const game = await ctx.client.getGame(game_id, { settings: true });
|
|
192
|
+
const sel = {
|
|
193
|
+
...(limit !== undefined ? { limit } : {}),
|
|
194
|
+
...(offset !== undefined ? { offset } : {}),
|
|
195
|
+
};
|
|
196
|
+
if (only)
|
|
197
|
+
sel.ids = new Set(only.map((t) => resolveTerritory(mapOf(game), t).id));
|
|
198
|
+
if (owner !== undefined && String(owner).trim() !== '') {
|
|
199
|
+
const o = String(owner).trim().toLowerCase();
|
|
200
|
+
sel.owner =
|
|
201
|
+
o === 'neutral'
|
|
202
|
+
? OWNER_NEUTRAL
|
|
203
|
+
: o === 'pickable'
|
|
204
|
+
? OWNER_PICKABLE
|
|
205
|
+
: inGameId(await resolveMe(ctx, game.players, o === 'me' ? undefined : owner));
|
|
206
|
+
}
|
|
207
|
+
const territories = await loadLiveTerritories(ctx, game);
|
|
208
|
+
const decoder = ctx.decoderReport();
|
|
209
|
+
return respond(view, VIEWS, (rung) => {
|
|
210
|
+
const out = liveBoardView(game, territories, rung, sel);
|
|
211
|
+
// What the decoding rests on (#148): always on full; on compact only when a stand-in decoded it.
|
|
212
|
+
if (!decoder || (rung !== 'full' && !decoder.fallback))
|
|
213
|
+
return out;
|
|
214
|
+
return {
|
|
215
|
+
...out,
|
|
216
|
+
decoder: rung === 'full'
|
|
217
|
+
? decoder
|
|
218
|
+
: { bundleVersion: decoder.bundleVersion, fallback: true, note: FALLBACK_NOTE },
|
|
219
|
+
};
|
|
220
|
+
});
|
|
221
|
+
});
|
|
222
|
+
server.registerTool('warapp_get_my_picks', {
|
|
223
|
+
title: 'Get my territory picks in a war.app game',
|
|
224
|
+
description: untrustedDescription('The territory picks you have submitted for a war.app (Warzone) game in manual distribution, in priority ' +
|
|
225
|
+
"order and by name, with the most war.app's client lets a player list (players × the territory limit). " +
|
|
226
|
+
`${BRIDGE_NOTE} Read-only; use warapp_submit_picks to change them.`),
|
|
227
|
+
_meta: lookupMeta(['my picks', 'territory picks', 'what did i pick']),
|
|
228
|
+
annotations: readAnnotations('Get my war.app picks'),
|
|
229
|
+
inputSchema: z.object({ game_id: gameIdArg, player: playerArg }),
|
|
230
|
+
}, async ({ game_id, player }) => {
|
|
231
|
+
const game = await ctx.client.getGame(game_id, { settings: true });
|
|
232
|
+
const me = await resolveMe(ctx, game.players, player);
|
|
233
|
+
const picks = await loadPicks(ctx, game.id, inGameId(me));
|
|
234
|
+
// Kept while territories are being distributed, so the award can be read from it later (#166):
|
|
235
|
+
// only for the signed-in account (no `player` given), the one war.app answers for.
|
|
236
|
+
if (ctx.dataDir && player === undefined && game.state === 'DistributingTerritories' && picks.length)
|
|
237
|
+
await writePickList(ctx.dataDir, game.id, me.id, picks);
|
|
238
|
+
const name = nameIn(mapOf(game));
|
|
239
|
+
return respond(undefined, ['compact'], () => ({
|
|
240
|
+
game: { id: game.id, state: game.state },
|
|
241
|
+
player: { id: me.id, name: me.name },
|
|
242
|
+
picks: picks.map((id, i) => ({ priority: i + 1, id, name: name(id) })),
|
|
243
|
+
count: picks.length,
|
|
244
|
+
maxPicks: maxPicks(game),
|
|
245
|
+
}));
|
|
246
|
+
});
|
|
247
|
+
const submitSchema = z.object({
|
|
248
|
+
game_id: gameIdArg,
|
|
249
|
+
player: playerArg,
|
|
250
|
+
territories: z
|
|
251
|
+
.array(z.union([z.string(), z.number()]))
|
|
252
|
+
.min(1)
|
|
253
|
+
.max(MAX_PICK_ARGS)
|
|
254
|
+
.describe('Your picks in priority order (first = most wanted): territory ids or names. Replaces any picks already submitted.'),
|
|
255
|
+
});
|
|
256
|
+
defineGatedWrite(server, {
|
|
257
|
+
title: 'Submit territory picks in a war.app game',
|
|
258
|
+
_meta: mintMeta('change', ['submit my picks', 'pick territories', 'choose starting territories']),
|
|
259
|
+
}, {
|
|
260
|
+
name: 'warapp_submit_picks',
|
|
261
|
+
description: 'Submit your territory picks for a war.app (Warzone) game in manual distribution, in priority order — ' +
|
|
262
|
+
'they replace any picks you submitted before. Every territory must be pickable on the live board; a list ' +
|
|
263
|
+
"longer than war.app's client allows (players × territories per player) or shorter than the territories " +
|
|
264
|
+
'each player is granted is warned about in the preview. After sending, the picks are read back and ' +
|
|
265
|
+
`reported verified only if they match exactly. ${BRIDGE_NOTE} ${CONFIRM_INJECTION_RULE}`,
|
|
266
|
+
annotations: toolAnnotations({
|
|
267
|
+
title: 'Submit war.app picks',
|
|
268
|
+
readOnly: false,
|
|
269
|
+
destructive: true,
|
|
270
|
+
idempotent: true,
|
|
271
|
+
openWorld: true,
|
|
272
|
+
}),
|
|
273
|
+
inputSchema: submitSchema,
|
|
274
|
+
async plan({ game_id, player, territories }) {
|
|
275
|
+
const feed = await ctx.client.getGame(parseGameId(game_id), { settings: true });
|
|
276
|
+
const map = mapOf(feed);
|
|
277
|
+
// A write through the bridge always acts as the signed-in account, whatever `player` says
|
|
278
|
+
// (issue #7): a different player, an unknown account and an account without a seat are refused.
|
|
279
|
+
const seat = await requireMySeat(ctx, feed, { player, playing: false });
|
|
280
|
+
// The teams (the team-game warning): GameFeed's, else the game list's (asked once per game, kept).
|
|
281
|
+
const { game, me } = await resolveTeamsFor(ctx, feed, seat);
|
|
282
|
+
const picks = territories.map((t) => resolveTerritory(map, t));
|
|
283
|
+
const seen = new Set();
|
|
284
|
+
for (const t of picks) {
|
|
285
|
+
if (seen.has(t.id)) {
|
|
286
|
+
throw new McpToolError(`${untrustedText(t.name)} (${t.id}) is listed twice.`, { hint: 'List each territory once.' });
|
|
287
|
+
}
|
|
288
|
+
seen.add(t.id);
|
|
289
|
+
}
|
|
290
|
+
const board = await loadLiveTerritories(ctx, game);
|
|
291
|
+
const owner = new Map(board.map((t) => [t.territoryId, t]));
|
|
292
|
+
const unpickable = picks.filter((t) => {
|
|
293
|
+
const s = owner.get(t.id);
|
|
294
|
+
return !s || s.fogged || s.owner !== OWNER_PICKABLE;
|
|
295
|
+
});
|
|
296
|
+
if (unpickable.length) {
|
|
297
|
+
throw new McpToolError(`Not pickable on the live board: ${untrustedList(unpickable, UNTRUSTED_LIST_MAX, (t) => `${untrustedText(t.name)} (${t.id})`)}.`, {
|
|
298
|
+
hint: game.state === 'DistributingTerritories'
|
|
299
|
+
? 'Pick only territories warapp_get_live_board lists as "pickable".'
|
|
300
|
+
: `Picks are only open while the game distributes territories (game state: ${game.state}).`,
|
|
301
|
+
});
|
|
302
|
+
}
|
|
303
|
+
// The list's length is checked against the client's own bounds (#129) as a warning:
|
|
304
|
+
// its picking UI stops at the maximum, and its validation rejects a list shorter
|
|
305
|
+
// than the minimum, but neither is verified against the server.
|
|
306
|
+
const pickable = board.filter((t) => !t.fogged && t.owner === OWNER_PICKABLE).map((t) => t.territoryId);
|
|
307
|
+
const pickableCount = pickable.length;
|
|
308
|
+
// Kept for the turns to come: where a player could have started (warapp_locate_opponents).
|
|
309
|
+
// #201: with the picking board's neutrals, so a fogged one keeps its size later.
|
|
310
|
+
if (ctx.dataDir)
|
|
311
|
+
await writePickable(ctx.dataDir, game.id, me.id, pickable, pickingNeutrals(board));
|
|
312
|
+
const bounds = clientPickLimits({
|
|
313
|
+
territoryLimit: game.settings?.territoryLimit,
|
|
314
|
+
players: game.players.length,
|
|
315
|
+
pickable: pickableCount,
|
|
316
|
+
});
|
|
317
|
+
const lengthWarnings = [];
|
|
318
|
+
if (bounds && picks.length > bounds.max)
|
|
319
|
+
lengthWarnings.push(`war.app's client lets a player list at most ${bounds.max} picks here (${game.players.length} players × ${bounds.perPlayer} territories each); got ${picks.length}. The extra picks may be ignored.`);
|
|
320
|
+
// A team game (C2): my list and my teammate's are not agreed, so a pick we both list goes to one of
|
|
321
|
+
// us; a list as long as the client allows (starts × all players) is the one that cannot run out.
|
|
322
|
+
if (bounds && isTeamGame(game.players) && picks.length < bounds.max)
|
|
323
|
+
lengthWarnings.push(`In a team game your list and your teammate's are not agreed: a pick you both list goes to one of you. ` +
|
|
324
|
+
`A list of ${bounds.max} picks (${game.players.length} players × ${bounds.perPlayer} each) cannot run out; got ${picks.length}. ` +
|
|
325
|
+
"A shorter list is safe only when no teammate lists any of its picks (warapp_plan_picks shortens it only then).");
|
|
326
|
+
if (bounds && picks.length < bounds.min)
|
|
327
|
+
lengthWarnings.push(`war.app expects at least ${bounds.min} picks here (the territories each player is granted); got ${picks.length}, which it may reject.`);
|
|
328
|
+
const playerId = inGameId(me);
|
|
329
|
+
const territoryIds = picks.map((t) => t.id);
|
|
330
|
+
const named = picks.map((t) => ({ id: t.id, name: t.name }));
|
|
331
|
+
return {
|
|
332
|
+
gate: {
|
|
333
|
+
action: 'warapp.submit_picks',
|
|
334
|
+
// By id only: player and territory names are other people's words and go,
|
|
335
|
+
// delimited, in labelled fields.
|
|
336
|
+
summary: `Submit ${picks.length} territory pick${picks.length === 1 ? '' : 's'} for player ${me.id} in game ${game.id}`,
|
|
337
|
+
account: writeAccount(me.id),
|
|
338
|
+
target: game.id,
|
|
339
|
+
payload: { method: 'SendTerritoryPicks', gameId: game.id, playerId, territoryIds },
|
|
340
|
+
willSend: {
|
|
341
|
+
game: game.id,
|
|
342
|
+
player: untrustedText(me.name),
|
|
343
|
+
picksInPriorityOrder: named.map((t) => ({ id: t.id, name: untrustedText(t.name) })),
|
|
344
|
+
},
|
|
345
|
+
preview: {
|
|
346
|
+
account: shownAccount(me.name, me.id),
|
|
347
|
+
note: 'Replaces any picks already submitted for this game.',
|
|
348
|
+
untrusted: UNTRUSTED_PREVIEW_NOTE,
|
|
349
|
+
...(lengthWarnings.length ? { warnings: lengthWarnings } : {}),
|
|
350
|
+
},
|
|
351
|
+
},
|
|
352
|
+
state: { gameId: game.id, playerId, picks: named, me: me.id },
|
|
353
|
+
};
|
|
354
|
+
},
|
|
355
|
+
async execute({ gameId, playerId, picks, me }) {
|
|
356
|
+
await requireApprovedAccount(ctx, writeAccount(me));
|
|
357
|
+
const ids = picks.map((p) => p.id);
|
|
358
|
+
const base = { game: gameId, picks };
|
|
359
|
+
return sendAndVerify({
|
|
360
|
+
send: async () => {
|
|
361
|
+
await ctx.rpc.call('SendTerritoryPicks', Method.SendTerritoryPicks, (w) => writeSendTerritoryPicksParams(w, gameId, ids));
|
|
362
|
+
},
|
|
363
|
+
unanswered: (failure) => ({
|
|
364
|
+
status: 'unknown',
|
|
365
|
+
outcome: 'unknown',
|
|
366
|
+
verified: false,
|
|
367
|
+
...base,
|
|
368
|
+
readBack: null,
|
|
369
|
+
warning: `war.app did not confirm the picks (${failure}), so they may already have been saved. ` +
|
|
370
|
+
'Check warapp_get_my_picks before resubmitting.',
|
|
371
|
+
}),
|
|
372
|
+
readBack: () => loadPicks(ctx, gameId, playerId),
|
|
373
|
+
// The send went through: a failed read-back must not hide that (#130).
|
|
374
|
+
unreadable: (failure) => ({
|
|
375
|
+
status: 'unconfirmed',
|
|
376
|
+
outcome: 'unconfirmed',
|
|
377
|
+
sent: true,
|
|
378
|
+
verified: false,
|
|
379
|
+
...base,
|
|
380
|
+
readBack: null,
|
|
381
|
+
readBackError: failure,
|
|
382
|
+
warning: 'war.app accepted the picks, but reading them back failed. Check warapp_get_my_picks before resubmitting.',
|
|
383
|
+
}),
|
|
384
|
+
classify: async (readBack) => {
|
|
385
|
+
// What war.app holds is the list the award will use: kept to read the award from (#166).
|
|
386
|
+
if (ctx.dataDir && readBack.length)
|
|
387
|
+
await writePickList(ctx.dataDir, gameId, me, readBack);
|
|
388
|
+
const verified = readBack.length === ids.length && readBack.every((id, i) => id === ids[i]);
|
|
389
|
+
return verified
|
|
390
|
+
? { status: 'verified', outcome: 'confirmed', sent: true, verified, ...base, readBack }
|
|
391
|
+
: {
|
|
392
|
+
status: 'unconfirmed',
|
|
393
|
+
outcome: 'unconfirmed',
|
|
394
|
+
sent: true,
|
|
395
|
+
verified,
|
|
396
|
+
...base,
|
|
397
|
+
readBack,
|
|
398
|
+
warning: 'war.app did not read back exactly these picks. Check warapp_get_my_picks before resubmitting.',
|
|
399
|
+
};
|
|
400
|
+
},
|
|
401
|
+
});
|
|
402
|
+
},
|
|
403
|
+
});
|
|
404
|
+
}
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
// warapp_map_stats: what has worked on a map, learned from finished ladder
|
|
2
|
+
// games — OPT-IN (WARAPP_STATS=1) and never on a hosted server. See
|
|
3
|
+
// src/stats.ts (collection, throttle, cache) and src/map-stats.ts (the pure
|
|
4
|
+
// aggregation).
|
|
5
|
+
import { McpToolError } from '@chrischall/mcp-utils';
|
|
6
|
+
import { z } from 'zod';
|
|
7
|
+
import { MIN_RATE_SAMPLE, MIN_SAMPLE, mapStats } from '../map-stats.js';
|
|
8
|
+
import { DEFAULT_NEW_GAMES, MAX_NEW_GAMES, STATS_ENV, statsGate } from '../stats.js';
|
|
9
|
+
import { readAnnotations, respond, untrustedDescription } from './common.js';
|
|
10
|
+
import { lookupMeta } from './hints.js';
|
|
11
|
+
function refusal(gate) {
|
|
12
|
+
if (gate.reason === 'hosted') {
|
|
13
|
+
return new McpToolError('Map statistics are off on a hosted server.', {
|
|
14
|
+
hint: 'They make many war.app requests and keep a cache on disk, so they run only on a local install with ' +
|
|
15
|
+
`${STATS_ENV}=1 set. Use warapp_get_map for the map's bonuses meanwhile.`,
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
return new McpToolError('Map statistics are off (opt-in).', {
|
|
19
|
+
hint: `Set ${STATS_ENV}=1 in this server's environment (or its .env file) on a local install and restart it. ` +
|
|
20
|
+
`Each call then fetches up to ${DEFAULT_NEW_GAMES} new finished ladder games (at most ${MAX_NEW_GAMES}), ` +
|
|
21
|
+
'one request a second, and caches them forever.',
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
/** Attach territory and bonus names when the map is known (cached this process). */
|
|
25
|
+
function named(stats, map) {
|
|
26
|
+
const territory = new Map(map?.territories.map((t) => [t.id, t.name]));
|
|
27
|
+
const bonus = new Map(map?.bonuses.map((b) => [b.id, b.name]));
|
|
28
|
+
return {
|
|
29
|
+
...stats,
|
|
30
|
+
mostPicked: stats.mostPicked.map(({ territoryId, ...rest }) => ({
|
|
31
|
+
territoryId,
|
|
32
|
+
...(territory.has(territoryId) ? { name: territory.get(territoryId) } : {}),
|
|
33
|
+
...rest,
|
|
34
|
+
})),
|
|
35
|
+
winRateByStartingBonus: stats.winRateByStartingBonus.map(({ bonusId, ...rest }) => ({
|
|
36
|
+
bonusId,
|
|
37
|
+
...(bonus.has(bonusId) ? { name: bonus.get(bonusId) } : {}),
|
|
38
|
+
...rest,
|
|
39
|
+
})),
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
export function registerMapStatsTool(server, deps) {
|
|
43
|
+
server.registerTool('warapp_map_stats', {
|
|
44
|
+
title: 'war.app map statistics',
|
|
45
|
+
description: untrustedDescription('Statistics for a war.app (Warzone) map learned from finished ladder games: the most-picked starting ' +
|
|
46
|
+
'territories (and how often their pickers won), the win rate by every bonus a player started in, the ' +
|
|
47
|
+
'turn of each player’s first bonus completion, and the sample size — a sample under ' +
|
|
48
|
+
`${MIN_SAMPLE} games and a bonus rate under ${MIN_RATE_SAMPLE} players are flagged, and games whose history ` +
|
|
49
|
+
'could not be read are counted apart, never cached. Each call reads the ladder’s game-ID feed and fetches up to ' +
|
|
50
|
+
`max_new_games new games (default ${DEFAULT_NEW_GAMES}, max ${MAX_NEW_GAMES}, one request a second); ` +
|
|
51
|
+
'finished games are cached forever, so stats grow across calls. OPT-IN: off unless the server runs ' +
|
|
52
|
+
`locally with ${STATS_ENV}=1, and always off when hosted. Read-only.`),
|
|
53
|
+
_meta: lookupMeta(['map stats', 'best starting picks', 'ladder statistics', 'which bonus wins']),
|
|
54
|
+
annotations: readAnnotations('war.app map statistics'),
|
|
55
|
+
inputSchema: z.object({
|
|
56
|
+
map_id: z.number().int().positive().describe('The map id (warapp_get_game names it under settings.mapId).'),
|
|
57
|
+
ladder_id: z
|
|
58
|
+
.number()
|
|
59
|
+
.int()
|
|
60
|
+
.min(0)
|
|
61
|
+
.optional()
|
|
62
|
+
.describe('The ladder whose games to learn from: 1v1 is 0 (default), 2v2 is 1, 3v3 is 4.'),
|
|
63
|
+
max_new_games: z
|
|
64
|
+
.number()
|
|
65
|
+
.int()
|
|
66
|
+
.min(0)
|
|
67
|
+
.max(MAX_NEW_GAMES)
|
|
68
|
+
.optional()
|
|
69
|
+
.describe(`New games to fetch this call (default ${DEFAULT_NEW_GAMES}, max ${MAX_NEW_GAMES}); 0 reads the cache only.`),
|
|
70
|
+
}),
|
|
71
|
+
}, async ({ map_id, ladder_id, max_new_games }) => {
|
|
72
|
+
const gate = statsGate(deps.env);
|
|
73
|
+
if (!gate.enabled)
|
|
74
|
+
throw refusal(gate);
|
|
75
|
+
const ladderId = ladder_id ?? 0;
|
|
76
|
+
// 0 reads the cache only: no feed request, so no throttle either.
|
|
77
|
+
let collected = { ladderId, cacheOnly: true };
|
|
78
|
+
let warning;
|
|
79
|
+
let feedError;
|
|
80
|
+
if (max_new_games !== 0) {
|
|
81
|
+
try {
|
|
82
|
+
collected = await deps.collector.collect(ladderId, max_new_games ?? DEFAULT_NEW_GAMES);
|
|
83
|
+
}
|
|
84
|
+
catch (e) {
|
|
85
|
+
collected = undefined;
|
|
86
|
+
feedError = e;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
const records = await deps.collector.records(map_id);
|
|
90
|
+
if (feedError !== undefined) {
|
|
91
|
+
// The feed failed: the cache can still answer; with nothing cached the error stands.
|
|
92
|
+
if (records.length === 0)
|
|
93
|
+
throw feedError;
|
|
94
|
+
const why = feedError instanceof Error ? feedError.message : String(feedError);
|
|
95
|
+
warning = `The game-ID feed failed (${why}), so no new games were collected; these stats are from the cache.`;
|
|
96
|
+
}
|
|
97
|
+
const [stats] = mapStats(records);
|
|
98
|
+
const map = deps.mapCache.get(map_id);
|
|
99
|
+
return respond(undefined, ['compact'], () => ({
|
|
100
|
+
map: map ? { id: map.id, name: map.name } : { id: map_id },
|
|
101
|
+
...(collected ? { collected } : {}),
|
|
102
|
+
...(warning ? { warning } : {}),
|
|
103
|
+
...(stats
|
|
104
|
+
? { stats: named(stats, map) }
|
|
105
|
+
: {
|
|
106
|
+
message: `No finished games on map ${map_id} are cached yet. Ladder games use many maps: call again to ` +
|
|
107
|
+
'collect more, or try the ladder this map is played on.',
|
|
108
|
+
}),
|
|
109
|
+
assumptions: 'Starting territories are read from the first history board where players hold land (a game with no ' +
|
|
110
|
+
'such board is left out of every figure and never cached; `collected.unreadable` says how many this call skipped, ' +
|
|
111
|
+
'across the ladder), a player counts toward every bonus holding one ' +
|
|
112
|
+
'of its starts, and a bonus ' +
|
|
113
|
+
'turn is the history entry (completed turns) on which a player first held a whole positive bonus. ' +
|
|
114
|
+
'The game-ID feed and history shapes are unverified (docs/WARAPP-API.md).',
|
|
115
|
+
}));
|
|
116
|
+
});
|
|
117
|
+
}
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
import { McpToolError } from '@chrischall/mcp-utils';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
import { analyzeBonuses, applyBonusOverrides, findChokepoints } from '../analysis/index.js';
|
|
4
|
+
import { gameIdArg, graphOf, mapSummary, readAnnotations, respond, round2, untrustedDescription, untrustedText, viewArg } from './common.js';
|
|
5
|
+
import { lookupMeta } from './hints.js';
|
|
6
|
+
const VIEWS = ['compact', 'full'];
|
|
7
|
+
const DEFAULT_LIMIT = 25;
|
|
8
|
+
const COMPACT_CHOKEPOINTS = 20;
|
|
9
|
+
const SORTS = {
|
|
10
|
+
easiest: (a, b) => b.score - a.score || b.value - a.value || a.territoryIds.length - b.territoryIds.length || a.bonusId - b.bonusId,
|
|
11
|
+
value: (a, b) => b.value - a.value || b.score - a.score || a.bonusId - b.bonusId,
|
|
12
|
+
name: (a, b) => a.name.localeCompare(b.name) || a.bonusId - b.bonusId,
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* The game's map with the game's bonus values (its `OverriddenBonuses` applied —
|
|
16
|
+
* load the game with `settings: true`), or a clear error when the feed did not send one.
|
|
17
|
+
*/
|
|
18
|
+
export function mapOf(game) {
|
|
19
|
+
if (game.map)
|
|
20
|
+
return applyBonusOverrides(game.map, game.settings);
|
|
21
|
+
throw new McpToolError(`war.app sent no map for game ${game.id}.`, {
|
|
22
|
+
hint: 'Try again in a moment; if it persists the game may not have a map assigned yet.',
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
const named = (g, ids) => ids.map((id) => ({ id, name: g.territoryById.get(id)?.name ?? String(id) }));
|
|
26
|
+
const row = (b) => ({
|
|
27
|
+
bonusId: b.bonusId,
|
|
28
|
+
name: b.name,
|
|
29
|
+
value: b.value,
|
|
30
|
+
territories: b.territoryIds.length,
|
|
31
|
+
borders: b.borderTerritoryIds.length,
|
|
32
|
+
entryPoints: b.entryPointIds.length,
|
|
33
|
+
valuePerTerritory: round2(b.valuePerTerritory),
|
|
34
|
+
score: round2(b.score),
|
|
35
|
+
});
|
|
36
|
+
function detail(g, b) {
|
|
37
|
+
const out = {
|
|
38
|
+
bonusId: b.bonusId,
|
|
39
|
+
name: b.name,
|
|
40
|
+
value: b.value,
|
|
41
|
+
territories: named(g, b.territoryIds),
|
|
42
|
+
borders: named(g, b.borderTerritoryIds),
|
|
43
|
+
entryPoints: named(g, b.entryPointIds),
|
|
44
|
+
valuePerTerritory: round2(b.valuePerTerritory),
|
|
45
|
+
valuePerBorder: round2(b.valuePerBorder),
|
|
46
|
+
score: round2(b.score),
|
|
47
|
+
};
|
|
48
|
+
if (b.isSuperbonus) {
|
|
49
|
+
out.memberBonuses = b.memberBonusIds.map((id) => ({ id, name: g.bonusById.get(id)?.name ?? String(id) }));
|
|
50
|
+
}
|
|
51
|
+
return out;
|
|
52
|
+
}
|
|
53
|
+
function chokepoints(g, limit) {
|
|
54
|
+
const all = findChokepoints(g);
|
|
55
|
+
const bonusName = (id) => (id === null ? null : (g.bonusById.get(id)?.name ?? String(id)));
|
|
56
|
+
return (limit === undefined ? all : all.slice(0, limit)).map((c) => ({
|
|
57
|
+
territoryId: c.territoryId,
|
|
58
|
+
name: c.name,
|
|
59
|
+
degree: c.degree,
|
|
60
|
+
reasons: c.reasons,
|
|
61
|
+
bonus: bonusName(c.bonusId),
|
|
62
|
+
connects: c.connectsBonusIds.map((id) => bonusName(id)),
|
|
63
|
+
}));
|
|
64
|
+
}
|
|
65
|
+
export function registerMapTool(server, client) {
|
|
66
|
+
server.registerTool('warapp_get_map', {
|
|
67
|
+
title: 'Get a war.app game map: bonuses and chokepoints',
|
|
68
|
+
description: untrustedDescription('Analyze the map of a war.app (Warzone) game: a bonus table ranked easiest-to-take first (army value, ' +
|
|
69
|
+
'territory count, border territories to defend, entry points, value per territory, ease score) and the ' +
|
|
70
|
+
'map\'s chokepoints (articulation points, bridges between regions, narrow connectors). Filter with ' +
|
|
71
|
+
'`bonus` (part of a bonus name) to see one bonus\'s territories, borders and entry points by name. ' +
|
|
72
|
+
'Map-only — needs no board, so it works in a lobby. Read-only.'),
|
|
73
|
+
_meta: lookupMeta(['warzone map', 'best bonuses', 'easiest bonus', 'chokepoints']),
|
|
74
|
+
annotations: readAnnotations('Get a war.app map'),
|
|
75
|
+
inputSchema: z.object({
|
|
76
|
+
game_id: gameIdArg,
|
|
77
|
+
bonus: z.string().optional().describe('Only bonuses whose name contains this (case-insensitive); rows list member territories by name.'),
|
|
78
|
+
sort: z
|
|
79
|
+
.enum(['easiest', 'value', 'name'])
|
|
80
|
+
.optional()
|
|
81
|
+
.describe('Bonus order: "easiest" (default — ease score = value / (territories + borders)), "value", or "name".'),
|
|
82
|
+
limit: z.coerce.number().int().min(1).max(1000).optional().describe(`Max bonus rows (default ${DEFAULT_LIMIT} on compact; all on full).`),
|
|
83
|
+
view: viewArg(VIEWS, `compact (default) keeps positive-value bonuses as one-line rows (counts, value per territory, score) and the top ${COMPACT_CHOKEPOINTS} chokepoints; ` +
|
|
84
|
+
'"full" lists every bonus (zero and negative included) with member, border and entry-point territories by name, and every chokepoint.'),
|
|
85
|
+
}),
|
|
86
|
+
}, async ({ game_id, bonus, sort, limit, view }) => {
|
|
87
|
+
// Settings carry the game's overridden bonus values, which the bonus table reports.
|
|
88
|
+
const game = await client.getGame(game_id, { settings: true });
|
|
89
|
+
const map = mapOf(game);
|
|
90
|
+
const g = graphOf(map);
|
|
91
|
+
const order = SORTS[sort ?? 'easiest'];
|
|
92
|
+
return respond(view, VIEWS, (rung) => {
|
|
93
|
+
const all = analyzeBonuses(g);
|
|
94
|
+
if (bonus?.trim()) {
|
|
95
|
+
const q = bonus.trim().toLowerCase();
|
|
96
|
+
const hits = all.filter((b) => b.name.toLowerCase().includes(q)).sort(order);
|
|
97
|
+
if (!hits.length) {
|
|
98
|
+
// The map name is map-maker text: delimited, since errors sit outside the untrusted envelope.
|
|
99
|
+
throw new McpToolError(`No bonus on map ${map.id} (${untrustedText(map.name)}) matches ${JSON.stringify(bonus)}.`, {
|
|
100
|
+
hint: 'Use part of the bonus name as the game spells it, or omit `bonus` to list the ranked table.',
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
const shown = hits.slice(0, limit ?? DEFAULT_LIMIT);
|
|
104
|
+
return { map: mapSummary(map), bonuses: shown.map((b) => detail(g, b)), bonusesShown: `${shown.length} of ${hits.length}` };
|
|
105
|
+
}
|
|
106
|
+
if (rung === 'full') {
|
|
107
|
+
const sorted = all.sort(order);
|
|
108
|
+
const shown = limit === undefined ? sorted : sorted.slice(0, limit);
|
|
109
|
+
return {
|
|
110
|
+
map: mapSummary(map),
|
|
111
|
+
bonuses: shown.map((b) => detail(g, b)),
|
|
112
|
+
bonusesShown: `${shown.length} of ${sorted.length}`,
|
|
113
|
+
chokepoints: chokepoints(g),
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
const positive = all.filter((b) => b.value >= 1).sort(order);
|
|
117
|
+
const shown = positive.slice(0, limit ?? DEFAULT_LIMIT);
|
|
118
|
+
const hidden = all.length - positive.length;
|
|
119
|
+
return {
|
|
120
|
+
map: mapSummary(map),
|
|
121
|
+
bonuses: shown.map(row),
|
|
122
|
+
bonusesShown: `${shown.length} of ${positive.length}`,
|
|
123
|
+
// #70: say what compact leaves out (the turn planner always counts every bonus).
|
|
124
|
+
...(hidden
|
|
125
|
+
? {
|
|
126
|
+
bonusesHidden: `${hidden} zero- or negative-value bonuses not listed (view "full" or a \`bonus\` filter shows them; the turn planner counts every bonus)`,
|
|
127
|
+
}
|
|
128
|
+
: {}),
|
|
129
|
+
chokepoints: chokepoints(g, COMPACT_CHOKEPOINTS),
|
|
130
|
+
};
|
|
131
|
+
});
|
|
132
|
+
});
|
|
133
|
+
}
|