@chrischall/warapp-mcp 0.7.0 → 0.9.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.
Files changed (65) hide show
  1. package/.claude-plugin/marketplace.json +2 -2
  2. package/.claude-plugin/plugin.json +1 -1
  3. package/README.md +5 -4
  4. package/dist/analysis/card-support.js +12 -4
  5. package/dist/analysis/coalition.js +55 -0
  6. package/dist/analysis/local-deploy.js +14 -0
  7. package/dist/analysis/opponents.js +2 -1
  8. package/dist/analysis/picks.js +270 -37
  9. package/dist/analysis/plan/after-leftover.js +26 -4
  10. package/dist/analysis/plan/captures.js +86 -14
  11. package/dist/analysis/plan/completed.js +8 -1
  12. package/dist/analysis/plan/conceded-out.js +16 -11
  13. package/dist/analysis/plan/deploy-estimates.js +544 -0
  14. package/dist/analysis/plan/doomed-out.js +135 -0
  15. package/dist/analysis/plan/estimates.js +4 -1
  16. package/dist/analysis/plan/free-capture.js +34 -0
  17. package/dist/analysis/plan/holds.js +8 -309
  18. package/dist/analysis/plan/horizon.js +42 -0
  19. package/dist/analysis/plan/leftover.js +43 -5
  20. package/dist/analysis/plan/observe.js +896 -0
  21. package/dist/analysis/plan/orders.js +35 -1
  22. package/dist/analysis/plan/report.js +10 -4
  23. package/dist/analysis/plan/shared.js +4 -1376
  24. package/dist/analysis/plan/spread-bind.js +49 -0
  25. package/dist/analysis/plan/stand-still.js +5 -3
  26. package/dist/analysis/plan/state.js +12 -0
  27. package/dist/analysis/plan/strike-stack.js +467 -0
  28. package/dist/analysis/plan/strike.js +3 -463
  29. package/dist/analysis/plan/targets.js +219 -28
  30. package/dist/analysis/plan/threats.js +23 -9
  31. package/dist/analysis/plan/transfers.js +24 -1
  32. package/dist/analysis/plan/two-move.js +1 -1
  33. package/dist/analysis/plan/withdraw.js +316 -0
  34. package/dist/analysis/planner.js +106 -43
  35. package/dist/analysis/player.js +4 -0
  36. package/dist/analysis/relations.js +8 -2
  37. package/dist/analysis/stress.js +1 -1
  38. package/dist/bundle.js +4578 -3405
  39. package/dist/cards.js +37 -0
  40. package/dist/my-games.js +2 -0
  41. package/dist/my-orders.js +134 -0
  42. package/dist/open-games.js +94 -10
  43. package/dist/team-cards.js +2 -2
  44. package/dist/team-orders.js +51 -23
  45. package/dist/tools/card-advice.js +57 -13
  46. package/dist/tools/card-support-advice.js +17 -1
  47. package/dist/tools/check-plan.js +2 -1
  48. package/dist/tools/commander-check.js +2 -1
  49. package/dist/tools/decision-capture.js +4 -2
  50. package/dist/tools/index.js +3 -0
  51. package/dist/tools/join-game.js +44 -8
  52. package/dist/tools/live.js +43 -5
  53. package/dist/tools/my-orders.js +110 -0
  54. package/dist/tools/open-games.js +2 -2
  55. package/dist/tools/picks.js +128 -51
  56. package/dist/tools/team-brief.js +1 -1
  57. package/dist/tools/team.js +25 -9
  58. package/dist/tools/turn.js +61 -6
  59. package/dist/tools/uncommit.js +27 -5
  60. package/dist/trend.js +36 -1
  61. package/dist/version.js +1 -1
  62. package/manifest.json +5 -1
  63. package/package.json +1 -1
  64. package/server.json +2 -2
  65. package/skills/warapp-mcp/SKILL.md +9 -2
package/dist/cards.js CHANGED
@@ -435,3 +435,40 @@ export function readActiveCards(info) {
435
435
  walk(standing, 0);
436
436
  return out;
437
437
  }
438
+ const GAME_TURN = /\.GameTurn$/;
439
+ const REINFORCEMENT_PLAY = /\.GameOrderPlayCardReinforcement$/;
440
+ /**
441
+ * #427: who played a Reinforcement card in the last turn, from a decoded LatestGameInfo's `GameTurn` — the
442
+ * turn just resolved: its order list, every player's orders in it that this player may see — and that
443
+ * turn's number (1-based: the GameTurn carries it 0-based). In-game player ids, in order; `undefined` when
444
+ * the info carries no readable GameTurn. Never walks my pending orders (the info's own order list).
445
+ *
446
+ * VERIFIED live 2026-11-22 (read-only GetLatestGameInfo on games in progress): the info carries one
447
+ * `warlight.shared.GameTurn` { null, the order list, int32 turn (0-based: one less than the turns
448
+ * completed), a date }; a card play there is `GameOrderPlayCard<X>` { its own fields, the card GUID, the
449
+ * player (in-game id), its result (pointing back at the order), null } — a Reinforcement play has no own
450
+ * field and no armies. In a game with `CardPlayingsFogged` false an opponent's Reinforcement play showed
451
+ * though none of its deploys were in view. Whether a fogged game hides them was not seen; callers read
452
+ * this only when the game does not fog card plays.
453
+ */
454
+ export function readTurnReinforcementPlays(info) {
455
+ if (!isObj(info))
456
+ return undefined;
457
+ const turn = fields(info).find((v) => isObj(v) && typeof v.$type === 'string' && GAME_TURN.test(v.$type));
458
+ if (!turn)
459
+ return undefined;
460
+ const own = fields(turn);
461
+ const ints = own.filter((v) => typeof v === 'number' && Number.isInteger(v));
462
+ const orders = own.find((v) => Array.isArray(v));
463
+ if (ints.length !== 1 || !orders)
464
+ return undefined;
465
+ const players = [];
466
+ for (const o of orders) {
467
+ if (!isObj(o) || typeof o.$type !== 'string' || !REINFORCEMENT_PLAY.test(o.$type))
468
+ continue;
469
+ const player = fields(o).filter((v) => typeof v === 'number' && Number.isInteger(v)).at(-1);
470
+ if (player !== undefined)
471
+ players.push(player);
472
+ }
473
+ return { turn: ints[0] + 1, players };
474
+ }
package/dist/my-games.js CHANGED
@@ -175,6 +175,8 @@ export function activeGameIds(games, myInGameId) {
175
175
  .filter((g) => g.players.some((p) => p.id === myInGameId && p.stateCode === PLAYER_PLAYING))
176
176
  .map((g) => g.id);
177
177
  }
178
+ /** Games I am playing now: being played or picked with my seat playing (the policy's cap counts these, #423). */
179
+ export const attendedGames = (games, myInGameId) => activeGameIds(games, myInGameId).length;
178
180
  /**
179
181
  * Games whose chat is live (#256): lobbies, games being picked and games being played — every
180
182
  * game in the list but a finished one, whatever my seat's state — plus a finished game whose chat
@@ -0,0 +1,134 @@
1
+ // My own orders this turn, read back from a decoded LatestGameInfo (warapp_get_my_orders).
2
+ //
3
+ // From the client bundle (6.08.0.2, read 2026-11-22): LatestGameInfo's FIRST field is a list of GameOrder —
4
+ // the client's "active orders" (its log line "EndCommit Wrote N active orders"), which it fills on a commit and
5
+ // shows again in "Modify orders" (its ShowCommittedTurn state). The server builds it from the game's
6
+ // ActiveTurnOrders entry for the asking player only, while the game is being played (its second field is the
7
+ // same for picks while distributing). VERIFIED live 2026-11-22: a committed turn read back exactly — two
8
+ // deploys, a Gift card play (recipient and territory), six moves — and five more committed games read their
9
+ // deploys, moves and an Order Priority play. Still UNVERIFIED: what it holds while my orders are entered but not
10
+ // committed (the same ActiveTurnOrders carries a teammate's entered orders before it commits, V5).
11
+ //
12
+ // The field is found by its values, not its minified name: the one field of the info that is a non-empty list of
13
+ // GameOrder records (a teammate's orders sit inside the TeammateOrders dict, never directly in the info). An empty
14
+ // list or none names no field, so it reads as unknown, never as "no orders". Each order is decoded by
15
+ // `decodeOrder` (src/team-orders.ts, shared with the teammate reader) and projected into the shape
16
+ // warapp_submit_turn takes; a card play's own fields are read by class, in the order the bundle's writer puts them
17
+ // (src/protocol/methods.ts `writeCardPlayOrder`). Players come back as GameFeed ids. Never throws.
18
+ import { playersByInGameId } from './live.js';
19
+ import { fields, isObj } from './protocol/decoded.js';
20
+ import { armiesOf, decodeOrder, orderClass } from './team-orders.js';
21
+ const ORDER_PREFIX = 'warlight.shared.GameOrder';
22
+ const isInt = (v) => typeof v === 'number' && Number.isInteger(v);
23
+ const isOrder = (v) => isObj(v) && typeof v.$type === 'string' && v.$type.startsWith(ORDER_PREFIX);
24
+ /**
25
+ * The list of my orders in a decoded LatestGameInfo: the one field that is a non-empty list of GameOrder
26
+ * records. `undefined` (unknown) when there is none, or more than one.
27
+ */
28
+ export function readMyOrderList(info) {
29
+ if (!isObj(info))
30
+ return undefined;
31
+ const lists = fields(info).filter((v) => Array.isArray(v) && v.length > 0 && v.every((o) => o === null || isOrder(o)) && v.some(isOrder));
32
+ return lists.length === 1 ? lists[0].filter((o) => o !== null) : undefined;
33
+ }
34
+ /** Which own fields each card play carries, by class (the bundle's writers; `Abandon` is Emergency Blockade). */
35
+ const TERRITORY_CARDS = new Set(['Blockade', 'Abandon', 'Bomb', 'Reconnaissance']);
36
+ const PLAYER_CARDS = new Set(['Spy', 'Sanctions']);
37
+ const PLAIN_CARDS = new Set(['Reinforcement', 'OrderPriority', 'OrderDelay']);
38
+ /**
39
+ * My orders projected into `warapp_submit_turn`'s shape; `null` (unknown) when the info carries no list of them.
40
+ * A card naming a player not in `players` (in-game ids) is unread, never sent back with a wrong id.
41
+ */
42
+ export function myOrdersOf(info, players) {
43
+ const list = readMyOrderList(info);
44
+ if (!list)
45
+ return null;
46
+ const byInGame = playersByInGameId(players);
47
+ const feedId = (inGame) => (inGame === 0 ? 0 : byInGame.get(inGame)?.id);
48
+ const orders = [];
49
+ const unread = [];
50
+ let movesSeen = 0;
51
+ const delays = [];
52
+ for (const raw of list) {
53
+ const cls = orderClass(raw);
54
+ const d = decodeOrder(raw);
55
+ if (!d) {
56
+ unread.push(cls);
57
+ continue;
58
+ }
59
+ if (d.kind === 'deploy') {
60
+ orders.push({ kind: 'deploy', territory: d.territoryId, armies: d.armies });
61
+ continue;
62
+ }
63
+ if (d.kind === 'move') {
64
+ movesSeen += 1;
65
+ orders.push({
66
+ kind: 'move',
67
+ from: d.from,
68
+ to: d.to,
69
+ armies: d.armies,
70
+ ...(d.mode === 'attack' ? { mode: 'attack-only' } : {}),
71
+ ...(d.mode === 'transfer' ? { mode: 'transfer-only' } : {}),
72
+ ...(d.percent ? { percent: true } : {}),
73
+ ...(d.attackTeammates ? { attack_teammates: true } : {}),
74
+ ...(d.commander ? { commander: true } : {}),
75
+ });
76
+ continue;
77
+ }
78
+ if (d.kind === 'discard') {
79
+ if (d.cardId === undefined)
80
+ unread.push(`${cls} (no card id)`);
81
+ else
82
+ orders.push({ kind: 'discard', card: d.cardId });
83
+ continue;
84
+ }
85
+ const card = { kind: 'card', card: d.cardId ?? d.name, cardType: d.name };
86
+ const ints = d.own.filter(isInt);
87
+ let fieldsOf;
88
+ let missingPlayer;
89
+ const who = (n) => {
90
+ if (n === undefined)
91
+ return undefined;
92
+ const id = feedId(n);
93
+ if (id === undefined)
94
+ missingPlayer = n;
95
+ return id;
96
+ };
97
+ if (PLAIN_CARDS.has(d.cls))
98
+ fieldsOf = {};
99
+ else if (TERRITORY_CARDS.has(d.cls) && ints.length === 1)
100
+ fieldsOf = { target: ints[0] };
101
+ else if (d.cls === 'Surveillance' && ints.length === 1)
102
+ fieldsOf = { bonus: ints[0] };
103
+ else if (PLAYER_CARDS.has(d.cls) && ints.length === 1)
104
+ fieldsOf = { player: who(ints[0]) };
105
+ else if (d.cls === 'Gift' && ints.length === 2)
106
+ fieldsOf = { target: ints[1], player: who(ints[0]) };
107
+ else if (d.cls === 'Diplomacy' && ints.length === 2)
108
+ fieldsOf = { players: [who(ints[0]), who(ints[1])] };
109
+ else if (d.cls === 'Airlift') {
110
+ // An optional Armies, then from, a legacy count the client leaves 0, to.
111
+ const army = armiesOf(d.own[0]);
112
+ if (army && ints.length === 3) {
113
+ fieldsOf = { from: ints[0], to: ints[2], armies: army.count, ...(army.commander ? { commander: true } : {}) };
114
+ }
115
+ }
116
+ if (missingPlayer !== undefined) {
117
+ unread.push(`${cls} (player ${missingPlayer} is not in the game)`);
118
+ continue;
119
+ }
120
+ if (!fieldsOf) {
121
+ unread.push(cls);
122
+ continue;
123
+ }
124
+ const order = { ...card, ...fieldsOf };
125
+ orders.push(order);
126
+ if (d.cls === 'OrderDelay')
127
+ delays.push({ order, movesBefore: movesSeen });
128
+ }
129
+ // Order Delay is written above the move it delays (`before`, 1-based over the moves); after every move, none.
130
+ for (const { order, movesBefore } of delays)
131
+ if (movesBefore < movesSeen)
132
+ order.before = movesBefore + 1;
133
+ return { orders, unread };
134
+ }
@@ -47,7 +47,15 @@ const GI = {
47
47
  players: 16,
48
48
  realTime: 19,
49
49
  settings: 21,
50
+ tournament: 25,
50
51
  };
52
+ /**
53
+ * GameInfoTournament (#423): the coin structure, a number, and the tournament's id (verified live 2026-11-22: the id of
54
+ * both of my tournament games was in war.app's `/API/GameIDFeed?TournamentID=` list; 54 other games held no record).
55
+ */
56
+ const GAME_INFO_TOURNAMENT = 'warlight.shared.GameInfoTournament';
57
+ const GAME_INFO_TOURNAMENT_FIELDS = 3;
58
+ const GT = { tournamentId: 2 };
51
59
  /** GameInfoPlayer: the colour (an optional GameColor), the in-game id, the state (GamePlayerState) and the team. */
52
60
  // `ai` is the client's IsAI (GameInfoPlayer is built from GamePlayer's get_IsAI in that place; read from the bundle).
53
61
  const GP = { color: 0, ai: 4, id: 6, state: 7, team: 8 };
@@ -325,12 +333,25 @@ function readOpenGame(record) {
325
333
  game.openSeatTeams = openSeatTeams;
326
334
  if (settings?.cards)
327
335
  game.cards = settings.cards;
336
+ const tournamentId = tournamentOf(f[GI.tournament]);
337
+ if (tournamentId !== undefined)
338
+ game.tournamentId = tournamentId;
328
339
  const colorsTaken = [...new Set(all.map((p) => p.color).filter((c) => c !== null))];
329
340
  return {
330
341
  game: orderKeys(game),
331
342
  lobby: { seatedPlayerIds: seated.map((p) => p.id), colorsTaken, seated: seated.map((p) => ({ id: p.id, team: p.team, ai: p.ai })) },
332
343
  };
333
344
  }
345
+ /** The tournament id a GameInfoTournament carries (#423); undefined for none or a shape this server does not know. */
346
+ function tournamentOf(v) {
347
+ if (!isObj(v) || v.$type !== GAME_INFO_TOURNAMENT)
348
+ return undefined;
349
+ const f = fields(v);
350
+ if (f.length !== GAME_INFO_TOURNAMENT_FIELDS)
351
+ return undefined;
352
+ const id = f[GT.tournamentId];
353
+ return isInt(id) && id > 0 ? id : undefined;
354
+ }
334
355
  /** `games` with `joined: true` on each lobby where the in-game id `me` holds a seat. */
335
356
  export function markJoined(games, lobbies, me) {
336
357
  return games.map((g) => (lobbies.get(g.id)?.seatedPlayerIds.includes(me) ? orderKeys({ ...g, joined: true }) : g));
@@ -341,7 +362,7 @@ export function withLottery(game, verdict) {
341
362
  }
342
363
  const KEY_ORDER = [
343
364
  'id', 'name', 'url', 'pace', 'bootTime', 'bootTimeMinutes', 'players', 'openSeats', 'seats', 'maxPlayers',
344
- 'teamGame', 'joined', 'lottery', 'lotteryBasis', 'randomTeamsOf', 'openSeatTeams', 'mapId', 'entryFeeCoins', 'prizeCoins', 'cards', 'rules', 'plannerGaps',
365
+ 'teamGame', 'joined', 'tournamentId', 'lottery', 'lotteryBasis', 'randomTeamsOf', 'openSeatTeams', 'mapId', 'entryFeeCoins', 'prizeCoins', 'cards', 'rules', 'plannerGaps',
345
366
  ];
346
367
  function orderKeys(g) {
347
368
  const out = {};
@@ -473,19 +494,58 @@ const POLICY_MIN_BOOT_MINUTES = 12 * 60;
473
494
  * boot time — war.app's "never" — keeps it); no lotteries (#217: `game.lottery`; a likely one whose
474
495
  * map size went unread breaks it too). Lobbies are not counted against the game cap. Pure.
475
496
  */
476
- export function joiningPolicy(game, screen) {
477
- const breaks = policyBreaks(game, screen).map((b) => b.text);
497
+ export function joiningPolicy(game, screen, account) {
498
+ const breaks = policyBreaks(game, screen, account).map((b) => b.text);
499
+ const warnings = policyWarnings(game);
500
+ const warned = warnings.length ? { warnings } : {};
478
501
  if (breaks.length)
479
- return { passes: false, breaks };
502
+ return { passes: false, breaks, ...warned };
480
503
  const unchecked = [];
481
504
  if (!screen)
482
505
  unchecked.push("the cheapest neutral's cost");
483
- return unchecked.length ? { passes: null, breaks, unchecked } : { passes: true, breaks };
506
+ if (account && account.attendedGames === undefined)
507
+ unchecked.push('how many games I am playing');
508
+ if (account && account.negativeBonus === undefined)
509
+ unchecked.push("whether the map has a negative bonus");
510
+ return unchecked.length ? { passes: null, breaks, unchecked, ...warned } : { passes: true, breaks, ...warned };
511
+ }
512
+ /**
513
+ * What the joining policy warns about but never refuses (#423; owner 2026-11-22: a tournament game warns, it never
514
+ * refuses; a game from a template already running is allowed with no preference, so it is not here). Pure.
515
+ */
516
+ export function policyWarnings(game) {
517
+ const out = [];
518
+ if (game.tournamentId !== undefined) {
519
+ out.push(`A tournament game (tournament ${game.tournamentId}): it counts in the tournament, a surrender or boot is a loss there, ` +
520
+ 'and a vote to end is not allowed — join only meaning to play it out');
521
+ }
522
+ return out;
484
523
  }
524
+ /**
525
+ * The owner's cap on games played at once (2026-11-22: 15): a game being played or picked, my seat playing; lobbies
526
+ * are not counted. Joining at the cap breaks the policy.
527
+ */
528
+ export const ATTENDED_GAMES_LIMIT = 15;
485
529
  /** The joining policy's checks, by code, in policy order (#437: the decision log's join context). */
486
- export const POLICY_CHECKS = ['commerce', 'mods', 'custom-scenario', 'neutral-cost', 'seats', 'boot-time', 'lottery'];
530
+ export const POLICY_CHECKS = [
531
+ 'commerce',
532
+ 'mods',
533
+ 'custom-scenario',
534
+ 'neutral-cost',
535
+ 'seats',
536
+ 'boot-time',
537
+ 'lottery',
538
+ 'local-deployment',
539
+ 'commanders',
540
+ 'no-split',
541
+ 'army-cap',
542
+ 'multi-attack',
543
+ 'kill-rates',
544
+ 'attended-games',
545
+ 'negative-bonus',
546
+ ];
487
547
  /** Each rule `game` breaks, its code and the policy's words, in policy order. Pure. */
488
- function policyBreaks(game, screen) {
548
+ function policyBreaks(game, screen, account) {
489
549
  const breaks = [];
490
550
  if (game.rules.some((r) => r.startsWith('Commerce')))
491
551
  breaks.push({ code: 'commerce', text: 'Commerce — the policy joins no Commerce games' });
@@ -501,6 +561,19 @@ function policyBreaks(game, screen) {
501
561
  : `Costly neutrals — the cheapest takes ${screen.armiesToTake} armies, ${screen.turnsOfBaseIncome ?? '∞'} turns of base income; the policy is at most one turn`,
502
562
  });
503
563
  }
564
+ // #423: handicap rules (12 of 26 games played under them): each one is a break, so a join needs an explicit override.
565
+ if (game.rules.includes('Local deployments'))
566
+ breaks.push({ code: 'local-deployment', text: 'Local Deployment — the policy joins no Local Deployment games' });
567
+ if (game.rules.includes('Commanders'))
568
+ breaks.push({ code: 'commanders', text: 'Commanders — the policy joins no Commanders games' });
569
+ if (game.rules.includes('No-split mode'))
570
+ breaks.push({ code: 'no-split', text: 'No-Split — the policy joins no No-Split games' });
571
+ if (game.rules.some((r) => r.startsWith('Army cap')))
572
+ breaks.push({ code: 'army-cap', text: 'An army cap — the policy joins no capped games' });
573
+ if (game.rules.includes('Multi-attack'))
574
+ breaks.push({ code: 'multi-attack', text: 'Multi-Attack — the policy joins no Multi-Attack games' });
575
+ if (game.rules.some((r) => r.startsWith('Kill rates')))
576
+ breaks.push({ code: 'kill-rates', text: 'Kill rates other than 60/70 — the policy joins only the default rates' });
504
577
  const seats = game.maxPlayers ?? game.seats;
505
578
  if (seats > POLICY_MAX_SEATS)
506
579
  breaks.push({ code: 'seats', text: `${seats} seats — the policy is 1v1 or at most four players` });
@@ -513,16 +586,27 @@ function policyBreaks(game, screen) {
513
586
  // breaks must not let one through (#217 live check).
514
587
  if (game.lottery === null)
515
588
  breaks.push({ code: 'lottery', text: `Likely a lottery (${game.lotteryBasis ?? 'map size not read'}) — the policy joins no lotteries` });
589
+ if (account?.attendedGames !== undefined && account.attendedGames >= ATTENDED_GAMES_LIMIT) {
590
+ breaks.push({ code: 'attended-games', text: `${account.attendedGames} games already being played — the policy is at most ${ATTENDED_GAMES_LIMIT} at once` });
591
+ }
592
+ if (account?.negativeBonus === true)
593
+ breaks.push({ code: 'negative-bonus', text: 'The map has a negative bonus — the policy joins no negative-bonus maps' });
516
594
  return breaks;
517
595
  }
518
596
  /**
519
597
  * {@link joiningPolicy} by code (#437): the checks broken, passed and not checked (the neutral cost without
520
598
  * the lobby's screen), and the verdict. Pure.
521
599
  */
522
- export function policyChecks(game, screen) {
523
- const broke = [...new Set(policyBreaks(game, screen).map((b) => b.code))];
600
+ export function policyChecks(game, screen, account) {
601
+ const broke = [...new Set(policyBreaks(game, screen, account).map((b) => b.code))];
524
602
  const unchecked = screen ? [] : ['neutral-cost'];
525
- const passed = POLICY_CHECKS.filter((c) => !broke.includes(c) && !unchecked.includes(c));
603
+ // The two account checks run only when the caller gave an account (the list tool has none: not evaluated, not unchecked).
604
+ if (account && account.attendedGames === undefined)
605
+ unchecked.push('attended-games');
606
+ if (account && account.negativeBonus === undefined)
607
+ unchecked.push('negative-bonus');
608
+ const notEvaluated = account ? [] : ['attended-games', 'negative-bonus'];
609
+ const passed = POLICY_CHECKS.filter((c) => !broke.includes(c) && !unchecked.includes(c) && !notEvaluated.includes(c));
526
610
  return { passes: broke.length ? false : unchecked.length ? null : true, broke, passed, unchecked };
527
611
  }
528
612
  /**
@@ -2,7 +2,7 @@
2
2
  // card my teammate has already entered a play or a discard of is theirs this turn: the plan never plays it
3
3
  // too, and the card advice says who plays each card.
4
4
  //
5
- // UNVERIFIED live: whether war.app sends a teammate's orders before they commit (V5). VERIFIED (V8, #310): how a
5
+ // VERIFIED live 2026-11-22 (V5, #435): war.app sends a teammate's entered orders before they commit. VERIFIED (V8, #310): how a
6
6
  // team's hand and its limit are keyed (teamCardLimit). Tolerant: no teammate orders read means no claim.
7
7
  import { cardsToShed } from './cards.js';
8
8
  /** Every card play and discard in my teammates' entered orders (`teammates`: their player ids), in entry order. */
@@ -82,7 +82,7 @@ export function claimedCardWarning(uses) {
82
82
  return undefined;
83
83
  const each = uses.map((u) => `${u.mine === 'play' ? 'plays' : 'discards'} the ${u.card.name} card ${u.card.id}, which player ${u.player} has already entered a ${u.theirs} of`);
84
84
  return (`These orders ${each.join('; ')}. A team shares one hand and must not use one card twice: leave it to them, or agree in ` +
85
- 'team chat who uses it before committing. Their entered orders are read from the live board (UNVERIFIED live, V5).');
85
+ 'team chat who uses it before committing. Their entered orders are read from the live board (V5, verified live before commit).');
86
86
  }
87
87
  /** The hand with the cards my teammates have claimed moved last (order otherwise kept): a card named by type is then an unclaimed one when there is one. */
88
88
  export function unclaimedFirst(hand, claimed) {
@@ -4,8 +4,9 @@
4
4
  // in-game player id → `warlight.shared.TeammateOrders` { a stamp (int), the orders entered (a list of
5
5
  // GameOrder, during a turn), the picks entered (a list of territory ids, while distributing) }. The client
6
6
  // shows a teammate's orders and picks from it, and counts the card plays and discards in it against the
7
- // team's hand. UNVERIFIED live (V5): whether war.app fills it before the teammate commits, and what it holds
8
- // once they have.
7
+ // team's hand. VERIFIED live 2026-11-22 (V5, #435): war.app fills it with a teammate's entered orders before the
8
+ // teammate commits, never with mine, and sends it empty when no teammate has entered anything (no value names
9
+ // it then: read as unknown). Still UNVERIFIED: the pick list while distributing, and what it holds after a commit.
9
10
  //
10
11
  // Field names are minified, so the dict is found by the registered type name of its values, and an order's
11
12
  // kind by its class name. Within an order, fields are read by kind and read order, as the bundle's readers
@@ -44,7 +45,10 @@ function teammateDict(info) {
44
45
  }
45
46
  return undefined;
46
47
  }
47
- function armiesOf(a) {
48
+ /** The short class name of a decoded order (`GameOrderDeploy`), `unknown` when it has none. */
49
+ export const orderClass = (o) => (isObj(o) ? shortName(o.$type) : 'unknown');
50
+ /** An Armies record's count and whether my commander rides in it; `undefined` when it is not one. */
51
+ export function armiesOf(a) {
48
52
  if (!isObj(a) || a.$type !== ARMIES)
49
53
  return undefined;
50
54
  const f = fields(a);
@@ -54,27 +58,30 @@ function armiesOf(a) {
54
58
  const units = f.find((x) => Array.isArray(x)) ?? [];
55
59
  return { count: numbers[0], commander: units.some((u) => isObj(u) && u.$type === COMMANDER) };
56
60
  }
57
- /** Reads one order into `out`; false when its shape is not understood. */
58
- function readOrder(o, out) {
59
- const type = String(o.$type);
61
+ /** Decodes one GameOrder record by class and read order; `undefined` when its shape is not understood. */
62
+ export function decodeOrder(o) {
63
+ if (!isObj(o) || typeof o.$type !== 'string' || !o.$type.startsWith(ORDER_PREFIX))
64
+ return undefined;
65
+ const type = o.$type;
60
66
  const f = fields(o);
61
67
  const ints = f.filter(isInt);
62
68
  if (type === DEPLOY) {
63
69
  if (ints.length < 2)
64
- return false;
65
- out.deploys.push({ territoryId: ints[0], armies: ints[1] });
66
- return true;
70
+ return undefined;
71
+ return { kind: 'deploy', territoryId: ints[0], armies: ints[1] };
67
72
  }
68
73
  if (type === ATTACK_TRANSFER) {
69
74
  // attackTeammates, mode, byPercent, from, Armies, to, then the base (player …).
70
75
  const [attackTeammates, mode, percent, from, armies, to] = f;
71
76
  const army = armiesOf(armies);
72
- if (typeof attackTeammates !== 'boolean' || typeof percent !== 'boolean' || !isInt(mode) || !isInt(from) || !isInt(to) || !army)
73
- return false;
77
+ if (typeof attackTeammates !== 'boolean' || typeof percent !== 'boolean' || !isInt(mode) || !isInt(from) || !isInt(to) || !army) {
78
+ return undefined;
79
+ }
74
80
  const m = MODES[mode];
75
81
  if (!m)
76
- return false;
77
- out.moves.push({
82
+ return undefined;
83
+ return {
84
+ kind: 'move',
78
85
  from,
79
86
  to,
80
87
  armies: army.count,
@@ -82,21 +89,42 @@ function readOrder(o, out) {
82
89
  ...(percent ? { percent: true } : {}),
83
90
  ...(attackTeammates ? { attackTeammates: true } : {}),
84
91
  ...(army.commander ? { commander: true } : {}),
85
- });
86
- return true;
87
- }
88
- const cardId = f.map(normalizeGuid).find((g) => g !== undefined);
89
- if (type === DISCARD) {
90
- out.discards.push(cardId !== undefined ? { cardId } : {});
91
- return true;
92
+ };
92
93
  }
94
+ const at = f.findIndex((v) => normalizeGuid(v) !== undefined);
95
+ const cardId = at >= 0 ? normalizeGuid(f[at]) : undefined;
96
+ if (type === DISCARD)
97
+ return { kind: 'discard', ...(cardId !== undefined ? { cardId } : {}) };
93
98
  if (type.startsWith(PLAY_CARD)) {
94
99
  const cls = type.slice(PLAY_CARD.length);
95
100
  const t = CARD_CLASS_TYPES[cls] ?? cardTypeByName(cls) ?? null;
96
- out.cards.push({ ...(cardId !== undefined ? { cardId } : {}), type: t, name: t !== null ? cardTypeName(t) : cls || 'card' });
97
- return true;
101
+ return {
102
+ kind: 'card',
103
+ cls,
104
+ type: t,
105
+ name: t !== null ? cardTypeName(t) : cls || 'card',
106
+ ...(cardId !== undefined ? { cardId } : {}),
107
+ own: at >= 0 ? f.slice(0, at) : [],
108
+ };
109
+ }
110
+ return undefined;
111
+ }
112
+ /** Reads one order into `out`; false when its shape is not understood. */
113
+ function readOrder(o, out) {
114
+ const d = decodeOrder(o);
115
+ if (!d)
116
+ return false;
117
+ if (d.kind === 'deploy')
118
+ out.deploys.push({ territoryId: d.territoryId, armies: d.armies });
119
+ else if (d.kind === 'move') {
120
+ const { kind: _kind, ...move } = d;
121
+ out.moves.push(move);
98
122
  }
99
- return false;
123
+ else if (d.kind === 'discard')
124
+ out.discards.push(d.cardId !== undefined ? { cardId: d.cardId } : {});
125
+ else
126
+ out.cards.push({ ...(d.cardId !== undefined ? { cardId: d.cardId } : {}), type: d.type, name: d.name });
127
+ return true;
100
128
  }
101
129
  function ordersOf(list) {
102
130
  if (!Array.isArray(list))
@@ -4,12 +4,12 @@
4
4
  // (Diplomacy, Sanctions), and (PLAN-TEAMS D2) where to play my Diplomacy, Sanctions, Airlift and
5
5
  // Gift. Read-only; everything here is advice — of these only the advised Order Delay is added to the
6
6
  // orders; my Bomb and Emergency Blockade and the D2 cards carry an `order` to pass to warapp_submit_turn.
7
- import { adviseOrderDelay, CARD_BLOCKADE, CARD_ORDER_DELAY, CARD_REINFORCEMENT, isMyCard, readActiveCards } from '../cards.js';
7
+ import { adviseOrderDelay, CARD_BLOCKADE, CARD_ORDER_DELAY, CARD_REINFORCEMENT, isMyCard, readActiveCards, readTurnReinforcementPlays } from '../cards.js';
8
8
  import { blockadeOffer, bombAdvice, bombExposure, wallOffer, wallThreats } from '../analysis/card-threats.js';
9
9
  import { bonusTerritories } from '../analysis/bonuses.js';
10
10
  import { diplomacyOpponents, supportAdvice } from './card-support-advice.js';
11
- export { intelOrders } from './card-support-advice.js';
12
- import { inGameId } from '../live.js';
11
+ export { giftInOrders, intelOrders } from './card-support-advice.js';
12
+ import { inGameId, playersByInGameId } from '../live.js';
13
13
  import { capturePieceValue, cardClock } from '../strategy/card-clock.js';
14
14
  import { isTeamGame, teammatesOf as teamOf } from '../teams.js';
15
15
  const CARD_BOMB = 13;
@@ -299,15 +299,59 @@ export function cardPieceOption(settings, hand) {
299
299
  return v.armies !== null && v.armies > 0 ? { cardPieceValue: v.armies } : {};
300
300
  }
301
301
  /**
302
- * #164: an opponent's Reinforcement card for the threat model: the first turn one can be in a hand
303
- * (the card clock's fastest), the armies it adds (a fixed card's `FixedArmies`, else the
304
- * Reinforcement card in my hand as it is worth now) and the capturing turns each further card
305
- * takes. `undefined` when no Reinforcement card is in play or what it adds is unknown.
302
+ * #427: who played a Reinforcement card in the turn just before `turn` (the one being planned), by GameFeed
303
+ * id, from the LatestGameInfo's last GameTurn (`readTurnReinforcementPlays`); `undefined` when the info has
304
+ * none, the turn is unknown, or the GameTurn is another turn's. A player no seat matches is left out.
305
+ */
306
+ export function lastTurnPlays(info, players, turn) {
307
+ const read = readTurnReinforcementPlays(info);
308
+ if (!read || turn === null || read.turn !== turn - 1)
309
+ return undefined;
310
+ const byInGame = playersByInGameId(players);
311
+ return { turn: read.turn, players: read.players.flatMap((id) => (byInGame.has(id) ? [byInGame.get(id).id] : [])) };
312
+ }
313
+ /** #427: whether the game shows every Reinforcement play: a Reinforcement card in play and `CardPlayingsFogged` false. */
314
+ export function reinforcementPlaysShown(settings) {
315
+ const clock = cardClock(settings);
316
+ return clock !== undefined && clock.playsHidden === false && clock.cards.some((c) => c.card === 'Reinforcement');
317
+ }
318
+ /**
319
+ * #427: the Reinforcement plays seen turn by turn (`seen`: turn → the GameFeed ids that played one; a turn
320
+ * present was read), for the threat model — only when the game says card plays are not fogged
321
+ * (`CardPlayingsFogged` false) and a Reinforcement card is in play: there every play shows. `undefined`
322
+ * otherwise, or with no turn read: the clock alone, as before.
323
+ */
324
+ export function seenReinforcementPlays(settings, seen) {
325
+ if (!reinforcementPlaysShown(settings) || seen.size === 0)
326
+ return undefined;
327
+ const read = [...seen.keys()].sort((a, b) => a - b);
328
+ return { read, plays: read.flatMap((turn) => seen.get(turn).map((player) => ({ player, turn }))) };
329
+ }
330
+ /**
331
+ * #164: an opponent's Reinforcement card for the threat model: the first turn one can be in a hand,
332
+ * the armies it adds (a fixed card's `FixedArmies`, else the Reinforcement card in my hand as it is
333
+ * worth now) and the capturing turns each further card takes. `undefined` when no Reinforcement card
334
+ * is in play, none ever comes, or what it adds is unknown.
335
+ *
336
+ * #427 (proposed, owner approval pending): the clock runs at the EXPECTED weighted rate — the card's
337
+ * minimum per capturing turn plus its weighted share of the pieces drawn at random (`capturePieceValue`'s
338
+ * rate) — not the fastest (every random piece a Reinforcement piece), which counted a card every turn or
339
+ * two where one comes every few. Where no piece is drawn at random (most games) the two are the same.
306
340
  */
307
341
  export function opponentReinforcement(settings, hand) {
308
- const entry = cardClock(settings)?.cards.find((c) => c.card === 'Reinforcement');
309
- const first = entry?.firstPlayableTurn.fastest;
310
- if (!entry || first === null || first === undefined)
342
+ const clock = cardClock(settings);
343
+ const entry = clock?.cards.find((c) => c.card === 'Reinforcement');
344
+ if (!clock || !entry)
345
+ return undefined;
346
+ const drawWeight = clock.cards.reduce((n, c) => n + c.weight, 0);
347
+ const rate = entry.minimumPerTurn + (entry.weight > 0 && drawWeight > 0 ? (clock.randomPerTurn * entry.weight) / drawWeight : 0);
348
+ // Capturing turns until the k-th card is complete (pieces carried over); null when it never comes.
349
+ const turnsFor = (k) => {
350
+ const need = k * entry.pieces - entry.initialPieces;
351
+ return need <= 0 ? 0 : rate > 0 ? Math.ceil(need / rate - 1e-9) : null;
352
+ };
353
+ const firstTurns = turnsFor(1);
354
+ if (firstTurns === null)
311
355
  return undefined;
312
356
  const raw = settings.raw.ReinforcementCard;
313
357
  const fixed = typeof raw === 'object' && raw !== null ? Number(raw.FixedArmies) : NaN;
@@ -315,7 +359,7 @@ export function opponentReinforcement(settings, hand) {
315
359
  const armies = Number.isFinite(fixed) && fixed > 0 ? Math.floor(fixed) : inHand;
316
360
  if (armies === undefined || armies <= 0)
317
361
  return undefined;
318
- const after = entry.cardsAfter.fastest;
319
- const turnsPerCard = after && after.length >= 2 ? Math.max(1, after[1] - after[0]) : null;
320
- return { firstTurn: first, armies, turnsPerCard };
362
+ const second = turnsFor(2);
363
+ // Pieces arrive at the end of a turn, so the first card is playable the turn after its last piece.
364
+ return { firstTurn: firstTurns + 1, armies, turnsPerCard: second === null ? null : Math.max(1, second - firstTurns) };
321
365
  }
@@ -24,6 +24,18 @@ const CARD_SANCTIONS = 9;
24
24
  export function intelOrders(view) {
25
25
  return [view.spy, view.reconnaissance, view.surveillance].flatMap((a) => (a?.inOrders ? [a.order] : []));
26
26
  }
27
+ /**
28
+ * #435: the advised completing Gift when its play is verified live: the card orders warapp_plan_turn adds,
29
+ * and whether a planned move is one of the transfers the gift drops. Nothing (no cards, no move dropped)
30
+ * while Gift is unverified or none is advised.
31
+ */
32
+ export function giftInOrders(view) {
33
+ const g = view.gift?.inOrders ? view.gift : undefined;
34
+ return {
35
+ cards: g ? g.orders : [],
36
+ drops: (m) => !!g?.drop?.some((d) => d.from === m.from && d.to === m.to),
37
+ };
38
+ }
27
39
  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).';
28
40
  const IN_ORDERS = 'In the orders: its encoding is verified live. Drop it from the orders to keep the card.';
29
41
  /** The Sanctions percentage (`SanctionsCard.Percentage`), when the settings carry one. */
@@ -157,13 +169,17 @@ export function supportAdvice(input) {
157
169
  if (gifts.length) {
158
170
  const g = giftAdvice(cb, input.plan.team?.sharedBonuses ?? [], gifts.length);
159
171
  if (g) {
172
+ // #435: a completing gift goes into the orders once its play is verified live (as #434's spy cards).
173
+ const live = !(input.unverifiedPlays ?? UNVERIFIED_CARD_PLAYS).has('Gift');
160
174
  view.gift = {
161
175
  player: g.player,
162
176
  bonus: g.bonus,
163
177
  territories: g.territories,
178
+ ...(g.drop.length ? { drop: g.drop } : {}),
179
+ ...(live ? { inOrders: true } : {}),
164
180
  orders: g.territories.map((t, i) => ({ kind: 'card', card: gifts[i].id, target: t, player: g.player })),
165
181
  };
166
- warnings.push(`${g.why} ${PLAY_IT}`);
182
+ warnings.push(`${g.why} ${live ? `${IN_ORDERS}${g.drop.length ? ' The transfers it drops are out of the orders.' : ''}` : PLAY_IT}`);
167
183
  }
168
184
  }
169
185
  return { view, warnings };
@@ -3,6 +3,7 @@
3
3
  // opponent could make with its estimated deploy, and the replies that cost something are
4
4
  // reported, worst first (src/analysis/stress.ts, on the turn resolver src/analysis/turn-sim.ts).
5
5
  // Read-only on war.app, and it writes nothing but its verdict to the decision log (#437): not the board cache.
6
+ import { gameBaseIncome } from '../analysis/player.js';
6
7
  import { McpToolError } from '@chrischall/mcp-utils';
7
8
  import { z } from 'zod';
8
9
  import { stressPlan } from '../analysis/stress.js';
@@ -354,7 +355,7 @@ export function registerCheckPlanTool(server, ctx) {
354
355
  ...(teams.size ? { teams } : {}),
355
356
  ...(first_mover !== undefined ? { firstMover: first_mover } : {}),
356
357
  orderPriority,
357
- ...(settings.localDeployments ? { localDeployments: true } : {}),
358
+ ...(settings.localDeployments ? { localDeployments: true, baseIncome: gameBaseIncome(settings) } : {}),
358
359
  ...(settings.localDeployments && (settings.bonusArmyPer ?? 0) > 0 ? { perTerritoryIncome: true } : {}),
359
360
  leader,
360
361
  ...(binding.length ? { truces: binding.map((r) => ({ player: r.player, covered: r.coveredMine })) } : {}),