@chrischall/warapp-mcp 0.11.0 → 0.12.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 (59) hide show
  1. package/.claude-plugin/marketplace.json +3 -3
  2. package/.claude-plugin/plugin.json +1 -1
  3. package/README.md +10 -8
  4. package/dist/analysis/cards-in-effect.js +10 -1
  5. package/dist/analysis/chat-mentions.js +17 -0
  6. package/dist/analysis/commander-fog.js +126 -0
  7. package/dist/analysis/end-game-stats.js +149 -0
  8. package/dist/analysis/local-deploy.js +3 -2
  9. package/dist/analysis/outlook.js +133 -55
  10. package/dist/analysis/picks.js +125 -0
  11. package/dist/analysis/plan/commander.js +3 -2
  12. package/dist/analysis/plan/deploy-estimates.js +11 -7
  13. package/dist/analysis/plan/estimates.js +63 -9
  14. package/dist/analysis/plan/relations.js +24 -14
  15. package/dist/analysis/plan/shared.js +21 -0
  16. package/dist/analysis/plan/threats.js +74 -5
  17. package/dist/analysis/player.js +23 -10
  18. package/dist/analysis/relations.js +29 -4
  19. package/dist/analysis/scale.js +71 -0
  20. package/dist/analysis/single-pick.js +356 -0
  21. package/dist/bundle.js +2559 -594
  22. package/dist/finished-store.js +30 -0
  23. package/dist/index.js +1 -1
  24. package/dist/known-mods.js +33 -0
  25. package/dist/map-stats.js +24 -2
  26. package/dist/mod-alliances.js +217 -0
  27. package/dist/mod-data.js +160 -0
  28. package/dist/my-games.js +53 -2
  29. package/dist/normalize.js +7 -0
  30. package/dist/outlook-log.js +13 -0
  31. package/dist/protocol/methods.js +14 -2
  32. package/dist/tools/card-advice.js +29 -9
  33. package/dist/tools/card-effects.js +3 -1
  34. package/dist/tools/card-support-advice.js +1 -1
  35. package/dist/tools/chat-inbox.js +61 -8
  36. package/dist/tools/check-plan.js +101 -10
  37. package/dist/tools/close-finished-game.js +110 -0
  38. package/dist/tools/commander-check.js +80 -1
  39. package/dist/tools/diplomacy.js +11 -2
  40. package/dist/tools/end-of-game.js +57 -3
  41. package/dist/tools/game.js +7 -3
  42. package/dist/tools/how-lost.js +68 -5
  43. package/dist/tools/index.js +21 -1
  44. package/dist/tools/map.js +50 -1
  45. package/dist/tools/mod-alliances.js +191 -0
  46. package/dist/tools/my-games.js +12 -1
  47. package/dist/tools/pace.js +44 -0
  48. package/dist/tools/picks.js +41 -1
  49. package/dist/tools/relations.js +16 -1
  50. package/dist/tools/session.js +20 -6
  51. package/dist/tools/stress-opponents.js +25 -2
  52. package/dist/tools/turn.js +257 -32
  53. package/dist/tools/write-kit.js +1 -0
  54. package/dist/version.js +1 -1
  55. package/manifest.json +10 -2
  56. package/mint.yaml +3 -4
  57. package/package.json +1 -1
  58. package/server.json +2 -2
  59. package/skills/warapp-mcp/SKILL.md +57 -9
@@ -0,0 +1,191 @@
1
+ // The Diplomacy 2 mod's alliances (mod 191) for the turn and diplomacy tools, and the read-only
2
+ // warapp_get_mod_alliances. Where the data lives and what the mod does: src/mod-alliances.ts. UNVERIFIED live.
3
+ //
4
+ // A game that does not run the mod (its GameFeed settings' mod ids, src/normalize.ts) costs nothing: no
5
+ // request, no change to any plan. In a game that does, one GameRefresh (details, no chat) per read.
6
+ // Never throws: a failed or unreadable read is `unreadable`, never "no alliance".
7
+ import { McpToolError } from '@chrischall/mcp-utils';
8
+ import { z } from 'zod';
9
+ import { inGameOf, playersByInGameId } from '../live.js';
10
+ import { Method, writeGameRefreshParams } from '../protocol/methods.js';
11
+ import { readMyOrderList } from '../my-orders.js';
12
+ import { allianceMismatches, allyAttacksIn, breakAlerts, breaksInOrders, diplomacy2From, modPairs, myAllies, readModData, runsDiplomacy2, } from '../mod-alliances.js';
13
+ import { currentTurn, gameIdArg, readAnnotations, respond, untrustedDescription, untrustedText } from './common.js';
14
+ import { lookupMeta } from './hints.js';
15
+ import { readLatestBoard } from './live-context.js';
16
+ import { BRIDGE_NOTE, resolveMe } from './live.js';
17
+ /** How every result that carries mod alliances says where they come from. */
18
+ export const MOD_ALLIANCES_NOTE = "Diplomacy 2 (mod 191) alliances, read from the game details (the web client's GameRefresh: the mod's public " +
19
+ 'data and your own), UNVERIFIED live: the format is the mod\'s published source and the client bundle, not yet ' +
20
+ 'checked against a game with an alliance in it. The game skips every attack between allies (owners at the start ' +
21
+ 'of the turn), both ways; a break is an order in the breaker\'s own turn that applies at its end, so an ally can ' +
22
+ 'attack from the next turn and no one else sees a break coming. Proposals you sent are in the other player\'s ' +
23
+ 'private data and are not shown; the mod keeps no turn for an alliance, only its order (`id`).';
24
+ /** One GameRefresh for the details; `undefined` when unreadable. Throws on a failed request. */
25
+ async function fetchDiplomacy2(ctx, gameId) {
26
+ const env = await ctx.rpc.call('GameRefresh', Method.GameRefresh, (w) => writeGameRefreshParams(w, { gameId, chat: false, nonChat: true, lobby: false }));
27
+ const data = readModData(await ctx.bundle(), env.body);
28
+ return data ? diplomacy2From(data) : undefined;
29
+ }
30
+ /**
31
+ * Diplomacy 2's alliances in `game` as `me` sees them. `no-mod` (no request) when the game's settings do not
32
+ * list the mod; `unreadable` when the request failed or the reply was not understood. Never throws.
33
+ */
34
+ export async function readModAlliances(ctx, game, me) {
35
+ if (!runsDiplomacy2(game.settings?.modIds))
36
+ return { status: 'no-mod' };
37
+ let state;
38
+ try {
39
+ state = await fetchDiplomacy2(ctx, game.id);
40
+ }
41
+ catch (e) {
42
+ return { status: 'unreadable', reason: e instanceof Error ? e.message : String(e) };
43
+ }
44
+ if (!state)
45
+ return { status: 'unreadable', reason: 'the game details carried no Diplomacy 2 data this server understands' };
46
+ const byInGame = playersByInGameId(game.players);
47
+ const feedOf = (inGame) => byInGame.get(inGame)?.id ?? null;
48
+ const mine = inGameOf(me);
49
+ const ids = mine === undefined ? [] : myAllies(state, mine);
50
+ const allies = ids.map(feedOf).filter((x) => x !== null);
51
+ return { status: 'read', state, me: mine, allies, unmapped: ids.length - allies.length, feedOf };
52
+ }
53
+ /** The warnings a turn tool adds for a mod-191 game (none for `no-mod`). */
54
+ export function modAllianceWarnings(read) {
55
+ if (read.status === 'no-mod')
56
+ return [];
57
+ if (read.status === 'unreadable')
58
+ return [
59
+ `This game runs the Diplomacy 2 mod, but its alliances could not be read (${read.reason}): no alliance is honoured ` +
60
+ 'here. An attack on an ally is skipped by the game and its armies sit idle — check the mod\'s menu in the web client.',
61
+ ];
62
+ const out = [];
63
+ if (read.unmapped)
64
+ out.push(`${read.unmapped} Diplomacy 2 ${read.unmapped === 1 ? 'ally' : 'allies'} could not be matched to a player in this game: not honoured.`);
65
+ const breaks = breakAlerts(read.state);
66
+ if (breaks.length)
67
+ out.push(`Notice: the Diplomacy 2 mod reports ${breaks.length === 1 ? 'a broken alliance' : `${breaks.length} broken alliances`} with you ` +
68
+ `(${breaks.map((b) => untrustedText(b.message)).join('; ')}). That player is an ordinary opponent now.`);
69
+ return out;
70
+ }
71
+ /** Each ally attack named for a person, by territory and player id. */
72
+ export const allyAttackLine = (a, name) => `move ${a.index + 1} attacks ${name(a.to)} from ${name(a.from)}, held by player ${a.ally} (a Diplomacy 2 ally)`;
73
+ /** The attacks of `moves` on my allies at the start of this turn (owners by GameFeed id on `ownerAt`). */
74
+ export function attacksOnAllies(read, moves, ownerAt) {
75
+ return read.status === 'read' ? allyAttacksIn(moves, new Set(read.allies), ownerAt) : [];
76
+ }
77
+ /**
78
+ * The mod's alliances beside the ledger's agreements (warapp_get_relations, warapp_advise_diplomacy): `undefined` in a
79
+ * game without the mod. `live`: the ledger's agreements active or in notice. `who`: a GameFeed id for the result.
80
+ */
81
+ export function modRelationsView(read, live, who) {
82
+ if (read.status === 'no-mod')
83
+ return undefined;
84
+ if (read.status === 'unreadable')
85
+ return { source: 'mod', read: false, reason: read.reason, alliances: null, note: MOD_ALLIANCES_NOTE };
86
+ const mine = read.me;
87
+ const alliances = read.state.alliances
88
+ .filter((a) => mine !== undefined && (a.proposer === mine || a.accepter === mine))
89
+ .sort((x, y) => x.id - y.id)
90
+ .flatMap((a) => {
91
+ const other = read.feedOf(a.proposer === mine ? a.accepter : a.proposer);
92
+ return other === null ? [] : [{ source: 'mod', player: who(other), proposedBy: a.proposer === mine ? 'me' : 'them', id: a.id }];
93
+ });
94
+ const mismatches = allianceMismatches(read.allies, live).map((m) => ({
95
+ player: who(m.player),
96
+ kind: m.kind,
97
+ ...(m.agreement ? { agreement: m.agreement } : {}),
98
+ line: m.kind === 'mod-only'
99
+ ? 'allied in the Diplomacy 2 mod with no agreement recorded: the game enforces it, but its terms (notice, until) are not in the ledger'
100
+ : 'an agreement is active or in notice but the mod shows no alliance: the game does not enforce it — the player may have broken the alliance, or it was never made in the mod',
101
+ }));
102
+ const notices = breakAlerts(read.state).map((a) => ({ id: a.id, message: untrustedText(a.message) }));
103
+ return {
104
+ source: 'mod',
105
+ read: true,
106
+ alliances,
107
+ ...(read.state.proposalsToMe.length
108
+ ? {
109
+ proposalsToMe: read.state.proposalsToMe.flatMap((p) => {
110
+ const from = read.feedOf(p.from);
111
+ return from === null ? [] : [{ player: who(from), id: p.id }];
112
+ }),
113
+ }
114
+ : {}),
115
+ mismatches,
116
+ // An ally's break shows only once it applied: the mod's alert to me, kept until the web client shows it.
117
+ ...(notices.length ? { notices } : {}),
118
+ note: MOD_ALLIANCES_NOTE,
119
+ };
120
+ }
121
+ /** warapp_get_mod_alliances. */
122
+ export function registerModAlliancesTool(server, ctx) {
123
+ server.registerTool('warapp_get_mod_alliances', {
124
+ title: 'Read Diplomacy 2 mod alliances in a war.app game',
125
+ description: untrustedDescription('The alliances of the "Diplomacy 2" mod (mod 191) in a war.app (Warzone) game that runs it: each pair with its ' +
126
+ '`state` — `allied` (the game skips every attack between them this turn), `breaking` (your own break order is ' +
127
+ 'entered this turn: it still holds this turn, and either side can attack from `endsTurn`) or `pending` (a ' +
128
+ 'proposal to you, not yet answered) — who `proposer` was, and `id`, the mod\'s counter (the order they were ' +
129
+ 'made in: the mod keeps no turn). Also `allies` (yours) and `alerts` (the mod\'s notices to you, such as a ' +
130
+ 'player who broke an alliance with you). UNVERIFIED live. Proposals you sent and an ally\'s break before it ' +
131
+ 'applies are not visible. Proposing, accepting, declining and breaking are manual only (the mod\'s menu in the ' +
132
+ `web client): no tool sends them. A game without the mod is refused. ${BRIDGE_NOTE} Read-only.`),
133
+ _meta: lookupMeta(['mod alliances', 'diplomacy 2', 'who is allied', 'alliance mod', 'my allies']),
134
+ annotations: readAnnotations('Read Diplomacy 2 alliances'),
135
+ inputSchema: z.object({ game_id: gameIdArg }),
136
+ }, async ({ game_id }) => {
137
+ const game = await ctx.client.getGame(game_id, { settings: true, map: false });
138
+ if (!runsDiplomacy2(game.settings?.modIds)) {
139
+ throw new McpToolError(`Game ${game.id} does not run the Diplomacy 2 mod (mod 191).`, {
140
+ hint: 'warapp_get_relations shows the agreements recorded with warapp_record_agreement.',
141
+ });
142
+ }
143
+ const me = await resolveMe(ctx, game.players, undefined);
144
+ const read = await readModAlliances(ctx, game, me);
145
+ if (read.status !== 'read') {
146
+ return respond(undefined, ['compact'], () => ({
147
+ game: { id: game.id, name: game.name === undefined ? null : untrustedText(game.name), state: game.state },
148
+ alliances: null,
149
+ warnings: modAllianceWarnings(read),
150
+ readNote: MOD_ALLIANCES_NOTE,
151
+ }));
152
+ }
153
+ const turn = currentTurn(game);
154
+ // My own break orders this turn (only while a turn is played: the orders live on the live board).
155
+ let breaksByMe = [];
156
+ const warnings = modAllianceWarnings(read);
157
+ if (game.state === 'Playing' && turn !== null && read.me !== undefined) {
158
+ try {
159
+ const { info } = await readLatestBoard(ctx, game.id);
160
+ breaksByMe = breaksInOrders(readMyOrderList(info) ?? []);
161
+ }
162
+ catch (e) {
163
+ warnings.push(`Your orders could not be read (${e instanceof Error ? e.message : String(e)}): a break you entered this turn would not show as breaking.`);
164
+ }
165
+ }
166
+ const who = (inGame) => {
167
+ const feed = read.feedOf(inGame);
168
+ const p = feed === null ? undefined : game.players.find((x) => x.id === feed);
169
+ return { id: feed, inGameId: inGame, name: p ? untrustedText(p.name) : null };
170
+ };
171
+ return respond(undefined, ['compact'], () => ({
172
+ game: { id: game.id, name: game.name === undefined ? null : untrustedText(game.name), state: game.state, turn },
173
+ player: { id: me.id, name: untrustedText(me.name) },
174
+ alliances: modPairs(read.state, read.me, turn, breaksByMe).map((p) => ({
175
+ players: p.players.map(who),
176
+ state: p.state,
177
+ proposer: who(p.proposer),
178
+ id: p.id,
179
+ ...(p.endsTurn !== undefined ? { endsTurn: p.endsTurn } : {}),
180
+ })),
181
+ allies: read.allies.map((id) => {
182
+ const p = game.players.find((x) => x.id === id);
183
+ return { id, name: p ? untrustedText(p.name) : null };
184
+ }),
185
+ alerts: read.state.alerts.map((a) => ({ id: a.id, message: untrustedText(a.message) })),
186
+ ...(warnings.length ? { warnings } : {}),
187
+ modDiplomacy: 'manual only: propose, accept, decline and break in the mod\'s menu in the web client.',
188
+ readNote: MOD_ALLIANCES_NOTE,
189
+ }));
190
+ });
191
+ }
@@ -10,7 +10,7 @@
10
10
  // games together and that the server honours a count above 10.
11
11
  import { untrustedEnvelope } from '@chrischall/mcp-utils';
12
12
  import { z } from 'zod';
13
- import { briefGameLine, gameStateName, isFinished, readMyGames, summarizeMyGames } from '../my-games.js';
13
+ import { BOOT_NOTE, briefGameLine, gameStateName, isFinished, readMyGames, summarizeMyGames } from '../my-games.js';
14
14
  import { Method, MY_GAMES_DEFAULT_SORT, MyGamesFilterType, writeGetMyGamesParams } from '../protocol/methods.js';
15
15
  import { readAnnotations, respond, untrustedDescription, untrustedText, WARAPP_UNTRUSTED_NOTE } from './common.js';
16
16
  import { canonicalMeta } from './hints.js';
@@ -18,6 +18,7 @@ import { BRIDGE_NOTE } from './live.js';
18
18
  import { holdsSeat, playerStateName } from '../player-states.js';
19
19
  import { sweepFinished } from './end-of-game.js';
20
20
  import { accountUnknown } from './write-kit.js';
21
+ import { rememberPace } from './pace.js';
21
22
  import { pendingSurrenders, surrenderOwed } from '../surrender-pending.js';
22
23
  import { readDetailsSeats, SURRENDER_PENDING_NOTE, surrenderMayBePending } from './surrender-pending.js';
23
24
  const VIEWS = ['compact', 'brief'];
@@ -75,6 +76,8 @@ export async function fetchMyGames(ctx) {
75
76
  return readMyGames(await ctx.bundle(), env.body);
76
77
  };
77
78
  const [me, list] = await Promise.all([myInGameId(ctx), listMyGames(read)]);
79
+ // Pace: keep the boot clocks for warapp_session_status (no request of its own).
80
+ rememberPace(ctx, summarizeMyGames(list.games, me), Date.now());
78
81
  return { me, ...list };
79
82
  }
80
83
  /** #317: the most games whose details one call reads for a pending surrender (the rest are `null`). */
@@ -141,6 +144,10 @@ export function registerMyGamesTool(server, ctx, deps = {}) {
141
144
  'chat per channel (public, team, private, group) and toMe (unread private chat is addressed to you) — flags, ' +
142
145
  'not counts; null when they did not read. Games with unread private chat come right after the ones waiting on ' +
143
146
  'you, and the top-level unreadPrivateGames counts them; read them with warapp_chat_inbox. ' +
147
+ 'A multi-day game being played or picked with your seat playing carries `boot` (pace, from the game list: its boot ' +
148
+ 'time, your banked time, their sum, and while it waits on you `leftMinutes`, the sum less how long your turn has ' +
149
+ 'run, with `soon` under 6 hours; unverified live); `bootSoon` counts the games close to a boot, and brief adds ' +
150
+ '" — boot in …" to them. ' +
144
151
  'Finished games are left out unless ' +
145
152
  '`include_finished` (`finishedLeftOut` counts them). `listed` is how many games war.app returned and ' +
146
153
  '`complete` false (with a `warning`) means the list may be partial. Use the id with the other warapp tools. ' +
@@ -187,6 +194,10 @@ export function registerMyGamesTool(server, ctx, deps = {}) {
187
194
  count: games.length,
188
195
  waitingOnYou: games.filter((g) => g.waitingOnYou).length,
189
196
  unreadPrivateGames: games.filter((g) => g.unreadChat?.private === true).length,
197
+ // Pace: multi-day games whose boot is under six hours away (boot time plus bank, less my turn so far).
198
+ ...(games.some((g) => g.boot)
199
+ ? { bootSoon: games.filter((g) => g.boot?.soon).length, bootNote: BOOT_NOTE }
200
+ : {}),
190
201
  surrenderPending: games.filter((g) => surrenderOwed(g.surrenderPending)).length,
191
202
  surrenderNote: SURRENDER_PENDING_NOTE +
192
203
  (unread ? ` The details of ${unread} game(s) could not be read.` : '') +
@@ -0,0 +1,44 @@
1
+ // Pace: the boot clocks of my multi-day games, as the last game-list read in this process saw them
2
+ // (warapp_my_games, warapp_chat_inbox and every other tool that lists my games through `fetchMyGames`), so
3
+ // warapp_session_status can warn of a boot close by without a war.app request of its own.
4
+ import { BOOT_WARN_MINUTES, minutesText } from '../my-games.js';
5
+ import { untrustedText } from './common.js';
6
+ const snapshots = new WeakMap();
7
+ /** Keep the boot clocks of `games` (summarized for me) as read at `at`, for the context `owner`. */
8
+ export function rememberPace(owner, games, at) {
9
+ snapshots.set(owner, {
10
+ at,
11
+ games: games.flatMap((g) => (g.boot?.leftMinutes != null ? [{ id: g.id, name: g.name, leftMinutes: g.boot.leftMinutes }] : [])),
12
+ });
13
+ }
14
+ /**
15
+ * #532: drop one game from the kept snapshot — warapp_submit_turn calls it once war.app confirms my orders, since
16
+ * the game no longer waits on me and the snapshot would keep naming it until the list is read again.
17
+ */
18
+ export function forgetPaceGame(owner, gameId) {
19
+ const s = snapshots.get(owner);
20
+ if (s)
21
+ snapshots.set(owner, { ...s, games: s.games.filter((g) => g.id !== gameId) });
22
+ }
23
+ export const PACE_NOTE = `Read from the last game list this server read (warapp_my_games and the chat inbox read it): each game waiting on you ` +
24
+ `whose boot time plus your banked time, less how long your turn has run, is under ${BOOT_WARN_MINUTES / 60} hours ` +
25
+ 'away now. Unverified live; call warapp_my_games for a fresh read.';
26
+ export function paceStatus(owner, now) {
27
+ const s = snapshots.get(owner);
28
+ if (!s)
29
+ return undefined;
30
+ const ago = Math.max(0, Math.floor((now - s.at) / 60_000));
31
+ const bootSoon = s.games
32
+ .map((g) => ({ ...g, leftMinutes: Math.max(0, g.leftMinutes - ago) }))
33
+ .filter((g) => g.leftMinutes < BOOT_WARN_MINUTES)
34
+ .sort((a, b) => a.leftMinutes - b.leftMinutes || a.id - b.id)
35
+ .map((g) => ({ id: g.id, name: untrustedText(g.name), leftMinutes: g.leftMinutes, left: minutesText(g.leftMinutes) }));
36
+ return { listReadMinutesAgo: ago, bootSoon, note: PACE_NOTE };
37
+ }
38
+ /** The warning line for the games close to a boot, or undefined. */
39
+ export function paceWarning(p) {
40
+ if (!p?.bootSoon.length)
41
+ return undefined;
42
+ return (`Boot close: ${p.bootSoon.map((g) => `game ${g.id} in ${g.left}`).join(', ')} — take ${p.bootSoon.length === 1 ? 'that turn' : 'those turns'} ` +
43
+ `(under ${BOOT_WARN_MINUTES / 60} hours left, boot time plus bank).`);
44
+ }
@@ -164,6 +164,12 @@ export function registerPickTools(server, ctx, deps = {}) {
164
164
  'On a very large map (over 400 pickable territories) only the territories that score best alone are ranked, 400 at the default budget and more with a larger one (`candidates` says how many); ' +
165
165
  'the plan has a time budget (20 s; `WARAPP_PICKS_BUDGET_MS` sets it, 0 for none) and, when it runs out, answers `partial: true` with a valid list; ' +
166
166
  'the compact view caps its reasons, threats, coverage and warning lists (counts say what was cut; `submitPicks` is never cut). ' +
167
+ 'In a game that overrides bonus values, with a territory limit of 1 on a huge map (1,000+ territories, 3+ players, not a team game) it ranks single starts instead of groups: ' +
168
+ '`startRanking` shows 25 starts per `page`, each scored on income at the game\'s bonus values (overrides applied; a bonus worth 0 ' +
169
+ 'is crossed, never counted) over a 5-turn flood opening, the turn its income first exceeds the base income, the nearest paying bonus, ' +
170
+ 'wastelands within 2 hops (blocking a paying bonus or shielding an approach) and commander safety (open approaches, entries into its ' +
171
+ '2-hop pocket, the nearest other start and the rival starts expected within 3 hops), with reasons; `submitPicks` is the ranking in ' +
172
+ 'priority order, cut at the client\'s max (players × 1). The ranking is cached per map, so the next page costs nothing. ' +
167
173
  'In a team game only the players off your team are threats, `team` names your teammates, and the list is judged by both award ' +
168
174
  "orders that fit (`award.orders`; a team game's is unverified). When a teammate's pick list can be read (unverified), each " +
169
175
  "teammate carries `picks`, and `team.coordination` reports the overlap with your list, the bonuses their top picks into " +
@@ -179,13 +185,21 @@ export function registerPickTools(server, ctx, deps = {}) {
179
185
  inputSchema: z.object({
180
186
  game_id: gameIdArg,
181
187
  view: viewArg(VIEWS, 'compact (default) gives the ranked picks with reasons, the groups and submitPicks (and the first start bonuses of `mapRecord`); "full" adds the settings the plan assumed and every start bonus.'),
188
+ page: z.coerce
189
+ .number()
190
+ .int()
191
+ .min(1)
192
+ .max(200)
193
+ .optional()
194
+ .describe('Single-pick ranking only (a territory limit of 1 on a huge map): the page of 25 ranked starts to detail (default 1). ' +
195
+ 'The submit list is the same on every page.'),
182
196
  spread: z
183
197
  .boolean()
184
198
  .optional()
185
199
  .describe('In a 1v1, spread the primary across bonuses against a counter-pick instead of one compact cluster ' +
186
200
  '(default false); usually worse on large maps. Ignored with three or more players.'),
187
201
  }),
188
- }, async ({ game_id, view, spread }) => {
202
+ }, async ({ game_id, view, spread, page }) => {
189
203
  const feed = await ctx.client.getGame(game_id, { settings: true });
190
204
  requirePickPhase(feed);
191
205
  const { territories, info } = await loadLiveGame(ctx, feed);
@@ -248,6 +262,8 @@ export function registerPickTools(server, ctx, deps = {}) {
248
262
  ...(team ? { team: { teammates: team.length, ...(lists.some((l) => l.length) ? { lists } : {}) } } : {}),
249
263
  ...(budgetMs !== undefined ? { budgetMs } : {}),
250
264
  ...(limitRead.fullDeal ? { fullDeal: true } : {}),
265
+ ...(page !== undefined ? { singlePage: page } : {}),
266
+ ...((game.settings?.overriddenBonuses?.size ?? 0) > 0 ? { overridden: true } : {}),
251
267
  });
252
268
  }
253
269
  catch (e) {
@@ -400,6 +416,30 @@ export function registerPickTools(server, ctx, deps = {}) {
400
416
  },
401
417
  ...(plan.partial ? { partial: true } : {}),
402
418
  ...(plan.candidates ? { candidates: plan.candidates } : {}),
419
+ ...(plan.single
420
+ ? {
421
+ // Mega-game spec part 2: the ranked single starts of a huge map, one page at a time.
422
+ startRanking: {
423
+ shown: plan.single.shown,
424
+ page: plan.single.page,
425
+ pages: plan.single.pages,
426
+ simulated: plan.single.simulated,
427
+ payingBonuses: plan.single.paying,
428
+ ...(plan.single.cached ? { cached: true } : {}),
429
+ starts: plan.single.starts.map((x, i) => ({
430
+ rank: plan.single.shown.from + i,
431
+ territory: name(x.territoryId),
432
+ score: x.score,
433
+ firstIncomeTurn: x.firstIncomeTurn,
434
+ nearestPayingBonus: x.nearestPaying ? { ...bonusName(x.nearestPaying.bonusId), value: x.nearestPaying.value, hops: x.nearestPaying.hops } : null,
435
+ bonuses: x.bonuses.map((b) => ({ ...bonusName(b.bonusId), value: b.value, turn: b.turn, contest: b.contest })),
436
+ wastelands: { blocking: x.wastelands.blocking.map(name), shielding: x.wastelands.shielding.map(name) },
437
+ safety: x.safety,
438
+ reasons: x.reasons ?? [],
439
+ })),
440
+ },
441
+ }
442
+ : {}),
403
443
  ...cappedLines('warnings', [...warnings, ...plan.warnings], !lean(rung)),
404
444
  ...cappedLines('rationale', plan.rationale, !lean(rung)),
405
445
  submitPicks: { game_id: game.id, territories: plan.picks.map((p) => p.territoryId) },
@@ -5,6 +5,7 @@
5
5
  // and hosted, name-free per-agreement entries and tallies) — nothing is sent to war.app or to any
6
6
  // player, so it is not confirm-gated. An agreement exists only because the player recorded it here with
7
7
  // structured terms: chat is never parsed into one, and words change no flag — only the board does.
8
+ import { modRelationsView, readModAlliances } from './mod-alliances.js';
8
9
  import { McpToolError, toolAnnotations } from '@chrischall/mcp-utils';
9
10
  import { z } from 'zod';
10
11
  import { boardIncome, incomeRules, trackGame, trackOpponents } from '../analysis/index.js';
@@ -406,7 +407,10 @@ export function registerRelationsTools(server, ctx, opts = {}) {
406
407
  '`record`: how it kept earlier agreements — tallies, a kept rate, its notices honoured or broken, its breaks in ' +
407
408
  'the endgame or while leading, retaliation, proposing again and turns to a break (`full` adds the entries) — keyed ' +
408
409
  'by a salted hash, never its id or name. `playerRecord` says on, off or unreadable. Words in chat never change a ' +
409
- `flag or the trust: only the board does. ${BRIDGE_NOTE} Read-only on war.app; it caches the board it read.`),
410
+ 'flag or the trust: only the board does. Each agreement carries `source: "ledger"`; in a game running the Diplomacy 2 ' +
411
+ 'mod (mod 191) `modAlliances` lists the mod\'s alliances with you (`source: "mod"`, UNVERIFIED live) with `mismatches` ' +
412
+ '(`mod-only`: allied with no agreement recorded; `ledger-only`: a truce the game does not enforce) and `notices` (an ' +
413
+ `ally's break, shown once it applied). ${BRIDGE_NOTE} Read-only on war.app; it caches the board it read.`),
410
414
  _meta: lookupMeta(['my truces', 'agreements', 'is my truce holding', 'diplomacy', 'who kept their word']),
411
415
  annotations: readAnnotations('Read war.app agreements'),
412
416
  inputSchema: z.object({
@@ -476,6 +480,15 @@ export function registerRelationsTools(server, ctx, opts = {}) {
476
480
  ]);
477
481
  const tacit = tacitTruces({ graph, boards, me: me.id, exclude: excluded });
478
482
  const recordState = await playerRecordState(ctx.dataDir, env);
483
+ // The Diplomacy 2 mod's alliances beside the ledger's (a game without the mod: no request, no field).
484
+ const liveAgreements = ledger.agreements.filter((a) => {
485
+ const st = agreementState(a, turn, relationPlayers(game.players));
486
+ return st.phase === 'active' || st.phase === 'notice';
487
+ });
488
+ const modView = modRelationsView(await readModAlliances(ctx, game, me), liveAgreements, (id) => {
489
+ const p = game.players.find((x) => x.id === id);
490
+ return { id, name: p ? untrustedText(p.name) : null };
491
+ });
479
492
  const name = namer(map);
480
493
  const playerName = (id) => {
481
494
  const p = game.players.find((x) => x.id === id);
@@ -485,6 +498,7 @@ export function registerRelationsTools(server, ctx, opts = {}) {
485
498
  game: { id: game.id, name: game.name === undefined ? null : untrustedText(game.name), state: game.state, turn },
486
499
  player: { id: me.id, name: untrustedText(me.name) },
487
500
  agreements: agreements.map((x) => ({
501
+ source: 'ledger',
488
502
  ...agreementView(x.agreement, game, map, turn, rung),
489
503
  ...(x.trust ? { trust: x.trust, endgame: x.endgame } : {}),
490
504
  flags: x.flags.map((f) => ({ ...f, territories: f.territories.map(name) })),
@@ -492,6 +506,7 @@ export function registerRelationsTools(server, ctx, opts = {}) {
492
506
  ...(rung === 'full' && x.entries ? { recordEntries: x.entries.map(entryView) } : {}),
493
507
  })),
494
508
  tacit: tacit.map((t) => ({ player: playerName(t.player), quietTurns: t.quietTurns, border: t.border.map(name) })),
509
+ ...(modView ? { modAlliances: modView } : {}),
495
510
  boards: { turns: boards.map((b) => b.turn).sort((a, b) => a - b), live },
496
511
  incomes: { mine: incomes.mine, opponents: Object.fromEntries(incomes.opponents) },
497
512
  playerRecord: recordState,
@@ -20,6 +20,7 @@
20
20
  //
21
21
  // SECURITY: the AuthToken is a full-account credential. Neither tool returns,
22
22
  // logs, or previews it; the status output carries only `capturedAt`/`host`/age.
23
+ import { paceWarning } from './pace.js';
23
24
  import { CONFIRM_INJECTION_RULE, toolAnnotations } from '@chrischall/mcp-utils';
24
25
  import { z } from 'zod';
25
26
  import { linkSession } from '../direct/link.js';
@@ -83,7 +84,7 @@ export function registerSessionTools(server, deps) {
83
84
  };
84
85
  server.registerTool('warapp_session_status', {
85
86
  title: 'war.app direct-transport session status',
86
- description: untrustedDescription(hosted && hostToken === 'ok'
87
+ description: untrustedDescription((hosted && hostToken === 'ok'
87
88
  ? 'Report which transport serves war.app calls on this hosted server (direct to war.app with the session ' +
88
89
  'mcp-host captured at sign-in, or the browser bridge after that session stops working) and which ' +
89
90
  'transport the turn-notification push socket rides (websocket or xhr-polling) once it has run, and, once ' +
@@ -100,11 +101,24 @@ export function registerSessionTools(server, deps) {
100
101
  'which transport the turn-notification push socket rides (websocket or xhr-polling) once it has run, ' +
101
102
  'and, once a live board has been read, which client bundle decodes boards (a cached stand-in or not) and ' +
102
103
  'which of its reader helpers were verified. ' +
103
- 'Never shows the session cookie. Read-only; use warapp_link_session to link or relink.'),
104
+ 'Never shows the session cookie. Read-only; use warapp_link_session to link or relink.') +
105
+ ' `pace` lists the multi-day games waiting on you whose boot is under 6 hours away (boot time plus your banked ' +
106
+ 'time, less your turn so far), and `bootWarning` names them: from the game list this server last read ' +
107
+ '(warapp_my_games, the chat inbox), else it reads the list itself (one war.app request, over a working direct ' +
108
+ 'session only — never by waiting on the browser bridge); `paceUnread` says why when it could not.'),
104
109
  _meta: lookupMeta(['war.app session', 'is war.app linked', 'direct transport status']),
105
110
  annotations: readAnnotations('war.app session status'),
106
111
  inputSchema: z.object({}),
107
112
  }, async () => {
113
+ // Pace: a boot close by in a multi-day game, from the last game list read; with none kept, the list is read now
114
+ // (one request) — only over a direct session that works, never by waiting on the browser bridge.
115
+ const session = hosted ? undefined : await read();
116
+ const direct = deps.transport.activeLeg() === 'direct' && !deps.transport.sessionStale() && (hosted ? hostToken === 'ok' : session !== undefined);
117
+ const activeTransport = deps.transport.activeLeg();
118
+ const pace = await deps.pace?.(now(), direct);
119
+ const paceRead = pace && !('error' in pace) ? pace : undefined;
120
+ const bootWarning = paceWarning(paceRead);
121
+ const paceFields = paceRead ? { pace: paceRead, ...(bootWarning ? { bootWarning } : {}) } : pace && 'error' in pace ? { paceUnread: pace.error } : {};
108
122
  if (hosted && hostToken === 'ok') {
109
123
  const pt = deps.pushTransport?.();
110
124
  const wall = deps.transport.wall?.() ?? null;
@@ -112,10 +126,11 @@ export function registerSessionTools(server, deps) {
112
126
  hosted: true,
113
127
  linked: true,
114
128
  linkedBy: 'host',
115
- activeTransport: deps.transport.activeLeg(),
129
+ activeTransport,
116
130
  ...(wall ? { wall } : {}),
117
131
  ...(pt ? { pushTransport: pt } : {}),
118
132
  ...decoderView(),
133
+ ...paceFields,
119
134
  hostedNote: NOTE_HOSTED_DIRECT,
120
135
  };
121
136
  return respond(undefined, ['compact'], () => deps.transport.sessionStale() ? { ...base, sessionExpired: true, hint: HINT_HOST_EXPIRED } : base);
@@ -128,13 +143,12 @@ export function registerSessionTools(server, deps) {
128
143
  activeTransport: 'fetchproxy',
129
144
  ...(pt ? { pushTransport: pt } : {}),
130
145
  ...decoderView(),
146
+ ...paceFields,
131
147
  hostedNote: hostToken === 'malformed' ? NOTE_HOSTED_MALFORMED : NOTE_HOSTED,
132
148
  }));
133
149
  }
134
- const session = await read();
135
- const activeTransport = deps.transport.activeLeg();
136
150
  const pt = deps.pushTransport?.();
137
- const push = { ...(pt ? { pushTransport: pt } : {}), ...decoderView() };
151
+ const push = { ...(pt ? { pushTransport: pt } : {}), ...decoderView(), ...paceFields };
138
152
  return respond(undefined, ['compact'], () => {
139
153
  if (!session)
140
154
  return { linked: false, activeTransport, ...push, hint: HINT_NOT_LINKED };
@@ -7,6 +7,17 @@ import { carriesTeam } from '../teams.js';
7
7
  import { opponentReinforcement } from './card-advice.js';
8
8
  import { boardCardsInEffect } from './card-effects.js';
9
9
  import { commerceDeployOf } from './commerce-deploy.js';
10
+ /**
11
+ * An opponent's deploy for the stress test and its card apart: the estimate (its card on top) under `clock`,
12
+ * the estimate without the card under `none`; `cardBonus` the card's armies, absent with no card.
13
+ */
14
+ export function opponentDeploy(e, assume) {
15
+ const card = e.card?.armies ?? 0;
16
+ return {
17
+ deploy: assume === 'none' ? e.estimate - card : e.estimate,
18
+ ...(card > 0 ? { cardBonus: card, ...(e.card?.basis ? { cardBonusBasis: e.card.basis } : {}) } : {}),
19
+ };
20
+ }
10
21
  export function stressOpponents(input) {
11
22
  const { graph, map, game, me, seen, turn, settings, hand, info } = input;
12
23
  // #270: a player out of the game whose seat no AI plays deploys and attacks nothing: its
@@ -67,13 +78,25 @@ export function stressOpponents(input) {
67
78
  const onBoard = new Set(board.territories.flatMap((t) => (t.owner.kind === 'player' ? [t.owner.playerId] : [])));
68
79
  const stillIn = game.players.filter((p) => (p.state ?? 'Playing') === 'Playing').map((p) => p.id);
69
80
  const base = settings.baseIncome ?? 0;
70
- const estimateOf = (id) => estimates.find((x) => x.playerId === id)?.estimate ?? base;
81
+ const estimateOf = (id) => {
82
+ const e = estimates.find((x) => x.playerId === id);
83
+ return e ? opponentDeploy(e, input.assumeCards ?? 'clock').deploy : base;
84
+ };
71
85
  const opponents = [...new Set([...onBoard, ...stillIn])]
72
86
  .filter((id) => !friend(id))
73
87
  .sort((a, b) => a - b)
74
88
  .map((id) => {
75
89
  const e = estimates.find((x) => x.playerId === id);
76
- return { id, deploy: input.enemyDeploy ?? e?.estimate ?? base, base: e?.base ?? base, ...(e?.card ? { card: e.card.armies } : {}) };
90
+ const sized = e ? opponentDeploy(e, input.assumeCards ?? 'clock') : { deploy: base };
91
+ return {
92
+ id,
93
+ deploy: input.enemyDeploy ?? sized.deploy,
94
+ base: e?.base ?? base,
95
+ ...(e?.card ? { card: e.card.armies } : {}),
96
+ ...(sized.cardBonus !== undefined ? { cardBonus: sized.cardBonus } : {}),
97
+ ...(sized.cardBonusBasis !== undefined ? { cardBonusBasis: sized.cardBonusBasis } : {}),
98
+ ...(e?.sanctioned ? { sanctioned: e.sanctioned } : {}),
99
+ };
77
100
  });
78
101
  const teams = new Map();
79
102
  for (const p of game.players)