@chrischall/warapp-mcp 0.6.0 → 0.8.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 +2 -2
- package/.claude-plugin/plugin.json +1 -1
- package/README.md +100 -7
- package/dist/analysis/accept-surrender.js +20 -2
- package/dist/analysis/calibrate.js +1 -0
- package/dist/analysis/card-support.js +187 -20
- package/dist/analysis/card-threats.js +68 -3
- package/dist/analysis/chat-advice.js +182 -0
- package/dist/analysis/chat-blocks.js +106 -0
- package/dist/analysis/chat-intent.js +559 -0
- package/dist/analysis/chat-read.js +159 -0
- package/dist/analysis/coalition.js +55 -0
- package/dist/analysis/decision-replay.js +279 -0
- package/dist/analysis/decision-truth.js +146 -0
- package/dist/analysis/finished-game.js +62 -3
- package/dist/analysis/game-lessons.js +12 -6
- package/dist/analysis/local-deploy.js +14 -0
- package/dist/analysis/opponent-profile.js +46 -3
- package/dist/analysis/opponents.js +246 -19
- package/dist/analysis/outlook.js +323 -17
- package/dist/analysis/picks.js +270 -37
- package/dist/analysis/plan/after-leftover.js +28 -3
- package/dist/analysis/plan/captures.js +80 -16
- package/dist/analysis/plan/completed.js +8 -1
- package/dist/analysis/plan/conceded-out.js +16 -11
- package/dist/analysis/plan/deploy-estimates.js +513 -0
- package/dist/analysis/plan/doomed-out.js +135 -0
- package/dist/analysis/plan/estimates.js +73 -7
- package/dist/analysis/plan/free-capture.js +34 -0
- package/dist/analysis/plan/guard-off.js +2 -1
- package/dist/analysis/plan/holds.js +85 -313
- package/dist/analysis/plan/horizon.js +42 -0
- package/dist/analysis/plan/leftover.js +188 -10
- package/dist/analysis/plan/observe.js +896 -0
- package/dist/analysis/plan/orders.js +35 -1
- package/dist/analysis/plan/relations.js +115 -2
- package/dist/analysis/plan/report.js +10 -4
- package/dist/analysis/plan/shared.js +7 -1189
- package/dist/analysis/plan/stand-still.js +7 -5
- package/dist/analysis/plan/state.js +12 -0
- package/dist/analysis/plan/stockpile.js +104 -0
- package/dist/analysis/plan/strike-stack.js +467 -0
- package/dist/analysis/plan/strike.js +8 -441
- package/dist/analysis/plan/targets.js +374 -72
- package/dist/analysis/plan/threats.js +120 -9
- package/dist/analysis/plan/transfers.js +35 -1
- package/dist/analysis/plan/two-move.js +70 -0
- package/dist/analysis/plan/vacated.js +124 -2
- package/dist/analysis/plan/withdraw.js +316 -0
- package/dist/analysis/planner.js +356 -53
- package/dist/analysis/player.js +4 -0
- package/dist/analysis/relations.js +8 -2
- package/dist/analysis/since-last.js +18 -5
- package/dist/analysis/stress.js +1 -1
- package/dist/board.js +36 -2
- package/dist/build-id.js +106 -0
- package/dist/bundle.js +15863 -10242
- package/dist/chat-automation.js +22 -0
- package/dist/client.js +14 -0
- package/dist/decision-log.js +1093 -0
- package/dist/finished-store.js +5 -1
- package/dist/lessons-store.js +322 -21
- package/dist/my-games.js +2 -0
- package/dist/open-games.js +122 -18
- package/dist/outlook-log.js +42 -1
- package/dist/protocol/methods.js +4 -2
- package/dist/review-export.js +198 -0
- package/dist/state-bundle.js +62 -3
- package/dist/state-cli.js +5 -3
- package/dist/strategy/notes.js +56 -0
- package/dist/tools/accept-surrender.js +23 -9
- package/dist/tools/award.js +5 -1
- package/dist/tools/card-advice.js +102 -33
- package/dist/tools/card-support-advice.js +53 -8
- package/dist/tools/chat-advice.js +330 -0
- package/dist/tools/chat-inbox.js +15 -4
- package/dist/tools/chat.js +41 -11
- package/dist/tools/check-plan.js +16 -3
- package/dist/tools/commander-check.js +2 -1
- package/dist/tools/decision-capture.js +461 -0
- package/dist/tools/end-of-game.js +146 -18
- package/dist/tools/game-kind.js +92 -0
- package/dist/tools/how-lost.js +7 -2
- package/dist/tools/index.js +3 -0
- package/dist/tools/join-game.js +51 -9
- package/dist/tools/live-context.js +6 -0
- package/dist/tools/live.js +43 -6
- package/dist/tools/map-curves.js +73 -0
- package/dist/tools/notifications.js +4 -3
- package/dist/tools/open-games.js +2 -2
- package/dist/tools/opponents.js +2 -0
- package/dist/tools/past-games.js +74 -8
- package/dist/tools/picks.js +169 -57
- package/dist/tools/profile-hook.js +62 -3
- package/dist/tools/profile-opponents.js +2 -0
- package/dist/tools/push.js +2 -2
- package/dist/tools/relations.js +2 -0
- package/dist/tools/scout.js +16 -2
- package/dist/tools/state.js +6 -1
- package/dist/tools/strategy.js +3 -3
- package/dist/tools/stress-opponents.js +2 -0
- package/dist/tools/surrender-pending.js +10 -1
- package/dist/tools/surrender.js +18 -3
- package/dist/tools/turn.js +353 -19
- package/dist/tools/where.js +3 -1
- package/dist/version.js +1 -1
- package/manifest.json +23 -2
- package/mint.yaml +23 -0
- package/package.json +1 -1
- package/server.json +20 -2
- package/skills/warapp-mcp/SKILL.md +42 -8
|
@@ -20,6 +20,8 @@ export function outcomeOf(players, me) {
|
|
|
20
20
|
return players.some((p) => p.id !== me && p.state === 'Won') ? 'lost' : 'unknown';
|
|
21
21
|
}
|
|
22
22
|
const ownerOf = (t) => t?.owner.kind === 'player' ? t.owner.playerId : undefined;
|
|
23
|
+
/** A fog level that hides a territory's armies (fogged or owner-only, by word or number). */
|
|
24
|
+
const hidesArmies = (level) => level !== undefined && (/fog|owneronly/i.test(level) || level === '3' || level === '4');
|
|
23
25
|
/**
|
|
24
26
|
* Each of `players` on `board`: its income by THE income rule (`boardIncome`, src/analysis/player.ts:
|
|
25
27
|
* base or per-territory income, plus every full bonus; the map's values with the game's overrides
|
|
@@ -29,12 +31,21 @@ const ownerOf = (t) => t?.owner.kind === 'player' ? t.owner.playerId : undefined
|
|
|
29
31
|
export function turnIncomes(g, board, players, settings) {
|
|
30
32
|
const held = new Map(players.map((p) => [p, new Set()]));
|
|
31
33
|
const armies = new Map(players.map((p) => [p, 0]));
|
|
34
|
+
const unread = new Map();
|
|
35
|
+
const commanders = new Map();
|
|
32
36
|
for (const t of board.territories) {
|
|
33
37
|
const o = ownerOf(t);
|
|
34
38
|
if (o === undefined || !held.has(o) || !g.territoryById.has(t.territoryId))
|
|
35
39
|
continue;
|
|
36
40
|
held.get(o).add(t.territoryId);
|
|
41
|
+
const own = t.specialUnits?.filter((u) => u.kind === 'commander' && u.playerId === o).length ?? 0;
|
|
42
|
+
if (own)
|
|
43
|
+
commanders.set(o, (commanders.get(o) ?? 0) + own);
|
|
37
44
|
const a = armies.get(o);
|
|
45
|
+
if (t.armies === null && !hidesArmies(t.fogLevel)) {
|
|
46
|
+
unread.set(o, (unread.get(o) ?? 0) + 1);
|
|
47
|
+
continue;
|
|
48
|
+
}
|
|
38
49
|
armies.set(o, a === null || t.armies === null ? null : a + t.armies);
|
|
39
50
|
}
|
|
40
51
|
const rules = incomeRules(settings);
|
|
@@ -46,11 +57,15 @@ export function turnIncomes(g, board, players, settings) {
|
|
|
46
57
|
continue;
|
|
47
58
|
}
|
|
48
59
|
const inc = boardIncome(g, land, rules);
|
|
60
|
+
const u = unread.get(p);
|
|
61
|
+
const c = commanders.get(p);
|
|
49
62
|
out.set(p, {
|
|
50
63
|
income: inc.total,
|
|
51
64
|
territories: land.size,
|
|
52
65
|
armies: armies.get(p),
|
|
53
66
|
bonuses: inc.bonuses.map((b) => b.bonusId).sort((a, b) => a - b),
|
|
67
|
+
...(u ? { armiesUnread: u } : {}),
|
|
68
|
+
...(c ? { commanders: c } : {}),
|
|
54
69
|
});
|
|
55
70
|
}
|
|
56
71
|
return out;
|
|
@@ -118,19 +133,63 @@ export function failedAttacks(boards, orders, me) {
|
|
|
118
133
|
}
|
|
119
134
|
return out;
|
|
120
135
|
}
|
|
136
|
+
/** Outcomes in which my seat left the game, so my orders of that turn never ran (#437). */
|
|
137
|
+
const LEFT = new Set(['surrendered', 'booted']);
|
|
138
|
+
/**
|
|
139
|
+
* The turn being played when my seat left (#437): for a surrender or a boot, `leftTurn` (the decision log's
|
|
140
|
+
* events), else my out turn on the history; for an elimination, my out turn; `null` otherwise or unknown. Pure.
|
|
141
|
+
*/
|
|
142
|
+
export function leftTurnOf(result, outTurn, leftTurn) {
|
|
143
|
+
if (LEFT.has(result))
|
|
144
|
+
return leftTurn ?? outTurn;
|
|
145
|
+
return result === 'eliminated' ? outTurn : null;
|
|
146
|
+
}
|
|
121
147
|
/** The whole capture of a finished game from its history boards and my orders. Pure. */
|
|
122
148
|
export function captureFinished(input) {
|
|
123
149
|
const ids = input.players.map((p) => p.id).sort((a, b) => a - b);
|
|
124
150
|
const boards = ascending(input.boards);
|
|
151
|
+
const result = outcomeOf(input.players, input.me);
|
|
152
|
+
const outTurn = outTurnOf(boards, input.me);
|
|
153
|
+
const leftTurn = leftTurnOf(result, outTurn, input.leftTurn);
|
|
154
|
+
// #437: my orders of the turn my seat left (a surrender or a boot) never ran: no failed attack of theirs.
|
|
155
|
+
const ran = LEFT.has(result) && leftTurn !== null ? (f) => f.turn < leftTurn : () => true;
|
|
125
156
|
return {
|
|
126
157
|
outcome: {
|
|
127
|
-
result
|
|
158
|
+
result,
|
|
128
159
|
turn: input.numberOfTurns ?? null,
|
|
129
|
-
outTurn
|
|
160
|
+
outTurn,
|
|
161
|
+
leftTurn,
|
|
130
162
|
winners: input.players.filter((p) => p.state === 'Won').map((p) => p.id).sort((a, b) => a - b),
|
|
131
163
|
},
|
|
132
164
|
starts: startsOf(boards, ids),
|
|
133
165
|
turns: input.graph ? boards.map(({ turn, board }) => ({ afterTurn: turn, players: turnIncomes(input.graph, board, ids, input.settings) })) : [],
|
|
134
|
-
failedAttacks: failedAttacks(boards, input.orders, input.me),
|
|
166
|
+
failedAttacks: failedAttacks(boards, input.orders, input.me).filter(ran),
|
|
135
167
|
};
|
|
136
168
|
}
|
|
169
|
+
export const GAME_KINDS = ['lottery', 'no-show', 'legacy', 'team'];
|
|
170
|
+
/** The kinds kept out of the lessons, the map record and the profile folds. */
|
|
171
|
+
export const EXCLUDED_KINDS = ['lottery', 'no-show'];
|
|
172
|
+
/** The kinds of a finished game ({@link GameKind}), in {@link GAME_KINDS} order. Pure. */
|
|
173
|
+
export function gameKinds(k) {
|
|
174
|
+
const out = new Set();
|
|
175
|
+
const lottery = k.territories !== undefined ? k.territories <= k.lotteryMaxTerritories : k.joinLottery !== undefined || k.lotteryShape === true;
|
|
176
|
+
if (lottery)
|
|
177
|
+
out.add('lottery');
|
|
178
|
+
const legacy = !k.hasLog && !k.hasBoards;
|
|
179
|
+
// Never committed: only where this server kept the game (a legacy game's orders were never cached).
|
|
180
|
+
const neverCommitted = !legacy && k.committedTurns === 0 && k.result !== 'won';
|
|
181
|
+
// Booted before turn 2 was played: seen booted while turn 1 or 2 was being played (a boot at turn 1's
|
|
182
|
+
// deadline is first seen on turn 2), or the game ended with at most one turn completed.
|
|
183
|
+
const bootedEarly = k.result === 'booted' && ((k.leftTurn !== null && k.leftTurn <= 2) || (k.numberOfTurns !== null && k.numberOfTurns <= 1));
|
|
184
|
+
if (neverCommitted || bootedEarly)
|
|
185
|
+
out.add('no-show');
|
|
186
|
+
if (legacy)
|
|
187
|
+
out.add('legacy');
|
|
188
|
+
if (k.team)
|
|
189
|
+
out.add('team');
|
|
190
|
+
return GAME_KINDS.filter((x) => out.has(x));
|
|
191
|
+
}
|
|
192
|
+
/** The kind a game is kept apart for (lottery first), or `undefined` when it counts. Pure. */
|
|
193
|
+
export function excludedKind(kinds) {
|
|
194
|
+
return kinds.includes('lottery') ? 'lottery' : kinds.includes('no-show') ? 'no-show' : undefined;
|
|
195
|
+
}
|
|
@@ -87,19 +87,25 @@ export const MAX_CURVE_POINTS = 60;
|
|
|
87
87
|
/** The boards the pace is read on: the income after these completed turns. */
|
|
88
88
|
export const PACE_TURNS = [4, 8];
|
|
89
89
|
const incomeAfter = (curve, n) => curve.find((c) => c.afterTurn === n)?.income ?? null;
|
|
90
|
+
/** A curve as a map record keeps it: index = completed turns up to its last board, `null` where none read, at most {@link MAX_CURVE_POINTS}. Pure. */
|
|
91
|
+
export function curvePoints(curve) {
|
|
92
|
+
const last = Math.min(MAX_CURVE_POINTS, curve.length ? curve.at(-1).afterTurn + 1 : 0);
|
|
93
|
+
return Array.from({ length: last }, (_, i) => incomeAfter(curve, i));
|
|
94
|
+
}
|
|
90
95
|
/**
|
|
91
96
|
* My start region and income curve (index = completed turns, `null` where no board read, at most
|
|
92
|
-
* {@link MAX_CURVE_POINTS}), and each winner's start region
|
|
93
|
-
* to beat). Pure.
|
|
97
|
+
* {@link MAX_CURVE_POINTS}), and each winner's start region, income curve (#419, the same shape) and
|
|
98
|
+
* income after turns 4 and 8 (the pace to beat). Pure.
|
|
94
99
|
*/
|
|
95
100
|
export function mapFacts(g, me, winners, starts, turns) {
|
|
96
101
|
const mine = incomeCurve(turns, me);
|
|
97
|
-
const last = Math.min(MAX_CURVE_POINTS, mine.length ? mine.at(-1).afterTurn + 1 : 0);
|
|
98
|
-
const income = Array.from({ length: last }, (_, i) => incomeAfter(mine, i));
|
|
99
102
|
const pace = (curve) => ({ income4: incomeAfter(curve, PACE_TURNS[0]), income8: incomeAfter(curve, PACE_TURNS[1]) });
|
|
100
103
|
return {
|
|
101
|
-
me: { ...startRegion(g, starts.get(me) ?? []), income, ...pace(mine) },
|
|
102
|
-
winners: [...winners].sort((a, b) => a - b).map((w) =>
|
|
104
|
+
me: { ...startRegion(g, starts.get(me) ?? []), income: curvePoints(mine), ...pace(mine) },
|
|
105
|
+
winners: [...winners].sort((a, b) => a - b).map((w) => {
|
|
106
|
+
const curve = incomeCurve(turns, w);
|
|
107
|
+
return { ...startRegion(g, starts.get(w) ?? []), income: curvePoints(curve), ...pace(curve) };
|
|
108
|
+
}),
|
|
103
109
|
};
|
|
104
110
|
}
|
|
105
111
|
/**
|
|
@@ -127,6 +127,20 @@ export function chargeDeploys(pools, deploys) {
|
|
|
127
127
|
anywhereUsed += n;
|
|
128
128
|
return { anywhereUsed, used };
|
|
129
129
|
}
|
|
130
|
+
/**
|
|
131
|
+
* #433: what `needs` (armies by territory, e.g. the gates' shortfalls next turn) lack under Local Deployment, for a
|
|
132
|
+
* player holding `held` with `income`: a bonus's pool deploys only on its own territories, so each need is paid
|
|
133
|
+
* from the pools of the bonuses it is in ({@link chargeDeploys}, as well as they can be split) and the rest from the
|
|
134
|
+
* free income. `deployable` is the part of the income that can land on any of them: the free armies plus every pool
|
|
135
|
+
* holding a need. Without a held bonus it is the plain shortfall, Σ needs − income (at least 0).
|
|
136
|
+
*/
|
|
137
|
+
export function poolShortfall(g, held, income, needs) {
|
|
138
|
+
const pools = deployPools(g, held, income);
|
|
139
|
+
const wanted = new Map([...needs].filter(([, n]) => n > 0));
|
|
140
|
+
const { anywhereUsed } = chargeDeploys(pools, wanted);
|
|
141
|
+
const deployable = pools.anywhere + pools.bonuses.reduce((n, p) => n + (p.territoryIds.some((t) => wanted.has(t)) ? p.value : 0), 0);
|
|
142
|
+
return { short: Math.max(0, anywhereUsed - pools.anywhere), deployable };
|
|
143
|
+
}
|
|
130
144
|
/**
|
|
131
145
|
* What an opponent may deploy anywhere under Local Deployment (#293): its free income — its base
|
|
132
146
|
* income (never below `floor`) plus the Reinforcement card armies its estimate counts. Bonus armies
|
|
@@ -70,7 +70,8 @@ function leastFailing(armies, from, off, def) {
|
|
|
70
70
|
* My orders as cached (`MyOrders`): `moves` holds only plain orders; a percentage, Attack Only or
|
|
71
71
|
* Transfer Only order is in `sent` alone, and card plays in `cards`. A territory such an order leaves
|
|
72
72
|
* or enters, or one of my Airlifts touches, is never tested for `attackedMe` and gives no `reinforce`
|
|
73
|
-
* reading (its armies are not known); `iAttacked` counts every non-transfer order of `sent
|
|
73
|
+
* reading (its armies are not known); `iAttacked` counts every non-transfer order of `sent` (#442: onto its
|
|
74
|
+
* territory on T, or onto one not mine on T that is its on T+1 — my attack ran into its fresh capture). When the
|
|
74
75
|
* orders do not record card plays (`cards` absent: a cache written before they were) and the game may
|
|
75
76
|
* have Airlift, nothing is tested from armies at all, and when it may have Gift — orders unknown
|
|
76
77
|
* included — captures cannot be told (`tookFromMe: null`; it may have been my gift), so a game with
|
|
@@ -155,8 +156,10 @@ export function observeTurn(input) {
|
|
|
155
156
|
const contact = ids.some((id) => ownsWas(id) && neighborsOf(graph, id).some(mineWas));
|
|
156
157
|
const tookFromMe = giftUnknown ? null : ids.filter((id) => mineWas(id) && ownsNow(id) && !gifted.has(id));
|
|
157
158
|
const lostToMe = ids.filter((id) => ownsWas(id) && mineNow(id));
|
|
158
|
-
|
|
159
|
-
|
|
159
|
+
// #442: or onto a territory not mine on T that is its on T+1 — its fresh capture my attack ran into.
|
|
160
|
+
const hit = (to) => ownsWas(to) || (!mineWas(to) && ownsNow(to));
|
|
161
|
+
const iAttacked = moves.some((m) => hit(m.to) && m.armies > 0 && !transferOnly.has(`${m.from}:${m.to}`)) ||
|
|
162
|
+
sent.some((m) => hit(m.to) && !m.transferOnly && sentCount(m) > plain(m));
|
|
160
163
|
// attackedMe
|
|
161
164
|
let attackedMe = tookFromMe?.length ? true : null;
|
|
162
165
|
// #361: the borders read whose drop is exactly what one attacking army kills (a single-army jab);
|
|
@@ -435,6 +438,46 @@ export function habitsOf(turns) {
|
|
|
435
438
|
}
|
|
436
439
|
return h;
|
|
437
440
|
}
|
|
441
|
+
// ---- #420: the one profile read the planner may make (P1 amended, owner decision of 2026-11-20) ----
|
|
442
|
+
/** #420: the contact turns (each one whose attack on me could be told) a quiet neighbour needs. */
|
|
443
|
+
export const QUIET_CONTACT_TURNS = 10;
|
|
444
|
+
/** #420: the most attacks on me per contact turn a quiet neighbour may show. */
|
|
445
|
+
export const QUIET_ATTACK_RATE = 0.1;
|
|
446
|
+
/**
|
|
447
|
+
* #420 (owner decision of 2026-11-20): the one case P1 lets the planner read a profile. Over this
|
|
448
|
+
* game's observed turns in order, a contact turn whose attack on me could be told counts; once there are
|
|
449
|
+
* {@link QUIET_CONTACT_TURNS} or more at an attack rate of {@link QUIET_ATTACK_RATE} or less it is quiet,
|
|
450
|
+
* until its first attack on me after that, which ends it for the game (full sizing at once). Pure.
|
|
451
|
+
*/
|
|
452
|
+
export function quietNeighbour(turns) {
|
|
453
|
+
const by = new Map();
|
|
454
|
+
for (const t of turns)
|
|
455
|
+
by.set(t.turn, t.primitives);
|
|
456
|
+
let n = 0;
|
|
457
|
+
let e = 0;
|
|
458
|
+
let since;
|
|
459
|
+
let attackedOn;
|
|
460
|
+
for (const t of [...by.keys()].sort(byNum)) {
|
|
461
|
+
const p = by.get(t);
|
|
462
|
+
if (!p.contact || p.attackedMe === null)
|
|
463
|
+
continue;
|
|
464
|
+
n++;
|
|
465
|
+
if (p.attackedMe) {
|
|
466
|
+
e++;
|
|
467
|
+
if (since !== undefined && attackedOn === undefined)
|
|
468
|
+
attackedOn = t;
|
|
469
|
+
}
|
|
470
|
+
if (since === undefined && n >= QUIET_CONTACT_TURNS && e <= QUIET_ATTACK_RATE * n)
|
|
471
|
+
since = t;
|
|
472
|
+
}
|
|
473
|
+
return {
|
|
474
|
+
contactTurns: n,
|
|
475
|
+
attacks: e,
|
|
476
|
+
quiet: since !== undefined && attackedOn === undefined,
|
|
477
|
+
...(since !== undefined ? { since } : {}),
|
|
478
|
+
...(attackedOn !== undefined ? { attackedOn } : {}),
|
|
479
|
+
};
|
|
480
|
+
}
|
|
438
481
|
// ---- the estimate (B1): this game pooled with past games, shrunk toward the population or a default ----
|
|
439
482
|
/** How many opportunities the prior weighs as (docs/PLAN-PROFILES.md B1). */
|
|
440
483
|
export const PROFILE_PRIOR_WEIGHT = 4;
|