@chrischall/warapp-mcp 0.5.0 → 0.7.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 +133 -8
- package/dist/analysis/accept-surrender.js +20 -2
- package/dist/analysis/calibrate.js +1 -0
- package/dist/analysis/card-support.js +177 -17
- package/dist/analysis/card-threats.js +126 -14
- 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/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 +15 -10
- package/dist/analysis/hold-diff.js +3 -1
- package/dist/analysis/income-trend.js +38 -0
- package/dist/analysis/intel.js +75 -0
- package/dist/analysis/opens.js +64 -0
- package/dist/analysis/opponent-profile.js +121 -10
- package/dist/analysis/opponents.js +246 -20
- package/dist/analysis/outlook.js +360 -15
- package/dist/analysis/picks.js +91 -12
- package/dist/analysis/plan/after-leftover.js +4 -1
- package/dist/analysis/plan/bonus-attempts.js +105 -0
- package/dist/analysis/plan/capture-instead.js +116 -0
- package/dist/analysis/plan/captures.js +49 -7
- package/dist/analysis/plan/conceded-out.js +13 -2
- package/dist/analysis/plan/estimates.js +203 -30
- package/dist/analysis/plan/guard-off.js +2 -1
- package/dist/analysis/plan/holds.js +110 -9
- package/dist/analysis/plan/jabs.js +113 -0
- package/dist/analysis/plan/leftover.js +393 -8
- package/dist/analysis/plan/orders.js +76 -4
- package/dist/analysis/plan/relations.js +135 -2
- package/dist/analysis/plan/report.js +69 -3
- package/dist/analysis/plan/second-sizing.js +133 -0
- package/dist/analysis/plan/shared.js +279 -27
- package/dist/analysis/plan/siege.js +303 -0
- package/dist/analysis/plan/stand-still.js +9 -5
- package/dist/analysis/plan/state.js +8 -0
- package/dist/analysis/plan/stockpile.js +104 -0
- package/dist/analysis/plan/strike.js +39 -7
- package/dist/analysis/plan/targets.js +256 -110
- package/dist/analysis/plan/threats.js +148 -10
- package/dist/analysis/plan/transfers.js +57 -6
- package/dist/analysis/plan/two-move.js +70 -0
- package/dist/analysis/plan/vacated.js +124 -2
- package/dist/analysis/planner.js +527 -49
- package/dist/analysis/profile.js +13 -2
- package/dist/analysis/since-last.js +18 -5
- package/dist/analysis/stress.js +8 -2
- package/dist/board.js +36 -2
- package/dist/bonus-attempt-store.js +55 -0
- package/dist/build-id.js +106 -0
- package/dist/bundle.js +54138 -41059
- package/dist/cards.js +7 -5
- package/dist/chat-automation.js +22 -0
- package/dist/chat.js +35 -1
- package/dist/client.js +14 -0
- package/dist/commerce.js +111 -0
- package/dist/decision-log.js +1093 -0
- package/dist/finished-store.js +5 -1
- package/dist/index.js +9 -1
- package/dist/lessons-store.js +322 -21
- package/dist/live.js +43 -0
- package/dist/move-order.js +64 -3
- package/dist/normalize.js +17 -0
- package/dist/open-games.js +36 -16
- package/dist/outlook-log.js +42 -1
- package/dist/profile-store.js +12 -2
- package/dist/protocol/methods.js +62 -5
- package/dist/protocol/rpc.js +8 -0
- package/dist/relations-store.js +38 -4
- package/dist/review-export.js +198 -0
- package/dist/siege-store.js +49 -0
- package/dist/state-bundle.js +584 -0
- package/dist/state-cli.js +71 -0
- package/dist/strategy/notes.js +56 -0
- package/dist/team-cards.js +25 -0
- package/dist/tools/accept-surrender.js +23 -9
- package/dist/tools/award.js +20 -2
- package/dist/tools/card-advice.js +93 -28
- package/dist/tools/card-plays.js +2 -2
- package/dist/tools/card-support-advice.js +37 -7
- package/dist/tools/chat-advice.js +330 -0
- package/dist/tools/chat-inbox.js +19 -4
- package/dist/tools/chat.js +106 -17
- package/dist/tools/check-plan.js +68 -12
- package/dist/tools/commerce-deploy.js +33 -0
- package/dist/tools/common.js +31 -0
- package/dist/tools/decision-capture.js +459 -0
- package/dist/tools/end-of-game.js +151 -21
- package/dist/tools/game-kind.js +92 -0
- package/dist/tools/how-lost.js +7 -2
- package/dist/tools/index.js +10 -0
- package/dist/tools/join-game.js +10 -4
- package/dist/tools/live-context.js +6 -0
- package/dist/tools/live.js +10 -1
- package/dist/tools/map-curves.js +73 -0
- package/dist/tools/notifications.js +4 -3
- package/dist/tools/opponents.js +2 -0
- package/dist/tools/past-games.js +74 -8
- package/dist/tools/picks.js +61 -10
- package/dist/tools/profile-hook.js +62 -3
- package/dist/tools/profile-opponents.js +4 -0
- package/dist/tools/push.js +2 -2
- package/dist/tools/relations.js +139 -0
- package/dist/tools/scout.js +16 -2
- package/dist/tools/state.js +232 -0
- package/dist/tools/strategy.js +3 -3
- package/dist/tools/stress-opponents.js +7 -2
- package/dist/tools/surrender-pending.js +10 -1
- package/dist/tools/surrender.js +18 -3
- package/dist/tools/survival.js +11 -3
- package/dist/tools/team-brief.js +2 -2
- package/dist/tools/team.js +12 -3
- package/dist/tools/turn.js +643 -76
- package/dist/tools/where.js +3 -1
- package/dist/version.js +1 -1
- package/manifest.json +32 -3
- package/mint.yaml +37 -4
- package/package.json +4 -4
- package/server.json +20 -2
- package/skills/warapp-mcp/SKILL.md +73 -17
package/dist/cards.js
CHANGED
|
@@ -77,9 +77,11 @@ function cardOf(o, key) {
|
|
|
77
77
|
*
|
|
78
78
|
* A team shares one hand and one card limit (the wiki's Team Games). Given several in-game
|
|
79
79
|
* ids (mine and my teammates'), the hand is every card under any of them, each GUID once.
|
|
80
|
-
*
|
|
81
|
-
*
|
|
82
|
-
*
|
|
80
|
+
* VERIFIED (V8, #310): the standing keeps each player's cards (`PlayerCards`) under that player's
|
|
81
|
+
* id, and the client's own team hand (GameValidateOrders) is every teammate's entry merged, whole
|
|
82
|
+
* cards by GUID; a live 2v2 board showed two cards under me and three under my teammate, none
|
|
83
|
+
* repeated. Each card of a team hand carries the id it was read under (`owner`): the first id
|
|
84
|
+
* given (mine) when it is under that one at all. The team's limit is `teamCardLimit` (src/team-cards.ts).
|
|
83
85
|
*/
|
|
84
86
|
export function readHand(info, myInGameId) {
|
|
85
87
|
const ids = typeof myInGameId === 'number' ? [myInGameId] : [...myInGameId];
|
|
@@ -228,7 +230,7 @@ const KEEP_VALUE = {
|
|
|
228
230
|
};
|
|
229
231
|
const INFORMATION_CARDS = new Set([2, 10, 11]);
|
|
230
232
|
const ONE_V_ONE_CHEAP = new Set([7, 8]); // Gift, Diplomacy
|
|
231
|
-
/** Whether a card is mine to play: not read under a teammate's id (V8
|
|
233
|
+
/** Whether a card is mine to play: not read under a teammate's id (V8, #310: the planner leaves theirs to them). */
|
|
232
234
|
export const isMyCard = (c, me) => me === undefined || c.owner === undefined || c.owner === me;
|
|
233
235
|
/**
|
|
234
236
|
* A card's keep value in this game: the information cards (Spy, Reconnaissance, Surveillance)
|
|
@@ -300,7 +302,7 @@ export function chooseCardPlays(hand, rules, game = {}) {
|
|
|
300
302
|
const theirs = short - Math.min(short, byValue.length);
|
|
301
303
|
if (theirs > 0) {
|
|
302
304
|
warnings.push(`${theirs} more card${theirs === 1 ? '' : 's'} must leave the team's hand from your teammates' cards: ` +
|
|
303
|
-
|
|
305
|
+
"ask them to play or discard (war.app's order check takes a teammate's card too, but no such play has been sent live yet).");
|
|
304
306
|
}
|
|
305
307
|
}
|
|
306
308
|
const forced = plays.filter((c) => c.type === CARD_ORDER_PRIORITY);
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
// #415 task 4: the chat automation gate. Classification, advice and drafts are always on (read-only); an
|
|
2
|
+
// automated reply — a message an agent sends that the owner did not tell it to send — is behind
|
|
3
|
+
// `WARAPP_CHAT_AUTOMATION`, `off` unless it says `on` (owner decision of 2026-11-20; D2 is now "off unless the
|
|
4
|
+
// gate is on"). With the gate on, every send still goes through warapp_send_chat's confirm gate (D1).
|
|
5
|
+
import { readEnvVar } from '@chrischall/mcp-utils';
|
|
6
|
+
export const CHAT_AUTOMATION_ENV = 'WARAPP_CHAT_AUTOMATION';
|
|
7
|
+
/** The gate: `on` only when the variable says `on` (any case, trimmed); unset, `off` and anything else read `off`. */
|
|
8
|
+
export function chatAutomationMode(env = process.env) {
|
|
9
|
+
const v = readEnvVar(CHAT_AUTOMATION_ENV, { env });
|
|
10
|
+
return v !== undefined && v.trim().toLowerCase() === 'on' ? 'on' : 'off';
|
|
11
|
+
}
|
|
12
|
+
/** warapp_send_chat's refusal of an automated send with the gate off. */
|
|
13
|
+
export const AUTOMATED_CHAT_OFF = 'automated chat is off (WARAPP_CHAT_AUTOMATION); the owner sends replies';
|
|
14
|
+
// #415 task 4b: chat can block a turn — a second, independent gate. `WARAPP_CHAT_BLOCKS_TURN`, `off` unless it says
|
|
15
|
+
// `on` (owner request of 2026-11-20: "chat rarely blocks a turn, but can under very certain circumstances. Gate that
|
|
16
|
+
// as well; off by default."). Off: warapp_submit_turn never refuses for chat and its preview says what would block.
|
|
17
|
+
export const CHAT_BLOCKS_TURN_ENV = 'WARAPP_CHAT_BLOCKS_TURN';
|
|
18
|
+
/** The gate: `on` only when the variable says `on` (any case, trimmed); unset, `off` and anything else read `off`. */
|
|
19
|
+
export function chatBlocksTurnMode(env = process.env) {
|
|
20
|
+
const v = readEnvVar(CHAT_BLOCKS_TURN_ENV, { env });
|
|
21
|
+
return v !== undefined && v.trim().toLowerCase() === 'on' ? 'on' : 'off';
|
|
22
|
+
}
|
package/dist/chat.js
CHANGED
|
@@ -122,7 +122,8 @@ export function readGameRefreshChat(bundle, body) {
|
|
|
122
122
|
}
|
|
123
123
|
/**
|
|
124
124
|
* The SendChat reply: the updated message list, read straight after the result-present flag (each
|
|
125
|
-
* message behind its own present flag), oldest first; `undefined` when it cannot be read.
|
|
125
|
+
* message behind its own present flag), oldest first; `undefined` when it cannot be read. The replies of
|
|
126
|
+
* RetrieveChat and RetrievePrivateMessageHistory have the same shape (the client reads them alike).
|
|
126
127
|
*/
|
|
127
128
|
export function readSendChatReply(bundle, body) {
|
|
128
129
|
try {
|
|
@@ -135,6 +136,39 @@ export function readSendChatReply(bundle, body) {
|
|
|
135
136
|
return undefined;
|
|
136
137
|
}
|
|
137
138
|
}
|
|
139
|
+
/** RetrieveChat's and RetrievePrivateMessageHistory's reply: a message list as SendChat's. */
|
|
140
|
+
export const readMessageHistoryReply = readSendChatReply;
|
|
141
|
+
/**
|
|
142
|
+
* `lines` with `more` added, each message once (by id; a line with no id is kept as it is), oldest first.
|
|
143
|
+
* GameRefresh and the history reads may both return a message.
|
|
144
|
+
*/
|
|
145
|
+
export function mergeChatLines(lines, more) {
|
|
146
|
+
const ids = new Set(lines.flatMap((l) => (l.id === undefined ? [] : [l.id])));
|
|
147
|
+
const out = [...lines];
|
|
148
|
+
for (const l of more) {
|
|
149
|
+
if (l.id !== undefined) {
|
|
150
|
+
if (ids.has(l.id))
|
|
151
|
+
continue;
|
|
152
|
+
ids.add(l.id);
|
|
153
|
+
}
|
|
154
|
+
out.push(l);
|
|
155
|
+
}
|
|
156
|
+
return out.sort(byAge);
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* The oldest message id received among `lines` that `pick` keeps (decimal text), the "older than" marker of a
|
|
160
|
+
* history read; `undefined` when there is none (the read then asks from the newest).
|
|
161
|
+
*/
|
|
162
|
+
export function oldestId(lines, pick) {
|
|
163
|
+
let best;
|
|
164
|
+
for (const l of lines) {
|
|
165
|
+
if (l.id === undefined || !/^\d{1,20}$/.test(l.id) || !pick(l))
|
|
166
|
+
continue;
|
|
167
|
+
if (best === undefined || BigInt(l.id) < BigInt(best))
|
|
168
|
+
best = l.id;
|
|
169
|
+
}
|
|
170
|
+
return best;
|
|
171
|
+
}
|
|
138
172
|
const MESSAGE_ID = /^\d{1,20}$/;
|
|
139
173
|
const higher = (a, b) => (a === undefined || BigInt(b) > BigInt(a) ? b : a);
|
|
140
174
|
/**
|
package/dist/client.js
CHANGED
|
@@ -214,6 +214,8 @@ export class WarappClient {
|
|
|
214
214
|
#env;
|
|
215
215
|
#cache;
|
|
216
216
|
#dataDir;
|
|
217
|
+
/** #437: called with every game read (the decision log's seat capture); never fails a read. */
|
|
218
|
+
#gameObservers = [];
|
|
217
219
|
#api;
|
|
218
220
|
/** The same client with no retry, for a request that must go out at most once (`noRetry`). */
|
|
219
221
|
#apiOnce;
|
|
@@ -343,8 +345,20 @@ export class WarappClient {
|
|
|
343
345
|
// #302: what came instead of a history that does not read, by key name only.
|
|
344
346
|
if (opts.history)
|
|
345
347
|
game.feedKeys = safeKeys(Object.keys(body));
|
|
348
|
+
for (const observe of this.#gameObservers) {
|
|
349
|
+
try {
|
|
350
|
+
await observe(game);
|
|
351
|
+
}
|
|
352
|
+
catch {
|
|
353
|
+
// An observer never fails the read.
|
|
354
|
+
}
|
|
355
|
+
}
|
|
346
356
|
return game;
|
|
347
357
|
}
|
|
358
|
+
/** #437: call `fn` with every game this client reads (awaited, its failures swallowed). */
|
|
359
|
+
observeGames(fn) {
|
|
360
|
+
this.#gameObservers.push(fn);
|
|
361
|
+
}
|
|
348
362
|
/** Keep the territories read for a map's distribution modes (#328) on the cached map and in the store. */
|
|
349
363
|
async keepModeTerritories(mapId, byMode) {
|
|
350
364
|
await this.#cache.setModeTerritories(mapId, byMode, this.#dir());
|
package/dist/commerce.js
ADDED
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
/** The commerce rules of a game, or `undefined` outside a commerce game or when its settings were not read. */
|
|
2
|
+
export function commerceRules(s) {
|
|
3
|
+
if (!s?.commerce || !s.commerceRules)
|
|
4
|
+
return undefined;
|
|
5
|
+
const r = s.commerceRules;
|
|
6
|
+
return {
|
|
7
|
+
armyCostMultiplier: r.armyCostMultiplier ?? 0,
|
|
8
|
+
cityBaseCost: r.cityBaseCost ?? null,
|
|
9
|
+
territoryCityCostIncrease: r.territoryCityCostIncrease ?? 0,
|
|
10
|
+
globalCityCostIncrease: r.globalCityCostIncrease ?? 0,
|
|
11
|
+
cityIncome: r.cityIncome ?? 0,
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
const whole = (n) => (Number.isFinite(n) ? Math.max(0, Math.floor(n)) : 0);
|
|
15
|
+
/** The armies `gold` buys in one turn at multiplier `m` (the client's GameSettings function). */
|
|
16
|
+
export function armiesForGold(gold, m) {
|
|
17
|
+
let left = whole(gold);
|
|
18
|
+
const batch = whole(m);
|
|
19
|
+
if (batch === 0)
|
|
20
|
+
return left;
|
|
21
|
+
let armies = 0;
|
|
22
|
+
for (let price = 1; left > 0; price++) {
|
|
23
|
+
const n = Math.min(batch, Math.floor(left / price));
|
|
24
|
+
if (n === 0)
|
|
25
|
+
break;
|
|
26
|
+
armies += n;
|
|
27
|
+
left -= n * price;
|
|
28
|
+
}
|
|
29
|
+
return armies;
|
|
30
|
+
}
|
|
31
|
+
/** What `armies` cost in one turn at multiplier `m` (the client's GameSettings function). */
|
|
32
|
+
export function goldForArmies(armies, m) {
|
|
33
|
+
let left = whole(armies);
|
|
34
|
+
const batch = whole(m);
|
|
35
|
+
if (batch === 0)
|
|
36
|
+
return left;
|
|
37
|
+
let gold = 0;
|
|
38
|
+
for (let price = 1; left > 0; price++) {
|
|
39
|
+
gold += price * Math.min(batch, left);
|
|
40
|
+
left -= batch;
|
|
41
|
+
}
|
|
42
|
+
return gold;
|
|
43
|
+
}
|
|
44
|
+
/** What `gold` buys as this turn's deploy: the armies, their cost and the gold left (which carries over). */
|
|
45
|
+
export function deployBudget(gold, m) {
|
|
46
|
+
const g = whole(gold);
|
|
47
|
+
const armies = armiesForGold(g, m);
|
|
48
|
+
const cost = goldForArmies(armies, m);
|
|
49
|
+
return { gold: g, armies, cost, left: g - cost };
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* The armies this turn's gold buys: the standing's gold when read (it already holds what was saved and any Sanctions,
|
|
53
|
+
* since war.app pays it), else the modelled income.
|
|
54
|
+
*/
|
|
55
|
+
export function commerceDeploy(rules, standingGold, modelGold) {
|
|
56
|
+
const source = standingGold !== undefined ? 'standing' : 'model';
|
|
57
|
+
const b = deployBudget(standingGold ?? modelGold, rules.armyCostMultiplier);
|
|
58
|
+
return { source, ...b, armyCostMultiplier: rules.armyCostMultiplier };
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* What a purchase order's cities cost, by the client's formula (`GameOrderPurchase`, client 6.08.0.2): per city,
|
|
62
|
+
* CityBaseCost + (cities on that territory so far) × TerritoryCityCostIncrease + (my cities so far, everywhere — the
|
|
63
|
+
* ones I own, then each earlier city of this order) × GlobalCityCostIncrease, the global count starting at 0 when its
|
|
64
|
+
* increase is 0. `existing` gives the cities already on each territory, `myCities` all I own. `undefined` in a game
|
|
65
|
+
* that allows no cities.
|
|
66
|
+
*/
|
|
67
|
+
export function cityPurchaseCost(rules, order, existing, myCities) {
|
|
68
|
+
if (rules.cityBaseCost === null)
|
|
69
|
+
return undefined;
|
|
70
|
+
let total = 0;
|
|
71
|
+
let global = rules.globalCityCostIncrease === 0 ? 0 : whole(myCities);
|
|
72
|
+
for (const { territoryId, count } of order) {
|
|
73
|
+
let onTerritory = whole(existing.get(territoryId) ?? 0);
|
|
74
|
+
for (let n = 0; n < count; n++) {
|
|
75
|
+
total += rules.cityBaseCost + onTerritory * rules.territoryCityCostIncrease + global * rules.globalCityCostIncrease;
|
|
76
|
+
onTerritory++;
|
|
77
|
+
global++;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
return total;
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* #332, advice only (never an order of the plan): the cheapest city I can place on an interior territory this turn,
|
|
84
|
+
* and how many turns its income takes to repay its cost (`paysBackInTurns`, `worthIt` within `horizon` turns). A
|
|
85
|
+
* city's gold comes out of this turn's deploy. `undefined` when the game allows no cities or pays nothing for them,
|
|
86
|
+
* no interior territory is mine, or the gold does not cover one.
|
|
87
|
+
*/
|
|
88
|
+
export function cityAdvice(rules, sites, gold, horizon) {
|
|
89
|
+
if (rules.cityBaseCost === null || !(rules.cityIncome > 0))
|
|
90
|
+
return undefined;
|
|
91
|
+
const myCities = sites.reduce((n, s) => n + s.cities, 0);
|
|
92
|
+
let best;
|
|
93
|
+
for (const s of sites) {
|
|
94
|
+
if (!s.interior)
|
|
95
|
+
continue;
|
|
96
|
+
const cost = cityPurchaseCost(rules, [{ territoryId: s.territoryId, count: 1 }], new Map([[s.territoryId, s.cities]]), myCities);
|
|
97
|
+
if (!best || cost < best.cost || (cost === best.cost && s.territoryId < best.territoryId))
|
|
98
|
+
best = { territoryId: s.territoryId, cost };
|
|
99
|
+
}
|
|
100
|
+
if (!best || best.cost > gold)
|
|
101
|
+
return undefined;
|
|
102
|
+
const paysBackInTurns = Math.ceil(best.cost / rules.cityIncome);
|
|
103
|
+
return {
|
|
104
|
+
territoryId: best.territoryId,
|
|
105
|
+
cost: best.cost,
|
|
106
|
+
cityIncome: rules.cityIncome,
|
|
107
|
+
paysBackInTurns,
|
|
108
|
+
worthIt: paysBackInTurns <= horizon,
|
|
109
|
+
order: { territory: best.territoryId, count: 1 },
|
|
110
|
+
};
|
|
111
|
+
}
|