@chrischall/warapp-mcp 0.10.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.
- package/.claude-plugin/marketplace.json +3 -3
- package/.claude-plugin/plugin.json +1 -1
- package/README.md +10 -8
- package/dist/analysis/cards-in-effect.js +10 -1
- package/dist/analysis/chat-mentions.js +17 -0
- package/dist/analysis/commander-fog.js +126 -0
- package/dist/analysis/end-game-stats.js +149 -0
- package/dist/analysis/local-deploy.js +3 -2
- package/dist/analysis/outlook.js +133 -55
- package/dist/analysis/picks.js +125 -0
- package/dist/analysis/plan/commander.js +3 -2
- package/dist/analysis/plan/deploy-estimates.js +11 -7
- package/dist/analysis/plan/estimates.js +63 -9
- package/dist/analysis/plan/relations.js +29 -14
- package/dist/analysis/plan/shared.js +21 -0
- package/dist/analysis/plan/threats.js +74 -5
- package/dist/analysis/player-record.js +31 -1
- package/dist/analysis/player.js +23 -10
- package/dist/analysis/relations.js +83 -9
- package/dist/analysis/scale.js +71 -0
- package/dist/analysis/single-pick.js +356 -0
- package/dist/bundle.js +3099 -809
- package/dist/chat-links.js +141 -0
- package/dist/finished-store.js +30 -0
- package/dist/index.js +1 -1
- package/dist/known-mods.js +33 -0
- package/dist/map-stats.js +24 -2
- package/dist/mod-alliances.js +217 -0
- package/dist/mod-data.js +160 -0
- package/dist/my-games.js +53 -2
- package/dist/normalize.js +7 -0
- package/dist/outlook-log.js +13 -0
- package/dist/player-record-store.js +5 -3
- package/dist/protocol/methods.js +14 -2
- package/dist/relations-store.js +29 -1
- package/dist/tools/card-advice.js +29 -9
- package/dist/tools/card-effects.js +3 -1
- package/dist/tools/card-support-advice.js +1 -1
- package/dist/tools/chat-advice.js +1 -1
- package/dist/tools/chat-inbox.js +67 -10
- package/dist/tools/chat.js +46 -8
- package/dist/tools/check-plan.js +115 -11
- package/dist/tools/close-finished-game.js +110 -0
- package/dist/tools/commander-check.js +80 -1
- package/dist/tools/diplomacy.js +11 -2
- package/dist/tools/end-of-game.js +57 -3
- package/dist/tools/game.js +7 -3
- package/dist/tools/how-lost.js +68 -5
- package/dist/tools/index.js +21 -1
- package/dist/tools/map.js +50 -1
- package/dist/tools/mod-alliances.js +191 -0
- package/dist/tools/my-games.js +12 -1
- package/dist/tools/pace.js +44 -0
- package/dist/tools/picks.js +41 -1
- package/dist/tools/relations.js +120 -7
- package/dist/tools/session.js +20 -6
- package/dist/tools/stress-opponents.js +25 -2
- package/dist/tools/turn.js +338 -42
- package/dist/tools/write-kit.js +1 -0
- package/dist/version.js +1 -1
- package/manifest.json +10 -2
- package/mint.yaml +3 -4
- package/package.json +1 -1
- package/server.json +2 -2
- package/skills/warapp-mcp/SKILL.md +73 -11
package/dist/my-games.js
CHANGED
|
@@ -35,7 +35,17 @@ const GI = { gameId: 7, name: 13, lastTurn: 14, players: 16, state: 22 };
|
|
|
35
35
|
* the client bundle, UNVERIFIED live. The read-back for RegisterChatView.
|
|
36
36
|
*/
|
|
37
37
|
const GI_UNREAD = { group: 8, private: 17, public: 18, team: 23 };
|
|
38
|
+
/** GameInfo's boot-clock fields (pace; read from the bundle's GameInfo reader and game-list renderer). */
|
|
39
|
+
const GI_BOOT = { boot: 5, realTime: 19, banked: 24, turnFor: 26 };
|
|
40
|
+
/** The TimeSpan maximum (war.app's "never"), as a decoded number of milliseconds. */
|
|
41
|
+
const NEVER_MS = 922_336_666_814_565;
|
|
38
42
|
export const GAME_INFO_FIELDS = 27;
|
|
43
|
+
/**
|
|
44
|
+
* #523: GameInfo field 20, the client's `SeenEndGameWindow` for my seat (the GameInfo reader's 21st read; GamePlayer
|
|
45
|
+
* names the same minified field `SeenEndGameWindow`). Read from the bundle; VERIFIED live 2026-11-23 as the read-back of
|
|
46
|
+
* warapp_close_finished_game.
|
|
47
|
+
*/
|
|
48
|
+
const GI_SEEN_END = 20;
|
|
39
49
|
/** GameInfoPlayer field positions in read order, and its whole field count. */
|
|
40
50
|
const GP = { committed: 2, name: 5, id: 6, state: 7, team: 8 };
|
|
41
51
|
export const GAME_INFO_PLAYER_FIELDS = 10;
|
|
@@ -125,6 +135,7 @@ function gameOf(g) {
|
|
|
125
135
|
throw new MyGamesFormatError('a GameInfo lacks its fields');
|
|
126
136
|
}
|
|
127
137
|
const unreadChat = unreadFlagsOf(f);
|
|
138
|
+
const boot = bootClockOf(f);
|
|
128
139
|
return {
|
|
129
140
|
id,
|
|
130
141
|
name: name ?? '',
|
|
@@ -132,8 +143,44 @@ function gameOf(g) {
|
|
|
132
143
|
stateCode: state,
|
|
133
144
|
players: (players ?? []).filter((p) => p !== null).map(playerOf),
|
|
134
145
|
...(unreadChat ? { unreadChat } : {}),
|
|
146
|
+
...(f[GI_SEEN_END] === true ? { seenEndGame: true } : {}),
|
|
147
|
+
...(boot ? { boot } : {}),
|
|
135
148
|
};
|
|
136
149
|
}
|
|
150
|
+
/** The boot clock, read loosely: a field that is not what it should be leaves it unknown, never refuses the list. */
|
|
151
|
+
function bootClockOf(f) {
|
|
152
|
+
const boot = f[GI_BOOT.boot];
|
|
153
|
+
const realTime = f[GI_BOOT.realTime];
|
|
154
|
+
const banked = f[GI_BOOT.banked];
|
|
155
|
+
const turnFor = f[GI_BOOT.turnFor];
|
|
156
|
+
const num = (v) => typeof v === 'number' && Number.isFinite(v);
|
|
157
|
+
if (!num(boot) || !num(banked) || !num(turnFor) || typeof realTime !== 'boolean')
|
|
158
|
+
return undefined;
|
|
159
|
+
return { bootMs: boot, bankedMs: banked, turnForMs: turnFor, realTime };
|
|
160
|
+
}
|
|
161
|
+
/** Under this many minutes left before a boot, a game is reported as close to one (and `warapp_session_status` warns). */
|
|
162
|
+
export const BOOT_WARN_MINUTES = 6 * 60;
|
|
163
|
+
export const BOOT_NOTE = "From the game list: the game's boot time plus your banked time, less how long your turn has run (the web client " +
|
|
164
|
+
'shows the first two together beside each game). Banked time is eaten once the boot time is spent. The fields are ' +
|
|
165
|
+
"read from war.app's client; the arithmetic is unverified live.";
|
|
166
|
+
/** A multi-day game's boot view, or undefined: real-time, no boot time, the clock unread, or not a game I play. */
|
|
167
|
+
export function bootView(clock, waitingOnYou) {
|
|
168
|
+
if (!clock || clock.realTime || !(clock.bootMs > 0) || clock.bootMs >= NEVER_MS)
|
|
169
|
+
return undefined;
|
|
170
|
+
const min = (ms) => Math.max(0, Math.floor(ms / 60_000));
|
|
171
|
+
const bootMinutes = min(clock.bootMs);
|
|
172
|
+
const bankedMinutes = clock.bankedMs >= NEVER_MS ? 0 : min(clock.bankedMs);
|
|
173
|
+
const allowanceMinutes = bootMinutes + bankedMinutes;
|
|
174
|
+
const leftMinutes = waitingOnYou ? Math.max(0, allowanceMinutes - min(clock.turnForMs)) : null;
|
|
175
|
+
return { bootMinutes, bankedMinutes, allowanceMinutes, leftMinutes, soon: leftMinutes !== null && leftMinutes < BOOT_WARN_MINUTES };
|
|
176
|
+
}
|
|
177
|
+
/** Minutes as `2d 3h`, `5h 20m` or `45m`. */
|
|
178
|
+
export function minutesText(m) {
|
|
179
|
+
const d = Math.floor(m / 1440);
|
|
180
|
+
const h = Math.floor((m % 1440) / 60);
|
|
181
|
+
const mm = m % 60;
|
|
182
|
+
return d ? `${d}d${h ? ` ${h}h` : ''}` : h ? `${h}h${mm ? ` ${mm}m` : ''}` : `${mm}m`;
|
|
183
|
+
}
|
|
137
184
|
/** Read a GetMyGames result (the body positioned at the result-present flag). */
|
|
138
185
|
export function readMyGames(bundle, body) {
|
|
139
186
|
if (!body.bool())
|
|
@@ -159,18 +206,21 @@ export function summarizeMyGames(games, myInGameId) {
|
|
|
159
206
|
const out = games.map((g) => {
|
|
160
207
|
const me = g.players.find((p) => p.id === myInGameId);
|
|
161
208
|
const active = g.stateCode === GAME_PLAYING || g.stateCode === GAME_DISTRIBUTING;
|
|
209
|
+
const waitingOnYou = active && me !== undefined && me.stateCode === PLAYER_PLAYING && !me.committed;
|
|
210
|
+
const boot = active && me?.stateCode === PLAYER_PLAYING ? bootView(g.boot, waitingOnYou) : undefined;
|
|
162
211
|
return {
|
|
163
212
|
id: g.id,
|
|
164
213
|
name: g.name,
|
|
165
214
|
state: gameStateName(g.stateCode),
|
|
166
215
|
turn: g.lastTurn < 0 ? null : g.lastTurn + 1,
|
|
167
|
-
waitingOnYou
|
|
216
|
+
waitingOnYou,
|
|
168
217
|
players: g.players.map((p) => ({
|
|
169
218
|
name: p.name,
|
|
170
219
|
state: playerStateName(p.stateCode),
|
|
171
220
|
committed: p.committed,
|
|
172
221
|
})),
|
|
173
222
|
unreadChat: unreadChatView(g.unreadChat),
|
|
223
|
+
...(boot ? { boot } : {}),
|
|
174
224
|
};
|
|
175
225
|
});
|
|
176
226
|
// Waiting on me first, then unread private chat, then the rest (war.app's order within each).
|
|
@@ -231,7 +281,8 @@ export function briefGameLine(game) {
|
|
|
231
281
|
const u = game.unreadChat;
|
|
232
282
|
const others = u ? ['public', 'team', 'group'].filter((c) => u[c]) : [];
|
|
233
283
|
const unread = (u?.private ? ' — unread private' : '') + (others.length ? ` — unread ${others.join(', ')}` : '');
|
|
234
|
-
const
|
|
284
|
+
const soon = game.boot?.soon && game.boot.leftMinutes !== null ? ` — boot in ${minutesText(game.boot.leftMinutes)}` : '';
|
|
285
|
+
const tail = ` — ${where} — ${game.waitingOnYou ? 'waiting on you' : 'waiting on others'}${soon}${unread}`;
|
|
235
286
|
const flat = game.name.replace(/\s+/g, ' ').trim() || '(untitled)';
|
|
236
287
|
const escaped = flat.startsWith('-- ') || flat.startsWith('\\') ? `\\${flat}` : flat;
|
|
237
288
|
const room = BRIEF_MAX - tail.length;
|
package/dist/normalize.js
CHANGED
|
@@ -210,6 +210,13 @@ export function normalizeSettings(raw) {
|
|
|
210
210
|
if (r.Mods !== undefined && r.Mods !== null) {
|
|
211
211
|
const empty = r.Mods === '' || (isRec(r.Mods) && Object.keys(r.Mods).length === 0);
|
|
212
212
|
s.mods = Array.isArray(r.Mods) ? r.Mods.length : empty ? 0 : -1;
|
|
213
|
+
if (Array.isArray(r.Mods)) {
|
|
214
|
+
const ids = r.Mods.map((m) => (isRec(m) ? asInt(m.ModID) : undefined));
|
|
215
|
+
if (ids.every((id) => id !== undefined))
|
|
216
|
+
s.modIds = [...new Set(ids)].sort((a, b) => a - b);
|
|
217
|
+
}
|
|
218
|
+
else if (empty)
|
|
219
|
+
s.modIds = [];
|
|
213
220
|
}
|
|
214
221
|
if (r.OverriddenBonuses !== undefined && r.OverriddenBonuses !== null) {
|
|
215
222
|
const o = parseOverriddenBonuses(r.OverriddenBonuses);
|
package/dist/outlook-log.js
CHANGED
|
@@ -90,6 +90,19 @@ export async function recordOutlook(dir, gameId, playerId, outlook) {
|
|
|
90
90
|
estimate: t.income.theirs.estimate,
|
|
91
91
|
lean: t.income.lean,
|
|
92
92
|
calibrated: t.income.calibrated,
|
|
93
|
+
playerId: t.income.theirs.playerId,
|
|
94
|
+
...(t.income.theirs.team !== undefined ? { team: t.income.theirs.team } : {}),
|
|
95
|
+
},
|
|
96
|
+
}
|
|
97
|
+
: {}),
|
|
98
|
+
...(t.surrenderSide
|
|
99
|
+
? {
|
|
100
|
+
surrender: {
|
|
101
|
+
playerId: t.surrenderSide.playerId,
|
|
102
|
+
...(t.surrenderSide.team !== undefined ? { team: t.surrenderSide.team } : {}),
|
|
103
|
+
low: t.surrenderSide.low,
|
|
104
|
+
estimate: t.surrenderSide.estimate,
|
|
105
|
+
calibrated: t.surrenderSide.calibrated,
|
|
93
106
|
},
|
|
94
107
|
}
|
|
95
108
|
: {}),
|
|
@@ -23,7 +23,7 @@ import { createHmac, randomBytes, randomUUID } from 'node:crypto';
|
|
|
23
23
|
import { link, mkdir, readFile, rename, unlink, writeFile } from 'node:fs/promises';
|
|
24
24
|
import { join } from 'node:path';
|
|
25
25
|
import { readEnvVar } from '@chrischall/mcp-utils';
|
|
26
|
-
import { addCounts, COUNT_KEYS, MAX_RECORD_PLAYERS, talliesOf, upsertEntry, ZERO_COUNTS, } from './analysis/player-record.js';
|
|
26
|
+
import { addCounts, CORE_COUNT_KEYS, COUNT_KEYS, MAX_RECORD_PLAYERS, talliesOf, upsertEntry, ZERO_COUNTS, } from './analysis/player-record.js';
|
|
27
27
|
import { withPathLock } from './path-lock.js';
|
|
28
28
|
import { relationsDir } from './relations-store.js';
|
|
29
29
|
const isRec = (v) => typeof v === 'object' && v !== null && !Array.isArray(v);
|
|
@@ -97,11 +97,13 @@ export const legacyEntryKey = (salt, gameId, agreementId) => hmac(salt, `agreeme
|
|
|
97
97
|
const count = (v) => typeof v === 'number' && Number.isInteger(v) && v >= 0;
|
|
98
98
|
const intOrNull = (v) => v === null || (typeof v === 'number' && Number.isInteger(v));
|
|
99
99
|
function talliesFrom(v) {
|
|
100
|
-
|
|
100
|
+
// The exception tallies came later: absent reads as 0, present must be a count.
|
|
101
|
+
if (!isRec(v) || !CORE_COUNT_KEYS.every((k) => count(v[k])) || !COUNT_KEYS.every((k) => v[k] === undefined || count(v[k])))
|
|
101
102
|
return undefined;
|
|
102
103
|
const out = { ...ZERO_COUNTS };
|
|
103
104
|
for (const k of COUNT_KEYS)
|
|
104
|
-
|
|
105
|
+
if (v[k] !== undefined)
|
|
106
|
+
out[k] = v[k];
|
|
105
107
|
return out;
|
|
106
108
|
}
|
|
107
109
|
function entryOf(v) {
|
package/dist/protocol/methods.js
CHANGED
|
@@ -31,6 +31,12 @@ export const Method = {
|
|
|
31
31
|
GetTerritoryPicks: 81,
|
|
32
32
|
UnCommit: 82,
|
|
33
33
|
GetTurns: 83,
|
|
34
|
+
/**
|
|
35
|
+
* #523: the end-of-game window's data, which the client asks for when it shows that window (`EndGameWindowVM`) and
|
|
36
|
+
* which sets my seat's SeenEndGameWindow — the flag the app's My Games (the Default list) drops a finished game on.
|
|
37
|
+
* Parameters as UnCommit's (auth, int32 game id), read from the bundle's writer; UNVERIFIED live.
|
|
38
|
+
*/
|
|
39
|
+
GetEndGameWindowData: 85,
|
|
34
40
|
Subscribe: 242,
|
|
35
41
|
GameUpdated: 245,
|
|
36
42
|
GetInAppNotifications: 323,
|
|
@@ -154,6 +160,10 @@ export function writeBeginFirstTurnParams(w, gameId) {
|
|
|
154
160
|
export function writeUnCommitParams(w, gameId) {
|
|
155
161
|
w.int32(gameId);
|
|
156
162
|
}
|
|
163
|
+
/** GetEndGameWindowData(auth, gameId) — the parameters after the auth block (#523; the bundle's writer, UNVERIFIED live). */
|
|
164
|
+
export function writeGetEndGameWindowDataParams(w, gameId) {
|
|
165
|
+
w.int32(gameId);
|
|
166
|
+
}
|
|
157
167
|
/** The page size the client always asks GetInAppNotifications for. */
|
|
158
168
|
export const NOTIFICATIONS_PAGE_SIZE = 30;
|
|
159
169
|
/**
|
|
@@ -457,9 +467,11 @@ export const TARGETED_CARD_PLAYS = new Set([
|
|
|
457
467
|
* and the result carries `cardPlayCheck`. Airlift left it once verified live 2026-11-16 (#296), Diplomacy
|
|
458
468
|
* once verified live 2026-11-18 (#369: played through warapp_submit_turn, read in force on later boards),
|
|
459
469
|
* Reconnaissance once war.app accepted it live 2026-11-20 (#443: a turn with the play committed, no error;
|
|
460
|
-
* withdrawn before it resolved, so the reveal itself is not yet seen)
|
|
470
|
+
* withdrawn before it resolved, so the reveal itself is not yet seen), and Gift once verified live 2026-11-23
|
|
471
|
+
* (#435: played through warapp_submit_turn to a teammate; after the turn resolved the territory was the
|
|
472
|
+
* teammate's and the card had left the team hand).
|
|
461
473
|
*/
|
|
462
|
-
const VERIFIED_CARD_PLAYS = new Set(['Airlift', 'Diplomacy', 'Reconnaissance']);
|
|
474
|
+
const VERIFIED_CARD_PLAYS = new Set(['Airlift', 'Diplomacy', 'Reconnaissance', 'Gift']);
|
|
463
475
|
export const UNVERIFIED_CARD_PLAYS = new Set([...TARGETED_CARD_PLAYS].filter((kind) => !VERIFIED_CARD_PLAYS.has(kind)));
|
|
464
476
|
function need(v, card, what) {
|
|
465
477
|
if (v === undefined)
|
package/dist/relations-store.js
CHANGED
|
@@ -6,6 +6,10 @@
|
|
|
6
6
|
// record (src/player-record-store.ts); nothing is sent to war.app. Reads are loose: an unusable
|
|
7
7
|
// file or entry is dropped, never thrown on.
|
|
8
8
|
//
|
|
9
|
+
// An agreement's `exceptions` (partner-approved attacks that are no break: territory ids, turns, a
|
|
10
|
+
// direction) may carry a short `note` — the owner's own words, never a chat message, with every player
|
|
11
|
+
// name scrubbed to `Player <id>` before it is written (`scrubNames`). Files written before it have none.
|
|
12
|
+
//
|
|
9
13
|
// `commitments` (part B4): what my chat messages promised (warapp_send_chat's declared commitments,
|
|
10
14
|
// never the text), recorded once a message is sent; warapp_submit_turn warns when orders break one.
|
|
11
15
|
//
|
|
@@ -18,7 +22,7 @@ import { randomUUID } from 'node:crypto';
|
|
|
18
22
|
import { mkdir, readFile, rename, writeFile } from 'node:fs/promises';
|
|
19
23
|
import { join } from 'node:path';
|
|
20
24
|
import { withPathLock } from './path-lock.js';
|
|
21
|
-
import { AGREEMENT_STATUSES, MAX_NOTICE_TURNS, } from './analysis/relations.js';
|
|
25
|
+
import { AGREEMENT_STATUSES, EXCEPTION_DIRECTIONS, MAX_EXCEPTION_NOTE, MAX_EXCEPTIONS, MAX_NOTICE_TURNS, } from './analysis/relations.js';
|
|
22
26
|
import { COMMITMENT_KINDS } from './analysis/commitments.js';
|
|
23
27
|
import { AVOID_REASONS, intelIsEmpty } from './analysis/intel.js';
|
|
24
28
|
const isRec = (v) => typeof v === 'object' && v !== null && !Array.isArray(v);
|
|
@@ -86,8 +90,32 @@ export function agreementOf(v) {
|
|
|
86
90
|
a.enforced = v.enforced;
|
|
87
91
|
if (typeof v.retaliated === 'boolean')
|
|
88
92
|
a.retaliated = v.retaliated;
|
|
93
|
+
const exceptions = Array.isArray(v.exceptions) ? v.exceptions.map(exceptionOf).filter((e) => e !== undefined).slice(-MAX_EXCEPTIONS) : [];
|
|
94
|
+
if (exceptions.length)
|
|
95
|
+
a.exceptions = exceptions;
|
|
89
96
|
return a;
|
|
90
97
|
}
|
|
98
|
+
/** A partner-approved exception read back, or `undefined` when it is unusable (files before it have none). */
|
|
99
|
+
function exceptionOf(v) {
|
|
100
|
+
if (!isRec(v) || typeof v.id !== 'string' || !/^e\d{1,9}$/.test(v.id))
|
|
101
|
+
return undefined;
|
|
102
|
+
if (typeof v.direction !== 'string' || !EXCEPTION_DIRECTIONS.includes(v.direction))
|
|
103
|
+
return undefined;
|
|
104
|
+
const territories = ints(v.territories);
|
|
105
|
+
if (!territories?.length || !isInt(v.fromTurn) || !isInt(v.toTurn) || v.fromTurn > v.toTurn || !isInt(v.recordedTurn))
|
|
106
|
+
return undefined;
|
|
107
|
+
const e = {
|
|
108
|
+
id: v.id,
|
|
109
|
+
direction: v.direction,
|
|
110
|
+
territories,
|
|
111
|
+
fromTurn: v.fromTurn,
|
|
112
|
+
toTurn: v.toTurn,
|
|
113
|
+
recordedTurn: v.recordedTurn,
|
|
114
|
+
};
|
|
115
|
+
if (typeof v.note === 'string' && v.note.length)
|
|
116
|
+
e.note = v.note.slice(0, MAX_EXCEPTION_NOTE);
|
|
117
|
+
return e;
|
|
118
|
+
}
|
|
91
119
|
const COMMITMENT_ID = /^c(\d{1,9})$/;
|
|
92
120
|
/** A commitment read back, or `undefined` when it is unusable. */
|
|
93
121
|
export function commitmentOf(v) {
|
|
@@ -2,8 +2,9 @@
|
|
|
2
2
|
// players), the team's hand, Order Delay's place, my Bomb and Emergency Blockade, the
|
|
3
3
|
// opponents' Bomb and Emergency Blockade when they can hold one, the cards in effect
|
|
4
4
|
// (Diplomacy, Sanctions), and (PLAN-TEAMS D2) where to play my Diplomacy, Sanctions, Airlift and
|
|
5
|
-
// Gift. Read-only; everything here is advice — of these only the advised Order Delay
|
|
6
|
-
//
|
|
5
|
+
// Gift. Read-only; everything here is advice — of these only the advised Order Delay, a completing Gift
|
|
6
|
+
// (#435, verified live) and a spy card whose play is verified live (#434) are added to the orders; my Bomb
|
|
7
|
+
// and Emergency Blockade and the other D2 cards carry an `order` to pass to warapp_submit_turn.
|
|
7
8
|
import { adviseOrderDelay, CARD_BLOCKADE, CARD_ORDER_DELAY, CARD_REINFORCEMENT, isMyCard, readActiveCards, readTurnReinforcementPlays } from '../cards.js';
|
|
8
9
|
import { blockadeOffer, bombAdvice, bombExposure, wallOffer, wallThreats } from '../analysis/card-threats.js';
|
|
9
10
|
import { bonusTerritories } from '../analysis/bonuses.js';
|
|
@@ -279,7 +280,7 @@ export function adviseCards(input) {
|
|
|
279
280
|
}
|
|
280
281
|
warnings.push('Active cards are read from the live board by an unverified decoder (#163): check them in the game.');
|
|
281
282
|
}
|
|
282
|
-
// PLAN-TEAMS D2: my Diplomacy, Sanctions, Airlift and Gift — advice only,
|
|
283
|
+
// PLAN-TEAMS D2: my Diplomacy, Sanctions, Airlift and Gift, each with its order — advice only, save a completing Gift (#435).
|
|
283
284
|
const atPeace = new Set((view.active ?? []).flatMap((a) => (a.card === 'Diplomacy' && a.players?.includes(me.id) ? a.players.filter((p) => p !== me.id) : [])));
|
|
284
285
|
// #424: the cards in force whose last turn this is (gone by the next): chained, not passed over.
|
|
285
286
|
const lastTurn = new Set((view.active ?? []).flatMap((a) => a.card === 'Diplomacy' && a.players?.includes(me.id) && turn !== null && a.untilTurn === turn + 1 ? a.players.filter((p) => p !== me.id) : []));
|
|
@@ -327,10 +328,22 @@ export function seenReinforcementPlays(settings, seen) {
|
|
|
327
328
|
const read = [...seen.keys()].sort((a, b) => a - b);
|
|
328
329
|
return { read, plays: read.flatMap((turn) => seen.get(turn).map((player) => ({ player, turn }))) };
|
|
329
330
|
}
|
|
331
|
+
/**
|
|
332
|
+
* A progressive Reinforcement card's formula from its settings: `Mode` 1 / `ProgressiveByNumberOfTerritories`
|
|
333
|
+
* (by territories) or 2 / `ProgressiveByTurnNumber` (by turn), with a usable `ProgressivePercentage`. The names
|
|
334
|
+
* are the mod API's `ReinforcementCardMode`; the numbers follow its order — both UNVERIFIED against GameFeed.
|
|
335
|
+
* `undefined` for a flat card (Mode 0 / Fixed, or none) or an unknown one.
|
|
336
|
+
*/
|
|
337
|
+
function progressiveCard(rec) {
|
|
338
|
+
const mode = rec.Mode === undefined ? undefined : String(rec.Mode).toLowerCase();
|
|
339
|
+
const by = mode === '1' || mode === 'progressivebynumberofterritories' ? 'territories' : mode === '2' || mode === 'progressivebyturnnumber' ? 'turns' : undefined;
|
|
340
|
+
const pct = Number(rec.ProgressivePercentage);
|
|
341
|
+
return by && Number.isFinite(pct) && pct > 0 ? { by, percentage: pct } : undefined;
|
|
342
|
+
}
|
|
330
343
|
/**
|
|
331
344
|
* #164: an opponent's Reinforcement card for the threat model: the first turn one can be in a hand,
|
|
332
|
-
* the armies it adds (a fixed card's `FixedArmies
|
|
333
|
-
*
|
|
345
|
+
* the armies it adds (a fixed card's `FixedArmies`; a progressive card's formula in `progressive`, each
|
|
346
|
+
* opponent valued by it, with the Reinforcement card in my hand as `armies`, 0 with none) and the capturing turns each further card takes. `undefined` when no Reinforcement card
|
|
334
347
|
* is in play, none ever comes, or what it adds is unknown.
|
|
335
348
|
*
|
|
336
349
|
* #427 (proposed, owner approval pending): the clock runs at the EXPECTED weighted rate — the card's
|
|
@@ -354,12 +367,19 @@ export function opponentReinforcement(settings, hand) {
|
|
|
354
367
|
if (firstTurns === null)
|
|
355
368
|
return undefined;
|
|
356
369
|
const raw = settings.raw.ReinforcementCard;
|
|
357
|
-
const
|
|
370
|
+
const rec = typeof raw === 'object' && raw !== null ? raw : {};
|
|
371
|
+
const fixed = Number(rec.FixedArmies);
|
|
358
372
|
const inHand = hand.find((c) => c.type === CARD_REINFORCEMENT && c.armies !== undefined && c.armies > 0)?.armies;
|
|
359
|
-
const
|
|
360
|
-
|
|
373
|
+
const progressive = progressiveCard(rec);
|
|
374
|
+
const armies = !progressive && Number.isFinite(fixed) && fixed > 0 ? Math.floor(fixed) : inHand;
|
|
375
|
+
if (!progressive && (armies === undefined || armies <= 0))
|
|
361
376
|
return undefined;
|
|
362
377
|
const second = turnsFor(2);
|
|
363
378
|
// Pieces arrive at the end of a turn, so the first card is playable the turn after its last piece.
|
|
364
|
-
return {
|
|
379
|
+
return {
|
|
380
|
+
firstTurn: firstTurns + 1,
|
|
381
|
+
armies: armies ?? 0,
|
|
382
|
+
turnsPerCard: second === null ? null : Math.max(1, second - firstTurns),
|
|
383
|
+
...(progressive ? { progressive } : {}),
|
|
384
|
+
};
|
|
365
385
|
}
|
|
@@ -28,7 +28,7 @@ export const CARDS_IN_EFFECT_UNVERIFIED = 'The cards in effect are read from the
|
|
|
28
28
|
*/
|
|
29
29
|
export function sanctionMyIncome(income, effect, opts) {
|
|
30
30
|
if (!effect.sanctionsOnMe.length)
|
|
31
|
-
return { income, applied: false, warnings: [] };
|
|
31
|
+
return { income, applied: false, unmodelled: false, warnings: [] };
|
|
32
32
|
const pcts = effect.sanctionsOnMe.map((s) => s.percentage);
|
|
33
33
|
const pctText = pcts.map((p) => `${Math.round(p * 100)}%`).join(' then ');
|
|
34
34
|
const until = Math.max(...effect.sanctionsOnMe.map((s) => s.untilTurn));
|
|
@@ -36,6 +36,7 @@ export function sanctionMyIncome(income, effect, opts) {
|
|
|
36
36
|
return {
|
|
37
37
|
income,
|
|
38
38
|
applied: false,
|
|
39
|
+
unmodelled: true,
|
|
39
40
|
warnings: [
|
|
40
41
|
`Sanctions are on you (${pctText}, until turn ${until}): under Local Deployment the plan does not know which pools the cut comes from, so it plans on ${income} — deploy what the game shows.`,
|
|
41
42
|
],
|
|
@@ -44,6 +45,7 @@ export function sanctionMyIncome(income, effect, opts) {
|
|
|
44
45
|
return {
|
|
45
46
|
income: cut,
|
|
46
47
|
applied: true,
|
|
48
|
+
unmodelled: false,
|
|
47
49
|
warnings: [`Sanctions are on you (${pctText}, until turn ${until}): the plan's income is ${cut}, not ${income} (the client's rule, rounded to the nearest).`],
|
|
48
50
|
};
|
|
49
51
|
}
|
|
@@ -169,7 +169,7 @@ export function supportAdvice(input) {
|
|
|
169
169
|
if (gifts.length) {
|
|
170
170
|
const g = giftAdvice(cb, input.plan.team?.sharedBonuses ?? [], gifts.length);
|
|
171
171
|
if (g) {
|
|
172
|
-
// #435: a completing gift goes into the orders
|
|
172
|
+
// #435: a completing gift goes into the orders, its play verified live 2026-11-23 (as #434's spy cards).
|
|
173
173
|
const live = !(input.unverifiedPlays ?? UNVERIFIED_CARD_PLAYS).has('Gift');
|
|
174
174
|
view.gift = {
|
|
175
175
|
player: g.player,
|
|
@@ -175,7 +175,7 @@ export function planChatView(read, game, actx, view) {
|
|
|
175
175
|
const shownRows = rows.slice(-MAX_PLAN_CHAT_MESSAGES);
|
|
176
176
|
const messages = shownRows.map(({ i, r }) => {
|
|
177
177
|
const l = read.lines[i];
|
|
178
|
-
const s = shown(l, true, game.players, byInGame, read.me);
|
|
178
|
+
const s = shown(l, true, game.players, byInGame, read.me, game.map);
|
|
179
179
|
return {
|
|
180
180
|
from: s.from,
|
|
181
181
|
fromId: s.fromId,
|
package/dist/tools/chat-inbox.js
CHANGED
|
@@ -9,6 +9,8 @@ import { gameIdArg, readAnnotations, respond, untrustedDescription, untrustedTex
|
|
|
9
9
|
import { mintMeta } from './hints.js';
|
|
10
10
|
import { BRIDGE_NOTE } from './live.js';
|
|
11
11
|
import { fetchMyGames } from './my-games.js';
|
|
12
|
+
import { mentionsOf } from '../analysis/chat-mentions.js';
|
|
13
|
+
import { readBoardHistory } from '../trend.js';
|
|
12
14
|
/**
|
|
13
15
|
* #322: a finished game whose chat flags read clear is still read when it is among this many newest finished games
|
|
14
16
|
* (by id) in the list. A message GameFeed alone holds (a surrender "gg" sent as the game ended) leaves war.app's unread
|
|
@@ -33,7 +35,8 @@ export function recentClearFinished(games) {
|
|
|
33
35
|
export const INBOX_TIME_BUDGET_MS = 40_000;
|
|
34
36
|
/** The clock the budget is read on; tests replace `now`. */
|
|
35
37
|
export const inboxClock = { now: () => performance.now() };
|
|
36
|
-
const ONLY = ['all', 'private', 'toMe'];
|
|
38
|
+
const ONLY = ['all', 'private', 'toMe', 'mentionsMe'];
|
|
39
|
+
const PUBLIC_CHAT = ['messages', 'summary'];
|
|
37
40
|
/** Games read per call, at most (each costs a GameFeed read and a GameRefresh). */
|
|
38
41
|
export const MAX_INBOX_GAMES = 10;
|
|
39
42
|
/** The most game ids a call may name. */
|
|
@@ -46,6 +49,21 @@ const errorText = (e) => {
|
|
|
46
49
|
const s = e instanceof Error ? e.message : String(e);
|
|
47
50
|
return s.length > ERROR_MAX ? `${s.slice(0, ERROR_MAX - 1)}…` : s;
|
|
48
51
|
};
|
|
52
|
+
/**
|
|
53
|
+
* What `mentionsMe` matches in one game: my name there and the territories I hold — from GameFeed's standing when it
|
|
54
|
+
* has one, else the newest board this server cached for the game (no extra request); names from the cached map.
|
|
55
|
+
*/
|
|
56
|
+
async function mentionTargets(ctx, game, me) {
|
|
57
|
+
const mine = me ? playersByInGameId(game.players).get(me.inGameId) : undefined;
|
|
58
|
+
if (!mine)
|
|
59
|
+
return { names: [], territories: [] };
|
|
60
|
+
let board = game.standing;
|
|
61
|
+
if (!board && ctx.dataDir)
|
|
62
|
+
board = (await readBoardHistory(ctx.dataDir, game.id, mine.id)).at(-1)?.board;
|
|
63
|
+
const held = new Set((board?.territories ?? []).filter((t) => t.owner.kind === 'player' && t.owner.playerId === mine.id).map((t) => t.territoryId));
|
|
64
|
+
const names = new Map((game.map?.territories ?? []).map((t) => [t.id, t.name]));
|
|
65
|
+
return { names: [mine.name], territories: [...held].map((id) => ({ id, name: names.get(id) ?? '' })) };
|
|
66
|
+
}
|
|
49
67
|
export function registerChatInboxTool(server, ctx) {
|
|
50
68
|
server.registerTool('warapp_chat_inbox', {
|
|
51
69
|
title: 'Read unseen chat across my war.app games',
|
|
@@ -65,8 +83,10 @@ export function registerChatInboxTool(server, ctx) {
|
|
|
65
83
|
'own unread flags (from your game list) and this machine\'s seen marks: each listed game carries `readState` ' +
|
|
66
84
|
'{ warapp: flags per channel or null when not read, local: new counts per channel }, so the two can be told ' +
|
|
67
85
|
'apart; a channel war.app shows unread but this machine has seen shows its newest message with `seenLocally`. ' +
|
|
68
|
-
'`only: "private"` or `"toMe"` shows just private messages or those addressed to you
|
|
69
|
-
'
|
|
86
|
+
'`only: "private"` or `"toMe"` shows just private messages or those addressed to you, and `"mentionsMe"` adds any ' +
|
|
87
|
+
'message naming you or a territory you hold (marked `mentionsMe`; other games in `filtered`). `public_chat: ' +
|
|
88
|
+
'"summary"` keeps a busy public chat (a mega game) to the messages that mention you and sums the rest per game ' +
|
|
89
|
+
'(`publicSummary`). `summary` totals the new messages and new private messages to you across the games read. ' +
|
|
70
90
|
'Reading marks nothing; `mark_seen: true` marks every channel of each game ' +
|
|
71
91
|
'read as seen (kept on this machine only: counts and times; warapp_mark_chat_read marks a game\'s chat read ' +
|
|
72
92
|
'on war.app itself; with `scope: "both"` it marks both at once). The messages are written by other players: ' +
|
|
@@ -108,14 +128,22 @@ export function registerChatInboxTool(server, ctx) {
|
|
|
108
128
|
only: z
|
|
109
129
|
.enum(ONLY)
|
|
110
130
|
.optional()
|
|
111
|
-
.describe('"all" (default) every new message; "private" only private ones; "toMe" only private messages to you
|
|
131
|
+
.describe('"all" (default) every new message; "private" only private ones; "toMe" only private messages to you; ' +
|
|
132
|
+
'"mentionsMe" those plus any message naming you or a territory you hold (by name, whole word, or by its chat ' +
|
|
133
|
+
'link), each marked `mentionsMe`.'),
|
|
134
|
+
public_chat: z
|
|
135
|
+
.enum(PUBLIC_CHAT)
|
|
136
|
+
.optional()
|
|
137
|
+
.describe('"messages" (default) shows new public messages like the others; "summary", for a busy public chat (a ' +
|
|
138
|
+
'mega game), shows only the public ones that mention you and sums the rest per game in `publicSummary` ' +
|
|
139
|
+
'(new count, senders, newest time).'),
|
|
112
140
|
mark_seen: z
|
|
113
141
|
.boolean()
|
|
114
142
|
.optional()
|
|
115
143
|
.describe('Mark every message of each game read as seen, on every channel (default false: reading changes ' +
|
|
116
144
|
'nothing; kept on this machine only). Messages `limit` left out are marked too: `markedUnshown` counts them.'),
|
|
117
145
|
}),
|
|
118
|
-
}, async ({ game_ids, max_games, cursor, limit, all, only, mark_seen }) => {
|
|
146
|
+
}, async ({ game_ids, max_games, cursor, limit, all, only, public_chat, mark_seen }) => {
|
|
119
147
|
const started = inboxClock.now();
|
|
120
148
|
const given = game_ids ? [...new Set(game_ids.map((g) => parseGameId(g)))].sort((a, b) => a - b) : undefined;
|
|
121
149
|
const list = given ? undefined : await fetchMyGames(ctx);
|
|
@@ -160,7 +188,9 @@ export function registerChatInboxTool(server, ctx) {
|
|
|
160
188
|
const byInGame = playersByInGameId(game.players);
|
|
161
189
|
const freshAt = read.lines.map((_, i) => i).filter((i) => fresh[i]);
|
|
162
190
|
const fresh_ = freshAt.map((i) => read.lines[i]);
|
|
163
|
-
|
|
191
|
+
// #511: marked only once the game is listed — a game `only` filters out stays unread here, so a later
|
|
192
|
+
// call (or warapp_get_chat) still shows it.
|
|
193
|
+
const markSeen = () => (mark_seen ? markChatSeen(ctx, game.id, me, read, seen, channels) : Promise.resolve(undefined));
|
|
164
194
|
// war.app's own flags for the game (from the list; null when the list was not read or left it out).
|
|
165
195
|
const flags = list ? unreadChatOf(list.games, game.id) : undefined;
|
|
166
196
|
// A channel war.app shows unread while this machine has seen all of it: its newest message from another player.
|
|
@@ -182,29 +212,55 @@ export function registerChatInboxTool(server, ctx) {
|
|
|
182
212
|
if (fresh_.length)
|
|
183
213
|
gamesWithNew++;
|
|
184
214
|
if (!fresh_.length && !warappOnlyAt.length && !(flags && channels.some((c) => flags[CHANNEL_FLAG[c]]))) {
|
|
215
|
+
await markSeen();
|
|
185
216
|
quiet.push(id);
|
|
186
217
|
continue;
|
|
187
218
|
}
|
|
188
219
|
sources.add(read.source);
|
|
189
220
|
// #415: each new message another player sent, labelled and advised on (this machine's logs only).
|
|
190
221
|
const reading = chatReader(read.lines, game, me, await chatAdviceContext(ctx, game, me));
|
|
222
|
+
const toMeAt = (l) => l.channel === 'private' && me !== undefined && l.to === me.inGameId;
|
|
223
|
+
// Mentions of me (my name, a territory I hold), read only when asked for: no other read is costlier.
|
|
224
|
+
const wantMentions = only === 'mentionsMe' || public_chat === 'summary';
|
|
225
|
+
const targets = wantMentions ? await mentionTargets(ctx, game, me) : undefined;
|
|
226
|
+
const mentioned = (i) => {
|
|
227
|
+
const l = read.lines[i];
|
|
228
|
+
return targets !== undefined && !isMine(l) && mentionsOf(l.text, targets) !== undefined;
|
|
229
|
+
};
|
|
191
230
|
const keep = (i) => {
|
|
192
231
|
const l = read.lines[i];
|
|
232
|
+
if (public_chat === 'summary' && l.channel === 'public' && !mentioned(i))
|
|
233
|
+
return false;
|
|
193
234
|
if (only === 'private')
|
|
194
235
|
return l.channel === 'private';
|
|
195
236
|
if (only === 'toMe')
|
|
196
|
-
return l
|
|
237
|
+
return toMeAt(l);
|
|
238
|
+
if (only === 'mentionsMe')
|
|
239
|
+
return toMeAt(l) || mentioned(i);
|
|
197
240
|
return true;
|
|
198
241
|
};
|
|
199
|
-
const
|
|
200
|
-
|
|
242
|
+
const candidates = [...new Set([...freshAt.slice(-n), ...warappOnlyAt])].sort((a, b) => a - b);
|
|
243
|
+
const shownAt = candidates.filter(keep);
|
|
244
|
+
// The public summary: every new public message of others, whether shown (a mention) or summed.
|
|
245
|
+
const freshPublic = public_chat === 'summary' ? freshAt.filter((i) => read.lines[i].channel === 'public' && !isMine(read.lines[i])) : [];
|
|
246
|
+
const publicSummary = freshPublic.length
|
|
247
|
+
? {
|
|
248
|
+
newMessages: freshPublic.length,
|
|
249
|
+
mentionsShown: freshPublic.filter((i) => shownAt.includes(i)).length,
|
|
250
|
+
senders: new Set(freshPublic.map((i) => read.lines[i].sender ?? read.lines[i].senderName ?? null)).size,
|
|
251
|
+
newestTime: read.lines[freshPublic.at(-1)].time ?? null,
|
|
252
|
+
}
|
|
253
|
+
: undefined;
|
|
254
|
+
if (((only && only !== 'all') || public_chat === 'summary') && !shownAt.length && !publicSummary) {
|
|
201
255
|
filtered.push(id);
|
|
202
256
|
continue;
|
|
203
257
|
}
|
|
258
|
+
const marked = await markSeen();
|
|
204
259
|
const messages = shownAt.map((i) => ({
|
|
205
|
-
...shown(read.lines[i], fresh[i], game.players, byInGame, me),
|
|
260
|
+
...shown(read.lines[i], fresh[i], game.players, byInGame, me, game.map),
|
|
206
261
|
...readingFields(reading(i, fresh[i])),
|
|
207
262
|
...(fresh[i] ? {} : { seenLocally: true }),
|
|
263
|
+
...(wantMentions && mentioned(i) ? { mentionsMe: true } : {}),
|
|
208
264
|
}));
|
|
209
265
|
if (messages.some((m) => 'intent' in m))
|
|
210
266
|
advised = true;
|
|
@@ -226,6 +282,7 @@ export function registerChatInboxTool(server, ctx) {
|
|
|
226
282
|
local: unread,
|
|
227
283
|
},
|
|
228
284
|
messages,
|
|
285
|
+
...(publicSummary ? { publicSummary } : {}),
|
|
229
286
|
...(mark_seen ? { markedSeen: marked ?? [] } : {}),
|
|
230
287
|
...(marked && fresh_.length > messages.filter((m) => m.new).length
|
|
231
288
|
? { markedUnshown: fresh_.length - messages.filter((m) => m.new).length }
|