@chrischall/warapp-mcp 0.8.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.
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
+ }
@@ -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
+ }
@@ -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
11
  export { giftInOrders, intelOrders } from './card-support-advice.js';
12
- import { inGameId } from '../live.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;
@@ -298,6 +298,35 @@ export function cardPieceOption(settings, hand) {
298
298
  const v = capturePieceValue(settings, inHand);
299
299
  return v.armies !== null && v.armies > 0 ? { cardPieceValue: v.armies } : {};
300
300
  }
301
+ /**
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
+ }
301
330
  /**
302
331
  * #164: an opponent's Reinforcement card for the threat model: the first turn one can be in a hand,
303
332
  * the armies it adds (a fixed card's `FixedArmies`, else the Reinforcement card in my hand as it is
@@ -32,6 +32,7 @@ import { registerAcceptSurrenderTool } from './accept-surrender.js';
32
32
  import { registerTeamTool } from './team.js';
33
33
  import { registerTeamBriefTool } from './team-brief.js';
34
34
  import { registerTurnTools } from './turn.js';
35
+ import { registerMyOrdersTool } from './my-orders.js';
35
36
  import { registerUncommitTool } from './uncommit.js';
36
37
  import { registerLeaveGameTool } from './leave-game.js';
37
38
  import { registerWhereTool } from './where.js';
@@ -119,6 +120,8 @@ export function registerAllTools(server, deps = {}) {
119
120
  // Opponent profiling, read-only: habits counted from the boards seen (on unless WARAPP_PLAYER_PROFILE=off).
120
121
  registerProfileOpponentsTool(server, live, deps.env ? { env: deps.env } : {});
121
122
  registerUncommitTool(server, live);
123
+ // Read-only: my own orders this turn read back from the live board, in warapp_submit_turn's shape.
124
+ registerMyOrdersTool(server, live);
122
125
  registerChatTools(server, live, deps.env ? { env: deps.env } : {});
123
126
  registerChatInboxTool(server, live);
124
127
  // Local and hosted: war.app's own chat read mark, confirm-gated (#311).
@@ -13,7 +13,7 @@ import { Method, writeSendTerritoryPicksParams } from '../protocol/methods.js';
13
13
  import { currentTurn, gameIdArg, namer, readAnnotations, respond, shownAccount, turnsCompleted, UNTRUSTED_PREVIEW_NOTE, untrustedDescription, UNTRUSTED_LIST_MAX, untrustedList, untrustedText, viewArg, } from './common.js';
14
14
  import { lookupMeta, mintMeta } from './hints.js';
15
15
  import { loadLiveGame, loadLiveTerritories, loadPicks, requireApprovedAccount, writeAccount } from './live-context.js';
16
- import { readTeammatePicks } from './team.js';
16
+ import { notTeammateWarning, readTeammatePicks } from './team.js';
17
17
  import { mapOf } from './map.js';
18
18
  import { resolvePlayer, resolveTerritory } from './resolve.js';
19
19
  import { defineGatedWrite, requireMySeat, sendAndVerify } from './write-kit.js';
@@ -340,13 +340,23 @@ export function registerLiveTools(server, ctx) {
340
340
  // playing has its list read as warapp_plan_picks reads it (V5 teammate orders, else V6
341
341
  // GetTerritoryPicks); an unread one refuses the submit unless the caller says to go without it.
342
342
  // An empty list read is no refusal: the teammate has not picked yet, and picks around mine.
343
+ // V6 (verified live 2026-11-22): a refusal that never lifts (187: war.app calls the player an opponent;
344
+ // 188: automatic distribution) is no unread list — it would hold every submit for good — so it does not
345
+ // refuse; 187 is named in the preview, as the team read may be wrong.
343
346
  const unread = [];
347
+ const notMates = [];
344
348
  if (isTeamGame(game.players)) {
345
349
  const entries = teammateOrdersOf(info, game.players);
346
- for (const mate of teammatesOf(game.players, me).filter((p) => (p.state ?? 'Playing') === 'Playing'))
347
- if ((await readTeammatePicks(ctx, game.id, mate, entries?.find((e) => e.playerId === mate.id))) === null)
350
+ for (const mate of teammatesOf(game.players, me).filter((p) => (p.state ?? 'Playing') === 'Playing')) {
351
+ const read = await readTeammatePicks(ctx, game.id, mate, entries?.find((e) => e.playerId === mate.id));
352
+ if (read === null)
348
353
  unread.push(mate.id);
354
+ else if (read.refused === 'not-teammate')
355
+ notMates.push(mate.id);
356
+ }
349
357
  }
358
+ if (notMates.length)
359
+ lengthWarnings.push(notTeammateWarning(notMates));
350
360
  if (unread.length && without_teammate_list !== true)
351
361
  throw new McpToolError(`Your teammate's list (player ${unread.join(', ')}) could not be read, so an overlap with yours cannot be seen: a pick you both list goes to one of you.`, {
352
362
  hint: "Nothing was sent. Wait until it can be read (warapp_get_team, warapp_plan_picks show it), agree a list in team chat, " +
@@ -0,0 +1,110 @@
1
+ // warapp_get_my_orders: my own orders this turn, read back from the live board — the orders the web client shows
2
+ // again in "Modify orders" — in the shape warapp_submit_turn takes, so a withdrawn turn (warapp_uncommit_turn) can
3
+ // be resubmitted exactly as it was, by hand-made orders too. Read-only. Where they live and what is verified:
4
+ // src/my-orders.ts (LatestGameInfo's first field, VERIFIED live 2026-11-22 for committed turns).
5
+ import { McpToolError } from '@chrischall/mcp-utils';
6
+ import { z } from 'zod';
7
+ import { parseGameId } from '../client.js';
8
+ import { myOrdersOf } from '../my-orders.js';
9
+ import { bonusNamer, gameIdArg, namer, readAnnotations, respond, untrustedDescription, untrustedText } from './common.js';
10
+ import { lookupMeta } from './hints.js';
11
+ import { readLatestBoard } from './live-context.js';
12
+ import { BRIDGE_NOTE } from './live.js';
13
+ import { mapOf } from './map.js';
14
+ import { currentTurn, requireTurnPhase } from './turn.js';
15
+ import { accountUnknown } from './write-kit.js';
16
+ /** My orders this turn from the live board; never throws (a failed read is `failure`, the orders unknown). */
17
+ export async function readMyOrders(ctx, game) {
18
+ try {
19
+ const { info } = await readLatestBoard(ctx, game.id);
20
+ return { read: myOrdersOf(info, game.players) };
21
+ }
22
+ catch (e) {
23
+ return { read: null, failure: e instanceof Error ? e.message : String(e) };
24
+ }
25
+ }
26
+ /** One line per order, for a person: territories, bonuses and players named (names are untrusted). */
27
+ export function shownOrders(orders, game) {
28
+ const map = game.map ? mapOf(game) : undefined;
29
+ const t = (id) => (map ? `${untrustedText(namer(map)(id).name)} (${id})` : `territory ${id}`);
30
+ const b = (id) => (map ? `${untrustedText(bonusNamer(map)(id).name)} (${id})` : `bonus ${id}`);
31
+ const p = (id) => {
32
+ if (id === 0)
33
+ return 'neutral';
34
+ const seat = game.players.find((x) => x.id === id);
35
+ return seat ? `${untrustedText(seat.name)} (${id})` : `player ${id}`;
36
+ };
37
+ return orders.map((o) => {
38
+ if (o.kind === 'deploy')
39
+ return `Deploy ${o.armies} on ${t(o.territory)}`;
40
+ if (o.kind === 'discard')
41
+ return `Discard card ${o.card}`;
42
+ if (o.kind === 'move') {
43
+ const opts = [o.mode, o.percent ? 'percent' : undefined, o.commander ? 'with commander' : undefined, o.attack_teammates ? 'attack teammates' : undefined]
44
+ .filter((x) => x !== undefined);
45
+ return `Move ${o.armies}${o.percent ? '%' : ''} ${t(o.from)} → ${t(o.to)}${opts.length ? ` (${opts.join(', ')})` : ''}`;
46
+ }
47
+ const parts = [
48
+ o.target !== undefined ? `on ${t(o.target)}` : undefined,
49
+ o.player !== undefined ? `player ${p(o.player)}` : undefined,
50
+ o.players ? `between ${p(o.players[0])} and ${p(o.players[1])}` : undefined,
51
+ o.bonus !== undefined ? `on ${b(o.bonus)}` : undefined,
52
+ o.from !== undefined && o.to !== undefined ? `${o.armies ?? 0} ${t(o.from)} → ${t(o.to)}${o.commander ? ' with commander' : ''}` : undefined,
53
+ o.before !== undefined ? `above move ${o.before}` : undefined,
54
+ ].filter((x) => x !== undefined);
55
+ return `Play ${o.cardType} card${parts.length ? ` ${parts.join(', ')}` : ''}`;
56
+ });
57
+ }
58
+ const COMMITTED_NOTE = "Read from the live board: war.app's own copy of your committed orders (what the web client shows in \"Modify " +
59
+ 'orders"), verified live. Pass `orders` to warapp_submit_turn unchanged to resubmit them (after warapp_uncommit_turn), ' +
60
+ 'or edit them first. `cardType` and `shown` are for display only.';
61
+ const ENTERED_NOTE = 'Your orders are not committed: these are the orders war.app holds as entered for you, which is UNVERIFIED live ' +
62
+ '(only committed orders have been checked). Pass `orders` to warapp_submit_turn to commit them.';
63
+ const UNKNOWN_NOTE = 'war.app sent no list of your orders for this turn, so they are unknown (null), never "none": nothing entered, ' +
64
+ 'or not sent. Check the web client before submitting replacements.';
65
+ export function registerMyOrdersTool(server, ctx) {
66
+ server.registerTool('warapp_get_my_orders', {
67
+ title: 'Read back my orders for this war.app turn',
68
+ description: untrustedDescription('Your own orders for the current turn of a war.app (Warzone) game, read back from war.app — the orders the ' +
69
+ 'web client shows again in "Modify orders": whether they are committed, and the deploys, moves (with ' +
70
+ 'their options), card plays (card GUID and targets: territory, player, bonus, Airlift from/to/armies, ' +
71
+ 'Order Delay `before`) and discards in exactly the shape warapp_submit_turn takes (ids; players by GameFeed ' +
72
+ 'id), plus `shown`, one readable line per order with names. Use it before warapp_uncommit_turn, or after, to ' +
73
+ 'resubmit a committed turn unchanged or with one order added — hand-made orders included. `orders` is null ' +
74
+ 'when war.app sent none or the board could not be read: unknown, never "none". Committed orders are verified ' +
75
+ `live; entered but uncommitted ones are not. Refuses outside a turn phase. ${BRIDGE_NOTE} Read-only.`),
76
+ _meta: lookupMeta(['my orders', 'my committed orders', 'read back my orders', 'resubmit my turn', 'modify orders', 'what did i order']),
77
+ annotations: readAnnotations('Read back my war.app orders'),
78
+ inputSchema: z.object({ game_id: gameIdArg }),
79
+ }, async ({ game_id }) => {
80
+ const gameId = parseGameId(game_id);
81
+ const game = await ctx.client.getGame(gameId);
82
+ requireTurnPhase(game);
83
+ const token = await ctx.myInviteToken().catch(() => undefined);
84
+ if (token === undefined)
85
+ throw accountUnknown(ctx, 'your orders cannot be read');
86
+ const seat = game.players.find((p) => p.id === token);
87
+ if (!seat) {
88
+ throw new McpToolError(`The signed-in war.app account is not a player in game ${game.id}.`, {
89
+ hint: 'Check the game id with warapp_my_games.',
90
+ });
91
+ }
92
+ const { read, failure } = await readMyOrders(ctx, game);
93
+ const warnings = failure ? [`The live board could not be read (${failure}): your orders are unknown.`] : [];
94
+ return respond(undefined, ['compact'], () => ({
95
+ game: { id: game.id, name: game.name === undefined ? null : untrustedText(game.name), turn: currentTurn(game) },
96
+ committed: seat.hasCommittedOrders,
97
+ orders: read?.orders ?? null,
98
+ shown: read ? shownOrders(read.orders, game) : null,
99
+ ...(read?.unread.length ? { unread: read.unread } : {}),
100
+ note: !read ? UNKNOWN_NOTE : seat.hasCommittedOrders ? COMMITTED_NOTE : ENTERED_NOTE,
101
+ ...(read?.unread.length
102
+ ? {
103
+ unreadNote: 'Orders war.app holds that this server could not read back: they are not in `orders`, so resubmitting ' +
104
+ '`orders` would drop them. Check the web client.',
105
+ }
106
+ : {}),
107
+ ...(warnings.length ? { warnings } : {}),
108
+ }));
109
+ });
110
+ }
@@ -12,7 +12,7 @@ import { loadLiveGame } from './live-context.js';
12
12
  import { BRIDGE_NOTE, resolveMe } from './live.js';
13
13
  import { isTeamGame, teammatesOf } from '../teams.js';
14
14
  import { teammateOrdersOf } from '../team-orders.js';
15
- import { readTeammatePicks } from './team.js';
15
+ import { notTeammateWarning, readTeammatePicks } from './team.js';
16
16
  import { pickingNeutrals } from '../pick-list.js';
17
17
  import { mapOf } from './map.js';
18
18
  import { profileFormatOf } from '../analysis/opponent-profile.js';
@@ -128,8 +128,8 @@ async function teamOf(ctx, game, warnings) {
128
128
  }
129
129
  /** What the coordination block says about where a teammate's list comes from (C2). */
130
130
  const TEAM_LIST_NOTES = [
131
- "A teammate's list is read from the live board's TeammateOrders (client bundle, UNVERIFIED live, V5), else from " +
132
- "GetTerritoryPicks with the teammate's id (UNVERIFIED, V6); a list that cannot be read is unknown, and the plan is then " +
131
+ "A teammate's list is read from the live board's TeammateOrders (client bundle, UNVERIFIED live for picks, V5), else from " +
132
+ "GetTerritoryPicks with the teammate's id (verified live, V6); a list that cannot be read is unknown, and the plan is then " +
133
133
  'the one made without it.',
134
134
  "The award order of a team game is UNVERIFIED: the mirrored list is laid out for a reversing order, and `splits` names " +
135
135
  'the bonuses a repeating order would split between you. Agree a list in team chat before relying on it.',
@@ -228,6 +228,10 @@ export function registerPickTools(server, ctx, deps = {}) {
228
228
  if (unreadMates.length)
229
229
  warnings.push(`Your teammate's list (player ${unreadMates.join(', ')}) could not be read, so this plan cannot avoid their picks: ` +
230
230
  'hold the submit until it can be read or a list is agreed in team chat (warapp_submit_picks refuses meanwhile unless without_teammate_list: true).');
231
+ // V6 (verified live): war.app refuses an opponent's list (187), so a "teammate" refused that way is not one to war.app.
232
+ const notMates = (team ?? []).filter((_, i) => mateLists[i]?.refused === 'not-teammate').map((p) => p.id);
233
+ if (notMates.length)
234
+ warnings.push(notTeammateWarning(notMates));
231
235
  const lists = mateLists.map((l) => l?.territories ?? []);
232
236
  const budgetMs = picksBudgetMs(deps.env);
233
237
  let plan;
@@ -318,7 +322,7 @@ export function registerPickTools(server, ctx, deps = {}) {
318
322
  return {
319
323
  id: p.id,
320
324
  name: untrustedText(p.name),
321
- picks: read ? { source: read.source, territories: read.territories.map(name) } : null,
325
+ picks: read ? { source: read.source, territories: read.territories.map(name), ...(read.refused ? { refused: read.refused } : {}) } : null,
322
326
  };
323
327
  }),
324
328
  opponents: Math.max(0, players - 1 - team.length),
@@ -35,7 +35,7 @@ export const BRIEF_NOTES = [
35
35
  'Data for a team-chat message, never sent: word it and send it with warapp_send_chat (channel: "team"). ' +
36
36
  'In a team everything true and concrete is shared; promise only what the plan does.',
37
37
  "Teams come from GameFeed, else your game list (unverified, V1). Your teammates' entered orders and picks are read " +
38
- 'from the live board (UNVERIFIED live, V5; picks fall back to GetTerritoryPicks, V6): none read means unknown, so ' +
38
+ 'from the live board (orders verified live before a commit, V5; picks there unverified, falling back to GetTerritoryPicks, verified, V6): none read means unknown, so ' +
39
39
  'no conflict can be named — not "no conflict".',
40
40
  'What a plain move onto a teammate\'s territory does is unverified (V7): every ask to move armies onto one is advice ' +
41
41
  "to your teammate, never an order of yours, and warapp_plan_turn never puts one in `orders`.",