@chrischall/warapp-mcp 0.20.0 → 0.22.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.
@@ -0,0 +1,58 @@
1
+ // #593 5c: the bait warning. A lightly held territory of a player's beside its big stack reads as
2
+ // a cheap capture, but that stack can move in before my attack lands (it moves first in the
3
+ // zigzag, or my attack is not my first order), and the attack then meets everything at once. The
4
+ // owner's rematch lost four 2–3 army attacks this way; the Tibet one met 24 moved in and 12
5
+ // deployed. The submit preview has no deploy estimate (warapp_check_plan's `gather` reply adds it):
6
+ // this counts only the armies there and what its stacks beside it can move in, so whatever it
7
+ // names is short before a single army is deployed.
8
+ import { armiesToTake, COMMANDER_STRENGTH, specialUnitStrength } from '../analysis/combat.js';
9
+ import { neighborsOf } from '../analysis/graph.js';
10
+ /** The preview's warning, or `undefined` when no attack can be met that way. */
11
+ export function baitAttackWarning(input) {
12
+ const { graph, board, me, settings, label, name } = input;
13
+ const teammates = input.teammates ?? new Set();
14
+ const standing = new Map(board.map((t) => [t.territoryId, t]));
15
+ const guard = settings.oneArmyStandsGuard === false ? 0 : 1;
16
+ const rates = {
17
+ ...(settings.offensiveKillRate !== undefined ? { offensiveKillRate: settings.offensiveKillRate } : {}),
18
+ ...(settings.defensiveKillRate !== undefined ? { defensiveKillRate: settings.defensiveKillRate } : {}),
19
+ };
20
+ /** My attacks by target, in the order first listed: a player's visible territory, not a teammate's unless asked. */
21
+ const byTarget = new Map();
22
+ for (const m of input.moves) {
23
+ const t = standing.get(m.to.id);
24
+ if (m.mode === 'transfer-only' || !t || t.fogged || t.owner === me || t.owner < 0)
25
+ continue;
26
+ if (teammates.has(t.owner) && m.attackTeammates !== true)
27
+ continue;
28
+ const power = m.armies + (m.commander ? COMMANDER_STRENGTH : 0);
29
+ const g = byTarget.get(m.to.id);
30
+ if (g)
31
+ g.armies += power;
32
+ else
33
+ byTarget.set(m.to.id, { from: m.from, to: m.to, armies: power });
34
+ }
35
+ const parts = [];
36
+ for (const [id, a] of byTarget) {
37
+ const target = standing.get(id);
38
+ const owner = target.owner;
39
+ const stacks = neighborsOf(graph, id)
40
+ .map((n) => standing.get(n))
41
+ .filter((s) => s !== undefined && !s.fogged && s.owner === owner && (s.armies ?? 0) > guard)
42
+ .map((s) => ({ id: s.territoryId, moves: (s.armies ?? 0) - guard }))
43
+ .sort((x, y) => y.moves - x.moves || x.id - y.id);
44
+ if (!stacks.length)
45
+ continue;
46
+ const defenders = (target.armies ?? 0) + specialUnitStrength(target.specialUnits) + stacks.reduce((n, s) => n + s.moves, 0);
47
+ const needs = armiesToTake(defenders, rates);
48
+ if (needs !== null && a.armies >= needs)
49
+ continue;
50
+ parts.push(`${label(a.from)} → ${label(a.to)} with ${a.armies}: player ${owner}'s stacks beside it can move in first (${stacks
51
+ .map((s) => `${label(name(s.id))} ${s.moves}`)
52
+ .join(', ')}), ${defenders} defenders before any deploy, which ${needs === null ? 'no attack can take' : `needs ${needs}`}`);
53
+ }
54
+ if (!parts.length)
55
+ return undefined;
56
+ return (`Possible bait (#593): ${parts.join('; ')}. That happens when it moves first, or when its moves run before the attack in the zigzag. ` +
57
+ 'warapp_check_plan tries it with its deploy too (the `gather` reply).');
58
+ }
@@ -87,7 +87,8 @@ export function registerCheckPlanTool(server, ctx) {
87
87
  'order; each order an attack or a transfer by who holds its target when it runs; kill rates, the guard ' +
88
88
  'army, each army moving once, commanders), against the replies each opponent could make with ONE deploy: ' +
89
89
  'its whole estimated deploy on one stack and an attack on a territory you hold or are about to take, its ' +
90
- 'whole deploy on a territory you attack, or every stack attacking at once; a stack you attack moving out ' +
90
+ 'whole deploy on a territory you attack, or that plus its stacks beside it moving in first (`gather`, the bait: ' +
91
+ '`movedIn` names each), or every stack attacking at once; a stack you attack moving out ' +
91
92
  'first (a dodge: into its own territory, or a neutral or one of yours it can take — `dodges` lists each ' +
92
93
  'with the armies that got away and what your strike then hit); two opponents striking one of your ' +
93
94
  'territories together (teammates always; any two in a free-for-all when you lead — `jointFalls` gives the ' +
@@ -509,15 +510,19 @@ export function registerCheckPlanTool(server, ctx) {
509
510
  const sentence = (r) => {
510
511
  const act = r.kind === 'reinforce'
511
512
  ? `deploys ${r.deploy} on territory ${r.deployTo} and holds`
512
- : r.kind === 'attack'
513
- ? `deploys ${r.deploy} on territory ${r.deployTo} and attacks territory ${r.to} with ${r.armies}`
514
- : r.kind === 'dodge'
515
- ? `deploys ${r.deploy} on territory ${r.deployTo} and moves it out first, ${r.armies} into territory ${r.to}`
516
- : r.kind === 'chain'
517
- ? `deploys ${r.deploy} on territory ${r.deployTo} and attacks on through territories ${r.path.slice(1).join(' → ')}`
518
- : r.kind === 'joint'
519
- ? `and player ${r.partner} strike territory ${r.to} together from territories ${r.from} and ${r.partnerDeployTo} (deploying ${r.deploy} and ${r.partnerDeploy})`
520
- : `attacks with every stack at once (${r.attacks.length} attacks), its ${r.deploy} on territory ${r.deployTo}`;
513
+ : r.kind === 'gather'
514
+ ? `${r.deploy > 0 ? `deploys ${r.deploy} on territory ${r.deployTo} and ` : ''}moves ${(r.movedIn ?? [])
515
+ .map((m) => `${m.armies} in from territory ${m.from}`)
516
+ .join(' and ')} onto territory ${r.deployTo}`
517
+ : r.kind === 'attack'
518
+ ? `deploys ${r.deploy} on territory ${r.deployTo} and attacks territory ${r.to} with ${r.armies}`
519
+ : r.kind === 'dodge'
520
+ ? `deploys ${r.deploy} on territory ${r.deployTo} and moves it out first, ${r.armies} into territory ${r.to}`
521
+ : r.kind === 'chain'
522
+ ? `deploys ${r.deploy} on territory ${r.deployTo} and attacks on through territories ${r.path.slice(1).join(' → ')}`
523
+ : r.kind === 'joint'
524
+ ? `and player ${r.partner} strike territory ${r.to} together from territories ${r.from} and ${r.partnerDeployTo} (deploying ${r.deploy} and ${r.partnerDeploy})`
525
+ : `attacks with every stack at once (${r.attacks.length} attacks), its ${r.deploy} on territory ${r.deployTo}`;
521
526
  const when = (needs(r) === 'you' ? ', and you move first' : needs(r) === 'opponent' ? `, and ${r.kind === 'joint' ? 'they move' : 'it moves'} first` : '') +
522
527
  (r.firstOpponent !== undefined ? `, player ${r.firstOpponent} before the other` : '');
523
528
  // With my commander gone everything is: the rest is not listed.
@@ -541,6 +546,8 @@ export function registerCheckPlanTool(server, ctx) {
541
546
  deploy: r.deploy,
542
547
  deployTo: name(r.deployTo),
543
548
  ...(r.kind === 'attack' || r.kind === 'dodge' || r.kind === 'chain' ? { attack: { from: name(r.from), to: name(r.to), armies: r.armies } } : {}),
549
+ // #593 5c: the stacks a gather moved into the target, and what arrived from each.
550
+ ...(r.movedIn ? { movedIn: r.movedIn.map((m) => ({ from: name(m.from), armies: m.armies })) } : {}),
544
551
  // #180: a chain's every territory, and a joint strike's second opponent.
545
552
  ...(r.path ? { path: r.path.map(name) } : {}),
546
553
  ...(r.partner !== undefined
@@ -32,6 +32,10 @@ const READ_BACK_TARGETED = new Set(['Bomb', 'Blockade', 'EmergencyBlockade']);
32
32
  import { compareScores, planAirlift, STAGING_DISCOUNT } from '../analysis/airlift-plan.js';
33
33
  import { planBomb } from '../analysis/bomb-plan.js';
34
34
  import { planBlockade, planWall } from '../analysis/blockade-plan.js';
35
+ import { alternativePlans, STRATEGY_NOTE, stressSummary, turnOptions } from '../analysis/options.js';
36
+ import { FACT_PARTS, FACTS_AVAILABLE, MORE_ON_REQUEST, OWN_PLAN_STEPS, pickFacts, situation } from '../analysis/situation.js';
37
+ import { stressPlan } from '../analysis/stress.js';
38
+ import { baitAttackWarning } from './bait.js';
35
39
  import { breaksInOrders } from '../mod-alliances.js';
36
40
  import { allyAttackLine, attacksOnAllies, MOD_ALLIANCES_NOTE, modAllianceWarnings, readModAlliances } from './mod-alliances.js';
37
41
  import { adviseCards, cardGame, cardPieceOption, giftInOrders, intelOrders, handOwners, lastTurnPlays, opponentCanHold, opponentReinforcement, reinforcementPlaysShown, seenReinforcementPlays, TEAM_HAND } from './card-advice.js';
@@ -1663,6 +1667,8 @@ export async function livePlanSetup(ctx, a) {
1663
1667
  effect, sanction, incomeCap, capUnknown: incomeOnBoard.capUnknown === true, estimates, trip, teams, commerce, statedShifts: shifts,
1664
1668
  // #427: the last turn's Reinforcement plays, for warapp_plan_turn to keep (only when plays show).
1665
1669
  seenPlays: playsShown ? lastPlays : undefined,
1670
+ // #606: the earlier boards (and my orders on them) for the strategy view's summary of past turns.
1671
+ pastBoards: history.boards,
1666
1672
  };
1667
1673
  }
1668
1674
  /** The Airlift card's type id. */
@@ -2424,10 +2430,30 @@ export function registerTurnTools(server, ctx, opts = {}) {
2424
2430
  .optional()
2425
2431
  .describe('Airlift cards to keep in reserve: `airliftPlan` plays only those held beyond this many (default 0). ' +
2426
2432
  'Changes nothing when you hold no Airlift.'),
2433
+ strategy: z
2434
+ .boolean()
2435
+ .optional()
2436
+ .describe('true adds `strategy` (#606), a menu for choosing a turn yourself: `options.captures` — each territory in view beside ' +
2437
+ 'yours that is not yours, ranked by income gained per army: its defenders, the attackers that take it (and, a ' +
2438
+ "player's, after its owner's whole deploy), the spare armies beside it, the bonuses it completes or advances and the new " +
2439
+ 'borders facing a player it opens; `options.holds` — each border facing a player: the armies to add to hold against ' +
2440
+ 'the stacks beside it alone and against them plus one whole deploy, and the held bonuses it protects; `alternatives` — ' +
2441
+ "this plan and the planner under the goals expand and defend, each with its orders, what it expects and its stress test " +
2442
+ "against the opponents' replies (safe, harmful replies, the worst one); `available` — the raw facts you can ask for " +
2443
+ 'with `facts`; and `steps`. Choose, combine or build your own, then check with warapp_check_plan; ' +
2444
+ 'warapp_submit_turn keeps an override reason in the decision log. Default false.'),
2445
+ facts: z
2446
+ .array(z.enum(FACT_PARTS))
2447
+ .min(1)
2448
+ .optional()
2449
+ .describe('The raw game state behind the plan, only the parts you name (#606), as `facts`: `me` (' + FACTS_AVAILABLE.me + '), ' +
2450
+ '`territories` (' + FACTS_AVAILABLE.territories + '), `bonuses` (' + FACTS_AVAILABLE.bonuses + '), `opponents` (' +
2451
+ FACTS_AVAILABLE.opponents + '), `changes` (' + FACTS_AVAILABLE.changes + '), `past` (' + FACTS_AVAILABLE.past + '). ' +
2452
+ 'Ask for what your decision needs; whole past boards are in warapp_turn_history. Default none.'),
2427
2453
  view: viewArg(VIEWS, 'compact (default) gives the plan and orders (the profile as format, phase and standing); "full" adds each ' +
2428
2454
  'move\'s reason, the whole profile and the settings the plan assumed.'),
2429
2455
  }),
2430
- }, async ({ game_id, player, goal, siege_target, jabs, focus, reserve, enemy_deploy, known_income, fogged_attackers, avoid_territories, avoid_players, min_win_chance, first_mover, keep_cards, view }) => {
2456
+ }, async ({ game_id, player, goal, siege_target, jabs, focus, reserve, enemy_deploy, known_income, fogged_attackers, avoid_territories, avoid_players, min_win_chance, first_mover, keep_cards, strategy, facts, view }) => {
2431
2457
  // The chat comes in the same GameFeed read: the fallback for the unread counts (part A1).
2432
2458
  const feed = await ctx.client.getGame(game_id, { settings: true, chat: true });
2433
2459
  requireTurnPhase(feed);
@@ -2805,6 +2831,77 @@ export function registerTurnTools(server, ctx, opts = {}) {
2805
2831
  guessSkip = { reason: 'commander', message };
2806
2832
  }
2807
2833
  }
2834
+ // #606: the raw game state behind the plan, only the parts asked for (report only).
2835
+ const factsView = facts
2836
+ ? pickFacts(situation({
2837
+ graph,
2838
+ board,
2839
+ ...(setup.input.previousBoard ? { previousBoard: setup.input.previousBoard } : {}),
2840
+ me: me.id,
2841
+ ...(setup.teams ? { friends: new Set([...setup.teams].filter(([id, t]) => id !== me.id && t === setup.teams.get(me.id)).map(([id]) => id)) } : {}),
2842
+ rates: { offensiveKillRate: settings.offensiveKillRate, defensiveKillRate: settings.defensiveKillRate },
2843
+ guard: settings.oneArmyStandsGuard !== false,
2844
+ myIncome: income,
2845
+ ...(setup.input.incomeHistory ? { incomeHistory: setup.input.incomeHistory } : {}),
2846
+ pastBoards: setup.pastBoards,
2847
+ opponents: estimates.map((e) => {
2848
+ const t = tracks?.find((x) => x.playerId === e.playerId);
2849
+ return {
2850
+ playerId: e.playerId,
2851
+ estimate: e.estimate,
2852
+ source: e.source,
2853
+ visibleIncome: e.base + e.bonusIncome,
2854
+ tracked: t?.income ?? null,
2855
+ range: e.thinEvidence ? { low: e.thinEvidence.lower, high: e.thinEvidence.upper } : null,
2856
+ coverage: t?.coverage?.share ?? null,
2857
+ ...(t ? { history: t.turns.map((x) => ({ turn: x.to, observed: x.observed })) } : {}),
2858
+ };
2859
+ }),
2860
+ }), facts)
2861
+ : undefined;
2862
+ // #606: ranked options and alternative plans, each stress-tested (opt-in; never changes the plan above).
2863
+ const strategyView = strategy
2864
+ ? (() => {
2865
+ const deployOf = (p) => estimates.find((e) => e.playerId === p)?.estimate ?? 0;
2866
+ const stressOpp = estimates.map((e) => ({ id: e.playerId, deploy: e.estimate }));
2867
+ const stress = (p) => {
2868
+ if (!stressOpp.length)
2869
+ return undefined;
2870
+ try {
2871
+ return stressSummary(stressPlan({
2872
+ graph,
2873
+ board,
2874
+ me: me.id,
2875
+ deploys: p.deploys,
2876
+ moves: p.moves.map((m) => ({ from: m.from, to: m.to, armies: m.armies })),
2877
+ opponents: stressOpp,
2878
+ settings,
2879
+ ...(setup.teams ? { teams: setup.teams } : {}),
2880
+ lookAhead: false,
2881
+ maxReplies: 1,
2882
+ }));
2883
+ }
2884
+ catch {
2885
+ return undefined;
2886
+ }
2887
+ };
2888
+ return {
2889
+ options: turnOptions({
2890
+ graph,
2891
+ board,
2892
+ me: me.id,
2893
+ deployOf,
2894
+ rates: { offensiveKillRate: settings.offensiveKillRate, defensiveKillRate: settings.defensiveKillRate },
2895
+ guard: settings.oneArmyStandsGuard !== false,
2896
+ ...(setup.teams ? { friends: new Set([...setup.teams].filter(([id, t]) => id !== me.id && t === setup.teams.get(me.id)).map(([id]) => id)) } : {}),
2897
+ }),
2898
+ alternatives: alternativePlans(setup.input, plan, stress),
2899
+ available: FACTS_AVAILABLE,
2900
+ steps: OWN_PLAN_STEPS,
2901
+ note: STRATEGY_NOTE,
2902
+ };
2903
+ })()
2904
+ : undefined;
2808
2905
  // #275 (a): the smallest single deploy that takes each border of mine after the plan's orders.
2809
2906
  const headroom = safeHeadroom({
2810
2907
  graph,
@@ -3171,6 +3268,11 @@ export function registerTurnTools(server, ctx, opts = {}) {
3171
3268
  : `${plan.incomeTrend.turns.map((t) => t.income).join(' → ')} over turns ${plan.incomeTrend.turns[0].turn}–${plan.incomeTrend.turns[plan.incomeTrend.turns.length - 1].turn}: ${plan.incomeTrend.slope >= 0 ? '+' : ''}${plan.incomeTrend.slope}/turn${plan.incomeTrend.flat ? ', flat' : ''}`,
3172
3269
  }
3173
3270
  : {}),
3271
+ // #606: the mechanics for the calling model's own choice (opt-in).
3272
+ ...(strategyView ? { strategy: strategyView } : {}),
3273
+ ...(factsView ? { facts: factsView } : {}),
3274
+ // #606: every plan says what more can be asked for (the menu itself names the facts).
3275
+ ...(strategyView ? {} : { more: MORE_ON_REQUEST }),
3174
3276
  // #275 (a): each border's headroom, the weakest first (compact: the first few).
3175
3277
  headroom: headroomView(headroom, map, myIncome, rung === 'full', !teamsKnown, (p) => estimates.find((e) => e.playerId === p)?.estimate),
3176
3278
  ...(rung !== 'full' && headroom.length > HEADROOM_COMPACT ? { headroomMore: headroom.length - HEADROOM_COMPACT } : {}),
@@ -3970,6 +4072,19 @@ export function registerTurnTools(server, ctx, opts = {}) {
3970
4072
  const hopeless = hopelessAttackWarning(attacks, label);
3971
4073
  if (hopeless)
3972
4074
  warnings.push(hopeless);
4075
+ // #593 5c: an attack its stacks beside the target can reinforce before it lands.
4076
+ const bait = baitAttackWarning({
4077
+ graph: graphOf(map),
4078
+ board: territories,
4079
+ me: playerId,
4080
+ moves: moves.map((m, i) => ({ ...m, armies: m.percent ? (options.estimates.get(i) ?? 0) : m.armies })),
4081
+ settings: plannerSettings(game.settings),
4082
+ label,
4083
+ name: (id) => ({ id, name: map.territories.find((t) => t.id === id)?.name ?? String(id) }),
4084
+ teammates,
4085
+ });
4086
+ if (bait)
4087
+ warnings.push(bait);
3973
4088
  // #275 (c): a border of a held bonus these orders leave falling to a deploy below my own income.
3974
4089
  // A warning, never a refusal; the stress test (warapp_check_plan) tries the replies in full.
3975
4090
  const subTeams = teamsOf(game.players);
package/dist/version.js CHANGED
@@ -1,4 +1,4 @@
1
1
  // Single source of truth for the server version. release-please bumps the
2
2
  // literal on the marked line (registered in release-please-config.json
3
3
  // extra-files); every other module imports VERSION from here.
4
- export const VERSION = '0.20.0'; // x-release-please-version
4
+ export const VERSION = '0.22.0'; // x-release-please-version
package/manifest.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "manifest_version": "0.3",
4
4
  "name": "warapp-mcp",
5
5
  "display_name": "war.app (Warzone)",
6
- "version": "0.20.0",
6
+ "version": "0.22.0",
7
7
  "description": "war.app (Warzone) game advisor for Claude — your games, maps, bonuses, board analysis and routes via the GameFeed API, plus your games list (waiting on you first), opponent scouting with your head-to-head, the live board, territory picks, cards, turn planning and submission, turn notifications, and chat through your signed-in war.app tab (ContextMint Bridge). Joining, leaving or surrendering a game, closing out a finished game, accepting another player's surrender, Begin on a speed first turn, picks, turn orders, withdrawing them, chat sends, marking notifications and chat read, deleting notifications, importing local history into a hosted server and linking a session (local only) are confirm-gated.",
8
8
  "author": {
9
9
  "name": "Chris Hall",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@chrischall/warapp-mcp",
3
- "version": "0.20.0",
3
+ "version": "0.22.0",
4
4
  "mcpName": "io.github.chrischall/warapp-mcp",
5
5
  "description": "war.app (Warzone) game advisor MCP server for Claude — games, maps, bonuses and board analysis via the GameFeed API, plus your games list, opponent scouting, the live board, territory picks, cards, turn planning and submission, turn notifications and chat through your signed-in war.app tab. Developed and maintained by AI (Claude Code).",
6
6
  "author": "Claude Code (AI) <https://www.anthropic.com/claude>",
package/server.json CHANGED
@@ -6,12 +6,12 @@
6
6
  "url": "https://github.com/chrischall/warapp-mcp",
7
7
  "source": "github"
8
8
  },
9
- "version": "0.20.0",
9
+ "version": "0.22.0",
10
10
  "packages": [
11
11
  {
12
12
  "registryType": "npm",
13
13
  "identifier": "@chrischall/warapp-mcp",
14
- "version": "0.20.0",
14
+ "version": "0.22.0",
15
15
  "transport": {
16
16
  "type": "stdio"
17
17
  },