@chrischall/warapp-mcp 0.24.0 → 0.26.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,53 @@
1
+ // #693: the turn order for a game, from this server's decision log (the visible orders of each resolved turn it kept,
2
+ // #570) and, when given, the live board's own last turn — no request of its own. Pure model: src/analysis/turn-order.ts.
3
+ import { factOfTurn, readTurnOrder } from '../analysis/turn-order.js';
4
+ import { readDecisionLog } from '../decision-log.js';
5
+ import { readSeenTurn } from '../turn-orders.js';
6
+ import { currentTurn } from './common.js';
7
+ /** Turns projected after the one being played. */
8
+ export const TURN_ORDER_HORIZON = 5;
9
+ export const TURN_ORDER_NOTE = 'From the client code: a Cycle or No-luck Cycle game keeps one cycle, taken forward and backward on alternate turns ' +
10
+ '(whoever moved first moves last next turn; a seat that leaves drops out), and an Order Priority or Order Delay play ' +
11
+ 're-sorts its own turn only. Under Random every turn is drawn afresh. `known` rows are read from that turn: war.app\'s ' +
12
+ 'own MoveOrder when sent, else inferred from the order the visible moves ran in: moves run one per player per round ' +
13
+ 'and the order reverses after every round (A B C, C B A, …), so a player\'s j-th visible move before my j-th move puts ' +
14
+ 'it before me when j is odd, after me when j is even. `projected` rows apply the rule. Players by GameFeed id.';
15
+ /** The facts the log (and the live board's last turn, which wins for its turn) hold. */
16
+ export function orderFacts(log, me, info) {
17
+ const out = new Map();
18
+ for (const [k, e] of Object.entries(log?.turns ?? {})) {
19
+ if (!/^\d+$/.test(k) || !e.seen)
20
+ continue;
21
+ const f = factOfTurn({ turn: Number(k), ...e.seen }, me, e.sent ? { sentMoves: e.sent.moves.length } : {});
22
+ if (f)
23
+ out.set(f.turn, f);
24
+ }
25
+ const live = info?.seen;
26
+ if (live) {
27
+ const sent = log?.turns[String(live.turn)]?.sent;
28
+ const f = factOfTurn(live, me, sent ? { sentMoves: sent.moves.length } : {});
29
+ if (f)
30
+ out.set(f.turn, f);
31
+ }
32
+ return [...out.values()];
33
+ }
34
+ /**
35
+ * The turn order for `me` in `game` while it is played; `undefined` when not playing, my seat is out, or no data dir.
36
+ * `log` saves a read when the caller holds it; `info` is the live LatestGameInfo when the caller read one.
37
+ */
38
+ export async function turnOrderFor(a) {
39
+ const { game, me } = a;
40
+ const turn = currentTurn(game);
41
+ if (!a.dataDir || turn === null || game.state !== 'Playing')
42
+ return undefined;
43
+ if (game.players.find((p) => p.id === me)?.state !== 'Playing')
44
+ return undefined;
45
+ const log = a.log ?? (await readDecisionLog(a.dataDir, game.id, me).catch(() => undefined));
46
+ const seen = a.info !== undefined ? readSeenTurn(a.info, game.players) : undefined;
47
+ const facts = orderFacts(log, me, seen && seen.turn === turn - 1 ? { seen } : {});
48
+ const playing = game.players.filter((p) => p.id !== me && p.state === 'Playing').map((p) => p.id);
49
+ return {
50
+ ...readTurnOrder({ moveOrder: game.settings?.moveOrder, turn, me, playing, facts, horizon: TURN_ORDER_HORIZON }),
51
+ note: TURN_ORDER_NOTE,
52
+ };
53
+ }
@@ -22,6 +22,7 @@ import { SERVER_ERROR_MESSAGES } from '../protocol/rpc.js';
22
22
  import { inferFirstMover } from '../move-order.js';
23
23
  import { KNOWN_MODS } from '../known-mods.js';
24
24
  import { assumedWarning, awardView, firstMoverFor, loadAward, openingThreat } from './award.js';
25
+ import { turnOrderFor } from './turn-order.js';
25
26
  import { boardCardsInEffect, CARDS_IN_EFFECT_UNVERIFIED, sanctionMyIncome } from './card-effects.js';
26
27
  import { sanctionPercentage } from '../analysis/cards-in-effect.js';
27
28
  import { myOrdersOf as committedOrdersOf, readMyOrderList } from '../my-orders.js';
@@ -38,7 +39,7 @@ import { FACT_PARTS, FACTS_AVAILABLE, MORE_ON_REQUEST, OWN_PLAN_STEPS, pickFacts
38
39
  import { stressPlan } from '../analysis/stress.js';
39
40
  import { baitAttackWarning } from './bait.js';
40
41
  import { breaksInOrders } from '../mod-alliances.js';
41
- import { allyAttackLine, attacksOnAllies, MOD_ALLIANCES_NOTE, modAllianceWarnings, readModAlliances } from './mod-alliances.js';
42
+ import { allyAttackLine, attacksOnAllies, MOD_ALLIANCES_NOTE, modAllianceWarnings, modPacts, readModAlliances } from './mod-alliances.js';
42
43
  import { adviseCards, cardGame, cardPieceOption, giftInOrders, intelOrders, handOwners, lastTurnPlays, opponentCanHold, opponentReinforcement, reinforcementPlaysShown, seenReinforcementPlays, TEAM_HAND } from './card-advice.js';
43
44
  import { currentTurn, turnsCompleted, gameIdArg, knownIncomeArg, avoidPlayersArg, avoidTerritoriesArg, graphOf, namer, playerNamer, readAnnotations, respond, shownAccount, UNTRUSTED_PREVIEW_NOTE, untrustedDescription, untrustedText, viewArg, } from './common.js';
44
45
  import { lookupMeta, mintMeta } from './hints.js';
@@ -77,12 +78,13 @@ import { readDecisionLog, scrubNames } from '../decision-log.js';
77
78
  import { readPickRecord } from '../pick-list.js';
78
79
  import { commitmentWarnings } from '../analysis/commitments.js';
79
80
  import { MAX_EXCEPTION_NOTE, planRelationsFrom, truceBreaksIn } from '../analysis/relations.js';
80
- import { coordinationView, exceptionNote, recordBrokenByMe, recordPartnerApproved } from './relations.js';
81
+ import { coordinationView, exceptionNote, recordBrokenByMe, recordPartnerApproved, relationPlayers } from './relations.js';
81
82
  import { readPlayerRecord } from '../player-record-store.js';
82
83
  import { withTeammateOrders } from '../team-orders.js';
83
84
  import { claimedCardUses, claimedCardWarning, teamCardClaims, teamCardLimit, teamCardRoles, teamHandLeft, unclaimedFirst, } from '../team-cards.js';
84
85
  import { isTeamGame, teammatesOf } from '../teams.js';
85
- import { readLedger, recordTruceUsage } from '../relations-store.js';
86
+ import { ledgerTruces, readLedger, recordTruceUsage } from '../relations-store.js';
87
+ import { atPeaceWith, pactJointThreats, pactsBasis, pactsWithoutMe, pactThreatWarnings } from '../analysis/pacts.js';
86
88
  import { coordinationDue, coordinationLine } from '../analysis/coordination.js';
87
89
  import { resolveIntel } from '../analysis/intel.js';
88
90
  import { readSiegeMemory, writeSiegeMemory } from '../siege-store.js';
@@ -97,6 +99,9 @@ import { myCommanderTerritory } from '../analysis/commander-safety.js';
97
99
  import { commanderCheckOn, defaultFoggedCount, foggedAttackersArg, foggedCommanderOn, foggedCommanderText, guessKeepsCommander, myLargestStack, } from './commander-check.js';
98
100
  import { foggedStack, likelyStackAt } from '../analysis/commander-fog.js';
99
101
  import { VACATED_FOG_ARMIES } from '../analysis/plan/vacated.js';
102
+ import { nextIncomeLow } from '../analysis/income-range.js';
103
+ import { incomeRules } from '../analysis/player.js';
104
+ import { recordIncomeLow } from '../decision-log.js';
100
105
  import { HEADROOM_COMPACT, headroomView, headroomWarnings, keepTripwires, readTripwires, safeHeadroom, teamsOf, tripwireWarnings, untrustedDeploy } from './survival.js';
101
106
  const VIEWS = ['compact', 'full'];
102
107
  /** #415 task 4b: the chat-blocks-the-turn gate, the context's when set, else read from the environment. */
@@ -1293,6 +1298,7 @@ async function promiseWarnings(ctx, a) {
1293
1298
  return commitmentWarnings({
1294
1299
  commitments: ledger.commitments,
1295
1300
  agreements: ledger.agreements,
1301
+ pacts: ledger.pacts,
1296
1302
  graph: a.graph,
1297
1303
  board: a.board,
1298
1304
  me: a.me.id,
@@ -1314,8 +1320,21 @@ export async function truceRelations(ctx, a) {
1314
1320
  const ledger = ctx.dataDir ? await readLedger(ctx.dataDir, game.id, me.id) : undefined;
1315
1321
  // T9: the Diplomacy 2 mod's alliances (no request in a game without the mod).
1316
1322
  const mod = await readModAlliances(ctx, game, me);
1323
+ const players = relationPlayers(game.players);
1324
+ // #680: the pacts between other players (the ledger's, the cards', the mod's): report only, never planned on.
1325
+ // #686: watched over my boards for breaches (report only); a broken one stops counting as a pact.
1326
+ const pacts = pactsWithoutMe({
1327
+ pacts: ledger?.pacts,
1328
+ me: me.id,
1329
+ turn,
1330
+ players,
1331
+ diplomacy: a.diplomacyOthers,
1332
+ mod: modPacts(mod),
1333
+ watch: { graph, boards: [...a.boards, { turn, board: a.board }], ...cardsInPlay(game) },
1334
+ });
1317
1335
  const resolved = planRelationsFrom({
1318
- agreements: ledger?.agreements ?? [],
1336
+ // #680: a pact I am in reads as one pairwise truce per partner, exactly as the same truces recorded apart.
1337
+ agreements: ledgerTruces(ledger),
1319
1338
  graph,
1320
1339
  board: a.board,
1321
1340
  boards: [...a.boards, { turn, board: a.board }],
@@ -1341,7 +1360,18 @@ export async function truceRelations(ctx, a) {
1341
1360
  ...(a.diplomacy?.length ? { diplomacy: a.diplomacy } : {}),
1342
1361
  ...(mod.status === 'read' && mod.allies.length ? { modAllies: mod.allies } : {}),
1343
1362
  });
1344
- return { ...resolved, mod };
1363
+ return { ...resolved, mod, pacts };
1364
+ }
1365
+ /**
1366
+ * #680: the pacts between other players as threats to me: each with my teammates left out of its parties (their
1367
+ * stacks are no threat), and only those still naming two players or more.
1368
+ */
1369
+ export function foePacts(pacts, players, me) {
1370
+ const mates = new Set(teammatesOf(players, me).map((p) => p.id));
1371
+ return pacts.flatMap((k) => {
1372
+ const parties = k.parties.filter((p) => !mates.has(p));
1373
+ return parties.length >= 2 ? [{ ...k, parties }] : [];
1374
+ });
1345
1375
  }
1346
1376
  /**
1347
1377
  * The reads of my opponents in contact on `board` (a territory of theirs next to one of mine) with at
@@ -1423,7 +1453,11 @@ export async function livePlanSetup(ctx, a) {
1423
1453
  orderPriorityPossible: opponentCanHold(game.settings, 'Order Priority', turn - 1),
1424
1454
  })
1425
1455
  : null;
1426
- const mover = await firstMoverFor(ctx.dataDir, game, me, turn, first_mover, award, { write, ...(inferred ? { inferred } : {}) });
1456
+ const keptMover = await firstMoverFor(ctx.dataDir, game, me, turn, first_mover, award, { write, ...(inferred ? { inferred } : {}) });
1457
+ // #693: the move order of every seat, from the turns kept and this board's last turn (no request). It fills the
1458
+ // first mover only when nothing above gave one and every opponent still playing reads the same way; never verified.
1459
+ const turnOrder = await turnOrderFor({ dataDir: ctx.dataDir, game, me: me.id, info }).catch(() => undefined);
1460
+ const mover = keptMover.firstMover === undefined && turnOrder?.firstMover ? fromTurnOrder(turnOrder.firstMover, keptMover.warnings) : keptMover;
1427
1461
  const settings = plannerSettings(game.settings);
1428
1462
  const rules = cardRules(game.settings);
1429
1463
  // A team shares one hand (#163): mine and my teammates' cards.
@@ -1534,7 +1568,7 @@ export async function livePlanSetup(ctx, a) {
1534
1568
  // B2: the truces in force, from the agreement ledger (warapp_record_agreement) and my board
1535
1569
  // history, and the tacit truces (reported, never planned on).
1536
1570
  const truces = await truceRelations(ctx, {
1537
- game, me, turn, graph, board: seen, boards: history.boards, myIncome: boardIncome, tracks, diplomacy: effect.diplomacy,
1571
+ game, me, turn, graph, board: seen, boards: history.boards, myIncome: boardIncome, tracks, diplomacy: effect.diplomacy, diplomacyOthers: effect.diplomacyOthers,
1538
1572
  });
1539
1573
  // The per-opponent estimates the plan works from (as planTurn reads them), for the tripwire and the border guess.
1540
1574
  const estimateArgs = {
@@ -1677,6 +1711,22 @@ export async function livePlanSetup(ctx, a) {
1677
1711
  seenPlays: playsShown ? lastPlays : undefined,
1678
1712
  // #606: the earlier boards (and my orders on them) for the strategy view's summary of past turns.
1679
1713
  pastBoards: history.boards,
1714
+ // #693: who moves before me, this turn and the next ones (plan_turn's full view).
1715
+ turnOrder,
1716
+ };
1717
+ }
1718
+ /** #693: the plan's first mover from the turn order: inferred, never verified (it orders moves, never sizes a hold). */
1719
+ function fromTurnOrder(f, warnings) {
1720
+ const said = f.basis === 'move-order' ? "war.app's move order for an earlier turn" : 'the order earlier turns\' visible moves ran in';
1721
+ return {
1722
+ firstMover: f.who,
1723
+ verified: false,
1724
+ view: {
1725
+ who: f.who === 'me' ? 'you' : 'opponent',
1726
+ source: 'inferred',
1727
+ line: `${f.who === 'me' ? 'You move' : 'Every opponent moves'} first on turn ${f.turn} (the move order alternates every turn; from ${said}, not verified).`,
1728
+ },
1729
+ warnings,
1680
1730
  };
1681
1731
  }
1682
1732
  /** The Airlift card's type id. */
@@ -2223,7 +2273,10 @@ export function registerTurnTools(server, ctx, opts = {}) {
2223
2273
  'keep only the opponents in view or holding land within 2 steps of yours, and `scale` sums the rest: their count, ' +
2224
2274
  'summed deploy estimate and the biggest; the orders are planned as before): your income, deploys and attacks/transfers by territory name and id (each attack with ' +
2225
2275
  '`winChance`, its exact capture probability), the expected captures, completed bonuses and next income ' +
2226
- '(with `nextIncomeIfConcededFall` and `bonusesAtRisk` when the plan concedes borders of a bonus you hold), ' +
2276
+ '(with `nextIncomeIfConcededFall` and `bonusesAtRisk` when the plan concedes borders of a bonus you hold; ' +
2277
+ '#698: `nextIncome` is the best case, every capture landing and nothing falling, and `nextIncomeLow` with ' +
2278
+ '`nextIncomeLowFalls` the low end, the conceded borders and those the headroom says fall to less than their ' +
2279
+ "opponent's estimate gone), " +
2227
2280
  'the borders given up (`conceded`), the `frontier` budget, `incomeTrend` (my income over the last five turns, its slope per turn and whether it is flat; #303), in a 1v1 the `gates` (every border facing the opponent against its one floating deploy: what they need, what stands on them, the shortfall), your cards (plays and discards when you must), ' +
2228
2281
  'warnings and the reasoning. Its `orders` array is exactly what warapp_submit_turn takes — review it with ' +
2229
2282
  'the user first. Every plan reads the game profile (`profile`: format 1v1/ffa/teams, phase, standing ' +
@@ -2295,6 +2348,9 @@ export function registerTurnTools(server, ctx, opts = {}) {
2295
2348
  'With an army cap, `income` is what the cap leaves, min(income, cap × income − your armies on the board) (verified by ' +
2296
2349
  'six live cases; the line names a cut), and `incomeCapped` gives the arithmetic; Reinforcement card armies come on top. ' +
2297
2350
  'In a free-for-all, `relations` reports each truce recorded with warapp_record_agreement as the plan treated it ' +
2351
+ '(#680: an n-way truce you are in, once per partner, exactly as the same two-party truces; a pact between other ' +
2352
+ 'players is report only — a warning where two of its parties each have a stack beside one territory of yours, the ' +
2353
+ "outlook's basis naming it, and a coalition partner at peace with the leader left out — never a change to the orders) " +
2298
2354
  '(no covered territory of the partner attacked while it is active or in notice; a covered border facing only ' +
2299
2355
  'the partner held against its stacks with no deploy, except your commander\'s, a valuable border, or while trust ' +
2300
2356
  'is watch; a border cap kept; a partner-approved truce exception on this turn makes its territories normal ' +
@@ -2318,7 +2374,10 @@ export function registerTurnTools(server, ctx, opts = {}) {
2318
2374
  'neither takes alone) are advice, never in `orders`; `cards.team` says who plays each card, leaving theirs to them. ' +
2319
2375
  '`firstMover` is who the plan takes to move first this turn (null when unknown) and its `source`: ' +
2320
2376
  '"explicit" (`first_mover`), "award", or "remembered" — a turn this server kept, alternated (two players, ' +
2321
- 'cyclic order). ' +
2377
+ 'cyclic order) — or "inferred" (#693: from the move order of earlier turns, any number of players, only when every ' +
2378
+ 'opponent still playing moves on the same side of you; never verified, so it orders moves but sizes no hold). ' +
2379
+ 'View "full" adds `turnOrder`: who moves before you on the last turns read, this one and the next five (as ' +
2380
+ 'warapp_get_game reports it). ' +
2322
2381
  'When one opponent touches two or more of your borders and no fixed split of the deploys there holds them all, ' +
2323
2382
  '`guess` is a randomized split, weighted by what each border is worth, against an opponent who would read a fixed ' +
2324
2383
  'one, and `guessOrders` the plan\'s `orders` with that split — optional (the user chooses; `orders` stay the ' +
@@ -2925,6 +2984,21 @@ export function registerTurnTools(server, ctx, opts = {}) {
2925
2984
  ...(mover.firstMover !== undefined && mover.verified ? { firstMover: mover.firstMover } : {}),
2926
2985
  ...(advised ? { orderPriority: true } : {}),
2927
2986
  });
2987
+ // #698: the low end of next income — the conceded borders and those the headroom says fall to less than
2988
+ // their opponent's own estimate gone (report only; kept in the decision log to be scored against the outcome).
2989
+ const incomeLow = nextIncomeLow({
2990
+ graph,
2991
+ rules: incomeRules(game.settings),
2992
+ board,
2993
+ me: me.id,
2994
+ captures: plan.expected.captures,
2995
+ conceded: plan.conceded,
2996
+ nextIncome: plan.expected.nextIncome,
2997
+ headroom,
2998
+ estimateOf: (p) => estimates.find((e) => e.playerId === p)?.estimate,
2999
+ });
3000
+ if (incomeLow && ctx.dataDir && turn !== null && !whatIf)
3001
+ await recordIncomeLow(ctx.dataDir, game.id, me.id, turn, incomeLow, ctx.decisionLog ? { mode: ctx.decisionLog } : {});
2928
3002
  const guessOrders = guess ? guessOrdersOf(orders, guess) : undefined;
2929
3003
  // Owner request 2026-11-24: with Airlift cards in hand, the best plan that plays them, ALONGSIDE the plain
2930
3004
  // plan (whose orders never change): candidates scored by the plain plan's own measure (airlift-plan.ts).
@@ -2970,6 +3044,11 @@ export function registerTurnTools(server, ctx, opts = {}) {
2970
3044
  // #385: siege_target only means something under goal siege; say so rather than drop it silently.
2971
3045
  if (siege_target !== undefined && goal !== 'siege')
2972
3046
  warnings.push(`siege_target is ignored: it applies only with goal "siege" (this plan's goal is ${goal ?? 'chosen by the game profile'}).`);
3047
+ // #680: pacts I am not in, report only: two parties each with a stack beside one territory of mine may strike
3048
+ // together (no order changes), and the outlook's basis names the pacts.
3049
+ const otherPacts = foePacts(truces?.pacts ?? [], game.players, me);
3050
+ warnings.push(...pactThreatWarnings(pactJointThreats(graph, seen, me.id, otherPacts)));
3051
+ const outlookBasis = outlook.basis + pactsBasis(otherPacts);
2973
3052
  // #317: a surrender waiting on my acceptance is the first thing said, before the commander's line.
2974
3053
  // #436: the surrender line, advice only (the server never acts on it): said up front once crossed.
2975
3054
  // #445 (owner, 2026-11-23): in a free-for-all with three or more still playing, once the line is crossed, a
@@ -2990,7 +3069,10 @@ export function registerTurnTools(server, ctx, opts = {}) {
2990
3069
  breakers.add(p);
2991
3070
  }
2992
3071
  const ledger = ctx.dataDir ? await readLedger(ctx.dataDir, game.id, me.id) : undefined;
2993
- const atWar = atWarWith(ledger, trailing);
3072
+ // #680: a pact I am in counts per partner, as the same truces recorded apart would.
3073
+ const atWar = atWarWith(ledger ? { ...ledger, agreements: ledgerTruces(ledger) } : undefined, trailing);
3074
+ // #680: a player at peace with the leader (a pact I am not in) is no partner against it.
3075
+ const atPeace = new Set(atPeaceWith(truces?.pacts ?? [], leader));
2994
3076
  const leaderLand = new Set();
2995
3077
  for (const t of board.territories)
2996
3078
  if (t.owner.kind === 'player' && t.owner.playerId === leader)
@@ -3010,6 +3092,7 @@ export function registerTurnTools(server, ctx, opts = {}) {
3010
3092
  bordersLeader: beside,
3011
3093
  out: new Set(game.players.filter((p) => !holdsSeat(p.state)).map((p) => Number(p.id))),
3012
3094
  atWar,
3095
+ ...(atPeace.size ? { atPeace } : {}),
3013
3096
  breakers,
3014
3097
  bonuses: leaderBonuses(graph, board, leader, new Set([me.id, ...trailing])),
3015
3098
  turnsBelow: Math.max(line.turnsBelow, streak?.turns ?? 0),
@@ -3059,7 +3142,7 @@ export function registerTurnTools(server, ctx, opts = {}) {
3059
3142
  meId: me.id,
3060
3143
  board: seen,
3061
3144
  neighbors: graph.neighbors,
3062
- truces: chatTruces(planLedger?.agreements, turn, game.players),
3145
+ truces: chatTruces(planLedger ? ledgerTruces(planLedger) : undefined, turn, game.players),
3063
3146
  surrenders,
3064
3147
  })
3065
3148
  : [];
@@ -3073,7 +3156,7 @@ export function registerTurnTools(server, ctx, opts = {}) {
3073
3156
  territories: map.territories.map((t) => ({ id: t.id, name: t.name })),
3074
3157
  bonuses: map.bonuses.map((b) => ({ id: b.id, name: b.name })),
3075
3158
  standing: planStanding({ profile: plan.profile, me: me.id, myIncome, estimates, players: game.players }),
3076
- truces: chatTruces(planLedger?.agreements, turn, game.players),
3159
+ truces: chatTruces(planLedger ? ledgerTruces(planLedger) : undefined, turn, game.players),
3077
3160
  }, view === 'full' ? 'full' : 'compact')
3078
3161
  : undefined;
3079
3162
  // #412: the decision log keeps the chat read this turn, ids and labels only.
@@ -3141,12 +3224,12 @@ export function registerTurnTools(server, ctx, opts = {}) {
3141
3224
  // #178: the outlook and its basis; full adds each turn judged.
3142
3225
  // #304: the compact view keeps what the state rests on beside it (`evidence`).
3143
3226
  outlook: rung === 'full'
3144
- ? outlook
3227
+ ? { ...outlook, basis: outlookBasis }
3145
3228
  : {
3146
3229
  state: outlook.state,
3147
3230
  // #454: the income lean beside an even state (additive; the state keeps its four values).
3148
3231
  ...(outlook.lean ? { lean: outlook.lean } : {}),
3149
- basis: outlook.basis,
3232
+ basis: outlookBasis,
3150
3233
  ...(outlook.evidence ? { evidence: outlook.evidence } : {}),
3151
3234
  // #368: even while bonuses kept falling.
3152
3235
  ...(outlook.leaning ? { leaning: outlook.leaning } : {}),
@@ -3203,6 +3286,8 @@ export function registerTurnTools(server, ctx, opts = {}) {
3203
3286
  })(),
3204
3287
  // #127: who moves first this turn and how it is known; null when unknown.
3205
3288
  firstMover: mover.view,
3289
+ // #693: who moves before me this turn and the next ones (full view only).
3290
+ ...(rung === 'full' && setup.turnOrder ? { turnOrder: setup.turnOrder } : {}),
3206
3291
  // #166: what the award of picks showed (absent when no pick list is kept for this game).
3207
3292
  ...(award ? { award: awardView(award, game, turn, name) } : {}),
3208
3293
  trendSource: trend?.source ?? null,
@@ -3353,6 +3438,8 @@ export function registerTurnTools(server, ctx, opts = {}) {
3353
3438
  return { id, name: b.name, value: b.value };
3354
3439
  }),
3355
3440
  nextIncome: plan.expected.nextIncome,
3441
+ // #698: the low end, when a border falling would cost income (conceded, or below its opponent's estimate).
3442
+ ...(incomeLow ? { nextIncomeLow: incomeLow.low, nextIncomeLowFalls: incomeLow.falls.map(name) } : {}),
3356
3443
  // #109: present only when the plan's concessions put income at risk.
3357
3444
  ...(plan.expected.nextIncomeIfConcededFall !== undefined
3358
3445
  ? {
@@ -3846,7 +3933,7 @@ export function registerTurnTools(server, ctx, opts = {}) {
3846
3933
  meId: me.id,
3847
3934
  board,
3848
3935
  neighbors: graphOf(map).neighbors,
3849
- truces: chatTruces(ledger?.agreements, turnNumber, game.players),
3936
+ truces: chatTruces(ledger ? ledgerTruces(ledger) : undefined, turnNumber, game.players),
3850
3937
  })
3851
3938
  : [];
3852
3939
  const blocksGate = chatBlocksTurnFor(ctx, opts.env);
@@ -3861,7 +3948,8 @@ export function registerTurnTools(server, ctx, opts = {}) {
3861
3948
  : `would block with WARAPP_CHAT_BLOCKS_TURN=on: ${chatBlockLine(b)}`);
3862
3949
  const breaks = ctx.dataDir
3863
3950
  ? truceBreaksIn({
3864
- agreements: ledger?.agreements ?? [],
3951
+ // #680: a pact I am in reads per partner, as the same truces recorded apart would.
3952
+ agreements: ledgerTruces(ledger),
3865
3953
  graph: graphOf(map),
3866
3954
  board,
3867
3955
  me: me.id,
@@ -3981,6 +4069,7 @@ export function registerTurnTools(server, ctx, opts = {}) {
3981
4069
  const promises = commitmentWarnings({
3982
4070
  commitments: ledger?.commitments ?? [],
3983
4071
  agreements: ledger?.agreements ?? [],
4072
+ pacts: ledger?.pacts,
3984
4073
  graph: graphOf(map),
3985
4074
  board,
3986
4075
  me: me.id,
@@ -148,12 +148,12 @@ export function registerUncommitTool(server, ctx) {
148
148
  await dropOrdersCache(ctx.dataDir, gameId, me, turn);
149
149
  // B2: warapp_submit_turn's break_agreement recorded a truce broken-by-me when these orders
150
150
  // were committed. They never ran now, but broken-by-me is final: say so, never undo it.
151
- const stillBroken = ctx.dataDir && turn !== null
152
- ? ((await readLedger(ctx.dataDir, gameId, me))?.agreements ?? [])
153
- .filter((a) => a.status === 'broken-by-me' && a.endedTurn === turn)
154
- .map((a) => a.id)
155
- .sort()
156
- : [];
151
+ // #680: a pact broken by these orders too.
152
+ const recorded = ctx.dataDir && turn !== null ? await readLedger(ctx.dataDir, gameId, me) : undefined;
153
+ const stillBroken = [...(recorded?.agreements ?? []), ...(recorded?.pacts ?? [])]
154
+ .filter((a) => a.status === 'broken-by-me' && a.endedTurn === turn)
155
+ .map((a) => a.id)
156
+ .sort();
157
157
  return {
158
158
  status: 'uncommitted',
159
159
  outcome: 'confirmed',
@@ -8,13 +8,32 @@
8
8
  // (its own fields hold in-game ids not mapped here); any other order kind (a card received, an active card worn
9
9
  // off, …) is kept by its class name only. Attack results (the `…Result` records) are not decoded: what an attack
10
10
  // achieved shows on the next board. Ids and counts only, never a name. Pure; tolerant: nothing throws.
11
+ // #693: the GameTurn's first field is its MoveOrder (the bundle's reader: an optional list of int32 in-game player ids
12
+ // in the order they moved, then the orders, the turn number and the time). Live it has been null on every read so far
13
+ // (Cycle games, where war.app leaves the cycle for players to deduce); when it is sent it is kept as `moveOrder`.
14
+ // A move's result is read for one figure only, the armies it actually moved (`actual`): an order that could not run
15
+ // moved 0 and is still listed, beside the player's next order that ran in its slot.
11
16
  import { playersByInGameId } from './live.js';
12
17
  import { fields, isObj } from './protocol/decoded.js';
13
- import { decodeOrder, orderClass } from './team-orders.js';
18
+ import { armiesOf, decodeOrder, orderClass } from './team-orders.js';
14
19
  /** Orders kept per turn at most (a mega game can show hundreds); the rest are counted. */
15
20
  export const MAX_SEEN_ORDERS = 3000;
16
21
  const GAME_TURN = /\.GameTurn$/;
17
22
  const isInt = (v) => typeof v === 'number' && Number.isInteger(v);
23
+ const ATTACK_RESULT = /\.GameOrderAttackTransferResult$/;
24
+ /**
25
+ * The armies a move actually moved: its result record (the base order's optional result, after the player) read by
26
+ * the bundle's reader as ActualArmies, AttackingArmiesKilled, …, each an `Armies` — the first is ActualArmies.
27
+ * `undefined` without a result or its armies. In a finished game's GameFeed history the same field is
28
+ * `result.armies`, "0" on the orders that moved nothing.
29
+ */
30
+ function actualArmies(o) {
31
+ const result = fields(o).find((v) => isObj(v) && typeof v.$type === 'string' && ATTACK_RESULT.test(v.$type));
32
+ if (!result)
33
+ return undefined;
34
+ const first = fields(result).find((v) => armiesOf(v) !== undefined);
35
+ return first === undefined ? undefined : armiesOf(first).count;
36
+ }
18
37
  /** The resolved turn in a decoded LatestGameInfo, its players mapped to GameFeed ids; `undefined` without one. */
19
38
  export function readSeenTurn(info, players) {
20
39
  if (!isObj(info))
@@ -24,10 +43,14 @@ export function readSeenTurn(info, players) {
24
43
  return undefined;
25
44
  const own = fields(turn);
26
45
  const ints = own.filter(isInt);
27
- const list = own.find((v) => Array.isArray(v));
46
+ // The order list is the last list; a list before it is the MoveOrder (#693).
47
+ const lists = own.filter((v) => Array.isArray(v));
48
+ const list = lists.at(-1);
28
49
  if (ints.length !== 1 || !list)
29
50
  return undefined;
30
51
  const byInGame = playersByInGameId(players);
52
+ const order = lists.length === 2 ? lists[0] : undefined;
53
+ const moveOrder = order && order.length > 0 && order.every((v) => isInt(v) && byInGame.has(v)) ? order.map((v) => byInGame.get(v).id) : undefined;
31
54
  const orders = [];
32
55
  let omitted = 0;
33
56
  for (const o of list) {
@@ -54,11 +77,12 @@ export function readSeenTurn(info, players) {
54
77
  mode: d.mode,
55
78
  ...(d.percent ? { percent: true } : {}),
56
79
  ...(d.commander ? { commander: true } : {}),
80
+ ...((n) => (n === undefined ? {} : { actual: n }))(actualArmies(o)),
57
81
  });
58
82
  else if (d.kind === 'card')
59
83
  orders.push({ player, kind: 'card', card: d.name });
60
84
  else
61
85
  orders.push({ player, kind: 'discard' });
62
86
  }
63
- return { turn: ints[0] + 1, orders, ...(omitted ? { omitted } : {}) };
87
+ return { turn: ints[0] + 1, orders, ...(omitted ? { omitted } : {}), ...(moveOrder ? { moveOrder } : {}) };
64
88
  }
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.24.0'; // x-release-please-version
4
+ export const VERSION = '0.26.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.24.0",
6
+ "version": "0.26.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). Creating, joining, leaving or surrendering a game, accepting game invitations, closing out a finished game, accepting another player's surrender, a team surrender, a vote to end a game, booting a stalled player, Begin on a speed first turn, picks, turn orders, withdrawing them, chat sends, nudging a player, joining or leaving a ladder, answering a clan invite, joining or leaving a clan, changing quickmatch settings, voting on quickmatch templates, joining or declining a tournament, showing a tournament among your favourites, mail (new threads, replies, adding players, deleting threads), forum posts (new threads, replies, votes, watching a thread), chat reactions, 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.24.0",
3
+ "version": "0.26.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.24.0",
9
+ "version": "0.26.0",
10
10
  "packages": [
11
11
  {
12
12
  "registryType": "npm",
13
13
  "identifier": "@chrischall/warapp-mcp",
14
- "version": "0.24.0",
14
+ "version": "0.26.0",
15
15
  "transport": {
16
16
  "type": "stdio"
17
17
  },