@chrischall/warapp-mcp 0.23.2 → 0.24.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/dist/analysis/calibrate.js +54 -0
- package/dist/analysis/commitments.js +8 -2
- package/dist/bundle.js +280 -19
- package/dist/chat.js +73 -0
- package/dist/protocol/methods.js +29 -3
- package/dist/tools/calibration-harness.js +22 -6
- package/dist/tools/chat.js +204 -30
- package/dist/version.js +1 -1
- package/manifest.json +1 -1
- package/package.json +1 -1
- package/server.json +2 -2
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
},
|
|
8
8
|
"metadata": {
|
|
9
9
|
"description": "MCP server for war.app (Warzone) — your games, players, settings, map bonuses and chokepoints, board analysis and route planning through war.app's per-player GameFeed API, plus the live board, territory picks, cards, turn planning and submission, turn notifications and game chat through your signed-in war.app tab (creating, joining, leaving or surrendering a game, accepting game invitations, closing out a finished game, accepting another player's surrender, a team surrender, a vote to end a game, booting a stalled player, Begin on a speed first turn, picks, turn orders, withdrawing them, chat sends, nudging a player, joining or leaving a ladder, answering a clan invite, joining or leaving a clan, changing quickmatch settings, voting on quickmatch templates, joining or declining a tournament, showing a tournament among your favourites, mail (new threads, replies, adding players, deleting threads), forum posts (new threads, replies, votes, watching a thread), chat reactions, marking notifications and chat read, deleting notifications, importing local history and linking a session are confirm-gated).",
|
|
10
|
-
"version": "0.
|
|
10
|
+
"version": "0.24.0"
|
|
11
11
|
},
|
|
12
12
|
"plugins": [
|
|
13
13
|
{
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
"displayName": "war.app (Warzone)",
|
|
16
16
|
"source": "./",
|
|
17
17
|
"description": "war.app (Warzone) game advisor for Claude — games, maps, bonuses, routes, live board, picks, turns, cards and chat",
|
|
18
|
-
"version": "0.
|
|
18
|
+
"version": "0.24.0",
|
|
19
19
|
"author": {
|
|
20
20
|
"name": "Chris Hall"
|
|
21
21
|
},
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "warapp-mcp",
|
|
3
3
|
"displayName": "war.app (Warzone)",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.24.0",
|
|
5
5
|
"description": "war.app (Warzone) game advisor for Claude — games, maps, bonuses, routes, live board, picks, turns, cards and chat",
|
|
6
6
|
"author": {
|
|
7
7
|
"name": "Chris Hall",
|
|
@@ -296,6 +296,60 @@ export function openingFlags(input) {
|
|
|
296
296
|
const bt = input.booted?.turn ?? null;
|
|
297
297
|
return { noOrderTurns, bootedTurn: bt !== null && bt >= 1 && bt <= window ? bt : null };
|
|
298
298
|
}
|
|
299
|
+
/**
|
|
300
|
+
* #506: the territories `player` held on history board N − 1 and another player (not a neutral, not one of
|
|
301
|
+
* `allies`) held on board N, for N in 1..`window` — land taken from it in the opening. A turn the history lacks
|
|
302
|
+
* is not read. Pure.
|
|
303
|
+
*/
|
|
304
|
+
export function openingLosses(input) {
|
|
305
|
+
const window = input.window ?? OPENING_WINDOW;
|
|
306
|
+
const boards = new Map(input.history.map((b) => [b.turn, b.board]));
|
|
307
|
+
const friends = new Set([input.player, ...(input.allies ?? [])]);
|
|
308
|
+
let territories = 0;
|
|
309
|
+
const turns = [];
|
|
310
|
+
for (let n = 1; n <= window; n++) {
|
|
311
|
+
const before = boards.get(n - 1);
|
|
312
|
+
const after = boards.get(n);
|
|
313
|
+
if (!before || !after)
|
|
314
|
+
continue;
|
|
315
|
+
const had = landOf(before, input.player);
|
|
316
|
+
let lost = 0;
|
|
317
|
+
for (const t of after.territories)
|
|
318
|
+
if (had.has(t.territoryId) && t.owner.kind === 'player' && !friends.has(t.owner.playerId))
|
|
319
|
+
lost++;
|
|
320
|
+
if (lost) {
|
|
321
|
+
territories += lost;
|
|
322
|
+
turns.push(n);
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
return { territories, turns };
|
|
326
|
+
}
|
|
327
|
+
function lossAggregate(entries) {
|
|
328
|
+
const won = entries.filter((e) => e.winner !== null);
|
|
329
|
+
return {
|
|
330
|
+
games: entries.length,
|
|
331
|
+
withWinner: won.length,
|
|
332
|
+
iWon: entries.filter((e) => e.iWon).length,
|
|
333
|
+
iLost: entries.filter((e) => e.mine.territories > 0).length,
|
|
334
|
+
winnerLost: won.filter((e) => e.winner.territories > 0).length,
|
|
335
|
+
myTerritories: entries.reduce((n, e) => n + e.mine.territories, 0),
|
|
336
|
+
winnerTerritories: won.reduce((n, e) => n + e.winner.territories, 0),
|
|
337
|
+
};
|
|
338
|
+
}
|
|
339
|
+
/** #506: the opening losses by era, then format. Pure. */
|
|
340
|
+
export function earlyLossesByEra(entries) {
|
|
341
|
+
const out = {};
|
|
342
|
+
for (const era of ['pre-tool', 'pre-rule-4f', 'current']) {
|
|
343
|
+
const of = entries.filter((e) => e.era === era);
|
|
344
|
+
if (!of.length)
|
|
345
|
+
continue;
|
|
346
|
+
const byFormat = {};
|
|
347
|
+
for (const f of [...new Set(of.map((e) => e.format))].sort())
|
|
348
|
+
byFormat[f] = lossAggregate(of.filter((e) => e.format === f));
|
|
349
|
+
out[era] = { all: lossAggregate(of), byFormat };
|
|
350
|
+
}
|
|
351
|
+
return out;
|
|
352
|
+
}
|
|
299
353
|
/** A map this many times the median map's territories or more is counted as large. */
|
|
300
354
|
export const LARGE_MAP_FACTOR = 5;
|
|
301
355
|
/** The benchmarks grouped by era, then format; flagged games apart; how many eras were read from which basis. Pure. */
|
|
@@ -9,8 +9,8 @@ export const MAX_NO_ATTACK_TURNS = 10;
|
|
|
9
9
|
export const MAX_MESSAGE_COMMITMENTS = 10;
|
|
10
10
|
/**
|
|
11
11
|
* Why a propose, accept or notice with `partner` cannot go to `audience`: the partner would never read
|
|
12
|
-
* it. `undefined` when it reads it (the private recipient,
|
|
13
|
-
* team the message goes to).
|
|
12
|
+
* it. `undefined` when it reads it (the private recipient, a member of the game group, anyone on the public
|
|
13
|
+
* channel, a player on the team the message goes to).
|
|
14
14
|
*/
|
|
15
15
|
export function audienceRefusal(audience, partner, players) {
|
|
16
16
|
if (audience.kind === 'public')
|
|
@@ -19,6 +19,12 @@ export function audienceRefusal(audience, partner, players) {
|
|
|
19
19
|
return audience.to === partner
|
|
20
20
|
? undefined
|
|
21
21
|
: `the message goes privately to player ${audience.to}, so player ${partner}, the truce's partner, would never read it (D3: a truce changes only with the partner told)`;
|
|
22
|
+
if (audience.kind === 'group') {
|
|
23
|
+
const ids = audience.to.length > 1 ? `${audience.to.slice(0, -1).join(', ')} and ${audience.to.at(-1)}` : String(audience.to[0]);
|
|
24
|
+
return audience.to.includes(partner)
|
|
25
|
+
? undefined
|
|
26
|
+
: `the message goes to a group of players ${ids}, so player ${partner}, the truce's partner, would never read it (D3: a truce changes only with the partner told)`;
|
|
27
|
+
}
|
|
22
28
|
const p = players.find((x) => x.id === partner);
|
|
23
29
|
return p?.team === audience.team
|
|
24
30
|
? undefined
|
package/dist/bundle.js
CHANGED
|
@@ -116234,7 +116234,7 @@ function serverBuild() {
|
|
|
116234
116234
|
}
|
|
116235
116235
|
|
|
116236
116236
|
// src/version.ts
|
|
116237
|
-
var VERSION2 = "0.
|
|
116237
|
+
var VERSION2 = "0.24.0";
|
|
116238
116238
|
|
|
116239
116239
|
// src/decision-log.ts
|
|
116240
116240
|
var DECISION_LOG_VERSION = 1;
|
|
@@ -118079,6 +118079,10 @@ function audienceRefusal(audience, partner, players) {
|
|
|
118079
118079
|
if (audience.kind === "public") return void 0;
|
|
118080
118080
|
if (audience.kind === "private")
|
|
118081
118081
|
return audience.to === partner ? void 0 : `the message goes privately to player ${audience.to}, so player ${partner}, the truce's partner, would never read it (D3: a truce changes only with the partner told)`;
|
|
118082
|
+
if (audience.kind === "group") {
|
|
118083
|
+
const ids2 = audience.to.length > 1 ? `${audience.to.slice(0, -1).join(", ")} and ${audience.to.at(-1)}` : String(audience.to[0]);
|
|
118084
|
+
return audience.to.includes(partner) ? void 0 : `the message goes to a group of players ${ids2}, so player ${partner}, the truce's partner, would never read it (D3: a truce changes only with the partner told)`;
|
|
118085
|
+
}
|
|
118082
118086
|
const p = players.find((x) => x.id === partner);
|
|
118083
118087
|
return p?.team === audience.team ? void 0 : `the message goes to team ${audience.team} only, and player ${partner}, the truce's partner, is not on it: it would never read it (D3: a truce changes only with the partner told)`;
|
|
118084
118088
|
}
|
|
@@ -120024,6 +120028,8 @@ var Method = {
|
|
|
120024
120028
|
ForumVote: 204,
|
|
120025
120029
|
WatchForumThread: 328,
|
|
120026
120030
|
GetGroupForumThreads: 354,
|
|
120031
|
+
/** A game group: a private conversation of several players in one game (the bundle's writer; UNVERIFIED live). */
|
|
120032
|
+
CreateGameGroup: 356,
|
|
120027
120033
|
Subscribe: 243,
|
|
120028
120034
|
/** #633: the client's "Game Invite Code" screen (`GameInviteCode` reply); read from the bundle, UNVERIFIED live. */
|
|
120029
120035
|
GetGameByInviteCode: 295,
|
|
@@ -120226,6 +120232,14 @@ function checkIds(ids2, what) {
|
|
|
120226
120232
|
function writeOptionalIntList(w, ids2) {
|
|
120227
120233
|
w.bool(true).list(ids2, (ww, id) => ww.int32(id));
|
|
120228
120234
|
}
|
|
120235
|
+
var GAME_GROUP_COLOUR = 13811880;
|
|
120236
|
+
function writeCreateGameGroupParams(w, p) {
|
|
120237
|
+
if (p.members.length === 0) throw new RangeError("no members");
|
|
120238
|
+
checkIds(p.members, "player id");
|
|
120239
|
+
if (p.name.trim() === "") throw new RangeError("a game group needs a name");
|
|
120240
|
+
w.int32(p.gameId).string(p.name).int32(GAME_GROUP_COLOUR);
|
|
120241
|
+
writeOptionalIntList(w, p.members);
|
|
120242
|
+
}
|
|
120229
120243
|
function writeCreatePrivateDiscussionParams(w, p) {
|
|
120230
120244
|
if (p.recipients.length === 0) throw new RangeError("no recipients");
|
|
120231
120245
|
checkIds(p.recipients, "player id");
|
|
@@ -120402,10 +120416,16 @@ function writeRetrievePrivateMessageHistoryParams(w, p) {
|
|
|
120402
120416
|
w.int32(p.gameId).string(beforeMarker(p.before)).int32(p.counterpart);
|
|
120403
120417
|
}
|
|
120404
120418
|
function writeSendChatParams(w, p) {
|
|
120419
|
+
if (p.group !== void 0 && p.recipient !== void 0) throw new RangeError("a message cannot go both to a group and privately");
|
|
120405
120420
|
w.int32(p.gameId).string(p.text).int32(p.channel ?? CHAT_CHANNEL_PUBLIC);
|
|
120406
120421
|
if (p.recipient === void 0) w.bool(false);
|
|
120407
120422
|
else w.bool(true).int32(p.recipient);
|
|
120408
|
-
|
|
120423
|
+
if (p.group === void 0) w.bool(false);
|
|
120424
|
+
else {
|
|
120425
|
+
checkIds([p.group], "game group id");
|
|
120426
|
+
w.bool(true).int32(p.group);
|
|
120427
|
+
}
|
|
120428
|
+
w.string(NO_CHAT_MARKER).string(NO_CHAT_MARKER).bool(false).bool(false).bool(false);
|
|
120409
120429
|
}
|
|
120410
120430
|
var ReactionTarget = { GameMessage: 0 };
|
|
120411
120431
|
var REACTION_TIMED_OUT = 639;
|
|
@@ -143903,8 +143923,12 @@ function registerBoardTool(server, client, live) {
|
|
|
143903
143923
|
var GAME_DETAILS_AND_CHAT = "warlight.shared.GameDetailsAndChat";
|
|
143904
143924
|
var GAME_MESSAGE = "warlight.shared.GameMessage";
|
|
143905
143925
|
var MESSAGE_REACTION = "warlight.shared.MessageReaction";
|
|
143926
|
+
var GAME_GROUP = "warlight.shared.GameGroup";
|
|
143906
143927
|
var REACTION_TYPES = ["thumbs-up", "thumbs-down", "heart", "laugh", "angry"];
|
|
143907
143928
|
var GDC_REACTIONS = 5;
|
|
143929
|
+
var GDC_GROUPS = 6;
|
|
143930
|
+
var GG = { creator: 1, gameId: 3, id: 4, name: 6, members: 7 };
|
|
143931
|
+
var GAME_GROUP_FIELDS = 8;
|
|
143908
143932
|
var GM = { date: 0, sender: 1, group: 2, id: 4, images: 5, text: 6, reactions: 7, channel: 8, to: 9, turn: 11 };
|
|
143909
143933
|
var GAME_MESSAGE_FIELDS = 12;
|
|
143910
143934
|
var PUBLIC_CHANNEL = -1;
|
|
@@ -144024,6 +144048,48 @@ function applyReactionsDict(lines, dict2) {
|
|
|
144024
144048
|
if (line2.id !== void 0 && byId2.has(line2.id)) setReactions(line2, byId2.get(line2.id));
|
|
144025
144049
|
}
|
|
144026
144050
|
}
|
|
144051
|
+
function groupMembers(text2) {
|
|
144052
|
+
if (typeof text2 !== "string") return null;
|
|
144053
|
+
try {
|
|
144054
|
+
const v = JSON.parse(text2);
|
|
144055
|
+
if (!Array.isArray(v)) return null;
|
|
144056
|
+
const ids2 = v.map((x) => typeof x === "string" && /^-?\d+$/.test(x) ? Number(x) : x);
|
|
144057
|
+
return ids2.every(isInt12) ? ids2 : null;
|
|
144058
|
+
} catch {
|
|
144059
|
+
return null;
|
|
144060
|
+
}
|
|
144061
|
+
}
|
|
144062
|
+
function readGameGroups(bundle, body) {
|
|
144063
|
+
try {
|
|
144064
|
+
if (!body.bool()) return void 0;
|
|
144065
|
+
const ret = bundle.readClass(GAME_DETAILS_AND_CHAT, body);
|
|
144066
|
+
if (!isObj(ret) || ret.$type !== GAME_DETAILS_AND_CHAT) return void 0;
|
|
144067
|
+
const list4 = fields(ret)[GDC_GROUPS];
|
|
144068
|
+
if (!Array.isArray(list4)) return void 0;
|
|
144069
|
+
const out = [];
|
|
144070
|
+
for (const g of list4) {
|
|
144071
|
+
if (g === null) continue;
|
|
144072
|
+
if (!isObj(g) || g.$type !== GAME_GROUP) return void 0;
|
|
144073
|
+
const f = fields(g);
|
|
144074
|
+
if (f.length !== GAME_GROUP_FIELDS) return void 0;
|
|
144075
|
+
const [id, gameId, creator, name2] = [f[GG.id], f[GG.gameId], f[GG.creator], f[GG.name]];
|
|
144076
|
+
if (!isInt12(id) || !isInt12(gameId) || !isInt12(creator) || typeof name2 !== "string") return void 0;
|
|
144077
|
+
out.push({ id, gameId, creator, name: name2, members: groupMembers(f[GG.members]) });
|
|
144078
|
+
}
|
|
144079
|
+
return out;
|
|
144080
|
+
} catch {
|
|
144081
|
+
return void 0;
|
|
144082
|
+
}
|
|
144083
|
+
}
|
|
144084
|
+
function readCreateGameGroupReply(bundle, body) {
|
|
144085
|
+
try {
|
|
144086
|
+
if (!body.bool()) return void 0;
|
|
144087
|
+
const line2 = webLine(bundle.readClass(GAME_MESSAGE, body));
|
|
144088
|
+
return line2?.group;
|
|
144089
|
+
} catch {
|
|
144090
|
+
return void 0;
|
|
144091
|
+
}
|
|
144092
|
+
}
|
|
144027
144093
|
function readSendChatReply(bundle, body) {
|
|
144028
144094
|
try {
|
|
144029
144095
|
if (!body.bool()) return void 0;
|
|
@@ -160708,6 +160774,31 @@ async function checkMessageCommitments(ctx, game, me, args, audience, teamsKnown
|
|
|
160708
160774
|
// src/tools/chat.ts
|
|
160709
160775
|
var DEFAULT_LIMIT2 = 50;
|
|
160710
160776
|
var MAX_CHAT_LENGTH = 2e3;
|
|
160777
|
+
var MAX_GROUP_RECIPIENTS = 10;
|
|
160778
|
+
var MAX_GROUP_NAME = 50;
|
|
160779
|
+
var DEFAULT_GROUP_NAME = "Group chat";
|
|
160780
|
+
var GROUP_REFUSALS = {
|
|
160781
|
+
227: "a player in it has blocked you",
|
|
160782
|
+
751: "this game does not allow game groups"
|
|
160783
|
+
};
|
|
160784
|
+
var listIds = (ids2) => ids2.length > 1 ? `${ids2.slice(0, -1).join(", ")} and ${ids2.at(-1)}` : String(ids2[0]);
|
|
160785
|
+
async function existingGroup(ctx, game, meInGame2, members2) {
|
|
160786
|
+
try {
|
|
160787
|
+
const env = await ctx.rpc.call(
|
|
160788
|
+
"GameRefresh",
|
|
160789
|
+
Method.GameRefresh,
|
|
160790
|
+
(w) => writeGameRefreshParams(w, { gameId: game.id, chat: false, nonChat: true, lobby: game.state === "WaitingForPlayers" })
|
|
160791
|
+
);
|
|
160792
|
+
const groups = readGameGroups(await ctx.bundle(), env.body);
|
|
160793
|
+
if (!groups) return { read: false };
|
|
160794
|
+
const want = /* @__PURE__ */ new Set([meInGame2, ...members2]);
|
|
160795
|
+
const same3 = groups.filter((g) => g.gameId === game.id && g.members !== null && new Set(g.members).size === want.size && g.members.every((m) => want.has(m))).sort((a, b) => b.id - a.id);
|
|
160796
|
+
return same3[0] ? { read: true, group: same3[0] } : { read: true };
|
|
160797
|
+
} catch {
|
|
160798
|
+
return { read: false };
|
|
160799
|
+
}
|
|
160800
|
+
}
|
|
160801
|
+
var GROUP_UNVERIFIED = "Game groups (creating one, and a message to one) are read from the client bundle and UNVERIFIED live.";
|
|
160711
160802
|
var LINKS_NOTE = "Each link goes out as the client's token (`<a t=ID>` territory, `<a b=ID>` bonus) and players see the name from the map. Territory and bonus links are verified live (2026-11-23).";
|
|
160712
160803
|
var CHAT_SOURCE_NOTES = {
|
|
160713
160804
|
web: "Read from the web client's GameRefresh reply; its channel, recipient and turn fields come from the client bundle and are UNVERIFIED live.",
|
|
@@ -161005,7 +161096,7 @@ function registerChatTools(server, ctx, opts = {}) {
|
|
|
161005
161096
|
},
|
|
161006
161097
|
{
|
|
161007
161098
|
name: "warapp_send_chat",
|
|
161008
|
-
description: `Post a chat message in a war.app (Warzone) game \u2014 to the whole game, to your team (\`channel: "team"\`, in a team game), or privately to one named player (\`to\`; refused when the game turns private messages off
|
|
161099
|
+
description: `Post a chat message in a war.app (Warzone) game \u2014 to the whole game, to your team (\`channel: "team"\`, in a team game), or privately to one named player (\`to\`), or to several together (\`to\` as a list: a war.app game group, reused when one of exactly you and them exists, else created first, named by \`group_name\`; UNVERIFIED live); private sends are refused when the game turns private messages off. The message reaches other players and cannot be unsent. Sent through your signed-in war.app tab (ContextMint Bridge); the game is read from GameFeed first, so the GameFeed credentials are needed too. The result's \`outcome\` is \`confirmed\` when war.app's reply lists it as your newest message on that channel, \`accepted\` when the reply cannot be read, \`unconfirmed\` when it does not show it. Whatever the message promises must be declared in \`commitments\` (no-attack, will-attack, notice, propose, accept; the text is never read): each is checked against this turn's plan (re-planned in the call, or the orders already submitted) and the agreement ledger, a commitment they do not carry refuses the send, and once the message is confirmed or accepted they are recorded in the ledger as yours (a propose or accept creates or advances the agreement, a notice moves it to notice-by-me); warapp_submit_turn warns when later orders break one. Pass \`automated: true\` for a reply the owner did not tell you to send (e.g. an advice's \`send\`): it is refused unless WARAPP_CHAT_AUTOMATION is on (off by default: the owner sends replies), and even then it is confirm-gated. Link a territory or bonus as players see it in the official client with \`[[t:<id or name>]]\` / \`[[b:<id or name>]]\` in the message, or set \`link_territories\` to link every territory name it mentions: names resolve against the game's map (exact, case-insensitive; an unknown or shared name is refused, listing the ids), and the preview shows the message as rendered with its \`links\`. ${CONFIRM_INJECTION_RULE}`,
|
|
161009
161100
|
annotations: toolAnnotations({
|
|
161010
161101
|
title: "Send a war.app chat message",
|
|
161011
161102
|
readOnly: false,
|
|
@@ -161020,13 +161111,18 @@ function registerChatTools(server, ctx, opts = {}) {
|
|
|
161020
161111
|
"true: also link every whole-word mention of a territory name in the message, repeats included (the longest name where names overlap; never inside a [[\u2026]] link). Default false."
|
|
161021
161112
|
),
|
|
161022
161113
|
channel: external_exports.enum(["public", "team"]).optional().describe('"public" (default): the whole game. "team": your team only (a team game). Not with `to`.'),
|
|
161023
|
-
to: external_exports.union([external_exports.string(), external_exports.number()]).
|
|
161114
|
+
to: external_exports.union([external_exports.string(), external_exports.number(), external_exports.array(external_exports.union([external_exports.string(), external_exports.number()])).min(1).max(MAX_GROUP_RECIPIENTS)]).optional().describe(
|
|
161115
|
+
`A player (name or GameFeed id) to message privately, or a list of 2 to ${MAX_GROUP_RECIPIENTS} players to message together in a game group (one private conversation they all read). Omit to post to a channel.`
|
|
161116
|
+
),
|
|
161117
|
+
group_name: external_exports.string().trim().min(1).max(MAX_GROUP_NAME).optional().describe(
|
|
161118
|
+
`A list \`to\` only: the name of the game group if one has to be created (default "${DEFAULT_GROUP_NAME}"; the members see it). An existing group of exactly these players is reused, keeping its name.`
|
|
161119
|
+
),
|
|
161024
161120
|
commitments: commitmentsArg,
|
|
161025
161121
|
automated: external_exports.boolean().optional().describe(
|
|
161026
161122
|
"true when you send a reply the owner did not tell you to send (an automated reply). Refused unless WARAPP_CHAT_AUTOMATION is on; default false (a send the owner asked for)."
|
|
161027
161123
|
)
|
|
161028
161124
|
}),
|
|
161029
|
-
async plan({ game_id, message, channel, to, commitments, automated, link_territories }) {
|
|
161125
|
+
async plan({ game_id, message, channel, to, group_name, commitments, automated, link_territories }) {
|
|
161030
161126
|
const auto = automated === true;
|
|
161031
161127
|
if (auto && (ctx.chatAutomation ?? chatAutomationMode(opts.env ?? process.env)) !== "on") {
|
|
161032
161128
|
throw new McpToolError(`Refused: ${AUTOMATED_CHAT_OFF}. Nothing was sent.`, {
|
|
@@ -161034,7 +161130,18 @@ function registerChatTools(server, ctx, opts = {}) {
|
|
|
161034
161130
|
});
|
|
161035
161131
|
}
|
|
161036
161132
|
const gameId = parseGameId(game_id);
|
|
161037
|
-
const
|
|
161133
|
+
const toList = Array.isArray(to) ? to.filter((x) => String(x).trim() !== "") : void 0;
|
|
161134
|
+
const grouped = toList !== void 0 && toList.length >= 2;
|
|
161135
|
+
const single = toList ? toList.length === 1 ? toList[0] : void 0 : Array.isArray(to) ? void 0 : to;
|
|
161136
|
+
const privately = grouped || single !== void 0 && String(single).trim() !== "";
|
|
161137
|
+
if (toList !== void 0 && toList.length === 0) {
|
|
161138
|
+
throw new McpToolError("`to` lists no player: nothing was sent.", { hint: "Name the players to message, or omit `to` to post to the whole game." });
|
|
161139
|
+
}
|
|
161140
|
+
if (group_name !== void 0 && !grouped) {
|
|
161141
|
+
throw new McpToolError("`group_name` names a game group, which only a list of two or more players in `to` uses: nothing was sent.", {
|
|
161142
|
+
hint: "Pass `to` as a list of the players to message together, or drop `group_name`."
|
|
161143
|
+
});
|
|
161144
|
+
}
|
|
161038
161145
|
if (privately && channel === "team") {
|
|
161039
161146
|
throw new McpToolError("A private message (`to`) cannot also go to the team channel: nothing was sent.", {
|
|
161040
161147
|
hint: "Omit `to` to message your team, or omit `channel` to message one player privately."
|
|
@@ -161064,6 +161171,8 @@ function registerChatTools(server, ctx, opts = {}) {
|
|
|
161064
161171
|
let chatChannel = CHAT_CHANNEL_PUBLIC;
|
|
161065
161172
|
let recipient;
|
|
161066
161173
|
let shownRecipient;
|
|
161174
|
+
let group;
|
|
161175
|
+
let groupsRead = true;
|
|
161067
161176
|
if (privately) {
|
|
161068
161177
|
if (game.settings?.privateMessaging === false) {
|
|
161069
161178
|
throw new McpToolError(
|
|
@@ -161071,7 +161180,35 @@ function registerChatTools(server, ctx, opts = {}) {
|
|
|
161071
161180
|
{ hint: "Post to the whole game instead: the host turned private messages off." }
|
|
161072
161181
|
);
|
|
161073
161182
|
}
|
|
161074
|
-
|
|
161183
|
+
}
|
|
161184
|
+
if (grouped) {
|
|
161185
|
+
const people = toList.map((x) => resolvePlayer(game.players, x));
|
|
161186
|
+
const mine3 = people.find((p) => p.id === me);
|
|
161187
|
+
if (mine3) {
|
|
161188
|
+
throw new McpToolError(`${untrustedText(mine3.name)} (${mine3.id}) is you: list only the other players in \`to\`. Nothing was sent.`, {
|
|
161189
|
+
hint: "The group includes you anyway: name the players to message with you."
|
|
161190
|
+
});
|
|
161191
|
+
}
|
|
161192
|
+
const twice = people.find((p, i2) => people.findIndex((q) => q.id === p.id) !== i2);
|
|
161193
|
+
if (twice) {
|
|
161194
|
+
throw new McpToolError(`Player ${twice.id} is named twice in \`to\`: nothing was sent.`, { hint: "Name each player once." });
|
|
161195
|
+
}
|
|
161196
|
+
if (meInGame2 === void 0) {
|
|
161197
|
+
throw new McpToolError(`Your seat in game ${gameId} has no in-game id, so a game group cannot be made: nothing was sent.`, {
|
|
161198
|
+
hint: "Message each player privately instead."
|
|
161199
|
+
});
|
|
161200
|
+
}
|
|
161201
|
+
kind = "group";
|
|
161202
|
+
const members2 = people.map((p) => inGameId(p));
|
|
161203
|
+
const found = await existingGroup(ctx, game, meInGame2, members2);
|
|
161204
|
+
groupsRead = found.read;
|
|
161205
|
+
group = {
|
|
161206
|
+
...found.group ? { id: found.group.id, name: untrustedText(found.group.name) } : { name: group_name ?? DEFAULT_GROUP_NAME },
|
|
161207
|
+
members: members2,
|
|
161208
|
+
recipients: people.map((p) => ({ id: p.id, name: untrustedText(p.name) }))
|
|
161209
|
+
};
|
|
161210
|
+
} else if (privately) {
|
|
161211
|
+
const p = resolvePlayer(game.players, single);
|
|
161075
161212
|
if (p.id === me) {
|
|
161076
161213
|
throw new McpToolError(`${untrustedText(p.name)} (${p.id}) is you: a private message to yourself was not sent.`, {
|
|
161077
161214
|
hint: "Name another player in `to`, or omit it to post to the whole game."
|
|
@@ -161097,15 +161234,16 @@ function registerChatTools(server, ctx, opts = {}) {
|
|
|
161097
161234
|
hint: "Send the message without `commitments` \u2014 and then without any promise in it."
|
|
161098
161235
|
});
|
|
161099
161236
|
}
|
|
161100
|
-
const audience = kind === "private" ? { kind: "private", to: shownRecipient.id } : kind === "team" ? { kind: "team", team: chatChannel } : { kind: "public" };
|
|
161237
|
+
const audience = kind === "private" ? { kind: "private", to: shownRecipient.id } : kind === "group" ? { kind: "group", to: group.recipients.map((r) => r.id) } : kind === "team" ? { kind: "team", team: chatChannel } : { kind: "public" };
|
|
161101
161238
|
promised = await checkMessageCommitments(ctx, game, seat, promises, audience, teamsKnown);
|
|
161102
161239
|
}
|
|
161103
|
-
const
|
|
161240
|
+
const groupIds = group ? listIds(group.recipients.map((r) => r.id)) : "";
|
|
161241
|
+
const words = kind === "group" ? `privately to players ${groupIds} only, in a game group (${group.id !== void 0 ? `group ${group.id}, which exists` : "created first"})` : kind === "private" ? `privately to player ${shownRecipient.id} only` : kind === "team" ? `to your team (team ${chatChannel}) only` : "to everyone in the game";
|
|
161104
161242
|
const teamName = `your team (team ${chatChannel})`;
|
|
161105
161243
|
return {
|
|
161106
161244
|
gate: {
|
|
161107
161245
|
action: "warapp.send_chat",
|
|
161108
|
-
summary: kind === "private" ? `Send a private chat message to player ${shownRecipient.id} in game ${gameId}` : kind === "team" ? `Send a chat message to ${teamName} in game ${gameId}` : `Post a chat message to everyone in game ${gameId}`,
|
|
161246
|
+
summary: kind === "group" ? `Send a group chat message to players ${groupIds} in game ${gameId}` : kind === "private" ? `Send a private chat message to player ${shownRecipient.id} in game ${gameId}` : kind === "team" ? `Send a chat message to ${teamName} in game ${gameId}` : `Post a chat message to everyone in game ${gameId}`,
|
|
161109
161247
|
account,
|
|
161110
161248
|
target: gameId,
|
|
161111
161249
|
payload: {
|
|
@@ -161114,11 +161252,12 @@ function registerChatTools(server, ctx, opts = {}) {
|
|
|
161114
161252
|
text: text2,
|
|
161115
161253
|
channel: chatChannel,
|
|
161116
161254
|
recipient: recipient?.id ?? null,
|
|
161255
|
+
...group ? { group: group.id ?? null, createGroup: group.id === void 0 ? { name: group.name, members: group.members } : null } : {},
|
|
161117
161256
|
...promised ? { commitments: promised.commitments } : {}
|
|
161118
161257
|
},
|
|
161119
161258
|
willSend: {
|
|
161120
161259
|
game: gameId,
|
|
161121
|
-
to: shownRecipient?.name ?? (kind === "team" ? teamName : "everyone in the game"),
|
|
161260
|
+
to: group ? group.recipients.map((r) => r.name).join(", ") : shownRecipient?.name ?? (kind === "team" ? teamName : "everyone in the game"),
|
|
161122
161261
|
message
|
|
161123
161262
|
},
|
|
161124
161263
|
preview: {
|
|
@@ -161128,6 +161267,11 @@ function registerChatTools(server, ctx, opts = {}) {
|
|
|
161128
161267
|
note: kind === "team" ? "Your teammates will see this message; it cannot be unsent. The team channel value is UNVERIFIED live." : "Other players will see this message; it cannot be unsent.",
|
|
161129
161268
|
game: { id: game.id, name: game.name === void 0 ? null : untrustedText(game.name), state: game.state },
|
|
161130
161269
|
...shownRecipient ? { recipient: shownRecipient } : {},
|
|
161270
|
+
...group ? {
|
|
161271
|
+
recipients: group.recipients,
|
|
161272
|
+
group: group.id !== void 0 ? { id: group.id, name: group.name, reused: true } : { create: true, name: untrustedText(group.name) },
|
|
161273
|
+
groupNote: (group.id !== void 0 ? `The game's group ${group.id} holds exactly you and these players: the message goes there.` : groupsRead ? "No game group of exactly you and these players exists: one is created first, named as shown (the members see the name)." : "The game's groups could not be read, so a new group is created first, named as shown (the members see the name), even if one of exactly these players exists.") + ` ${GROUP_UNVERIFIED}`
|
|
161274
|
+
} : {},
|
|
161131
161275
|
...links ? {
|
|
161132
161276
|
rendered: untrustedBody(links.rendered),
|
|
161133
161277
|
links: links.links.map((l) => ({ ...l, name: l.name === null ? null : untrustedText(l.name) })),
|
|
@@ -161151,6 +161295,7 @@ function registerChatTools(server, ctx, opts = {}) {
|
|
|
161151
161295
|
kind,
|
|
161152
161296
|
channel: chatChannel,
|
|
161153
161297
|
...recipient ? { recipient } : {},
|
|
161298
|
+
...group ? { group } : {},
|
|
161154
161299
|
...meInGame2 !== void 0 ? { meInGame: meInGame2 } : {},
|
|
161155
161300
|
...auto ? { automated: true } : {},
|
|
161156
161301
|
account,
|
|
@@ -161165,18 +161310,74 @@ function registerChatTools(server, ctx, opts = {}) {
|
|
|
161165
161310
|
}
|
|
161166
161311
|
};
|
|
161167
161312
|
},
|
|
161168
|
-
async execute({ gameId, text: text2, kind, channel, recipient, meInGame: meInGame2, account, commitments, automated }) {
|
|
161313
|
+
async execute({ gameId, text: text2, kind, channel, recipient, group, meInGame: meInGame2, account, commitments, automated }) {
|
|
161169
161314
|
await requireApprovedAccount(ctx, account);
|
|
161170
|
-
const to = recipient?.name ?? (kind === "team" ? `your team (team ${channel})` : "everyone in the game");
|
|
161315
|
+
const to = group?.recipients ?? recipient?.name ?? (kind === "team" ? `your team (team ${channel})` : "everyone in the game");
|
|
161171
161316
|
const marked = automated ? { automated: true } : {};
|
|
161172
|
-
|
|
161317
|
+
let groupId = group?.id;
|
|
161318
|
+
if (group && groupId === void 0) {
|
|
161319
|
+
let createReply;
|
|
161320
|
+
const notSent2 = (warning) => ({
|
|
161321
|
+
status: "unknown",
|
|
161322
|
+
outcome: "unknown",
|
|
161323
|
+
game: gameId,
|
|
161324
|
+
channel: kind,
|
|
161325
|
+
to,
|
|
161326
|
+
...marked,
|
|
161327
|
+
group: { id: null, created: "unknown" },
|
|
161328
|
+
warning
|
|
161329
|
+
});
|
|
161330
|
+
const made = await sendAndVerify({
|
|
161331
|
+
send: async () => {
|
|
161332
|
+
createReply = await ctx.rpc.call(
|
|
161333
|
+
"CreateGameGroup",
|
|
161334
|
+
Method.CreateGameGroup,
|
|
161335
|
+
(w) => writeCreateGameGroupParams(w, { gameId, name: group.name, members: group.members })
|
|
161336
|
+
);
|
|
161337
|
+
},
|
|
161338
|
+
refused: (e) => new McpToolError(
|
|
161339
|
+
`war.app refused to create the game group (${GROUP_REFUSALS[e.code] ?? e.message}; war.app error ${e.code}): nothing was sent.`,
|
|
161340
|
+
{ hint: "Message each player privately instead, or post to the whole game." }
|
|
161341
|
+
),
|
|
161342
|
+
unanswered: (failure2) => notSent2(
|
|
161343
|
+
`war.app did not answer the game group's creation (${failure2}), so a group may now exist, but the message was NOT sent. Look at the game's groups in the web client before sending again.`
|
|
161344
|
+
),
|
|
161345
|
+
readBack: async () => {
|
|
161346
|
+
const id = createReply ? readCreateGameGroupReply(await ctx.bundle(), createReply.body) : void 0;
|
|
161347
|
+
if (id === void 0) throw new Error("its reply named no group");
|
|
161348
|
+
return id;
|
|
161349
|
+
},
|
|
161350
|
+
unreadable: (failure2) => notSent2(
|
|
161351
|
+
`war.app accepted the game group's creation, but ${failure2}, so the message was NOT sent. Look at the game's groups in the web client, then send it again (an existing group of exactly these players is reused).`
|
|
161352
|
+
),
|
|
161353
|
+
classify: (id) => id
|
|
161354
|
+
});
|
|
161355
|
+
if (typeof made !== "number") {
|
|
161356
|
+
return commitments ? {
|
|
161357
|
+
...made,
|
|
161358
|
+
commitments: {
|
|
161359
|
+
recorded: [],
|
|
161360
|
+
why: "The message was NOT sent (the game group could not be confirmed), so its commitments were not made: nothing to record."
|
|
161361
|
+
}
|
|
161362
|
+
} : made;
|
|
161363
|
+
}
|
|
161364
|
+
groupId = made;
|
|
161365
|
+
}
|
|
161366
|
+
const groupOut = group ? { group: { id: groupId, created: group.id === void 0 } } : {};
|
|
161367
|
+
const base = { status: "sent", game: gameId, channel: kind, to, ...groupOut, ...marked };
|
|
161173
161368
|
let reply;
|
|
161174
161369
|
const result2 = await sendAndVerify({
|
|
161175
161370
|
send: async () => {
|
|
161176
161371
|
reply = await ctx.rpc.call(
|
|
161177
161372
|
"SendChat",
|
|
161178
161373
|
Method.SendChat,
|
|
161179
|
-
(w) => writeSendChatParams(w, {
|
|
161374
|
+
(w) => writeSendChatParams(w, {
|
|
161375
|
+
gameId,
|
|
161376
|
+
text: text2,
|
|
161377
|
+
channel,
|
|
161378
|
+
...recipient ? { recipient: recipient.id } : {},
|
|
161379
|
+
...groupId !== void 0 ? { group: groupId } : {}
|
|
161380
|
+
})
|
|
161180
161381
|
);
|
|
161181
161382
|
},
|
|
161182
161383
|
// A refusal is rethrown (nothing was posted; 36, too many messages, is never retried).
|
|
@@ -161186,6 +161387,7 @@ function registerChatTools(server, ctx, opts = {}) {
|
|
|
161186
161387
|
game: gameId,
|
|
161187
161388
|
channel: kind,
|
|
161188
161389
|
to,
|
|
161390
|
+
...groupOut,
|
|
161189
161391
|
...marked,
|
|
161190
161392
|
warning: `war.app did not confirm this message (${failure2}), so it may already have been posted. Check warapp_get_chat before sending it again.`
|
|
161191
161393
|
}),
|
|
@@ -161198,7 +161400,7 @@ function registerChatTools(server, ctx, opts = {}) {
|
|
|
161198
161400
|
// A reply this server cannot read: war.app's acceptance is all there is.
|
|
161199
161401
|
unreadable: () => ({ ...base, outcome: "accepted" }),
|
|
161200
161402
|
classify: (lines) => {
|
|
161201
|
-
const onChannel = (l) => kind === "private" ? l.channel === "private" && l.to === recipient?.id : kind === "team" ? l.channel === "team" && l.team === channel : l.channel === "public";
|
|
161403
|
+
const onChannel = (l) => kind === "group" ? l.group === groupId : kind === "private" ? l.channel === "private" && l.to === recipient?.id : kind === "team" ? l.channel === "team" && l.team === channel : l.channel === "public";
|
|
161202
161404
|
const newest = lines.filter((l) => meInGame2 !== void 0 && l.sender === meInGame2 && onChannel(l)).at(-1);
|
|
161203
161405
|
const same3 = (a) => a.replace(/\s+/g, " ").trim() === text2.replace(/\s+/g, " ").trim();
|
|
161204
161406
|
if (newest && same3(newest.text)) return { ...base, outcome: "confirmed" };
|
|
@@ -173339,6 +173541,50 @@ function openingFlags(input2) {
|
|
|
173339
173541
|
const bt = input2.booted?.turn ?? null;
|
|
173340
173542
|
return { noOrderTurns, bootedTurn: bt !== null && bt >= 1 && bt <= window ? bt : null };
|
|
173341
173543
|
}
|
|
173544
|
+
function openingLosses(input2) {
|
|
173545
|
+
const window = input2.window ?? OPENING_WINDOW;
|
|
173546
|
+
const boards = new Map(input2.history.map((b) => [b.turn, b.board]));
|
|
173547
|
+
const friends = /* @__PURE__ */ new Set([input2.player, ...input2.allies ?? []]);
|
|
173548
|
+
let territories = 0;
|
|
173549
|
+
const turns = [];
|
|
173550
|
+
for (let n = 1; n <= window; n++) {
|
|
173551
|
+
const before = boards.get(n - 1);
|
|
173552
|
+
const after = boards.get(n);
|
|
173553
|
+
if (!before || !after) continue;
|
|
173554
|
+
const had = landOf3(before, input2.player);
|
|
173555
|
+
let lost = 0;
|
|
173556
|
+
for (const t of after.territories)
|
|
173557
|
+
if (had.has(t.territoryId) && t.owner.kind === "player" && !friends.has(t.owner.playerId)) lost++;
|
|
173558
|
+
if (lost) {
|
|
173559
|
+
territories += lost;
|
|
173560
|
+
turns.push(n);
|
|
173561
|
+
}
|
|
173562
|
+
}
|
|
173563
|
+
return { territories, turns };
|
|
173564
|
+
}
|
|
173565
|
+
function lossAggregate(entries2) {
|
|
173566
|
+
const won = entries2.filter((e) => e.winner !== null);
|
|
173567
|
+
return {
|
|
173568
|
+
games: entries2.length,
|
|
173569
|
+
withWinner: won.length,
|
|
173570
|
+
iWon: entries2.filter((e) => e.iWon).length,
|
|
173571
|
+
iLost: entries2.filter((e) => e.mine.territories > 0).length,
|
|
173572
|
+
winnerLost: won.filter((e) => e.winner.territories > 0).length,
|
|
173573
|
+
myTerritories: entries2.reduce((n, e) => n + e.mine.territories, 0),
|
|
173574
|
+
winnerTerritories: won.reduce((n, e) => n + e.winner.territories, 0)
|
|
173575
|
+
};
|
|
173576
|
+
}
|
|
173577
|
+
function earlyLossesByEra(entries2) {
|
|
173578
|
+
const out = {};
|
|
173579
|
+
for (const era of ["pre-tool", "pre-rule-4f", "current"]) {
|
|
173580
|
+
const of = entries2.filter((e) => e.era === era);
|
|
173581
|
+
if (!of.length) continue;
|
|
173582
|
+
const byFormat = {};
|
|
173583
|
+
for (const f of [...new Set(of.map((e) => e.format))].sort()) byFormat[f] = lossAggregate(of.filter((e) => e.format === f));
|
|
173584
|
+
out[era] = { all: lossAggregate(of), byFormat };
|
|
173585
|
+
}
|
|
173586
|
+
return out;
|
|
173587
|
+
}
|
|
173342
173588
|
var LARGE_MAP_FACTOR = 5;
|
|
173343
173589
|
function benchmarkByEra(entries2) {
|
|
173344
173590
|
const basis = {};
|
|
@@ -173479,6 +173725,7 @@ async function calibrationHarness(dir, opts = {}) {
|
|
|
173479
173725
|
const byFormat = {};
|
|
173480
173726
|
const benchByFormat = {};
|
|
173481
173727
|
const eraEntries = [];
|
|
173728
|
+
const lossEntries = [];
|
|
173482
173729
|
let done = 0;
|
|
173483
173730
|
for (const input2 of src.inputs) {
|
|
173484
173731
|
opts.signal?.throwIfAborted();
|
|
@@ -173520,11 +173767,25 @@ async function calibrationHarness(dir, opts = {}) {
|
|
|
173520
173767
|
winners: seated.filter((p) => p.state === "Won").map((p) => p.id),
|
|
173521
173768
|
...opts.turns ? { turns: opts.turns } : {}
|
|
173522
173769
|
});
|
|
173770
|
+
const o = input2.opening;
|
|
173771
|
+
const { era, basis } = openingEra({ planned: o.planned, ...o.gameId !== void 0 ? { gameId: o.gameId } : {} });
|
|
173772
|
+
const allies = (id) => {
|
|
173773
|
+
const team = seated.find((p) => p.id === id)?.team;
|
|
173774
|
+
return typeof team === "number" && team >= 0 ? seated.filter((p) => p.id !== id && p.team === team).map((p) => p.id) : [];
|
|
173775
|
+
};
|
|
173776
|
+
const won = seated.filter((p) => p.state === "Won").map((p) => p.id);
|
|
173777
|
+
const iWon = won.includes(me);
|
|
173778
|
+
const winner = iWon ? me : won[0];
|
|
173779
|
+
lossEntries.push({
|
|
173780
|
+
era,
|
|
173781
|
+
format,
|
|
173782
|
+
mine: openingLosses({ player: me, history: h.boards, allies: allies(me) }),
|
|
173783
|
+
winner: winner === void 0 ? null : openingLosses({ player: winner, history: h.boards, allies: allies(winner) }),
|
|
173784
|
+
iWon
|
|
173785
|
+
});
|
|
173523
173786
|
if (bench.turns.length) {
|
|
173524
173787
|
counts.benchmarked++;
|
|
173525
173788
|
(benchByFormat[format] ??= []).push(bench);
|
|
173526
|
-
const o = input2.opening;
|
|
173527
|
-
const { era, basis } = openingEra({ planned: o.planned, ...o.gameId !== void 0 ? { gameId: o.gameId } : {} });
|
|
173528
173789
|
const flags = openingFlags({
|
|
173529
173790
|
me,
|
|
173530
173791
|
history: h.boards,
|
|
@@ -173545,7 +173806,7 @@ async function calibrationHarness(dir, opts = {}) {
|
|
|
173545
173806
|
const benchmark = {};
|
|
173546
173807
|
for (const [format, list4] of Object.entries(benchByFormat)) benchmark[format] = aggregateBenchmarks(list4);
|
|
173547
173808
|
benchmark.all = aggregateBenchmarks(Object.values(benchByFormat).flat());
|
|
173548
|
-
return { counts, calibration, benchmark, byEra: benchmarkByEra(eraEntries) };
|
|
173809
|
+
return { counts, calibration, benchmark, byEra: benchmarkByEra(eraEntries), earlyLosses: earlyLossesByEra(lossEntries) };
|
|
173549
173810
|
}
|
|
173550
173811
|
|
|
173551
173812
|
// src/tools/calibration-job.ts
|
package/dist/chat.js
CHANGED
|
@@ -17,6 +17,7 @@ import { asInt } from './scalars.js';
|
|
|
17
17
|
export const GAME_DETAILS_AND_CHAT = 'warlight.shared.GameDetailsAndChat';
|
|
18
18
|
export const GAME_MESSAGE = 'warlight.shared.GameMessage';
|
|
19
19
|
export const MESSAGE_REACTION = 'warlight.shared.MessageReaction';
|
|
20
|
+
export const GAME_GROUP = 'warlight.shared.GameGroup';
|
|
20
21
|
/**
|
|
21
22
|
* `warlight.shared.ReactionType`, one byte, by its value (#634): the client's reaction menu lists exactly these five
|
|
22
23
|
* (its labels "Thumbs up", "Thumbs down", "Heart", "Laugh", "Angry").
|
|
@@ -24,6 +25,14 @@ export const MESSAGE_REACTION = 'warlight.shared.MessageReaction';
|
|
|
24
25
|
export const REACTION_TYPES = ['thumbs-up', 'thumbs-down', 'heart', 'laugh', 'angry'];
|
|
25
26
|
/** GameDetailsAndChat's reactions (243): a dict of message id → that message's reactions, read by position. */
|
|
26
27
|
const GDC_REACTIONS = 5;
|
|
28
|
+
/** GameDetailsAndChat's game groups: a list of optional `GameGroup`, last. */
|
|
29
|
+
const GDC_GROUPS = 6;
|
|
30
|
+
/**
|
|
31
|
+
* GameGroup field positions in read order (docs/WEB-PROTOCOL.md, Chat): colour, creator, moderator, game id, the group
|
|
32
|
+
* id, metadata, name, then the members as text (a JSON array of in-game ids, the creator included).
|
|
33
|
+
*/
|
|
34
|
+
const GG = { creator: 1, gameId: 3, id: 4, name: 6, members: 7 };
|
|
35
|
+
const GAME_GROUP_FIELDS = 8;
|
|
27
36
|
/**
|
|
28
37
|
* GameMessage field positions in read order, and its whole field count (protocol 243: the shared images,
|
|
29
38
|
* an optional list of strings, at 5, and the reactions, an optional list of records, at 7).
|
|
@@ -195,6 +204,70 @@ function applyReactionsDict(lines, dict) {
|
|
|
195
204
|
setReactions(line, byId.get(line.id));
|
|
196
205
|
}
|
|
197
206
|
}
|
|
207
|
+
/** The members text of a GameGroup: a JSON array of in-game ids, else `null`. */
|
|
208
|
+
function groupMembers(text) {
|
|
209
|
+
if (typeof text !== 'string')
|
|
210
|
+
return null;
|
|
211
|
+
try {
|
|
212
|
+
const v = JSON.parse(text);
|
|
213
|
+
if (!Array.isArray(v))
|
|
214
|
+
return null;
|
|
215
|
+
const ids = v.map((x) => (typeof x === 'string' && /^-?\d+$/.test(x) ? Number(x) : x));
|
|
216
|
+
return ids.every(isInt) ? ids : null;
|
|
217
|
+
}
|
|
218
|
+
catch {
|
|
219
|
+
return null;
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
/**
|
|
223
|
+
* The game's groups from a GameRefresh reply (the body at the result-present flag): `[]` when the list is there and
|
|
224
|
+
* empty, `undefined` when it is absent, there is no result, or the shape is not understood. Never throws.
|
|
225
|
+
*/
|
|
226
|
+
export function readGameGroups(bundle, body) {
|
|
227
|
+
try {
|
|
228
|
+
if (!body.bool())
|
|
229
|
+
return undefined;
|
|
230
|
+
const ret = bundle.readClass(GAME_DETAILS_AND_CHAT, body);
|
|
231
|
+
if (!isObj(ret) || ret.$type !== GAME_DETAILS_AND_CHAT)
|
|
232
|
+
return undefined;
|
|
233
|
+
const list = fields(ret)[GDC_GROUPS];
|
|
234
|
+
if (!Array.isArray(list))
|
|
235
|
+
return undefined;
|
|
236
|
+
const out = [];
|
|
237
|
+
for (const g of list) {
|
|
238
|
+
if (g === null)
|
|
239
|
+
continue;
|
|
240
|
+
if (!isObj(g) || g.$type !== GAME_GROUP)
|
|
241
|
+
return undefined;
|
|
242
|
+
const f = fields(g);
|
|
243
|
+
if (f.length !== GAME_GROUP_FIELDS)
|
|
244
|
+
return undefined;
|
|
245
|
+
const [id, gameId, creator, name] = [f[GG.id], f[GG.gameId], f[GG.creator], f[GG.name]];
|
|
246
|
+
if (!isInt(id) || !isInt(gameId) || !isInt(creator) || typeof name !== 'string')
|
|
247
|
+
return undefined;
|
|
248
|
+
out.push({ id, gameId, creator, name, members: groupMembers(f[GG.members]) });
|
|
249
|
+
}
|
|
250
|
+
return out;
|
|
251
|
+
}
|
|
252
|
+
catch {
|
|
253
|
+
return undefined;
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
/**
|
|
257
|
+
* The CreateGameGroup reply: a present flag, then the group's first message, whose game-group field is the new group's
|
|
258
|
+
* id. `undefined` when there is no result or no group id in it. Never throws.
|
|
259
|
+
*/
|
|
260
|
+
export function readCreateGameGroupReply(bundle, body) {
|
|
261
|
+
try {
|
|
262
|
+
if (!body.bool())
|
|
263
|
+
return undefined;
|
|
264
|
+
const line = webLine(bundle.readClass(GAME_MESSAGE, body));
|
|
265
|
+
return line?.group;
|
|
266
|
+
}
|
|
267
|
+
catch {
|
|
268
|
+
return undefined;
|
|
269
|
+
}
|
|
270
|
+
}
|
|
198
271
|
/**
|
|
199
272
|
* The SendChat reply: the updated message list, read straight after the result-present flag (each
|
|
200
273
|
* message behind its own present flag), oldest first; `undefined` when it cannot be read. The replies of
|
package/dist/protocol/methods.js
CHANGED
|
@@ -103,6 +103,8 @@ export const Method = {
|
|
|
103
103
|
ForumVote: 204,
|
|
104
104
|
WatchForumThread: 328,
|
|
105
105
|
GetGroupForumThreads: 354,
|
|
106
|
+
/** A game group: a private conversation of several players in one game (the bundle's writer; UNVERIFIED live). */
|
|
107
|
+
CreateGameGroup: 356,
|
|
106
108
|
Subscribe: 243,
|
|
107
109
|
/** #633: the client's "Game Invite Code" screen (`GameInviteCode` reply); read from the bundle, UNVERIFIED live. */
|
|
108
110
|
GetGameByInviteCode: 295,
|
|
@@ -486,6 +488,23 @@ function checkIds(ids, what) {
|
|
|
486
488
|
function writeOptionalIntList(w, ids) {
|
|
487
489
|
w.bool(true).list(ids, (ww, id) => ww.int32(id));
|
|
488
490
|
}
|
|
491
|
+
/** The colour a new game group gets: the client's default, "Normal". */
|
|
492
|
+
export const GAME_GROUP_COLOUR = 13811880;
|
|
493
|
+
/**
|
|
494
|
+
* CreateGameGroup(auth, …) — the client's "Create Game Group": the int32 game id, the name (string), the int32 colour
|
|
495
|
+
* ({@link GAME_GROUP_COLOUR}), then a present, counted list of the other members' int32 in-game ids. Reply: a present
|
|
496
|
+
* flag and the group's first `GameMessage`, whose game-group field is the new group's id. Read from the bundle's
|
|
497
|
+
* writer; UNVERIFIED live.
|
|
498
|
+
*/
|
|
499
|
+
export function writeCreateGameGroupParams(w, p) {
|
|
500
|
+
if (p.members.length === 0)
|
|
501
|
+
throw new RangeError('no members');
|
|
502
|
+
checkIds(p.members, 'player id');
|
|
503
|
+
if (p.name.trim() === '')
|
|
504
|
+
throw new RangeError('a game group needs a name');
|
|
505
|
+
w.int32(p.gameId).string(p.name).int32(GAME_GROUP_COLOUR);
|
|
506
|
+
writeOptionalIntList(w, p.members);
|
|
507
|
+
}
|
|
489
508
|
/**
|
|
490
509
|
* CreatePrivateDiscussion(auth, …) — the client's "Send mail": the subject (string), a present list (int32 count) of
|
|
491
510
|
* the recipients' int32 ids, the body (string), an optional list of shared-image strings (sent absent), then the
|
|
@@ -829,20 +848,27 @@ export function writeRetrievePrivateMessageHistoryParams(w, p) {
|
|
|
829
848
|
/**
|
|
830
849
|
* SendChat(auth, …) per docs/WEB-PROTOCOL.md (read from the client's
|
|
831
850
|
* serializer; the owner verifies it live): game id, text, channel, optional
|
|
832
|
-
* private recipient, optional game-group id
|
|
851
|
+
* private recipient, optional game-group id, two marker strings
|
|
833
852
|
* (`-1`: seen nothing), two optional "last seen" dicts (absent). An optional int32 is a
|
|
834
853
|
* present flag then the value.
|
|
835
854
|
*/
|
|
836
855
|
export function writeSendChatParams(w, p) {
|
|
856
|
+
if (p.group !== undefined && p.recipient !== undefined)
|
|
857
|
+
throw new RangeError('a message cannot go both to a group and privately');
|
|
837
858
|
w.int32(p.gameId).string(p.text).int32(p.channel ?? CHAT_CHANNEL_PUBLIC);
|
|
838
859
|
if (p.recipient === undefined)
|
|
839
860
|
w.bool(false);
|
|
840
861
|
else
|
|
841
862
|
w.bool(true).int32(p.recipient);
|
|
863
|
+
if (p.group === undefined)
|
|
864
|
+
w.bool(false);
|
|
865
|
+
else {
|
|
866
|
+
checkIds([p.group], 'game group id');
|
|
867
|
+
w.bool(true).int32(p.group);
|
|
868
|
+
}
|
|
842
869
|
// The two chat markers are the last message seen on each channel: war.app parses them as numbers
|
|
843
870
|
// (ParseLongSafe), so a null one is refused (server error 1); a client that has seen nothing sends `-1`.
|
|
844
|
-
w.
|
|
845
|
-
.string(NO_CHAT_MARKER)
|
|
871
|
+
w.string(NO_CHAT_MARKER)
|
|
846
872
|
.string(NO_CHAT_MARKER)
|
|
847
873
|
.bool(false)
|
|
848
874
|
.bool(false)
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
import { profileFormatOf } from '../analysis/opponent-profile.js';
|
|
7
7
|
import { trackGame } from '../analysis/opponents.js';
|
|
8
8
|
import { applyBonusOverrides } from '../analysis/overrides.js';
|
|
9
|
-
import { aggregateBenchmarks, aggregateEstimates, benchmarkByEra, estimateSamples, openingBenchmark, openingEra, openingFlags, ratioSummary, } from '../analysis/calibrate.js';
|
|
9
|
+
import { aggregateBenchmarks, aggregateEstimates, benchmarkByEra, earlyLossesByEra, estimateSamples, openingBenchmark, openingEra, openingFlags, openingLosses, ratioSummary, } from '../analysis/calibrate.js';
|
|
10
10
|
import { addCalibration } from '../analysis/game-lessons.js';
|
|
11
11
|
import { calibrationSources } from '../calibration-source.js';
|
|
12
12
|
import { holdsSeat } from '../player-states.js';
|
|
@@ -32,6 +32,7 @@ export async function calibrationHarness(dir, opts = {}) {
|
|
|
32
32
|
const byFormat = {};
|
|
33
33
|
const benchByFormat = {};
|
|
34
34
|
const eraEntries = [];
|
|
35
|
+
const lossEntries = [];
|
|
35
36
|
let done = 0;
|
|
36
37
|
for (const input of src.inputs) {
|
|
37
38
|
opts.signal?.throwIfAborted();
|
|
@@ -76,13 +77,28 @@ export async function calibrationHarness(dir, opts = {}) {
|
|
|
76
77
|
winners: seated.filter((p) => p.state === 'Won').map((p) => p.id),
|
|
77
78
|
...(opts.turns ? { turns: opts.turns } : {}),
|
|
78
79
|
});
|
|
80
|
+
// #503: the era (turn-1 time where known — no record keeps one yet — else the game id).
|
|
81
|
+
const o = input.opening;
|
|
82
|
+
const { era, basis } = openingEra({ planned: o.planned, ...(o.gameId !== undefined ? { gameId: o.gameId } : {}) });
|
|
83
|
+
// #506: land lost to a player in the opening, mine against the winner's (a teammate's capture is no loss).
|
|
84
|
+
const allies = (id) => {
|
|
85
|
+
const team = seated.find((p) => p.id === id)?.team;
|
|
86
|
+
return typeof team === 'number' && team >= 0 ? seated.filter((p) => p.id !== id && p.team === team).map((p) => p.id) : [];
|
|
87
|
+
};
|
|
88
|
+
const won = seated.filter((p) => p.state === 'Won').map((p) => p.id);
|
|
89
|
+
const iWon = won.includes(me);
|
|
90
|
+
const winner = iWon ? me : won[0];
|
|
91
|
+
lossEntries.push({
|
|
92
|
+
era,
|
|
93
|
+
format,
|
|
94
|
+
mine: openingLosses({ player: me, history: h.boards, allies: allies(me) }),
|
|
95
|
+
winner: winner === undefined ? null : openingLosses({ player: winner, history: h.boards, allies: allies(winner) }),
|
|
96
|
+
iWon,
|
|
97
|
+
});
|
|
79
98
|
if (bench.turns.length) {
|
|
80
99
|
counts.benchmarked++;
|
|
81
100
|
(benchByFormat[format] ??= []).push(bench);
|
|
82
|
-
// #503: the
|
|
83
|
-
// opening window's flags (turns with no orders of mine, a boot of my seat).
|
|
84
|
-
const o = input.opening;
|
|
85
|
-
const { era, basis } = openingEra({ planned: o.planned, ...(o.gameId !== undefined ? { gameId: o.gameId } : {}) });
|
|
101
|
+
// #503: the opening window's flags (turns with no orders of mine, a boot of my seat).
|
|
86
102
|
const flags = openingFlags({
|
|
87
103
|
me,
|
|
88
104
|
history: h.boards,
|
|
@@ -105,5 +121,5 @@ export async function calibrationHarness(dir, opts = {}) {
|
|
|
105
121
|
for (const [format, list] of Object.entries(benchByFormat))
|
|
106
122
|
benchmark[format] = aggregateBenchmarks(list);
|
|
107
123
|
benchmark.all = aggregateBenchmarks(Object.values(benchByFormat).flat());
|
|
108
|
-
return { counts, calibration, benchmark, byEra: benchmarkByEra(eraEntries) };
|
|
124
|
+
return { counts, calibration, benchmark, byEra: benchmarkByEra(eraEntries), earlyLosses: earlyLossesByEra(lossEntries) };
|
|
109
125
|
}
|
package/dist/tools/chat.js
CHANGED
|
@@ -4,12 +4,12 @@
|
|
|
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, mergeChatLines, oldestId, readGameRefreshChat, readMessageHistoryReply, readSendChatReply, } from '../chat.js';
|
|
7
|
+
import { CHAT_CHANNELS, feedChatLines, fillFromFeed, mergeChatLines, oldestId, readCreateGameGroupReply, readGameGroups, 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
10
|
import { inGameId, inGameOf, playersByInGameId } from '../live.js';
|
|
11
11
|
import { decodeChatLinks, encodeChatLinks, hasChatLinkMarkers } from '../chat-links.js';
|
|
12
|
-
import { CHAT_CHANNEL_PUBLIC, Method, writeGameRefreshParams, writeRetrieveChatParams, writeRetrievePrivateMessageHistoryParams, writeSendChatParams, } from '../protocol/methods.js';
|
|
12
|
+
import { CHAT_CHANNEL_PUBLIC, Method, writeGameRefreshParams, writeRetrieveChatParams, writeCreateGameGroupParams, writeRetrievePrivateMessageHistoryParams, writeSendChatParams, } from '../protocol/methods.js';
|
|
13
13
|
import { carriesTeam } from '../teams.js';
|
|
14
14
|
import { gameIdArg, readAnnotations, respond, UNTRUSTED_PREVIEW_NOTE, untrustedBody, untrustedDescription, untrustedText, } from './common.js';
|
|
15
15
|
import { checkMessageCommitments, commitmentsArg, COMMITMENTS_NOTE, DEFAULT_PLAN_CHECKED } from './commitments.js';
|
|
@@ -24,6 +24,40 @@ import { AUTOMATED_CHAT_OFF, chatAutomationMode } from '../chat-automation.js';
|
|
|
24
24
|
import { resolveTeams } from './team-source.js';
|
|
25
25
|
const DEFAULT_LIMIT = 50;
|
|
26
26
|
const MAX_CHAT_LENGTH = 2000;
|
|
27
|
+
/** The most players one game-group message names (`to` as a list). */
|
|
28
|
+
export const MAX_GROUP_RECIPIENTS = 10;
|
|
29
|
+
/** The most characters of a new game group's name. */
|
|
30
|
+
const MAX_GROUP_NAME = 50;
|
|
31
|
+
/** A new game group's name when none is given: it is shown to the members. */
|
|
32
|
+
export const DEFAULT_GROUP_NAME = 'Group chat';
|
|
33
|
+
/** CreateGameGroup's refusals as the client words them. */
|
|
34
|
+
const GROUP_REFUSALS = {
|
|
35
|
+
227: 'a player in it has blocked you',
|
|
36
|
+
751: 'this game does not allow game groups',
|
|
37
|
+
};
|
|
38
|
+
/** Ids as "1, 2 and 3". */
|
|
39
|
+
const listIds = (ids) => (ids.length > 1 ? `${ids.slice(0, -1).join(', ')} and ${ids.at(-1)}` : String(ids[0]));
|
|
40
|
+
/**
|
|
41
|
+
* The game's newest group holding exactly me and `members` (in-game ids), from one GameRefresh with the game details.
|
|
42
|
+
* `read: false` when the groups could not be read (a failed request, or a reply without them). Never throws.
|
|
43
|
+
*/
|
|
44
|
+
async function existingGroup(ctx, game, meInGame, members) {
|
|
45
|
+
try {
|
|
46
|
+
const env = await ctx.rpc.call('GameRefresh', Method.GameRefresh, (w) => writeGameRefreshParams(w, { gameId: game.id, chat: false, nonChat: true, lobby: game.state === 'WaitingForPlayers' }));
|
|
47
|
+
const groups = readGameGroups(await ctx.bundle(), env.body);
|
|
48
|
+
if (!groups)
|
|
49
|
+
return { read: false };
|
|
50
|
+
const want = new Set([meInGame, ...members]);
|
|
51
|
+
const same = groups
|
|
52
|
+
.filter((g) => g.gameId === game.id && g.members !== null && new Set(g.members).size === want.size && g.members.every((m) => want.has(m)))
|
|
53
|
+
.sort((a, b) => b.id - a.id);
|
|
54
|
+
return same[0] ? { read: true, group: same[0] } : { read: true };
|
|
55
|
+
}
|
|
56
|
+
catch {
|
|
57
|
+
return { read: false };
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
const GROUP_UNVERIFIED = 'Game groups (creating one, and a message to one) are read from the client bundle and UNVERIFIED live.';
|
|
27
61
|
/** The send preview's note on links: what goes out, and what is verified. */
|
|
28
62
|
const LINKS_NOTE = 'Each link goes out as the client\'s token (`<a t=ID>` territory, `<a b=ID>` bonus) and players see the name from ' +
|
|
29
63
|
'the map. Territory and bonus links are verified live (2026-11-23).';
|
|
@@ -436,8 +470,9 @@ export function registerChatTools(server, ctx, opts = {}) {
|
|
|
436
470
|
}, {
|
|
437
471
|
name: 'warapp_send_chat',
|
|
438
472
|
description: 'Post a chat message in a war.app (Warzone) game — to the whole game, to your team (`channel: "team"`, in ' +
|
|
439
|
-
'a team game), or privately to one named player (`to
|
|
440
|
-
'
|
|
473
|
+
'a team game), or privately to one named player (`to`), or to several together (`to` as a list: a war.app game ' +
|
|
474
|
+
'group, reused when one of exactly you and them exists, else created first, named by `group_name`; UNVERIFIED live); ' +
|
|
475
|
+
'private sends are refused when the game turns private messages off. The message reaches other players and cannot be unsent. Sent through your signed-in war.app tab ' +
|
|
441
476
|
'(ContextMint Bridge); the game is read from GameFeed first, so the GameFeed credentials are needed too. ' +
|
|
442
477
|
"The result's `outcome` is `confirmed` when war.app's reply lists it as your newest message on that " +
|
|
443
478
|
'channel, `accepted` when the reply cannot be read, `unconfirmed` when it does not show it. ' +
|
|
@@ -478,9 +513,19 @@ export function registerChatTools(server, ctx, opts = {}) {
|
|
|
478
513
|
.optional()
|
|
479
514
|
.describe('"public" (default): the whole game. "team": your team only (a team game). Not with `to`.'),
|
|
480
515
|
to: z
|
|
481
|
-
.union([z.string(), z.number()])
|
|
516
|
+
.union([z.string(), z.number(), z.array(z.union([z.string(), z.number()])).min(1).max(MAX_GROUP_RECIPIENTS)])
|
|
517
|
+
.optional()
|
|
518
|
+
.describe('A player (name or GameFeed id) to message privately, or a list of 2 to ' +
|
|
519
|
+
`${MAX_GROUP_RECIPIENTS} players to message together in a game group (one private conversation they all read). ` +
|
|
520
|
+
'Omit to post to a channel.'),
|
|
521
|
+
group_name: z
|
|
522
|
+
.string()
|
|
523
|
+
.trim()
|
|
524
|
+
.min(1)
|
|
525
|
+
.max(MAX_GROUP_NAME)
|
|
482
526
|
.optional()
|
|
483
|
-
.describe(
|
|
527
|
+
.describe(`A list \`to\` only: the name of the game group if one has to be created (default "${DEFAULT_GROUP_NAME}"; the members see it). ` +
|
|
528
|
+
'An existing group of exactly these players is reused, keeping its name.'),
|
|
484
529
|
commitments: commitmentsArg,
|
|
485
530
|
automated: z
|
|
486
531
|
.boolean()
|
|
@@ -488,7 +533,7 @@ export function registerChatTools(server, ctx, opts = {}) {
|
|
|
488
533
|
.describe('true when you send a reply the owner did not tell you to send (an automated reply). Refused unless ' +
|
|
489
534
|
'WARAPP_CHAT_AUTOMATION is on; default false (a send the owner asked for).'),
|
|
490
535
|
}),
|
|
491
|
-
async plan({ game_id, message, channel, to, commitments, automated, link_territories }) {
|
|
536
|
+
async plan({ game_id, message, channel, to, group_name, commitments, automated, link_territories }) {
|
|
492
537
|
// #415: an automated reply is refused with the gate off, before any request.
|
|
493
538
|
const auto = automated === true;
|
|
494
539
|
if (auto && (ctx.chatAutomation ?? chatAutomationMode(opts.env ?? process.env)) !== 'on') {
|
|
@@ -497,7 +542,19 @@ export function registerChatTools(server, ctx, opts = {}) {
|
|
|
497
542
|
});
|
|
498
543
|
}
|
|
499
544
|
const gameId = parseGameId(game_id);
|
|
500
|
-
|
|
545
|
+
// A list `to` of two or more players is a game group; a list of one is a private message to that player.
|
|
546
|
+
const toList = Array.isArray(to) ? to.filter((x) => String(x).trim() !== '') : undefined;
|
|
547
|
+
const grouped = toList !== undefined && toList.length >= 2;
|
|
548
|
+
const single = toList ? (toList.length === 1 ? toList[0] : undefined) : Array.isArray(to) ? undefined : to;
|
|
549
|
+
const privately = grouped || (single !== undefined && String(single).trim() !== '');
|
|
550
|
+
if (toList !== undefined && toList.length === 0) {
|
|
551
|
+
throw new McpToolError('`to` lists no player: nothing was sent.', { hint: 'Name the players to message, or omit `to` to post to the whole game.' });
|
|
552
|
+
}
|
|
553
|
+
if (group_name !== undefined && !grouped) {
|
|
554
|
+
throw new McpToolError('`group_name` names a game group, which only a list of two or more players in `to` uses: nothing was sent.', {
|
|
555
|
+
hint: 'Pass `to` as a list of the players to message together, or drop `group_name`.',
|
|
556
|
+
});
|
|
557
|
+
}
|
|
501
558
|
if (privately && channel === 'team') {
|
|
502
559
|
throw new McpToolError('A private message (`to`) cannot also go to the team channel: nothing was sent.', {
|
|
503
560
|
hint: 'Omit `to` to message your team, or omit `channel` to message one player privately.',
|
|
@@ -538,11 +595,42 @@ export function registerChatTools(server, ctx, opts = {}) {
|
|
|
538
595
|
let chatChannel = CHAT_CHANNEL_PUBLIC;
|
|
539
596
|
let recipient;
|
|
540
597
|
let shownRecipient;
|
|
598
|
+
let group;
|
|
599
|
+
let groupsRead = true;
|
|
541
600
|
if (privately) {
|
|
542
601
|
if (game.settings?.privateMessaging === false) {
|
|
543
602
|
throw new McpToolError(`Game ${gameId} turns private messaging off (its PrivateMessaging setting), so nothing was sent.`, { hint: 'Post to the whole game instead: the host turned private messages off.' });
|
|
544
603
|
}
|
|
545
|
-
|
|
604
|
+
}
|
|
605
|
+
if (grouped) {
|
|
606
|
+
const people = toList.map((x) => resolvePlayer(game.players, x));
|
|
607
|
+
const mine = people.find((p) => p.id === me);
|
|
608
|
+
if (mine) {
|
|
609
|
+
throw new McpToolError(`${untrustedText(mine.name)} (${mine.id}) is you: list only the other players in \`to\`. Nothing was sent.`, {
|
|
610
|
+
hint: 'The group includes you anyway: name the players to message with you.',
|
|
611
|
+
});
|
|
612
|
+
}
|
|
613
|
+
const twice = people.find((p, i) => people.findIndex((q) => q.id === p.id) !== i);
|
|
614
|
+
if (twice) {
|
|
615
|
+
throw new McpToolError(`Player ${twice.id} is named twice in \`to\`: nothing was sent.`, { hint: 'Name each player once.' });
|
|
616
|
+
}
|
|
617
|
+
if (meInGame === undefined) {
|
|
618
|
+
throw new McpToolError(`Your seat in game ${gameId} has no in-game id, so a game group cannot be made: nothing was sent.`, {
|
|
619
|
+
hint: 'Message each player privately instead.',
|
|
620
|
+
});
|
|
621
|
+
}
|
|
622
|
+
kind = 'group';
|
|
623
|
+
const members = people.map((p) => inGameId(p));
|
|
624
|
+
const found = await existingGroup(ctx, game, meInGame, members);
|
|
625
|
+
groupsRead = found.read;
|
|
626
|
+
group = {
|
|
627
|
+
...(found.group ? { id: found.group.id, name: untrustedText(found.group.name) } : { name: group_name ?? DEFAULT_GROUP_NAME }),
|
|
628
|
+
members,
|
|
629
|
+
recipients: people.map((p) => ({ id: p.id, name: untrustedText(p.name) })),
|
|
630
|
+
};
|
|
631
|
+
}
|
|
632
|
+
else if (privately) {
|
|
633
|
+
const p = resolvePlayer(game.players, single);
|
|
546
634
|
if (p.id === me) {
|
|
547
635
|
throw new McpToolError(`${untrustedText(p.name)} (${p.id}) is you: a private message to yourself was not sent.`, {
|
|
548
636
|
hint: 'Name another player in `to`, or omit it to post to the whole game.',
|
|
@@ -571,23 +659,34 @@ export function registerChatTools(server, ctx, opts = {}) {
|
|
|
571
659
|
});
|
|
572
660
|
}
|
|
573
661
|
// A truce changes only with its partner told (D3): the check knows who reads the message.
|
|
574
|
-
const audience = kind === 'private'
|
|
662
|
+
const audience = kind === 'private'
|
|
663
|
+
? { kind: 'private', to: shownRecipient.id }
|
|
664
|
+
: kind === 'group'
|
|
665
|
+
? { kind: 'group', to: group.recipients.map((r) => r.id) }
|
|
666
|
+
: kind === 'team'
|
|
667
|
+
? { kind: 'team', team: chatChannel }
|
|
668
|
+
: { kind: 'public' };
|
|
575
669
|
promised = await checkMessageCommitments(ctx, game, seat, promises, audience, teamsKnown);
|
|
576
670
|
}
|
|
577
|
-
const
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
671
|
+
const groupIds = group ? listIds(group.recipients.map((r) => r.id)) : '';
|
|
672
|
+
const words = kind === 'group'
|
|
673
|
+
? `privately to players ${groupIds} only, in a game group (${group.id !== undefined ? `group ${group.id}, which exists` : 'created first'})`
|
|
674
|
+
: kind === 'private'
|
|
675
|
+
? `privately to player ${shownRecipient.id} only`
|
|
676
|
+
: kind === 'team'
|
|
677
|
+
? `to your team (team ${chatChannel}) only`
|
|
678
|
+
: 'to everyone in the game';
|
|
582
679
|
const teamName = `your team (team ${chatChannel})`;
|
|
583
680
|
return {
|
|
584
681
|
gate: {
|
|
585
682
|
action: 'warapp.send_chat',
|
|
586
|
-
summary: kind === '
|
|
587
|
-
? `Send a
|
|
588
|
-
: kind === '
|
|
589
|
-
? `Send a chat message to ${
|
|
590
|
-
:
|
|
683
|
+
summary: kind === 'group'
|
|
684
|
+
? `Send a group chat message to players ${groupIds} in game ${gameId}`
|
|
685
|
+
: kind === 'private'
|
|
686
|
+
? `Send a private chat message to player ${shownRecipient.id} in game ${gameId}`
|
|
687
|
+
: kind === 'team'
|
|
688
|
+
? `Send a chat message to ${teamName} in game ${gameId}`
|
|
689
|
+
: `Post a chat message to everyone in game ${gameId}`,
|
|
591
690
|
account,
|
|
592
691
|
target: gameId,
|
|
593
692
|
payload: {
|
|
@@ -596,11 +695,16 @@ export function registerChatTools(server, ctx, opts = {}) {
|
|
|
596
695
|
text,
|
|
597
696
|
channel: chatChannel,
|
|
598
697
|
recipient: recipient?.id ?? null,
|
|
698
|
+
...(group
|
|
699
|
+
? { group: group.id ?? null, createGroup: group.id === undefined ? { name: group.name, members: group.members } : null }
|
|
700
|
+
: {}),
|
|
599
701
|
...(promised ? { commitments: promised.commitments } : {}),
|
|
600
702
|
},
|
|
601
703
|
willSend: {
|
|
602
704
|
game: gameId,
|
|
603
|
-
to:
|
|
705
|
+
to: group
|
|
706
|
+
? group.recipients.map((r) => r.name).join(', ')
|
|
707
|
+
: (shownRecipient?.name ?? (kind === 'team' ? teamName : 'everyone in the game')),
|
|
604
708
|
message,
|
|
605
709
|
},
|
|
606
710
|
preview: {
|
|
@@ -612,6 +716,20 @@ export function registerChatTools(server, ctx, opts = {}) {
|
|
|
612
716
|
: 'Other players will see this message; it cannot be unsent.',
|
|
613
717
|
game: { id: game.id, name: game.name === undefined ? null : untrustedText(game.name), state: game.state },
|
|
614
718
|
...(shownRecipient ? { recipient: shownRecipient } : {}),
|
|
719
|
+
...(group
|
|
720
|
+
? {
|
|
721
|
+
recipients: group.recipients,
|
|
722
|
+
group: group.id !== undefined
|
|
723
|
+
? { id: group.id, name: group.name, reused: true }
|
|
724
|
+
: { create: true, name: untrustedText(group.name) },
|
|
725
|
+
groupNote: (group.id !== undefined
|
|
726
|
+
? `The game's group ${group.id} holds exactly you and these players: the message goes there.`
|
|
727
|
+
: groupsRead
|
|
728
|
+
? 'No game group of exactly you and these players exists: one is created first, named as shown (the members see the name).'
|
|
729
|
+
: "The game's groups could not be read, so a new group is created first, named as shown (the members see the name), even if one of exactly these players exists.") +
|
|
730
|
+
` ${GROUP_UNVERIFIED}`,
|
|
731
|
+
}
|
|
732
|
+
: {}),
|
|
615
733
|
...(links
|
|
616
734
|
? {
|
|
617
735
|
rendered: untrustedBody(links.rendered),
|
|
@@ -639,6 +757,7 @@ export function registerChatTools(server, ctx, opts = {}) {
|
|
|
639
757
|
kind,
|
|
640
758
|
channel: chatChannel,
|
|
641
759
|
...(recipient ? { recipient } : {}),
|
|
760
|
+
...(group ? { group } : {}),
|
|
642
761
|
...(meInGame !== undefined ? { meInGame } : {}),
|
|
643
762
|
...(auto ? { automated: true } : {}),
|
|
644
763
|
account,
|
|
@@ -655,15 +774,67 @@ export function registerChatTools(server, ctx, opts = {}) {
|
|
|
655
774
|
},
|
|
656
775
|
};
|
|
657
776
|
},
|
|
658
|
-
async execute({ gameId, text, kind, channel, recipient, meInGame, account, commitments, automated }) {
|
|
777
|
+
async execute({ gameId, text, kind, channel, recipient, group, meInGame, account, commitments, automated }) {
|
|
659
778
|
await requireApprovedAccount(ctx, account);
|
|
660
|
-
const to = recipient?.name ?? (kind === 'team' ? `your team (team ${channel})` : 'everyone in the game');
|
|
779
|
+
const to = group?.recipients ?? recipient?.name ?? (kind === 'team' ? `your team (team ${channel})` : 'everyone in the game');
|
|
661
780
|
const marked = automated ? { automated: true } : {};
|
|
662
|
-
|
|
781
|
+
// A group message: the group first (created when none of exactly these players exists), then the message to it.
|
|
782
|
+
let groupId = group?.id;
|
|
783
|
+
if (group && groupId === undefined) {
|
|
784
|
+
let createReply;
|
|
785
|
+
const notSent = (warning) => ({
|
|
786
|
+
status: 'unknown',
|
|
787
|
+
outcome: 'unknown',
|
|
788
|
+
game: gameId,
|
|
789
|
+
channel: kind,
|
|
790
|
+
to,
|
|
791
|
+
...marked,
|
|
792
|
+
group: { id: null, created: 'unknown' },
|
|
793
|
+
warning,
|
|
794
|
+
});
|
|
795
|
+
const made = await sendAndVerify({
|
|
796
|
+
send: async () => {
|
|
797
|
+
createReply = await ctx.rpc.call('CreateGameGroup', Method.CreateGameGroup, (w) => writeCreateGameGroupParams(w, { gameId, name: group.name, members: group.members }));
|
|
798
|
+
},
|
|
799
|
+
refused: (e) => new McpToolError(`war.app refused to create the game group (${GROUP_REFUSALS[e.code] ?? e.message}; war.app error ${e.code}): nothing was sent.`, { hint: 'Message each player privately instead, or post to the whole game.' }),
|
|
800
|
+
unanswered: (failure) => notSent(`war.app did not answer the game group's creation (${failure}), so a group may now exist, but the message was NOT sent. ` +
|
|
801
|
+
"Look at the game's groups in the web client before sending again."),
|
|
802
|
+
readBack: async () => {
|
|
803
|
+
const id = createReply ? readCreateGameGroupReply(await ctx.bundle(), createReply.body) : undefined;
|
|
804
|
+
if (id === undefined)
|
|
805
|
+
throw new Error('its reply named no group');
|
|
806
|
+
return id;
|
|
807
|
+
},
|
|
808
|
+
unreadable: (failure) => notSent(`war.app accepted the game group's creation, but ${failure}, so the message was NOT sent. ` +
|
|
809
|
+
"Look at the game's groups in the web client, then send it again (an existing group of exactly these players is reused)."),
|
|
810
|
+
classify: (id) => id,
|
|
811
|
+
});
|
|
812
|
+
if (typeof made !== 'number') {
|
|
813
|
+
// Like an unconfirmed send, the result says what became of the commitments: the message never left.
|
|
814
|
+
return commitments
|
|
815
|
+
? {
|
|
816
|
+
...made,
|
|
817
|
+
commitments: {
|
|
818
|
+
recorded: [],
|
|
819
|
+
why: 'The message was NOT sent (the game group could not be confirmed), so its commitments were not made: nothing to record.',
|
|
820
|
+
},
|
|
821
|
+
}
|
|
822
|
+
: made;
|
|
823
|
+
}
|
|
824
|
+
groupId = made;
|
|
825
|
+
}
|
|
826
|
+
const groupOut = group ? { group: { id: groupId, created: group.id === undefined } } : {};
|
|
827
|
+
const base = { status: 'sent', game: gameId, channel: kind, to, ...groupOut, ...marked };
|
|
663
828
|
let reply;
|
|
664
829
|
const result = await sendAndVerify({
|
|
665
830
|
send: async () => {
|
|
666
|
-
reply = await ctx.rpc.call('SendChat', Method.SendChat, (w) => writeSendChatParams(w, {
|
|
831
|
+
reply = await ctx.rpc.call('SendChat', Method.SendChat, (w) => writeSendChatParams(w, {
|
|
832
|
+
gameId,
|
|
833
|
+
text,
|
|
834
|
+
channel,
|
|
835
|
+
...(recipient ? { recipient: recipient.id } : {}),
|
|
836
|
+
...(groupId !== undefined ? { group: groupId } : {}),
|
|
837
|
+
}));
|
|
667
838
|
},
|
|
668
839
|
// A refusal is rethrown (nothing was posted; 36, too many messages, is never retried).
|
|
669
840
|
unanswered: (failure) => ({
|
|
@@ -672,6 +843,7 @@ export function registerChatTools(server, ctx, opts = {}) {
|
|
|
672
843
|
game: gameId,
|
|
673
844
|
channel: kind,
|
|
674
845
|
to,
|
|
846
|
+
...groupOut,
|
|
675
847
|
...marked,
|
|
676
848
|
warning: `war.app did not confirm this message (${failure}), so it may ` +
|
|
677
849
|
'already have been posted. Check warapp_get_chat before sending it again.',
|
|
@@ -686,11 +858,13 @@ export function registerChatTools(server, ctx, opts = {}) {
|
|
|
686
858
|
// A reply this server cannot read: war.app's acceptance is all there is.
|
|
687
859
|
unreadable: () => ({ ...base, outcome: 'accepted' }),
|
|
688
860
|
classify: (lines) => {
|
|
689
|
-
const onChannel = (l) => kind === '
|
|
690
|
-
? l.
|
|
691
|
-
: kind === '
|
|
692
|
-
? l.channel === '
|
|
693
|
-
:
|
|
861
|
+
const onChannel = (l) => kind === 'group'
|
|
862
|
+
? l.group === groupId
|
|
863
|
+
: kind === 'private'
|
|
864
|
+
? l.channel === 'private' && l.to === recipient?.id
|
|
865
|
+
: kind === 'team'
|
|
866
|
+
? l.channel === 'team' && l.team === channel
|
|
867
|
+
: l.channel === 'public';
|
|
694
868
|
const newest = lines.filter((l) => meInGame !== undefined && l.sender === meInGame && onChannel(l)).at(-1);
|
|
695
869
|
const same = (a) => a.replace(/\s+/g, ' ').trim() === text.replace(/\s+/g, ' ').trim();
|
|
696
870
|
if (newest && same(newest.text))
|
package/dist/version.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
// Single source of truth for the server version. release-please bumps the
|
|
2
2
|
// literal on the marked line (registered in release-please-config.json
|
|
3
3
|
// extra-files); every other module imports VERSION from here.
|
|
4
|
-
export const VERSION = '0.
|
|
4
|
+
export const VERSION = '0.24.0'; // x-release-please-version
|
package/manifest.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"manifest_version": "0.3",
|
|
4
4
|
"name": "warapp-mcp",
|
|
5
5
|
"display_name": "war.app (Warzone)",
|
|
6
|
-
"version": "0.
|
|
6
|
+
"version": "0.24.0",
|
|
7
7
|
"description": "war.app (Warzone) game advisor for Claude — your games, maps, bonuses, board analysis and routes via the GameFeed API, plus your games list (waiting on you first), opponent scouting with your head-to-head, the live board, territory picks, cards, turn planning and submission, turn notifications, and chat through your signed-in war.app tab (ContextMint Bridge). Creating, joining, leaving or surrendering a game, accepting game invitations, closing out a finished game, accepting another player's surrender, a team surrender, a vote to end a game, booting a stalled player, Begin on a speed first turn, picks, turn orders, withdrawing them, chat sends, nudging a player, joining or leaving a ladder, answering a clan invite, joining or leaving a clan, changing quickmatch settings, voting on quickmatch templates, joining or declining a tournament, showing a tournament among your favourites, mail (new threads, replies, adding players, deleting threads), forum posts (new threads, replies, votes, watching a thread), chat reactions, marking notifications and chat read, deleting notifications, importing local history into a hosted server and linking a session (local only) are confirm-gated.",
|
|
8
8
|
"author": {
|
|
9
9
|
"name": "Chris Hall",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@chrischall/warapp-mcp",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.24.0",
|
|
4
4
|
"mcpName": "io.github.chrischall/warapp-mcp",
|
|
5
5
|
"description": "war.app (Warzone) game advisor MCP server for Claude — games, maps, bonuses and board analysis via the GameFeed API, plus your games list, opponent scouting, the live board, territory picks, cards, turn planning and submission, turn notifications and chat through your signed-in war.app tab. Developed and maintained by AI (Claude Code).",
|
|
6
6
|
"author": "Claude Code (AI) <https://www.anthropic.com/claude>",
|
package/server.json
CHANGED
|
@@ -6,12 +6,12 @@
|
|
|
6
6
|
"url": "https://github.com/chrischall/warapp-mcp",
|
|
7
7
|
"source": "github"
|
|
8
8
|
},
|
|
9
|
-
"version": "0.
|
|
9
|
+
"version": "0.24.0",
|
|
10
10
|
"packages": [
|
|
11
11
|
{
|
|
12
12
|
"registryType": "npm",
|
|
13
13
|
"identifier": "@chrischall/warapp-mcp",
|
|
14
|
-
"version": "0.
|
|
14
|
+
"version": "0.24.0",
|
|
15
15
|
"transport": {
|
|
16
16
|
"type": "stdio"
|
|
17
17
|
},
|