@chrischall/warapp-mcp 0.13.1 → 0.14.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 +2 -2
- package/.claude-plugin/plugin.json +1 -1
- package/README.md +7 -6
- package/dist/analysis/airlift-plan.js +288 -0
- package/dist/analysis/blockade-plan.js +178 -0
- package/dist/analysis/bomb-plan.js +72 -0
- package/dist/analysis/card-threats.js +10 -9
- package/dist/analysis/cards-in-effect.js +20 -0
- package/dist/analysis/combat.js +5 -0
- package/dist/analysis/coordination.js +47 -0
- package/dist/analysis/lookahead.js +4 -0
- package/dist/analysis/plan/relations.js +57 -8
- package/dist/analysis/player-record.js +1 -0
- package/dist/analysis/relations.js +40 -0
- package/dist/analysis/stress.js +42 -2
- package/dist/analysis/turn-sim.js +62 -0
- package/dist/bundle.js +23219 -21662
- package/dist/card-state.js +157 -0
- package/dist/local-time.js +142 -0
- package/dist/relations-store.js +30 -5
- package/dist/tools/airlift-readback.js +87 -0
- package/dist/tools/alternative-orders.js +21 -0
- package/dist/tools/begin-turn.js +19 -5
- package/dist/tools/card-advice.js +5 -4
- package/dist/tools/card-plays.js +32 -20
- package/dist/tools/card-state-view.js +26 -0
- package/dist/tools/card-support-advice.js +25 -8
- package/dist/tools/chat-inbox.js +1 -1
- package/dist/tools/chat.js +1 -1
- package/dist/tools/check-plan.js +90 -8
- package/dist/tools/game.js +11 -2
- package/dist/tools/index.js +7 -1
- package/dist/tools/notifications.js +1 -1
- package/dist/tools/player-card-readback.js +45 -0
- package/dist/tools/relations.js +146 -14
- package/dist/tools/sanctions-played.js +51 -0
- package/dist/tools/turn.js +479 -13
- package/dist/version.js +1 -1
- package/manifest.json +9 -2
- package/mint.yaml +7 -0
- package/package.json +1 -1
- package/server.json +8 -2
package/dist/tools/card-plays.js
CHANGED
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
import { McpToolError } from '@chrischall/mcp-utils';
|
|
9
9
|
import { inGameId } from '../live.js';
|
|
10
10
|
import { untrustedText } from './common.js';
|
|
11
|
+
import { percentText, sanctionsSettings } from '../analysis/cards-in-effect.js';
|
|
11
12
|
import { resolveBonus, resolvePlayer, resolveTerritory } from './resolve.js';
|
|
12
13
|
/** The fields each card takes; every one is required except an Airlift's `commander`. */
|
|
13
14
|
const TAKES = {
|
|
@@ -36,7 +37,7 @@ const FIELD_HELP = {
|
|
|
36
37
|
Bomb: "`target`: a territory next to one of yours, not yours or a teammate's (its armies are halved)",
|
|
37
38
|
Reconnaissance: '`target`: the territory to see',
|
|
38
39
|
Spy: "`player`: the player whose territories to see (0 or \"neutral\": the neutral, when the game's Spy card allows it)",
|
|
39
|
-
Sanctions: "`player`: the player whose income it
|
|
40
|
+
Sanctions: "`player`: the player whose income it changes — an opponent when the game's percentage is positive (a cut), yourself or a teammate when it is negative (a boost)",
|
|
40
41
|
Gift: '`target`: your territory to give, and `player`: who receives it',
|
|
41
42
|
Diplomacy: '`players`: the two players who may not attack each other (usually you and one opponent)',
|
|
42
43
|
Surveillance: '`bonus`: the bonus to see',
|
|
@@ -156,14 +157,6 @@ function canSpyOnNeutral(settings) {
|
|
|
156
157
|
const v = raw.CanSpyOnNeutral;
|
|
157
158
|
return v === true || (typeof v === 'string' && v.toLowerCase() === 'true');
|
|
158
159
|
}
|
|
159
|
-
/** The Sanctions percentage (`SanctionsCard.Percentage`), when the settings carry one. */
|
|
160
|
-
function sanctionsPercentage(settings) {
|
|
161
|
-
const raw = settings?.raw.SanctionsCard;
|
|
162
|
-
if (typeof raw !== 'object' || raw === null)
|
|
163
|
-
return undefined;
|
|
164
|
-
const pct = raw.Percentage;
|
|
165
|
-
return typeof pct === 'number' ? pct : undefined;
|
|
166
|
-
}
|
|
167
160
|
/**
|
|
168
161
|
* Resolve a targeted card play's fields against the map, the players and the live board, refusing
|
|
169
162
|
* what war.app's validator (the client bundle's `GameValidateOrders`) or the card's rules exclude.
|
|
@@ -199,21 +192,36 @@ export function resolveCardTargets(kind, cardName, input, ctx) {
|
|
|
199
192
|
return { fields: { player: p.inGameId }, player: p, warnings };
|
|
200
193
|
}
|
|
201
194
|
case 'Sanctions': {
|
|
202
|
-
// GameValidateOrders refuses only a player not playing (219)
|
|
203
|
-
//
|
|
195
|
+
// GameValidateOrders refuses only a player not playing (219), and the client offers every player still
|
|
196
|
+
// playing, me included. The side is our rule, read from the game's percentage (`sanctionsSettings`):
|
|
197
|
+
// a positive one cuts income, so never on me or a teammate; a negative one raises it (the client's own
|
|
198
|
+
// guide: play it on yourself), so never on an opponent; one that cannot be read keeps my side out.
|
|
204
199
|
const p = player(ctx, input.player, cardName);
|
|
205
200
|
requirePlaying(ctx, p, cardName, 'error 219');
|
|
206
|
-
const
|
|
201
|
+
const san = sanctionsSettings(ctx.settings);
|
|
202
|
+
const pct = san?.percentage ?? null;
|
|
207
203
|
const friendly = isMe(ctx, p) || isTeammate(ctx, p);
|
|
208
|
-
|
|
204
|
+
const side = isMe(ctx, p) ? 'yourself' : `your teammate ${who(p)}`;
|
|
205
|
+
const turns = san?.duration ? ` for ${san.duration} turn${san.duration === 1 ? '' : 's'}` : '';
|
|
206
|
+
if (pct === null) {
|
|
207
|
+
if (friendly) {
|
|
208
|
+
throw new McpToolError(`This game's Sanctions percentage could not be read from its settings, so whether the card cuts or raises income is not known: it is not played on ${side}.`, { hint: 'warapp_get_game shows the card settings (`cards.settings`). Sanction an opponent, or keep the card.' });
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
else if (pct < 0) {
|
|
209
212
|
if (!friendly) {
|
|
210
|
-
throw new McpToolError(`This game's Sanctions percentage is negative (${
|
|
213
|
+
throw new McpToolError(`This game's Sanctions percentage is negative (${percentText(pct)}): a sanction raises the target's income by ${percentText(-pct)}, so it does not go on an opponent (${who(p)}).`, { hint: 'Play it on yourself (or a teammate), or keep it.' });
|
|
211
214
|
}
|
|
215
|
+
warnings.push(`Sanctions on ${isMe(ctx, p) ? 'yourself' : `your teammate ${who(p)}`}: this game's percentage is ${percentText(pct)}, so it raises ` +
|
|
216
|
+
`${isMe(ctx, p) ? 'your' : 'their'} income by ${percentText(-pct)}${turns}, from the turn after this one (war.app caps an income at 10,000).`);
|
|
212
217
|
}
|
|
213
|
-
else if (
|
|
214
|
-
|
|
215
|
-
hint: 'Sanction an opponent — usually the leader.'
|
|
216
|
-
}
|
|
218
|
+
else if (pct > 0) {
|
|
219
|
+
if (friendly) {
|
|
220
|
+
throw new McpToolError(`This game's Sanctions percentage is ${percentText(pct)}: it cuts the target's income by ${percentText(pct)}, so it does not go on ${side}.`, { hint: 'Sanction an opponent — usually the leader.' });
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
else {
|
|
224
|
+
warnings.push("This game's Sanctions percentage is 0%: the card changes nobody's income.");
|
|
217
225
|
}
|
|
218
226
|
return { fields: { player: p.inGameId }, player: p, warnings };
|
|
219
227
|
}
|
|
@@ -399,8 +407,12 @@ function airlift(input, ctx, warnings) {
|
|
|
399
407
|
}
|
|
400
408
|
const there = (standingOf(ctx, f.id)?.armies ?? 0) + (ctx.deployedOn.get(f.id) ?? 0);
|
|
401
409
|
const total = (ctx.seen.airliftedFrom.get(f.id) ?? 0) + armies;
|
|
402
|
-
|
|
403
|
-
|
|
410
|
+
// Owner spec 2026-11-24: an Airlift leaves at least one army behind while One Army Must Stand Guard is on (the
|
|
411
|
+
// bundle's validator does not check the count; ours, as a move leaves its guard).
|
|
412
|
+
const guard = ctx.settings?.oneArmyStandsGuard === false ? 0 : 1;
|
|
413
|
+
if (total > there - guard) {
|
|
414
|
+
throw new McpToolError(`These orders airlift ${total} armies from ${place(from)}, but at most ${Math.max(0, there - guard)} can leave when the Airlift runs ` +
|
|
415
|
+
`(${there} stand there — its armies now plus this turn's deploys${guard ? ' — and one stays behind as its guard' : ''}).`, { hint: guard ? 'Airlift fewer armies: one must stay behind on the territory it leaves.' : 'Airlift no more armies than stand on the territory.' });
|
|
404
416
|
}
|
|
405
417
|
ctx.seen.airliftedFrom.set(f.id, total);
|
|
406
418
|
const out = { fields: { from: f.id, to: t.id, armies }, from, to, armies, warnings };
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
// My card state (src/card-state.ts) read from the live board for warapp_get_game and warapp_begin_turn: the whole
|
|
2
|
+
// cards I (or my team) hold by type and the pieces toward the next. One GetLatestGameInfo, only for a game being
|
|
3
|
+
// played or picked with my seat in it and a card in play; never throws (a failed read is `cardsUnread`).
|
|
4
|
+
import { cardState } from '../card-state.js';
|
|
5
|
+
import { handOwners } from './card-advice.js';
|
|
6
|
+
import { readLatestBoard } from './live-context.js';
|
|
7
|
+
const IN_PLAY = new Set(['Playing', 'DistributingTerritories']);
|
|
8
|
+
/** Whether {@link readCardState} would read anything for this game (no request). */
|
|
9
|
+
export const cardStateApplies = (game) => IN_PLAY.has(game.state) && (game.settings?.cards.length ?? 0) > 0;
|
|
10
|
+
/** My card state for `game`, or `{}` when it does not apply (no card in play, not being played). */
|
|
11
|
+
export async function readCardState(ctx, game, info) {
|
|
12
|
+
if (!cardStateApplies(game))
|
|
13
|
+
return {};
|
|
14
|
+
try {
|
|
15
|
+
const token = await ctx.myInviteToken();
|
|
16
|
+
const me = token === undefined ? undefined : game.players.find((p) => p.id === token);
|
|
17
|
+
if (!me)
|
|
18
|
+
return { cardsUnread: 'the signed-in account holds no seat in this game, or could not be read' };
|
|
19
|
+
const read = info ?? (await readLatestBoard(ctx, game.id)).info;
|
|
20
|
+
const cards = cardState(read, handOwners(game, me), game.settings);
|
|
21
|
+
return cards ? { cards } : {};
|
|
22
|
+
}
|
|
23
|
+
catch (e) {
|
|
24
|
+
return { cardsUnread: e instanceof Error ? e.message : String(e) };
|
|
25
|
+
}
|
|
26
|
+
}
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
// warapp_submit_turn as is, whose encodings are UNVERIFIED live (V9) save Airlift's and Diplomacy's (verified
|
|
4
4
|
// live, #296 and #369) — except (#434) a spy card whose play is verified live, which warapp_plan_turn puts
|
|
5
5
|
// into its orders (`intelOrders`). Players and territories by id only.
|
|
6
|
+
import { sanctionedIncome, sanctionsSettings } from '../analysis/cards-in-effect.js';
|
|
6
7
|
import { airliftAdvice, diplomacyAdvice, giftAdvice, intelAdvice, sanctionsAdvice } from '../analysis/card-support.js';
|
|
7
8
|
import { visibleIncomeFor } from '../analysis/plan/shared.js';
|
|
8
9
|
import { STRENGTH_INCOME_TURNS } from '../analysis/profile.js';
|
|
@@ -38,11 +39,19 @@ export function giftInOrders(view) {
|
|
|
38
39
|
}
|
|
39
40
|
const PLAY_IT = 'Advice only, not in the orders: pass its `order` to warapp_submit_turn to play it (the encoding is read from the client, not yet verified live).';
|
|
40
41
|
const IN_ORDERS = 'In the orders: its encoding is verified live. Drop it from the orders to keep the card.';
|
|
41
|
-
/**
|
|
42
|
-
function
|
|
43
|
-
const
|
|
44
|
-
|
|
45
|
-
|
|
42
|
+
/** A self-Sanctions boost on my next income (the client's rule), or why it is not modelled. */
|
|
43
|
+
function selfBoost(pct, turns, input) {
|
|
44
|
+
const lasting = turns ? ` for ${turns} turn${turns === 1 ? '' : 's'}` : '';
|
|
45
|
+
if (input.game.settings?.localDeployments === true)
|
|
46
|
+
return { line: `Under Local Deployment the boost's split across the pools is not modelled, so the income it adds${lasting} is not counted.` };
|
|
47
|
+
if (input.nextIncome === undefined)
|
|
48
|
+
return { line: `It raises your income${lasting} from next turn.` };
|
|
49
|
+
const before = input.nextIncome;
|
|
50
|
+
const after = sanctionedIncome(before, [pct]);
|
|
51
|
+
return {
|
|
52
|
+
income: { percentage: pct, turns, before, after, gain: after - before },
|
|
53
|
+
line: `Your next income ${before} → ${after} (+${after - before})${lasting} (the client's rule, rounded to the nearest; at most 10,000).`,
|
|
54
|
+
};
|
|
46
55
|
}
|
|
47
56
|
/**
|
|
48
57
|
* Each player in sight by strength (visible armies + {@link STRENGTH_INCOME_TURNS} × income): the
|
|
@@ -110,11 +119,19 @@ export function supportAdvice(input) {
|
|
|
110
119
|
pass.set(t.player, `your truce with it is ${t.state === 'notice' ? 'in notice' : 'in force'} — a sanction on a partner invites a break`);
|
|
111
120
|
for (const p of input.atPeace)
|
|
112
121
|
pass.set(p, 'a Diplomacy card between you is in force — it cannot attack you, so sanction a player who can');
|
|
113
|
-
|
|
122
|
+
// Owner request 2026-11-24: the percentage's sign decides the side — a cut on an opponent, a boost on me.
|
|
123
|
+
const sanSettings = sanctionsSettings(input.game.settings);
|
|
124
|
+
const pct = sanSettings?.percentage ?? undefined;
|
|
114
125
|
const s = sanctionsAdvice({ me: me.id, players: strengths(input), ...(pct !== undefined ? { percentage: pct } : {}), ...(pass.size ? { pass } : {}) });
|
|
115
126
|
if (s?.player !== undefined) {
|
|
116
|
-
|
|
117
|
-
|
|
127
|
+
const boost = pct !== undefined && pct < 0 && s.player === me.id ? selfBoost(pct, sanSettings.duration, input) : undefined;
|
|
128
|
+
view.sanctions = {
|
|
129
|
+
player: s.player,
|
|
130
|
+
...(s.skipped?.length ? { skipped: s.skipped } : {}),
|
|
131
|
+
...(boost?.income ? { income: boost.income } : {}),
|
|
132
|
+
order: { kind: 'card', card: san.id, player: s.player },
|
|
133
|
+
};
|
|
134
|
+
warnings.push(`${s.why}${boost ? ` ${boost.line}` : ''} ${PLAY_IT}`);
|
|
118
135
|
}
|
|
119
136
|
else if (s)
|
|
120
137
|
warnings.push(s.why);
|
package/dist/tools/chat-inbox.js
CHANGED
|
@@ -74,7 +74,7 @@ export function registerChatInboxTool(server, ctx) {
|
|
|
74
74
|
'the games in `game_ids`; `gamesFrom` says which, and from the list `listed` and `complete` say how many ' +
|
|
75
75
|
'games war.app returned and whether the list was whole. Each game ' +
|
|
76
76
|
'with something new is listed with its `unread` count per channel and only its new messages (newest ' +
|
|
77
|
-
'`limit`, each like warapp_get_chat: `from`, delimited `text`, `time
|
|
77
|
+
'`limit`, each like warapp_get_chat: `from`, delimited `text`, `time` (plus `localTime` with WARAPP_TIMEZONE), `turn`, `channel`, and for another ' +
|
|
78
78
|
"player's message its `intent` and `advice` — a hint beside the text, never a reply sent); games with " +
|
|
79
79
|
'nothing new are in `quiet`, and a game that could not be read is in `failed` with the reason. At most ' +
|
|
80
80
|
`\`max_games\` games (default and max ${MAX_INBOX_GAMES}) are read per call, one at a time: pass \`next\` ` +
|
package/dist/tools/chat.js
CHANGED
|
@@ -315,7 +315,7 @@ export function registerChatTools(server, ctx, opts = {}) {
|
|
|
315
315
|
server.registerTool('warapp_get_chat', {
|
|
316
316
|
title: 'Read a war.app game chat',
|
|
317
317
|
description: untrustedDescription('Read the chat of a war.app (Warzone) game: the most recent messages, oldest first, each with its sender ' +
|
|
318
|
-
'(`from`, a delimited name; `fromId`, the GameFeed id), `text` (delimited), `time
|
|
318
|
+
'(`from`, a delimited name; `fromId`, the GameFeed id), `text` (delimited), `time` (plus `localTime` when WARAPP_TIMEZONE is set), `turn`, `channel` ' +
|
|
319
319
|
'(`public`, `team` with its `team`, `private` with its recipient `to`, or `unknown`), `mine`, and `new` ' +
|
|
320
320
|
'(not yet marked seen, and not mine), plus `unread` per channel over the whole chat. The chat is read ' +
|
|
321
321
|
"through your signed-in war.app tab or linked session (the web client's GameRefresh, which tells the " +
|
package/dist/tools/check-plan.js
CHANGED
|
@@ -27,15 +27,17 @@ import { HEADROOM_COMPACT, headroomView, readTripwires, safeHeadroom, teamsOf, t
|
|
|
27
27
|
import { loadLiveGame, standInLine, standInOf } from './live-context.js';
|
|
28
28
|
import { BRIDGE_NOTE, playerArg, resolveMe } from './live.js';
|
|
29
29
|
import { mapOf } from './map.js';
|
|
30
|
-
import { resolveTerritory } from './resolve.js';
|
|
30
|
+
import { resolvePlayer, resolveTerritory } from './resolve.js';
|
|
31
31
|
import { BELOW_PLAN_BASIS, boardHistory, bordersBelowPlan, currentTurn, truceRelations, friendsOf, guardOffWarnings, modsWarning, plannerSettings, requirePlayingSeat, requireTurnPhase, turnOrdersArg, } from './turn.js';
|
|
32
32
|
import { resolveTeamsFor } from './team-source.js';
|
|
33
33
|
import { stressOpponents } from './stress-opponents.js';
|
|
34
34
|
import { sanctionPercentage } from '../analysis/cards-in-effect.js';
|
|
35
|
+
import { CARD_SANCTIONS, sanctionsPlayed } from './sanctions-played.js';
|
|
35
36
|
import { COMMANDER_SIZING, commanderCheckOn, defaultFoggedCount, foggedAttackersArg, foggedCommanderOn, foggedCommanderText, myLargestStack } from './commander-check.js';
|
|
36
37
|
import { DEFAULT_FOGGED_ATTACKERS, foggedStack } from '../analysis/commander-fog.js';
|
|
37
38
|
import { captureCheck, checkPlanLog } from './decision-capture.js';
|
|
38
39
|
import { farSummary, opponentScope } from '../analysis/scale.js';
|
|
40
|
+
import { territoryCapOverruns } from '../analysis/plan/relations.js';
|
|
39
41
|
const VIEWS = ['compact', 'full'];
|
|
40
42
|
const MAX_ENEMY_DEPLOY = 10_000;
|
|
41
43
|
/** Replies listed beside the worst one on the compact view; the full view lists the stress test's own maximum. */
|
|
@@ -43,11 +45,19 @@ const COMPACT_OTHERS = 2;
|
|
|
43
45
|
/** The most territories or bonuses any one list names; the rest are a count. */
|
|
44
46
|
const LIST_MAX = 10;
|
|
45
47
|
const ORDER_PRIORITY = cardTypeByName('Order Priority');
|
|
48
|
+
const BOMB = cardTypeByName('Bomb');
|
|
49
|
+
const EMERGENCY_BLOCKADE = cardTypeByName('Emergency Blockade');
|
|
50
|
+
const BLOCKADE = cardTypeByName('Blockade');
|
|
51
|
+
/** A wall card's `MultiplyAmount` from the settings (`EmergencyBlockadeCard`, `BlockadeCard`), when the game sets one. */
|
|
52
|
+
function wallMultiplier(raw, key) {
|
|
53
|
+
const r = raw?.[key];
|
|
54
|
+
if (typeof r !== 'object' || r === null)
|
|
55
|
+
return undefined;
|
|
56
|
+
const m = Number(r.MultiplyAmount);
|
|
57
|
+
return Number.isFinite(m) && m > 0 ? m : undefined;
|
|
58
|
+
}
|
|
46
59
|
/** Card plays that change the board this test does not simulate, each with what the test does instead. */
|
|
47
|
-
const UNSIMULATED_CARDS = new Map([
|
|
48
|
-
[cardTypeByName('Bomb'), (on) => `The Bomb${on} is not simulated: the test fights at its armies before the Bomb halves them.`],
|
|
49
|
-
[cardTypeByName('Emergency Blockade'), (on) => `The Emergency Blockade${on} is not simulated: the test keeps it yours, armies unchanged.`],
|
|
50
|
-
]);
|
|
60
|
+
const UNSIMULATED_CARDS = new Map([]);
|
|
51
61
|
/** #274: the card plays the commander check reads (an Airlift simulated, the others named on its territory). */
|
|
52
62
|
const COMMANDER_CARD_KINDS = new Map([
|
|
53
63
|
[cardTypeByName('Airlift'), 'Airlift'],
|
|
@@ -62,7 +72,7 @@ export const CHECK_PLAN_NOT_COVERED = [
|
|
|
62
72
|
'a deploy split over several stacks',
|
|
63
73
|
'two opponents together other than on one of your territories, and two free-for-all opponents together at all unless you lead (see leader)',
|
|
64
74
|
'under Multi-Attack, any chain of attacks but the one most damaging per stack',
|
|
65
|
-
'cards, apart from your own Order Priority',
|
|
75
|
+
'cards, apart from your own Order Priority, Airlifts, Bombs, Emergency Blockades and Blockades',
|
|
66
76
|
];
|
|
67
77
|
export function registerCheckPlanTool(server, ctx) {
|
|
68
78
|
server.registerTool('warapp_check_plan', {
|
|
@@ -110,6 +120,9 @@ export function registerCheckPlanTool(server, ctx) {
|
|
|
110
120
|
'implied and your own income (`enemyDeploy` source `untrusted`), said in the first warning. Each `enemyDeploy` entry ' +
|
|
111
121
|
"shows the Reinforcement card the clock says it may hold apart as `cardBonus` (in `deploy` unless `assume_enemy_cards` is " +
|
|
112
122
|
'"none"; a progressive card\'s source in `cardBonusBasis`, as warapp_plan_turn has it) and, under Sanctions, `sanctionApplied` (its income before and after the cut). ' +
|
|
123
|
+
'A Sanctions card in the orders is projected onto next turn in `sanctionsPlayed` (`nextIncome`: yours from this turn\'s ' +
|
|
124
|
+
'income when the game\'s percentage is negative and you play it on yourself, an opponent\'s estimate when positive), and ' +
|
|
125
|
+
'a card on the wrong side for its sign is a warning (warapp_submit_turn refuses it). ' +
|
|
113
126
|
'`belowPlan` compares these orders with the default plan made now on the same board (warapp_plan_turn with no ' +
|
|
114
127
|
'options, the award of picks read as it reads it), or with its border guess when the deploys given are the ' +
|
|
115
128
|
"guess's (`belowPlanAgainst`: plan or guess): each border they leave below what that plan leaves standing there, " +
|
|
@@ -131,7 +144,12 @@ export function registerCheckPlanTool(server, ctx) {
|
|
|
131
144
|
player: playerArg,
|
|
132
145
|
orders: turnOrdersArg.describe('The orders to test, in the order you would submit them: deploys and moves by territory id or name (the ' +
|
|
133
146
|
'`orders` array warapp_plan_turn returns). An Order Priority card play makes your first order run before ' +
|
|
134
|
-
"everyone's;
|
|
147
|
+
"everyone's; an Airlift (`from`, `to`, `armies`) is carried out at its phase — after every deploy, before every " +
|
|
148
|
+
'move: its source loses the armies, its destination gains them, and they cannot move again that turn — so ' +
|
|
149
|
+
'every reply is tried against the board it leaves; other card plays and discards are ignored by the test ' +
|
|
150
|
+
'(a Bomb is carried out at its phase too — after every deploy, its target keeps half its armies, rounded down; an ' +
|
|
151
|
+
'Emergency Blockade before the moves and a Blockade after them turn their territory neutral at its armies × the ' +
|
|
152
|
+
"game's multiplier; a wall whose multiplier the settings do not give is named " +
|
|
135
153
|
'in `warnings` as not simulated; in a team game, a card your teammate has ' +
|
|
136
154
|
"already entered is warned of). A move's options (mode, percent, commander, " +
|
|
137
155
|
'attack_teammates) are carried out as war.app would.'),
|
|
@@ -215,7 +233,13 @@ export function registerCheckPlanTool(server, ctx) {
|
|
|
215
233
|
uses.push({ card, kind });
|
|
216
234
|
};
|
|
217
235
|
let orderPriority = false;
|
|
236
|
+
const sanctionsTargets = [];
|
|
218
237
|
const airlifts = [];
|
|
238
|
+
/** My Bombs' targets: carried out at their phase (30) by the stress test. */
|
|
239
|
+
const bombs = [];
|
|
240
|
+
/** My Emergency Blockades (phase 37) and Blockades (phase 60): carried out by the stress test with the game's multiplier. */
|
|
241
|
+
const abandons = [];
|
|
242
|
+
const blockades = [];
|
|
219
243
|
const cardTargets = [];
|
|
220
244
|
const ignored = [];
|
|
221
245
|
const unsimulatedCards = [];
|
|
@@ -263,6 +287,15 @@ export function registerCheckPlanTool(server, ctx) {
|
|
|
263
287
|
// By GUID it is looked up in my hand; by type name the name is enough (this is a what-if).
|
|
264
288
|
const guid = normalizeGuid(o.card.trim());
|
|
265
289
|
const type = guid !== undefined ? hand.find((c) => c.id === guid)?.type : cardTypeByName(o.card);
|
|
290
|
+
// Owner request 2026-11-24: a Sanctions play's income change is projected on next turn (below).
|
|
291
|
+
if (type === CARD_SANCTIONS && o.player !== undefined) {
|
|
292
|
+
try {
|
|
293
|
+
sanctionsTargets.push(resolvePlayer(game.players, o.player).id);
|
|
294
|
+
}
|
|
295
|
+
catch {
|
|
296
|
+
// A player not in the game: warapp_submit_turn refuses it; nothing is projected.
|
|
297
|
+
}
|
|
298
|
+
}
|
|
266
299
|
const unsimulated = type !== undefined ? UNSIMULATED_CARDS.get(type) : undefined;
|
|
267
300
|
if (unsimulated) {
|
|
268
301
|
let on = '';
|
|
@@ -294,8 +327,35 @@ export function registerCheckPlanTool(server, ctx) {
|
|
|
294
327
|
}
|
|
295
328
|
if (type !== undefined && type === ORDER_PRIORITY)
|
|
296
329
|
orderPriority = true;
|
|
330
|
+
else if (type === BOMB) {
|
|
331
|
+
try {
|
|
332
|
+
if (o.target !== undefined)
|
|
333
|
+
bombs.push(resolveTerritory(map, o.target).id);
|
|
334
|
+
}
|
|
335
|
+
catch {
|
|
336
|
+
// A target not on the map: warapp_submit_turn refuses it; the test goes without it.
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
else if (type === EMERGENCY_BLOCKADE || type === BLOCKADE) {
|
|
340
|
+
const key = type === BLOCKADE ? 'BlockadeCard' : 'EmergencyBlockadeCard';
|
|
341
|
+
const multiplier = wallMultiplier(game.settings?.raw, key);
|
|
342
|
+
const name = type === BLOCKADE ? 'Blockade' : 'Emergency Blockade';
|
|
343
|
+
try {
|
|
344
|
+
const target = o.target !== undefined ? resolveTerritory(map, o.target).id : undefined;
|
|
345
|
+
if (target !== undefined && multiplier !== undefined)
|
|
346
|
+
(type === BLOCKADE ? blockades : abandons).push({ target, multiplier });
|
|
347
|
+
else if (target !== undefined)
|
|
348
|
+
unsimulatedCards.push(`The ${name} on ${target} is not simulated: the game's settings give no multiplier for it.`);
|
|
349
|
+
}
|
|
350
|
+
catch {
|
|
351
|
+
// A target not on the map: warapp_submit_turn refuses it; the test goes without it.
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
else if (kindOf === 'Airlift') {
|
|
355
|
+
// Owner request 2026-11-24: the stress test carries the Airlift out at its phase (below).
|
|
356
|
+
}
|
|
297
357
|
else if (type === undefined || cardTypeName(type) !== 'Reinforcement')
|
|
298
|
-
ignored.push('a card play other than Order Priority or
|
|
358
|
+
ignored.push('a card play other than Order Priority, Reinforcement, Airlift, Bomb or a Blockade');
|
|
299
359
|
}
|
|
300
360
|
}
|
|
301
361
|
// The same per-opponent estimates warapp_plan_turn works from (stress-opponents.ts); an opponent's
|
|
@@ -374,6 +434,13 @@ export function registerCheckPlanTool(server, ctx) {
|
|
|
374
434
|
const sanction = so.commerce?.source === 'standing'
|
|
375
435
|
? { income, warnings: [], applied: false }
|
|
376
436
|
: sanctionMyIncome(income, effect, { localDeployments: settings.localDeployments === true });
|
|
437
|
+
const played = sanctionsPlayed(sanctionsTargets, {
|
|
438
|
+
settings: game.settings,
|
|
439
|
+
me: me.id,
|
|
440
|
+
friends,
|
|
441
|
+
myIncome: sanction.income,
|
|
442
|
+
estimateOf: (p) => so.estimates.find((e) => e.playerId === p)?.estimate,
|
|
443
|
+
});
|
|
377
444
|
const report = stressPlan({
|
|
378
445
|
graph,
|
|
379
446
|
board,
|
|
@@ -385,6 +452,10 @@ export function registerCheckPlanTool(server, ctx) {
|
|
|
385
452
|
...(teams.size ? { teams } : {}),
|
|
386
453
|
...(first_mover !== undefined ? { firstMover: first_mover } : {}),
|
|
387
454
|
orderPriority,
|
|
455
|
+
...(airlifts.length ? { airlifts } : {}),
|
|
456
|
+
...(bombs.length ? { bombs } : {}),
|
|
457
|
+
...(abandons.length ? { abandons } : {}),
|
|
458
|
+
...(blockades.length ? { blockades } : {}),
|
|
388
459
|
...(settings.localDeployments ? { localDeployments: true, baseIncome: gameBaseIncome(settings) } : {}),
|
|
389
460
|
...(settings.localDeployments && (settings.bonusArmyPer ?? 0) > 0 ? { perTerritoryIncome: true } : {}),
|
|
390
461
|
leader,
|
|
@@ -635,10 +706,18 @@ export function registerCheckPlanTool(server, ctx) {
|
|
|
635
706
|
// A Diplomacy 2 ally's territory (owner at the start of the turn): the game skips the attack, its armies sit idle.
|
|
636
707
|
const allyHits = modRead ? attacksOnAllies(modRead, moves, ownerOf) : [];
|
|
637
708
|
const avoidedHits = [...new Set(moves.map((m) => m.to))].filter((to) => !mine.has(to) && (avoidT.has(to) || avoidP.has(ownerOf(to) ?? Number.NaN)));
|
|
709
|
+
// A territory cap I promised a truce partner, which these orders go over (armies moved off are taken to leave).
|
|
710
|
+
const capOver = territoryCapOverruns(binding, {
|
|
711
|
+
mine,
|
|
712
|
+
armiesOf: (t) => board.territories.find((x) => x.territoryId === t)?.armies ?? 0,
|
|
713
|
+
deploys,
|
|
714
|
+
moves,
|
|
715
|
+
});
|
|
638
716
|
const warnings = [
|
|
639
717
|
// The owner, 2026-11-17: while an older build stands in for a client this server cannot read, say so first.
|
|
640
718
|
...[standInLine(standInOf(ctx))].filter((w) => w !== undefined),
|
|
641
719
|
...intel.warnings,
|
|
720
|
+
...capOver.map((c) => `These orders leave ${c.armies} on ${name(c.territory).name} (#${c.territory}), above the cap of ${c.max} you agreed with player ${c.player}${c.agreement ? ` (agreement ${c.agreement})` : ''}: deploy or move less there, or record the cap lifted (caps_remove) once the partner agrees.`),
|
|
642
721
|
...(avoidedHits.length
|
|
643
722
|
? [`These orders attack ${avoidedHits.map((t) => name(t)).join(', ')}, which you asked to avoid (avoid_territories / avoid_players).`]
|
|
644
723
|
: []),
|
|
@@ -667,6 +746,7 @@ export function registerCheckPlanTool(server, ctx) {
|
|
|
667
746
|
? [`These orders use ${[...refused].join(', ')}: war.app would refuse them in this game, and warapp_submit_turn does; the test ran them anyway.`]
|
|
668
747
|
: []),
|
|
669
748
|
...sanction.warnings,
|
|
749
|
+
...played.warnings,
|
|
670
750
|
// #505: orders that delay the nearest bonus say by how many turns (advice only).
|
|
671
751
|
...[bonusDelayWarning(belowPlan?.bonusDelay)].filter((w) => w !== undefined),
|
|
672
752
|
...effect.unsure,
|
|
@@ -733,6 +813,8 @@ export function registerCheckPlanTool(server, ctx) {
|
|
|
733
813
|
orderPriority,
|
|
734
814
|
// #277: what I may deploy this turn, after any Sanctions on me (as warapp_plan_turn reports it).
|
|
735
815
|
income: sanction.income,
|
|
816
|
+
// Owner request 2026-11-24: the Sanctions these orders play, with the income they change next turn.
|
|
817
|
+
...(played.entries.length ? { sanctionsPlayed: played.entries } : {}),
|
|
736
818
|
deployed,
|
|
737
819
|
warnings,
|
|
738
820
|
// #386: the intel warapp_record_intel kept and what this check did with it (absent when none is kept).
|
package/dist/tools/game.js
CHANGED
|
@@ -70,7 +70,9 @@ function compact(game) {
|
|
|
70
70
|
* (`endOfGame`, #312, src/tools/end-of-game.ts): the account is the board cache's, else `identity` (the
|
|
71
71
|
* signed-in account).
|
|
72
72
|
*/
|
|
73
|
-
export function registerGameTool(server, client, dir, env, identity
|
|
73
|
+
export function registerGameTool(server, client, dir, env, identity,
|
|
74
|
+
/** My card state from the live board (src/tools/card-state-view.ts); absent: not read. */
|
|
75
|
+
cards) {
|
|
74
76
|
server.registerTool('warapp_get_game', {
|
|
75
77
|
title: 'Get a war.app (Warzone) game',
|
|
76
78
|
description: untrustedDescription('Look up one war.app (Warzone) multiplayer game by id: its state (lobby, distributing, playing, finished), ' +
|
|
@@ -96,7 +98,12 @@ export function registerGameTool(server, client, dir, env, identity) {
|
|
|
96
98
|
'(`endOfGame.processed`); a failed read is recorded and not retried, except by a call with ' +
|
|
97
99
|
'`include_history`, which re-runs it from that read and adds the stats to a game processed before them ' +
|
|
98
100
|
'(`backfilled`). To take a finished game off the app\'s My Games use warapp_close_finished_game. ' +
|
|
99
|
-
'
|
|
101
|
+
'While the game is played or picked with a card in play, `cards` is my hand from the live board (one more ' +
|
|
102
|
+
'request): `held` (each card type with `count`), `total`, `maxCardsHold`, and `pieces` (per card in play, the ' +
|
|
103
|
+
'pieces toward the next one and `of` how many make one; read by shape, UNVERIFIED live; `null` when unread), and ' +
|
|
104
|
+
'`settings` (each card in play with a `duration`, and Sanctions\' `percentage` — negative raises the target\'s income — ' +
|
|
105
|
+
'with its `effect` and `targets`: opponents, or your side when negative) — a ' +
|
|
106
|
+
'failed read is `cardsUnread`, never an error. For the map\'s bonuses and chokepoints use warapp_get_map. Read-only.'),
|
|
100
107
|
_meta: lookupMeta(['warzone game', 'war.app game', 'whose turn is it', 'game status']),
|
|
101
108
|
annotations: readAnnotations('Get a war.app game'),
|
|
102
109
|
inputSchema: z.object({
|
|
@@ -137,7 +144,9 @@ export function registerGameTool(server, client, dir, env, identity) {
|
|
|
137
144
|
end = await endOfGame({ client, dataDir: dir(), env: env ?? process.env }, game.id, me, game, include_history ? { history: game, retry: true } : {});
|
|
138
145
|
}
|
|
139
146
|
}
|
|
147
|
+
const cardRead = cards ? await cards(game) : {};
|
|
140
148
|
const folded = {
|
|
149
|
+
...cardRead,
|
|
141
150
|
...(fold && fold.status !== 'off' ? { profileFold: fold } : {}),
|
|
142
151
|
...(lost ? { howLost: lost } : {}),
|
|
143
152
|
...(end && end.status !== 'off' ? { endOfGame: end } : {}),
|
package/dist/tools/index.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { readCardState } from './card-state-view.js';
|
|
1
2
|
import { defaultMapCache, WarappClient } from '../client.js';
|
|
2
3
|
import { captureSeats } from './decision-capture.js';
|
|
3
4
|
import { dataDir } from '../config.js';
|
|
@@ -49,8 +50,13 @@ import { createDirectFirstBridge } from '../direct/transport.js';
|
|
|
49
50
|
import { isHosted } from '../hosted.js';
|
|
50
51
|
import { registerSignInTool } from './sign-in.js';
|
|
51
52
|
import { createWarappBridge } from '../transport-bridge.js';
|
|
53
|
+
import { readTimezone, withLocalTimes } from '../local-time.js';
|
|
52
54
|
/** Every tool this server serves. index.ts and the tests share this list. */
|
|
53
55
|
export function registerAllTools(server, deps = {}) {
|
|
56
|
+
// WARAPP_TIMEZONE: every tool's timestamps gain a local-time sibling, added at the output layer (src/local-time.ts).
|
|
57
|
+
withLocalTimes(server, readTimezone(deps.env ?? process.env), () => registerEveryTool(server, deps));
|
|
58
|
+
}
|
|
59
|
+
function registerEveryTool(server, deps) {
|
|
54
60
|
// One client for the game tools, so they share the map cache. Config is
|
|
55
61
|
// deferred: the client reads credentials per call, never at construction.
|
|
56
62
|
// The map cache is kept on disk too (`<dataDir>/maps/`, src/map-store.ts),
|
|
@@ -88,7 +94,7 @@ export function registerAllTools(server, deps = {}) {
|
|
|
88
94
|
client.observeGames((game) => captureSeats(live, game));
|
|
89
95
|
registerHealthcheckTool(server, fetchproxy, bridge, { ...deps, standIn: () => live.decoderReport()?.standIn });
|
|
90
96
|
// The signed-in account names a finished game's player for its end-of-game pass when no board was cached (#312).
|
|
91
|
-
registerGameTool(server, client, () => dataDir(deps.env), deps.env, () => live.myInviteToken());
|
|
97
|
+
registerGameTool(server, client, () => dataDir(deps.env), deps.env, () => live.myInviteToken(), (game) => readCardState(live, game));
|
|
92
98
|
registerMapTool(server, client, live);
|
|
93
99
|
// Opt-in (WARAPP_STATS=1), never hosted: the tool refuses before any request
|
|
94
100
|
// when off. One collector per registration, so its 1 s throttle spans calls.
|
|
@@ -159,7 +159,7 @@ export function registerNotificationTools(server, ctx, opts = {}) {
|
|
|
159
159
|
description: untrustedDescription("Your war.app (Warzone) in-app notifications (the client's notifications screen, war.app's " +
|
|
160
160
|
'GetInAppNotifications), 30 per page, by id only: each with `id` (what warapp_dismiss_notification takes), ' +
|
|
161
161
|
'`kind` (`game-ended` when the title is war.app\'s "Game … has ended." line, else `other`), `gameId` (the ' +
|
|
162
|
-
'game its link names, or null), `time` and `unread`. The title and body are never shown (they carry other ' +
|
|
162
|
+
'game its link names, or null), `time` (plus `localTime` when WARAPP_TIMEZONE is set) and `unread`. The title and body are never shown (they carry other ' +
|
|
163
163
|
"players' names). " +
|
|
164
164
|
'`total` is how many notifications war.app holds; pass `next` back as `start` for the next page; ' +
|
|
165
165
|
'`unread_only` keeps the unread ones of the page. A game-ended notification runs the end-of-game pass on ' +
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
// Owner request 2026-11-24 (self-Sanctions): after warapp_submit_turn commits, the player-targeted card plays it sent
|
|
2
|
+
// (Sanctions) are read back from war.app's own copy of my committed orders (the warapp_get_my_orders read, as the
|
|
3
|
+
// Airlift read-back does: src/tools/airlift-readback.ts) and compared: the card instance and the player it names.
|
|
4
|
+
// A missing or retargeted one makes the tool throw. Pure.
|
|
5
|
+
import { normalizeGuid } from '../cards.js';
|
|
6
|
+
/** The player-targeted card plays read back after a commit. */
|
|
7
|
+
export const READ_BACK_PLAYER_CARDS = new Set(['Sanctions']);
|
|
8
|
+
/** The plays of these kinds among the orders sent, the player by GameFeed id (`feedOf` the in-game id; unknown: left out). */
|
|
9
|
+
export function sentPlayerCards(orders, feedOf, kinds = READ_BACK_PLAYER_CARDS) {
|
|
10
|
+
return orders.flatMap((o) => {
|
|
11
|
+
if (o.kind !== 'card' || !kinds.has(o.card) || o.player === undefined)
|
|
12
|
+
return [];
|
|
13
|
+
const player = feedOf(o.player);
|
|
14
|
+
return player === undefined ? [] : [{ card: normalizeGuid(o.cardId) ?? o.cardId, kind: o.card, player }];
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
/** Compare the plays sent with my orders read back (`null`: unknown): by card instance, else the same kind and player. */
|
|
18
|
+
export function checkPlayerCards(sent, read) {
|
|
19
|
+
if (!read)
|
|
20
|
+
return { status: 'unread', sent: [...sent], missing: [], altered: [] };
|
|
21
|
+
const back = read.orders.flatMap((o) => o.kind === 'card' && o.player !== undefined ? [{ card: normalizeGuid(o.card) ?? o.card, kind: o.cardType, player: o.player }] : []);
|
|
22
|
+
const used = new Set();
|
|
23
|
+
const missing = [];
|
|
24
|
+
const altered = [];
|
|
25
|
+
for (const s of sent) {
|
|
26
|
+
let i = back.findIndex((b, k) => !used.has(k) && b.card === s.card);
|
|
27
|
+
if (i < 0)
|
|
28
|
+
i = back.findIndex((b, k) => !used.has(k) && b.kind === s.kind && b.player === s.player);
|
|
29
|
+
if (i < 0) {
|
|
30
|
+
missing.push(s);
|
|
31
|
+
continue;
|
|
32
|
+
}
|
|
33
|
+
used.add(i);
|
|
34
|
+
if (back[i].player !== s.player)
|
|
35
|
+
altered.push({ sent: s, read: { card: back[i].card, player: back[i].player } });
|
|
36
|
+
}
|
|
37
|
+
return { status: missing.length || altered.length ? 'mismatch' : 'verified', sent: [...sent], missing, altered };
|
|
38
|
+
}
|
|
39
|
+
/** The error message's parts for a mismatch, by id. */
|
|
40
|
+
export function playerCardMismatchParts(r) {
|
|
41
|
+
return [
|
|
42
|
+
...r.missing.map((x) => `the ${x.kind} on player ${x.player} is missing`),
|
|
43
|
+
...r.altered.map((x) => `the ${x.sent.kind} on player ${x.sent.player} reads back on player ${x.read.player}`),
|
|
44
|
+
];
|
|
45
|
+
}
|