@chrischall/warapp-mcp 0.4.0 → 0.6.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 (92) hide show
  1. package/.claude-plugin/marketplace.json +3 -3
  2. package/.claude-plugin/plugin.json +1 -1
  3. package/README.md +41 -5
  4. package/dist/analysis/card-support.js +2 -1
  5. package/dist/analysis/card-threats.js +59 -12
  6. package/dist/analysis/game-lessons.js +3 -4
  7. package/dist/analysis/hold-diff.js +3 -1
  8. package/dist/analysis/income-trend.js +38 -0
  9. package/dist/analysis/intel.js +75 -0
  10. package/dist/analysis/opens.js +64 -0
  11. package/dist/analysis/opponent-profile.js +75 -7
  12. package/dist/analysis/opponents.js +2 -2
  13. package/dist/analysis/outlook.js +39 -0
  14. package/dist/analysis/picks.js +91 -12
  15. package/dist/analysis/plan/bonus-attempts.js +105 -0
  16. package/dist/analysis/plan/capture-instead.js +116 -0
  17. package/dist/analysis/plan/captures.js +45 -4
  18. package/dist/analysis/plan/conceded-out.js +13 -2
  19. package/dist/analysis/plan/estimates.js +135 -26
  20. package/dist/analysis/plan/holds.js +31 -3
  21. package/dist/analysis/plan/jabs.js +113 -0
  22. package/dist/analysis/plan/leftover.js +249 -4
  23. package/dist/analysis/plan/orders.js +76 -4
  24. package/dist/analysis/plan/relations.js +21 -1
  25. package/dist/analysis/plan/report.js +69 -3
  26. package/dist/analysis/plan/second-sizing.js +133 -0
  27. package/dist/analysis/plan/shared.js +82 -20
  28. package/dist/analysis/plan/siege.js +303 -0
  29. package/dist/analysis/plan/stand-still.js +7 -3
  30. package/dist/analysis/plan/state.js +8 -0
  31. package/dist/analysis/plan/strike.js +10 -5
  32. package/dist/analysis/plan/targets.js +91 -60
  33. package/dist/analysis/plan/threats.js +41 -6
  34. package/dist/analysis/plan/transfers.js +46 -6
  35. package/dist/analysis/planner.js +234 -16
  36. package/dist/analysis/profile.js +13 -2
  37. package/dist/analysis/stress.js +8 -2
  38. package/dist/bonus-attempt-store.js +55 -0
  39. package/dist/bundle.js +48009 -39350
  40. package/dist/cards.js +7 -5
  41. package/dist/chat.js +46 -4
  42. package/dist/commerce.js +111 -0
  43. package/dist/index.js +9 -1
  44. package/dist/live.js +43 -0
  45. package/dist/move-order.js +64 -3
  46. package/dist/my-games.js +1 -1
  47. package/dist/normalize.js +17 -0
  48. package/dist/profile-store.js +12 -2
  49. package/dist/protocol/bundle.js +28 -10
  50. package/dist/protocol/codec.js +1 -1
  51. package/dist/protocol/dialect.js +371 -0
  52. package/dist/protocol/interp.js +143 -66
  53. package/dist/protocol/methods.js +95 -34
  54. package/dist/protocol/rpc.js +35 -3
  55. package/dist/push/socketio.js +2 -2
  56. package/dist/relations-store.js +38 -4
  57. package/dist/siege-store.js +49 -0
  58. package/dist/state-bundle.js +525 -0
  59. package/dist/state-cli.js +69 -0
  60. package/dist/surrender-pending.js +4 -4
  61. package/dist/team-cards.js +25 -0
  62. package/dist/tools/award.js +15 -1
  63. package/dist/tools/card-advice.js +16 -5
  64. package/dist/tools/card-plays.js +2 -2
  65. package/dist/tools/card-support-advice.js +2 -1
  66. package/dist/tools/chat-inbox.js +36 -3
  67. package/dist/tools/chat-read-mark.js +3 -1
  68. package/dist/tools/chat.js +65 -6
  69. package/dist/tools/check-plan.js +54 -10
  70. package/dist/tools/commerce-deploy.js +33 -0
  71. package/dist/tools/common.js +31 -0
  72. package/dist/tools/end-of-game.js +5 -3
  73. package/dist/tools/index.js +7 -0
  74. package/dist/tools/my-games.js +10 -3
  75. package/dist/tools/notifications.js +2 -2
  76. package/dist/tools/picks.js +12 -0
  77. package/dist/tools/profile-opponents.js +2 -0
  78. package/dist/tools/push.js +2 -1
  79. package/dist/tools/relations.js +137 -0
  80. package/dist/tools/state.js +227 -0
  81. package/dist/tools/stress-opponents.js +5 -2
  82. package/dist/tools/surrender-pending.js +11 -6
  83. package/dist/tools/survival.js +11 -3
  84. package/dist/tools/team-brief.js +2 -2
  85. package/dist/tools/team.js +12 -3
  86. package/dist/tools/turn.js +332 -60
  87. package/dist/version.js +1 -1
  88. package/manifest.json +10 -2
  89. package/mint.yaml +14 -4
  90. package/package.json +4 -4
  91. package/server.json +2 -2
  92. package/skills/warapp-mcp/SKILL.md +31 -9
@@ -177,6 +177,11 @@ export function awardView(a, game, turn, name) {
177
177
  notes,
178
178
  };
179
179
  }
180
+ const FROM_SAID = {
181
+ explicit: 'first_mover given',
182
+ award: 'the award of picks',
183
+ inferred: 'inferred from my first order there, not verified',
184
+ };
180
185
  /**
181
186
  * Who moves first on `turn` (#127): `first_mover` when given, else what this server knows — a
182
187
  * turn kept at `<dataDir>/move-order/` alternated, or the award of picks — in a two-player game
@@ -190,6 +195,7 @@ export async function firstMoverFor(dataDir, game, me, turn, explicit, award, o
190
195
  cyclicDuel,
191
196
  ...(explicit ? { explicit } : {}),
192
197
  award: award?.firstMover ?? null,
198
+ ...(o.inferred ? { inferred: o.inferred } : {}),
193
199
  ...(remembered ? { remembered } : {}),
194
200
  });
195
201
  if (dataDir && record && o.write !== false)
@@ -200,7 +206,15 @@ export async function firstMoverFor(dataDir, game, me, turn, explicit, award, o
200
206
  firstMover: resolved.firstMover,
201
207
  // #215 review: only a first mover the user gave is verified; the award's is the wiki's rule.
202
208
  verified: verifiedFirstMover(resolved),
203
- view: { who: resolved.firstMover === 'me' ? 'you' : 'opponent', source: resolved.source, ...(resolved.from ? { from: resolved.from } : {}) },
209
+ view: {
210
+ who: resolved.firstMover === 'me' ? 'you' : 'opponent',
211
+ source: resolved.source,
212
+ ...(resolved.from ? { from: resolved.from } : {}),
213
+ line: `${resolved.firstMover === 'me' ? 'You move' : 'The opponent moves'} first` +
214
+ `${turn === null ? ' this turn' : ` on turn ${turn}`} (` +
215
+ (resolved.from ? `alternated from turn ${resolved.from.turn}: ${FROM_SAID[resolved.from.source]}` : FROM_SAID[resolved.source]) +
216
+ ').',
217
+ },
204
218
  warnings,
205
219
  };
206
220
  }
@@ -6,6 +6,7 @@
6
6
  // orders; my Bomb and Emergency Blockade and the D2 cards carry an `order` to pass to warapp_submit_turn.
7
7
  import { adviseOrderDelay, CARD_ORDER_DELAY, CARD_REINFORCEMENT, isMyCard, readActiveCards } from '../cards.js';
8
8
  import { bombAdvice, bombExposure, wallOffer, wallThreats } from '../analysis/card-threats.js';
9
+ import { bonusTerritories } from '../analysis/bonuses.js';
9
10
  import { supportAdvice } from './card-support-advice.js';
10
11
  import { inGameId } from '../live.js';
11
12
  import { capturePieceValue, cardClock } from '../strategy/card-clock.js';
@@ -50,8 +51,8 @@ export const handOwners = (game, me) => [
50
51
  ];
51
52
  /** In a team game: the hand and the limit are the team's (said once in the plan's warnings). */
52
53
  export const TEAM_HAND = "This is a team game: the hand and the card limit are the team's, shared with your teammates. The hand shown " +
53
- "gathers every card under you and your teammates on the live board; how war.app keys a team's hand is not yet " +
54
- 'verified, so check the hand in the game before shedding cards.';
54
+ "is every card under you and your teammates (war.app keeps each player's cards under that player's id), and war.app " +
55
+ 'refuses only the last of the team to commit while the team is over the limit: agree in team chat who sheds.';
55
56
  /** A card setting's `MultiplyAmount` (Blockade, Emergency Blockade), when the game sets one. */
56
57
  function multiplier(settings, key) {
57
58
  const r = settings?.raw[key];
@@ -79,7 +80,7 @@ export function adviseCards(input) {
79
80
  const { game, me, turn, hand, choice, plan, label } = input;
80
81
  const view = {};
81
82
  const warnings = [];
82
- // V8: in a team game a card read under a teammate's id is theirs to play (unverified), never advised to me.
83
+ // V8 (#310): in a team game a card read under a teammate's id is left to them, never advised to me.
83
84
  const own = hand.filter((c) => isMyCard(c, cardGame(game, me).me));
84
85
  const gone = new Set([...choice.plays, ...choice.discards].map((c) => c.id));
85
86
  const held = (type) => own.find((c) => c.type === type && !gone.has(c.id));
@@ -160,9 +161,19 @@ export function adviseCards(input) {
160
161
  const offer = ebMultiplier !== undefined ? wallOffer(cb, ebMultiplier, plan.conceded) : undefined;
161
162
  if (offer) {
162
163
  view.emergencyBlockade = { ...offer, order: { kind: 'card', card: wallCard.id, target: offer.territory } };
164
+ const bonusName = (id) => input.graph.map.bonuses.find((b) => b.id === id)?.name ?? `${id}`;
165
+ const p = offer.protects;
166
+ const shields = p.territories.length
167
+ ? ` It shields ${p.territories
168
+ .map((t) => {
169
+ const of = p.bonuses.filter((b) => bonusTerritories(input.graph, b.bonus).includes(t));
170
+ return `${label(t)}${of.length ? ` (${of.map((b) => `bonus ${bonusName(b.bonus)}, +${b.value} a turn`).join('; ')})` : ''}`;
171
+ })
172
+ .join(', ')}${p.commander ? ', where your commander stands,' : ''} from player ${offer.player}'s ~${offer.reach}, which can reach ${p.territories.length === 1 ? 'it' : 'them'} next turn only through the wall.`
173
+ : '';
163
174
  warnings.push(`Consider an Emergency Blockade on ${label(offer.territory)}: the plan concedes it, and its ${offer.givesUp} armies × ${ebMultiplier} make a ` +
164
- `wall of ${offer.wall} that player ${offer.player}'s ~${offer.reach} would lose ~${offer.kills} attacking — if it attacks; if not, ` +
165
- 'the territory and its armies are given away. Advice only, not in the orders: pass `cards.advice.emergencyBlockade.order` ' +
175
+ `wall of ${offer.wall} that player ${offer.player}'s ~${offer.reach} would lose ~${offer.kills} attacking — if it attacks.${shields} ` +
176
+ `It gives up ${label(offer.territory)} and its ${offer.givesUp} armies for good (it turns neutral). Advice only, not in the orders: pass \`cards.advice.emergencyBlockade.order\` ` +
166
177
  'to warapp_submit_turn to play it (the encoding is read from the client, not yet verified live).');
167
178
  }
168
179
  else if (ebMultiplier === undefined) {
@@ -2,8 +2,8 @@
2
2
  // Surveillance, Airlift, Gift, Diplomacy and Sanctions, and the combat cards Bomb and Emergency Blockade. Each card's fields come from the client
3
3
  // bundle's `GameOrderPlayCard<X>` writer and its refusals mirror the bundle's `GameValidateOrders`
4
4
  // (the error code each check stands in for is named), so a target war.app would refuse is refused
5
- // here before anything is sent. The encodings are golden-pinned but UNVERIFIED live (V9,
6
- // docs/WEB-PROTOCOL.md "Targeted card plays"). Third-party names reach errors only through
5
+ // here before anything is sent. The encodings are golden-pinned; Airlift's (#296) and Diplomacy's (#369) are
6
+ // verified live, the rest UNVERIFIED live (V9, docs/WEB-PROTOCOL.md "Targeted card plays"). Third-party names reach errors only through
7
7
  // `untrustedText`.
8
8
  import { McpToolError } from '@chrischall/mcp-utils';
9
9
  import { inGameId } from '../live.js';
@@ -1,6 +1,7 @@
1
1
  // PLAN-TEAMS D2: where to play my Diplomacy, Sanctions, Airlift and Gift cards this turn, read against the
2
2
  // plan (src/analysis/card-support.ts). Advice only, never auto-played: each carries the `order` to pass to
3
- // warapp_submit_turn as is, whose encodings are UNVERIFIED live (V9). Players and territories by id only.
3
+ // warapp_submit_turn as is, whose encodings are UNVERIFIED live (V9) save Airlift's and Diplomacy's (verified
4
+ // live, #296 and #369). Players and territories by id only.
4
5
  import { airliftAdvice, diplomacyAdvice, giftAdvice, intelAdvice, sanctionsAdvice } from '../analysis/card-support.js';
5
6
  import { visibleIncomeFor } from '../analysis/plan/shared.js';
6
7
  import { STRENGTH_INCOME_TURNS } from '../analysis/profile.js';
@@ -1,6 +1,6 @@
1
1
  import { z } from 'zod';
2
2
  import { CHAT_CHANNELS } from '../chat.js';
3
- import { chatGameIds, unflaggedFinished } from '../my-games.js';
3
+ import { chatGameIds, GAME_FINISHED, unflaggedFinished } from '../my-games.js';
4
4
  import { playersByInGameId } from '../live.js';
5
5
  import { CHAT_SOURCE_NOTES, chatMe, chatUnread, feedFillFields, markChatSeen, readChat, shown } from './chat.js';
6
6
  import { parseGameId } from '../client.js';
@@ -8,6 +8,23 @@ import { gameIdArg, readAnnotations, respond, untrustedDescription, untrustedTex
8
8
  import { mintMeta } from './hints.js';
9
9
  import { BRIDGE_NOTE } from './live.js';
10
10
  import { fetchMyGames } from './my-games.js';
11
+ /**
12
+ * #322: a finished game whose chat flags read clear is still read when it is among this many newest finished games
13
+ * (by id) in the list. A message GameFeed alone holds (a surrender "gg" sent as the game ended) leaves war.app's unread
14
+ * flag clear, and such a message comes as a game ends, so the newest finished games are where it hides; older ones stay
15
+ * judged by the flag. A bound, not a scan: at most this many extra reads over a whole sweep.
16
+ */
17
+ export const FINISHED_CLEAR_WINDOW = 3;
18
+ /** The newest `FINISHED_CLEAR_WINDOW` finished games (by id) whose flags read clear, which `chatGameIds` leaves out. */
19
+ export function recentClearFinished(games) {
20
+ const listed = new Set(chatGameIds(games));
21
+ return games
22
+ .filter((g) => g.stateCode === GAME_FINISHED && !listed.has(g.id))
23
+ .map((g) => g.id)
24
+ .sort((a, b) => b - a)
25
+ .slice(0, FINISHED_CLEAR_WINDOW)
26
+ .sort((a, b) => a - b);
27
+ }
11
28
  /** Games read per call, at most (each costs a GameFeed read and a GameRefresh). */
12
29
  export const MAX_INBOX_GAMES = 10;
13
30
  /** The most game ids a call may name. */
@@ -77,7 +94,8 @@ export function registerChatInboxTool(server, ctx) {
77
94
  const list = given ? undefined : await fetchMyGames(ctx);
78
95
  const me = await chatMe(ctx);
79
96
  const after = cursor === undefined ? undefined : Number(cursor);
80
- const ids = (given ?? chatGameIds(list.games)).filter((id) => after === undefined || id > after);
97
+ const clearFinished = list ? recentClearFinished(list.games) : [];
98
+ const ids = (given ?? [...chatGameIds(list.games), ...clearFinished].sort((a, b) => a - b)).filter((id) => after === undefined || id > after);
81
99
  const batch = ids.slice(0, max_games ?? MAX_INBOX_GAMES);
82
100
  const n = limit ?? DEFAULT_INBOX_LIMIT;
83
101
  const channels = [...CHAT_CHANNELS];
@@ -107,14 +125,21 @@ export function registerChatInboxTool(server, ctx) {
107
125
  }
108
126
  sources.add(read.source);
109
127
  const messages = fresh_.slice(-n).map((l) => shown(l, true, game.players, byInGame, me));
128
+ const name = game.name === undefined ? null : untrustedText(game.name);
129
+ // #387: new private messages addressed to me (diplomacy), counted for the watcher.
130
+ const toMe = me ? fresh_.filter((l) => l.channel === 'private' && l.to === me.inGameId).length : 0;
110
131
  withNew.push({
132
+ // #322/#323: the game as warapp_get_chat nests it; the top-level keys stay for existing callers.
133
+ game: { id: game.id, name, state: game.state },
111
134
  id: game.id,
112
- name: game.name === undefined ? null : untrustedText(game.name),
135
+ name,
113
136
  state: game.state,
114
137
  source: read.source,
115
138
  ...feedFillFields(read),
139
+ ...(read.olderUnread ? { olderUnread: read.olderUnread } : {}),
116
140
  unread,
117
141
  newCount: fresh_.length,
142
+ ...(toMe ? { toMe } : {}),
118
143
  messages,
119
144
  ...(mark_seen ? { markedSeen: marked ?? [] } : {}),
120
145
  ...(marked && fresh_.length > messages.length ? { markedUnshown: fresh_.length - messages.length } : {}),
@@ -152,6 +177,14 @@ export function registerChatInboxTool(server, ctx) {
152
177
  'are read like the rest rather than left out (the flags are not yet verified against war.app).',
153
178
  }
154
179
  : {}),
180
+ ...(clearFinished.length
181
+ ? {
182
+ finishedClearChecked: clearFinished.length,
183
+ finishedClearNote: `${clearFinished.length} recent finished game(s) are read although war.app's unread flag for their chat ` +
184
+ 'is clear: a message GameFeed alone holds (a surrender line, say) leaves that flag clear (#322). Only the ' +
185
+ `${FINISHED_CLEAR_WINDOW} newest finished games are read so; older ones go by the flag.`,
186
+ }
187
+ : {}),
155
188
  ...(sources.size ? { sourceNotes: Object.fromEntries([...sources].map((s) => [s, CHAT_SOURCE_NOTES[s]])) } : {}),
156
189
  }));
157
190
  });
@@ -79,7 +79,9 @@ export function registerMarkChatReadTool(server, ctx) {
79
79
  const read = await readChat(ctx, game, me);
80
80
  // A filled web read (#313) still carries the web messages' ids; GameFeed's added lines carry none and mark nothing.
81
81
  if (!read || read.source === 'gamefeed') {
82
- refuse(`The chat of game ${game.id} could be read only from GameFeed, which gives no message ids, so nothing was sent.`, 'Make sure your war.app tab is open and signed in (reload or focus it if it is frozen), then retry.');
82
+ refuse(`The chat of game ${game.id} could be read only from GameFeed, which gives no message ids, so nothing was sent.`, 'A message read from GameFeed carries no id, so war.app has nothing to mark for it. Read the game with ' +
83
+ 'warapp_get_chat: if its `source` is `web`, those messages can be marked; if it stays `gamefeed`, the web ' +
84
+ 'read failed or the signed-in account could not be read, and marking waits until it reads.');
83
85
  }
84
86
  // #313: the web read answered with no message at all while GameFeed holds some (a finished game's chat,
85
87
  // seen live). Every line is then GameFeed's, with no id; a retry reads the same, so it says why instead.
@@ -4,11 +4,11 @@
4
4
  // confirmation — a message reaches other players and cannot be unsent.
5
5
  import { CONFIRM_INJECTION_RULE, McpToolError, toolAnnotations } from '@chrischall/mcp-utils';
6
6
  import { z } from 'zod';
7
- import { CHAT_CHANNELS, feedChatLines, fillFromFeed, readGameRefreshChat, readSendChatReply } from '../chat.js';
7
+ import { CHAT_CHANNELS, feedChatLines, fillFromFeed, mergeChatLines, oldestId, readGameRefreshChat, readMessageHistoryReply, readSendChatReply, } from '../chat.js';
8
8
  import { advanceCursor, markedChannels, markNew, readChatCursor, unreadCounts, writeChatCursor, } from '../chat-cursor.js';
9
9
  import { parseGameId } from '../client.js';
10
- import { inGameId, playersByInGameId } from '../live.js';
11
- import { CHAT_CHANNEL_PUBLIC, Method, writeGameRefreshParams, writeSendChatParams } from '../protocol/methods.js';
10
+ import { inGameId, inGameOf, playersByInGameId } from '../live.js';
11
+ import { CHAT_CHANNEL_PUBLIC, Method, writeGameRefreshParams, writeRetrieveChatParams, writeRetrievePrivateMessageHistoryParams, writeSendChatParams, } from '../protocol/methods.js';
12
12
  import { carriesTeam } from '../teams.js';
13
13
  import { gameIdArg, readAnnotations, respond, UNTRUSTED_PREVIEW_NOTE, untrustedBody, untrustedDescription, untrustedText, } from './common.js';
14
14
  import { checkMessageCommitments, commitmentsArg, COMMITMENTS_NOTE, DEFAULT_PLAN_CHECKED } from './commitments.js';
@@ -54,9 +54,12 @@ export async function readChat(ctx, game, me) {
54
54
  if (me) {
55
55
  try {
56
56
  const env = await ctx.rpc.call('GameRefresh', Method.GameRefresh, (w) => writeGameRefreshParams(w, { gameId: game.id, chat: true, nonChat: false, lobby: game.state === 'WaitingForPlayers' }));
57
- const lines = readGameRefreshChat(await ctx.bundle(), env.body);
58
- if (lines)
59
- return lines.length < (feed?.length ?? 0) ? withFeed(lines, feed) : { source: 'web', lines };
57
+ const refreshed = readGameRefreshChat(await ctx.bundle(), env.body);
58
+ if (refreshed) {
59
+ const { lines, olderUnread } = await withOlder(ctx, game, me, refreshed);
60
+ const read = lines.length < (feed?.length ?? 0) ? withFeed(lines, feed) : { source: 'web', lines };
61
+ return olderUnread.length ? { ...read, olderUnread } : read;
62
+ }
60
63
  }
61
64
  catch {
62
65
  // Fall back to GameFeed.
@@ -64,6 +67,59 @@ export async function readChat(ctx, game, me) {
64
67
  }
65
68
  return feed ? { source: 'gamefeed', lines: feed } : undefined;
66
69
  }
70
+ /** The most private conversations whose history one chat read asks for (one request each). */
71
+ export const MAX_PRIVATE_HISTORY = 8;
72
+ /**
73
+ * GameRefresh's chat with the messages it leaves out added (#363, #387). Sent `-1` markers (as the client
74
+ * sends on a first load), GameRefresh leaves out messages war.app counts as seen — live, an own team message
75
+ * showed in the official app only after "Show older messages". The client's button sends RetrieveChat (45)
76
+ * with, per channel, the oldest message id received (9999E14 when none), and a private conversation's history
77
+ * button RetrievePrivateMessageHistory (46) the same per counterpart: both are asked here, once each, the
78
+ * private one per other human seat with an in-game id (at most {@link MAX_PRIVATE_HISTORY}) unless the game
79
+ * turns private messaging off. A read that fails or does not decode adds nothing and names its channels.
80
+ */
81
+ async function withOlder(ctx, game, me, refreshed) {
82
+ let lines = refreshed;
83
+ const olderUnread = [];
84
+ const history = async (name, method, write) => {
85
+ try {
86
+ const env = await ctx.rpc.call(name, method, write);
87
+ return readMessageHistoryReply(await ctx.bundle(), env.body);
88
+ }
89
+ catch {
90
+ return undefined;
91
+ }
92
+ };
93
+ const older = await history('RetrieveChat', Method.RetrieveChat, (w) => writeRetrieveChatParams(w, {
94
+ gameId: game.id,
95
+ publicBefore: oldestId(refreshed, (l) => l.channel === 'public'),
96
+ teamBefore: oldestId(refreshed, (l) => l.channel === 'team'),
97
+ }));
98
+ if (older)
99
+ lines = mergeChatLines(lines, older);
100
+ else
101
+ olderUnread.push('public', 'team');
102
+ if (game.settings?.privateMessaging !== false) {
103
+ const counterparts = game.players
104
+ .filter((p) => !p.isAI)
105
+ .map((p) => inGameOf(p))
106
+ .filter((id) => id !== undefined && id !== me.inGameId)
107
+ .sort((a, b) => a - b)
108
+ .slice(0, MAX_PRIVATE_HISTORY);
109
+ let failed = false;
110
+ for (const counterpart of counterparts) {
111
+ const withThem = (l) => l.channel === 'private' && (l.to === counterpart || (l.sender === counterpart && l.to === me.inGameId));
112
+ const got = await history('RetrievePrivateMessageHistory', Method.RetrievePrivateMessageHistory, (w) => writeRetrievePrivateMessageHistoryParams(w, { gameId: game.id, before: oldestId(refreshed, withThem), counterpart }));
113
+ if (got)
114
+ lines = mergeChatLines(lines, got);
115
+ else
116
+ failed = true;
117
+ }
118
+ if (failed)
119
+ olderUnread.push('private');
120
+ }
121
+ return { lines, olderUnread };
122
+ }
67
123
  /** A web read shorter than GameFeed's list, filled from it (#313). */
68
124
  function withFeed(web, feed) {
69
125
  const counts = `The web client's read returned fewer messages (${web.length}) than GameFeed's chat (${feed.length})`;
@@ -184,6 +240,8 @@ export function shown(line, isNew, players, byInGame, me) {
184
240
  channel: line.channel,
185
241
  ...(line.team !== undefined ? { team: line.team } : {}),
186
242
  ...(to ? { to } : {}),
243
+ // #387: a private message addressed to me, so a watcher can flag diplomacy the moment it arrives.
244
+ ...(line.channel === 'private' && me !== undefined && line.to === me.inGameId ? { toMe: true } : {}),
187
245
  mine: isMine(line, me),
188
246
  new: isNew,
189
247
  };
@@ -249,6 +307,7 @@ export function registerChatTools(server, ctx, opts = {}) {
249
307
  ...header,
250
308
  source: read.source,
251
309
  ...feedFillFields(read),
310
+ ...(read.olderUnread ? { olderUnread: read.olderUnread } : {}),
252
311
  messages,
253
312
  count: picked.length,
254
313
  shown: messages.length,
@@ -14,7 +14,9 @@ import { claimedCardUses, claimedCardWarning, teamCardClaims, teamHandLeft, uncl
14
14
  import { boardStateFromLive } from '../live.js';
15
15
  import { withTeammateOrders } from '../team-orders.js';
16
16
  import { assumedWarning, awardView, loadAward, openingThreat } from './award.js';
17
- import { gameIdArg, graphOf, namer, readAnnotations, respond, untrustedDescription, untrustedText, viewArg } from './common.js';
17
+ import { readLedger } from '../relations-store.js';
18
+ import { resolveIntel } from '../analysis/intel.js';
19
+ import { avoidPlayersArg, avoidTerritoriesArg, gameIdArg, graphOf, knownIncomeArg, namer, readAnnotations, respond, untrustedDescription, untrustedText, viewArg } from './common.js';
18
20
  import { lookupMeta } from './hints.js';
19
21
  import { HEADROOM_COMPACT, headroomView, readTripwires, safeHeadroom, teamsOf, tripwireWarnings, untrustedDeploy } from './survival.js';
20
22
  import { loadLiveGame, standInLine, standInOf } from './live-context.js';
@@ -125,6 +127,9 @@ export function registerCheckPlanTool(server, ctx) {
125
127
  'income when larger; in a 1v1 that started even, an opponent bordering the fog at least your own income; while an ' +
126
128
  'observation has made its estimate untrusted, the larger of what it implied and your own income). ' +
127
129
  'Income in the fog is unseen, so raise it to test a stronger opponent.'),
130
+ known_income: knownIncomeArg,
131
+ avoid_territories: avoidTerritoriesArg,
132
+ avoid_players: avoidPlayersArg,
128
133
  first_mover: z
129
134
  .enum(['me', 'opponent'])
130
135
  .optional()
@@ -133,7 +138,7 @@ export function registerCheckPlanTool(server, ctx) {
133
138
  view: viewArg(VIEWS, `compact (default) gives the verdict, the worst reply and up to ${COMPACT_OTHERS} more; "full" adds every ` +
134
139
  'reply listed, each order\'s result unanswered and the rules assumed.'),
135
140
  }),
136
- }, async ({ game_id, player, orders, enemy_deploy, first_mover, view }) => {
141
+ }, async ({ game_id, player, orders, enemy_deploy, known_income, avoid_territories, avoid_players, first_mover, view }) => {
137
142
  const feed = await ctx.client.getGame(game_id, { settings: true });
138
143
  requireTurnPhase(feed);
139
144
  const map = mapOf(feed);
@@ -142,6 +147,12 @@ export function registerCheckPlanTool(server, ctx) {
142
147
  // The teams: GameFeed's, else the game list's (asked once per game, kept).
143
148
  const { game, me, source: teamSource, known: teamsKnown } = await resolveTeamsFor(ctx, feed, seat);
144
149
  const turn = currentTurn(game);
150
+ // #386: the avoid targets and stated incomes warapp_record_intel kept, as warapp_plan_turn applies them.
151
+ const intel = resolveIntel(ctx.dataDir ? (await readLedger(ctx.dataDir, game.id, me.id))?.intel : undefined, turn, {
152
+ ...(known_income !== undefined ? { knownIncome: known_income } : {}),
153
+ ...(avoid_territories !== undefined ? { avoidTerritories: avoid_territories } : {}),
154
+ ...(avoid_players !== undefined ? { avoidPlayers: avoid_players } : {}),
155
+ });
145
156
  const [{ territories, info }, history] = await Promise.all([loadLiveGame(ctx, game), boardHistory(ctx, game, me, turn)]);
146
157
  const graph = graphOf(map);
147
158
  // As warapp_plan_turn does (#166): the opponent's starts the award of picks proves stand on
@@ -294,7 +305,14 @@ export function registerCheckPlanTool(server, ctx) {
294
305
  staticSeats: staticSeats(game.players, game.endRules, me.id),
295
306
  });
296
307
  const untrustedOf = new Map(trip.tripwires.map((w) => [w.player, untrustedDeploy(w, income)]));
308
+ // #368: an income the caller knows replaces the estimate (a Reinforcement card the clock adds on top),
309
+ // before an untrusted mark; enemy_deploy, a what-if for everyone, wins over both. The commander check
310
+ // below keeps the submit's sizing, so it never calls safe what warapp_submit_turn refuses.
311
+ const knownOf = new Map((enemy_deploy === undefined ? (intel.knownIncome ?? []) : []).map((k) => [k.player, k.income]));
297
312
  const opponents = so.opponents.map((o) => {
313
+ const known = knownOf.get(o.id);
314
+ if (known !== undefined)
315
+ return { ...o, deploy: known + (o.card ?? 0) };
298
316
  const untrusted = untrustedOf.get(o.id);
299
317
  return enemy_deploy !== undefined || untrusted === undefined ? o : { ...o, deploy: Math.max(untrusted, o.deploy) };
300
318
  });
@@ -313,7 +331,10 @@ export function registerCheckPlanTool(server, ctx) {
313
331
  ? r.enforcedUntil === undefined || turn === null || turn < r.enforcedUntil
314
332
  : teams.size === 0 && (r.state === 'active' || r.state === 'notice') && (r.endsTurn === undefined || turn === null || turn < r.endsTurn)));
315
333
  // D3: the deploy total is checked against my income under the Sanctions on me.
316
- const sanction = sanctionMyIncome(income, effect, { localDeployments: settings.localDeployments === true });
334
+ // #332: a commerce game's gold, read from the standing, already carries any Sanctions (war.app pays it).
335
+ const sanction = so.commerce?.source === 'standing'
336
+ ? { income, warnings: [], applied: false }
337
+ : sanctionMyIncome(income, effect, { localDeployments: settings.localDeployments === true });
317
338
  const report = stressPlan({
318
339
  graph,
319
340
  board,
@@ -481,6 +502,7 @@ export function registerCheckPlanTool(server, ctx) {
481
502
  opponent: who(e.opponent),
482
503
  bonusesLost: e.bonusesLost.map((b) => bonusOf(b.id)),
483
504
  incomeLost: e.incomeLost,
505
+ ...(e.breaksTruce ? { breaksTruce: true } : {}),
484
506
  });
485
507
  const orderView = (e) => ({
486
508
  order: e.index + 1,
@@ -498,9 +520,15 @@ export function registerCheckPlanTool(server, ctx) {
498
520
  ? ` ${report.blindBorders.length} of your territories border the fog and were not tested.`
499
521
  : '';
500
522
  const inexact = report.exact ? '' : ' Battles are not exact in this game (luck or weighted rounding): each was resolved at its expectation.';
501
- const ahead = report.exposedNextTurn.length
502
- ? ` Next turn: ${report.exposedNextTurn.length} ${plural(report.exposedNextTurn.length, 'territory is', 'territories are')} within reach of a stack two steps away if you add nothing (see exposedNextTurn). First: ${exposure(report.exposedNextTurn[0])}`
503
- : '';
523
+ // #376: an exposure only a truce break reaches is counted apart, after the real ones.
524
+ const reachable = report.exposedNextTurn.filter((x) => !x.breaksTruce);
525
+ const ifBroken = report.exposedNextTurn.length - reachable.length;
526
+ const brokenLine = ifBroken ? ` ${ifBroken} more only if a truce breaks.` : '';
527
+ const ahead = reachable.length
528
+ ? ` Next turn: ${reachable.length} ${plural(reachable.length, 'territory is', 'territories are')} within reach of a stack two steps away if you add nothing (see exposedNextTurn). First: ${exposure(reachable[0])}${brokenLine}`
529
+ : ifBroken
530
+ ? ` Next turn: ${ifBroken} ${plural(ifBroken, 'territory is', 'territories are')} within reach of a stack two steps away only if a truce breaks (see exposedNextTurn).`
531
+ : '';
504
532
  // #180: stacks you attack that can step out of the way first.
505
533
  const escapes = report.dodges.filter((d) => d.took && d.escaped > 0);
506
534
  const escapingStacks = new Set(escapes.map((d) => d.stack)).size;
@@ -539,9 +567,21 @@ export function registerCheckPlanTool(server, ctx) {
539
567
  });
540
568
  // #275 pattern 3: each border these orders leave below what the default plan leaves there (one plan per call).
541
569
  const belowPlan = await bordersBelowPlan(ctx, { game, map, me, turn, territories, info, history, teamsKnown, given: { deploys, moves } });
570
+ // #375: an order into a territory to avoid, or one an avoided player holds.
571
+ const avoidT = new Set((intel.avoidTerritories ?? []).map((t) => resolveTerritory(map, t).id));
572
+ const avoidP = new Set(intel.avoidPlayers ?? []);
573
+ const ownerOf = (id) => {
574
+ const o = board.territories.find((t) => t.territoryId === id)?.owner;
575
+ return o?.kind === 'player' ? o.playerId : undefined;
576
+ };
577
+ const avoidedHits = [...new Set(moves.map((m) => m.to))].filter((to) => !mine.has(to) && (avoidT.has(to) || avoidP.has(ownerOf(to) ?? Number.NaN)));
542
578
  const warnings = [
543
579
  // The owner, 2026-11-17: while an older build stands in for a client this server cannot read, say so first.
544
580
  ...[standInLine(standInOf(ctx))].filter((w) => w !== undefined),
581
+ ...intel.warnings,
582
+ ...(avoidedHits.length
583
+ ? [`These orders attack ${avoidedHits.map((t) => name(t)).join(', ')}, which you asked to avoid (avoid_territories / avoid_players).`]
584
+ : []),
545
585
  // #275 (b): an untrusted estimate is the first thing said (not under an explicit enemy_deploy).
546
586
  ...(enemy_deploy === undefined ? tripwireWarnings(trip.tripwires, (w) => untrustedOf.get(w.player) ?? untrustedDeploy(w, income), (p) => estimates.find((x) => x.playerId === p)?.estimate) : []),
547
587
  ...(award ? assumedWarning(award) : []),
@@ -563,7 +603,8 @@ export function registerCheckPlanTool(server, ctx) {
563
603
  ...effect.unsure,
564
604
  ...[claimedCardWarning(claimedCardUses(uses, claimed))].filter((w) => w !== undefined),
565
605
  ...unsimulatedCards,
566
- ...(deployed !== sanction.income
606
+ // #332: in a commerce game a smaller deploy saves gold, so only a larger one is worth a line.
607
+ ...(deployed !== sanction.income && !(so.commerce && deployed < sanction.income)
567
608
  ? [
568
609
  `The orders deploy ${deployed} and your income is ${sanction.income}: the test used the orders as given (a Reinforcement card adds to the income; otherwise war.app refuses a wrong total).`,
569
610
  ]
@@ -596,16 +637,19 @@ export function registerCheckPlanTool(server, ctx) {
596
637
  // #166: what the award of picks showed, the move order it implies included (absent with no pick list kept).
597
638
  ...(award ? { award: awardView(award, game, turn, name) } : {}),
598
639
  orderPriority,
599
- income,
640
+ // #277: what I may deploy this turn, after any Sanctions on me (as warapp_plan_turn reports it).
641
+ income: sanction.income,
600
642
  deployed,
601
643
  warnings,
644
+ // #386: the intel warapp_record_intel kept and what this check did with it (absent when none is kept).
645
+ ...(intel.report ? { intel: intel.report } : {}),
602
646
  // Only an opponent with a stack in view can be given a reply; the others are named apart.
603
647
  enemyDeploy: opponents
604
648
  .filter((o) => inView.has(o.id))
605
649
  .map((o) => ({
606
650
  player: { id: o.id, name: playerName.get(o.id) ?? String(o.id) },
607
651
  deploy: o.deploy,
608
- source: enemy_deploy !== undefined ? 'enemy_deploy' : untrustedOf.has(o.id) ? 'untrusted' : 'estimate',
652
+ source: enemy_deploy !== undefined ? 'enemy_deploy' : knownOf.has(o.id) ? 'known_income' : untrustedOf.has(o.id) ? 'untrusted' : 'estimate',
609
653
  })),
610
654
  // #180: in a free-for-all, whether you lead (any two opponents are then tried together).
611
655
  leader,
@@ -655,7 +699,7 @@ export function registerCheckPlanTool(server, ctx) {
655
699
  jointFalls: report.jointFalls.slice(0, LIST_MAX).map(jointView),
656
700
  ...(report.jointFalls.length > LIST_MAX ? { jointFallsMore: report.jointFalls.length - LIST_MAX } : {}),
657
701
  // #275 (a): each border's headroom, the weakest first (compact: the first few).
658
- headroom: headroomView(headroom, map, income, rung === 'full', !teamsKnown),
702
+ headroom: headroomView(headroom, map, income, rung === 'full', !teamsKnown, (p) => estimates.find((e) => e.playerId === p)?.estimate),
659
703
  ...(rung !== 'full' && headroom.length > HEADROOM_COMPACT ? { headroomMore: headroom.length - HEADROOM_COMPACT } : {}),
660
704
  // #275 pattern 3: absent when the default plan could not be made.
661
705
  ...(belowPlan
@@ -0,0 +1,33 @@
1
+ // #332: a commerce game's deploy this turn, for every tool that checks or plans a deploy total (warapp_plan_turn,
2
+ // warapp_submit_turn, warapp_check_plan): one computation, so the three never disagree.
3
+ import { commerceDeploy, commerceRules } from '../commerce.js';
4
+ import { inGameOf, standingGold } from '../live.js';
5
+ /**
6
+ * The armies my gold buys at the game's army price: from the standing's gold (`standingGold`) when it reads — it
7
+ * already holds what was saved and any Sanctions, since war.app pays it — else from `modelGold` (the income model).
8
+ * `undefined` outside a commerce game, or when its settings were not read.
9
+ */
10
+ export function commerceDeployOf(game, me, info, modelGold) {
11
+ const rules = commerceRules(game.settings);
12
+ if (!rules)
13
+ return undefined;
14
+ const id = inGameOf(me);
15
+ return commerceDeploy(rules, id === undefined ? undefined : standingGold(info, id), modelGold);
16
+ }
17
+ /**
18
+ * What `warapp_submit_turn` checks a commerce deploy against (#353 review). Gold read from the board is authoritative,
19
+ * so it is the deploy budget (`commerce`: deploying more than it buys is refused, error 597; less saves gold). Gold
20
+ * from the income model leaves out what was saved on earlier turns, so it is not enforced: it adds an `uncertain`
21
+ * reason instead, and a different total is a warning, as an uncertain income always was.
22
+ */
23
+ export function submitCommerceCheck(c) {
24
+ if (!c)
25
+ return { uncertain: [] };
26
+ if (c.source === 'standing')
27
+ return { commerce: { gold: c.gold, armyCostMultiplier: c.armyCostMultiplier }, uncertain: [] };
28
+ return {
29
+ uncertain: [
30
+ `Your gold could not be read from the board, so the check uses the income model's ${c.gold}, which leaves out gold saved from earlier turns.`,
31
+ ],
32
+ };
33
+ }
@@ -7,6 +7,37 @@ export const readAnnotations = (title) => toolAnnotations({ title, readOnly: tru
7
7
  export const gameIdArg = z
8
8
  .union([z.number(), z.string()])
9
9
  .describe('The war.app game id — the number after GameID= in the game URL (war.app/MultiPlayer?GameID=<n>).');
10
+ /**
11
+ * #368: per-player incomes the caller knows (warapp_plan_turn's and warapp_check_plan's `known_income`):
12
+ * each replaces that opponent's estimate.
13
+ */
14
+ export const knownIncomeArg = z
15
+ .array(z.object({
16
+ player: z.coerce.number().int().describe('The player\'s GameFeed id (as warapp_get_game lists it).'),
17
+ income: z.coerce.number().int().min(0).max(10_000).describe('The income it earns per turn, card armies aside.'),
18
+ }))
19
+ .max(50)
20
+ .optional()
21
+ .describe('Per-player incomes you know (what a player said in diplomacy chat, say), by GameFeed id: each replaces that ' +
22
+ "opponent's estimate (a Reinforcement card the card clock adds stays on top), and the plan's warning says it was " +
23
+ 'supplied. Taken as given, never checked against the board. Given, it replaces the incomes warapp_record_intel kept for this call. `enemy_deploy`, a what-if ' +
24
+ 'for every opponent, wins over it; a player with none of its territories in view is named as unused.');
25
+ /** #375: territories never to attack (warapp_plan_turn's and warapp_check_plan's `avoid_territories`). */
26
+ export const avoidTerritoriesArg = z
27
+ .array(z.union([z.string(), z.number()]))
28
+ .max(200)
29
+ .optional()
30
+ .describe('Territories (ids or names) never to attack this turn, whoever holds them: a neutral promised to someone, say. ' +
31
+ 'warapp_plan_turn plans around them; warapp_check_plan warns when the orders attack one. Given, it replaces the territories ' +
32
+ 'warapp_record_intel kept, for this call (`[]`: none); omitted, those apply.');
33
+ /** #375: players never to attack (warapp_plan_turn's and warapp_check_plan's `avoid_players`). */
34
+ export const avoidPlayersArg = z
35
+ .array(z.coerce.number().int())
36
+ .max(50)
37
+ .optional()
38
+ .describe('Players (GameFeed ids) never to attack this turn: peace promised outside a recorded truce. warapp_plan_turn ' +
39
+ 'attacks none of their territories; warapp_check_plan warns when the orders do. Given, it replaces the players ' +
40
+ 'warapp_record_intel kept, for this call (`[]`: none); omitted, those apply.');
10
41
  /**
11
42
  * Who writes the text these tools return: player and game names, chat, and
12
43
  * map / territory / bonus names (maps are user-designed). None of it is the user.
@@ -355,10 +355,12 @@ export const sweepWindow = (keep = MAX_FINISHED_RECORDS) => Math.max(1, Math.flo
355
355
  * the newest {@link sweepWindow} games (half the record bound): older ones are never its candidates.
356
356
  * Its writes never prune a record of a game in that window (`protectIds`), and each call refreshes the
357
357
  * window's records, so the records the harness and the reports read stay the newest games'. A game the
358
- * sweep processed is so never read again (P2).
358
+ * sweep processed is so never read again (P2). `window` widens (or narrows) it for warapp_backfill_history,
359
+ * at most `keep` games.
359
360
  */
360
- export async function sweepFinished(deps, me, gameIds, { limit = END_OF_GAME_PER_CALL, keep = MAX_FINISHED_RECORDS } = {}) {
361
- const window = gameIds.slice(0, sweepWindow(keep));
361
+ export async function sweepFinished(deps, me, gameIds, { limit = END_OF_GAME_PER_CALL, keep = MAX_FINISHED_RECORDS, window: size, } = {}) {
362
+ // warapp_backfill_history may widen the window, never past the record bound (every game in it is protected).
363
+ const window = gameIds.slice(0, Math.max(1, Math.min(size ?? sweepWindow(keep), keep)));
362
364
  const todo = [];
363
365
  for (const id of window)
364
366
  if (await needsEndOfGame(deps.dataDir, deps.env, id, me))
@@ -34,6 +34,8 @@ import { registerTurnTools } from './turn.js';
34
34
  import { registerUncommitTool } from './uncommit.js';
35
35
  import { registerLeaveGameTool } from './leave-game.js';
36
36
  import { registerWhereTool } from './where.js';
37
+ import { registerStateTools } from './state.js';
38
+ import { blobStoreFromEnv } from '@chrischall/mcp-utils/export';
37
39
  import { registerProfileOpponentsTool } from './profile-opponents.js';
38
40
  import { pushListenerFor } from '../push/listener.js';
39
41
  import { pushWebSocketLeg } from '../push/websocket.js';
@@ -152,6 +154,11 @@ export function registerAllTools(server, deps = {}) {
152
154
  ...(env ? { env } : {}),
153
155
  });
154
156
  registerPushTools(server, live, push, deps.env ? { env: deps.env } : {});
157
+ // Moving a local install's history in (hosted: only with mcp-host's blob store) and the end-of-game backfill.
158
+ registerStateTools(server, live, {
159
+ ...(deps.env ? { env: deps.env } : {}),
160
+ store: deps.blobStore === undefined ? blobStoreFromEnv(deps.env ?? process.env) : deps.blobStore,
161
+ });
155
162
  // Hosted only: the war.app sign-in mcp-host's authFlow captures the AuthToken from (#333 part B).
156
163
  // Locally warapp_link_session stays the way to the direct transport.
157
164
  if (hosted)
@@ -83,7 +83,9 @@ export const MAX_SURRENDER_READS = 20;
83
83
  const SURRENDER_READ_BATCH = 4;
84
84
  /**
85
85
  * #317: each game's pending surrenders, by game id: read for a game being played or picked where my seat
86
- * still plays (at most {@link MAX_SURRENDER_READS}, war.app's order), `null` elsewhere or when unreadable.
86
+ * still plays (at most {@link MAX_SURRENDER_READS}, war.app's order; `null` when unreadable, and absent —
87
+ * so `null` — past the bound); every other game is an empty list, read from nothing (#327: a lobby or a
88
+ * finished game has none, and a game I am out of owes none from me).
87
89
  * GetMyGames carries no GameFeed id, so `player` is `null`; the name is the list's, untrusted.
88
90
  */
89
91
  export async function myGamesSurrenders(ctx, games, me) {
@@ -92,6 +94,9 @@ export async function myGamesSurrenders(ctx, games, me) {
92
94
  const mine = g.players.find((p) => p.id === me);
93
95
  return surrenderMayBePending(gameStateName(g.stateCode), mine ? playerStateName(mine.stateCode) : undefined);
94
96
  });
97
+ for (const g of games)
98
+ if (!eligible.includes(g))
99
+ byGame.set(g.id, []);
95
100
  const read = eligible.slice(0, MAX_SURRENDER_READS);
96
101
  for (let i = 0; i < read.length; i += SURRENDER_READ_BATCH) {
97
102
  const batch = read.slice(i, i + SURRENDER_READ_BATCH);
@@ -129,7 +134,8 @@ export function registerMyGamesTool(server, ctx, deps = {}) {
129
134
  'they have committed this turn) and waitingOnYou — true when the game is being played or distributing ' +
130
135
  'territories, you are still playing, and you have not committed — and surrenderPending: the surrenders other ' +
131
136
  'players asked for that are still pending, each with owedByMe (true: waiting for you to accept it), read from ' +
132
- 'the game details (unverified live; null when not read or unreadable, never "none"); the top-level ' +
137
+ 'the game details (unverified live; null when not read or unreadable, never "none"; empty without a read ' +
138
+ 'for a lobby, a finished game or a game you no longer play in, where none can wait on you); the top-level ' +
133
139
  'surrenderPending counts the games where one waits on you, and those games come first too. ' +
134
140
  'Finished games are left out unless ' +
135
141
  '`include_finished` (`finishedLeftOut` counts them). `listed` is how many games war.app returned and ' +
@@ -163,7 +169,8 @@ export function registerMyGamesTool(server, ctx, deps = {}) {
163
169
  if (view === 'brief')
164
170
  return briefResult(summary, partial ? raw.length : undefined);
165
171
  const finishedLeftOut = raw.length - kept.length;
166
- // #317: the surrenders pending in each game (the game details; null: not read or unreadable, never "none").
172
+ // #317: the surrenders pending in each game (the game details; null: not read or unreadable, never "none";
173
+ // #327: [] without a read where none can wait on me).
167
174
  const { byGame, skipped } = await myGamesSurrenders(ctx, kept, me);
168
175
  const withSurrenders = summary.map((g) => ({ ...g, surrenderPending: byGame.get(g.id) ?? null }));
169
176
  // A game waiting on my acceptance waits on me too: it goes first with the turns waiting on me.