@chrischall/warapp-mcp 0.24.0 → 0.25.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/cards-in-effect.js +19 -3
- package/dist/analysis/coalition.js +6 -3
- package/dist/analysis/commitments.js +253 -42
- package/dist/analysis/pacts.js +285 -0
- package/dist/analysis/relations.js +10 -0
- package/dist/analysis/stress.js +8 -3
- package/dist/bundle.js +1255 -306
- package/dist/mod-alliances.js +14 -0
- package/dist/protocol/codec.js +4 -0
- package/dist/relations-store.js +83 -18
- package/dist/tools/chat-advice.js +2 -2
- package/dist/tools/chat.js +275 -66
- package/dist/tools/check-plan.js +14 -4
- package/dist/tools/commitments.js +40 -8
- package/dist/tools/diplomacy.js +37 -5
- package/dist/tools/mod-alliances.js +13 -1
- package/dist/tools/relations.js +411 -33
- package/dist/tools/turn.js +53 -13
- package/dist/tools/uncommit.js +6 -6
- package/dist/version.js +1 -1
- package/manifest.json +1 -1
- package/package.json +1 -1
- package/server.json +2 -2
package/dist/tools/chat.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
// (`GetChat=true`, channels unknown), with what is new since the messages were last marked seen; send
|
|
3
3
|
// through the web-client protocol (`SendChat`) publicly, to my team or privately, gated on the user's
|
|
4
4
|
// confirmation — a message reaches other players and cannot be unsent.
|
|
5
|
+
import { WarappServerError } from '../protocol/rpc.js';
|
|
5
6
|
import { CONFIRM_INJECTION_RULE, McpToolError, toolAnnotations } from '@chrischall/mcp-utils';
|
|
6
7
|
import { z } from 'zod';
|
|
7
8
|
import { CHAT_CHANNELS, feedChatLines, fillFromFeed, mergeChatLines, oldestId, readCreateGameGroupReply, readGameGroups, readGameRefreshChat, readMessageHistoryReply, readSendChatReply, } from '../chat.js';
|
|
@@ -28,29 +29,128 @@ const MAX_CHAT_LENGTH = 2000;
|
|
|
28
29
|
export const MAX_GROUP_RECIPIENTS = 10;
|
|
29
30
|
/** The most characters of a new game group's name. */
|
|
30
31
|
const MAX_GROUP_NAME = 50;
|
|
31
|
-
/** A new game group's name when
|
|
32
|
+
/** A new game group's name when no other can be made (the members' names unreadable): it is shown to the members. */
|
|
32
33
|
export const DEFAULT_GROUP_NAME = 'Group chat';
|
|
34
|
+
/**
|
|
35
|
+
* The waits before resending a message to a game group this call just created, after war.app refused it with 752
|
|
36
|
+
* (NotInGameGroup). Live 2026-11-30: right after CreateGameGroup war.app refused a message to the new group's right id
|
|
37
|
+
* (read back from the chat), and took the same message minutes later. A refusal posts nothing, so resending is safe.
|
|
38
|
+
* Mutable for tests only.
|
|
39
|
+
*/
|
|
40
|
+
export const GROUP_SEND_RETRY = { delaysMs: [2_000, 4_000, 8_000, 16_000] };
|
|
41
|
+
const NOT_IN_GAME_GROUP = 752;
|
|
42
|
+
const wait = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
43
|
+
const CONTROL_CHARS = /\p{Cc}/gu;
|
|
44
|
+
/** A name for war.app: control characters out, whitespace runs one space, trimmed. */
|
|
45
|
+
const cleanName = (name) => name.replace(CONTROL_CHARS, '').replace(/\s+/g, ' ').trim();
|
|
46
|
+
/** `text` cut to MAX_GROUP_NAME characters with an ellipsis, never splitting a surrogate pair. */
|
|
47
|
+
function cutName(text) {
|
|
48
|
+
if (text.length <= MAX_GROUP_NAME)
|
|
49
|
+
return text;
|
|
50
|
+
let end = MAX_GROUP_NAME - 1;
|
|
51
|
+
const code = text.charCodeAt(end - 1);
|
|
52
|
+
if (code >= 0xd800 && code <= 0xdbff)
|
|
53
|
+
end -= 1;
|
|
54
|
+
return `${text.slice(0, end)}…`;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* A new game group's default name from its members' names, the first (me) first: "Ann, Bob and Cat". Over
|
|
58
|
+
* {@link MAX_GROUP_NAME} characters it names as many as fit, then "and N more"; still too long, it is cut to 49 and an
|
|
59
|
+
* ellipsis. The raw names (war.app shows the name; only the preview delimits it), control characters stripped; with
|
|
60
|
+
* fewer than two names left, {@link DEFAULT_GROUP_NAME}.
|
|
61
|
+
*/
|
|
62
|
+
export function defaultGroupName(names) {
|
|
63
|
+
const clean = names.map(cleanName).filter((n) => n !== '');
|
|
64
|
+
if (clean.length < 2)
|
|
65
|
+
return DEFAULT_GROUP_NAME;
|
|
66
|
+
const and = (first, last) => `${first.join(', ')} and ${last}`;
|
|
67
|
+
const full = and(clean.slice(0, -1), clean.at(-1));
|
|
68
|
+
if (full.length <= MAX_GROUP_NAME)
|
|
69
|
+
return full;
|
|
70
|
+
for (let k = clean.length - 1; k >= 1; k--) {
|
|
71
|
+
const some = and(clean.slice(0, k), `${clean.length - k} more`);
|
|
72
|
+
if (some.length <= MAX_GROUP_NAME)
|
|
73
|
+
return some;
|
|
74
|
+
}
|
|
75
|
+
return cutName(and(clean.slice(0, 1), `${clean.length - 1} more`));
|
|
76
|
+
}
|
|
77
|
+
/** What the preview says of a new group's name: it cannot be changed. */
|
|
78
|
+
const GROUP_NAME_NOTE = 'war.app cannot rename or delete a game group, and the members see its name and a creation line in the game chat, ' +
|
|
79
|
+
'so choose the name now (`group_name`).';
|
|
33
80
|
/** CreateGameGroup's refusals as the client words them. */
|
|
34
81
|
const GROUP_REFUSALS = {
|
|
35
82
|
227: 'a player in it has blocked you',
|
|
36
83
|
751: 'this game does not allow game groups',
|
|
84
|
+
752: 'you are not in that group',
|
|
85
|
+
753: 'you do not moderate that group',
|
|
37
86
|
};
|
|
38
87
|
/** Ids as "1, 2 and 3". */
|
|
39
88
|
const listIds = (ids) => (ids.length > 1 ? `${ids.slice(0, -1).join(', ')} and ${ids.at(-1)}` : String(ids[0]));
|
|
89
|
+
/** Whether a group holds exactly me and `members` (in-game ids). */
|
|
90
|
+
const sameMembers = (g, meInGame, members) => {
|
|
91
|
+
const want = new Set([meInGame, ...members]);
|
|
92
|
+
return g.members !== null && new Set(g.members).size === want.size && g.members.every((m) => want.has(m));
|
|
93
|
+
};
|
|
94
|
+
/**
|
|
95
|
+
* The id of the group this call just created, from the chat GameRefresh (the read warapp_get_chat makes): the game's
|
|
96
|
+
* newest group of exactly me and `members` under `name` when the reply lists the groups, else the newest line in a
|
|
97
|
+
* group with no sender whose text names it (the creation line). Live 2026-11-30 the id read from CreateGameGroup's
|
|
98
|
+
* reply was refused (752), and the chat's id worked. `undefined` when neither shows it or the read fails. Never throws.
|
|
99
|
+
*/
|
|
100
|
+
async function createdGroupInChat(ctx, gameId, lobby, meInGame, members, name, replyId) {
|
|
101
|
+
try {
|
|
102
|
+
const env = await ctx.rpc.call('GameRefresh', Method.GameRefresh, (w) => writeGameRefreshParams(w, { gameId, chat: true, nonChat: false, lobby }));
|
|
103
|
+
const bundle = await ctx.bundle();
|
|
104
|
+
const groups = readGameGroups(bundle, env.body.fork());
|
|
105
|
+
const group = groups
|
|
106
|
+
?.filter((g) => g.gameId === gameId && g.name === name && sameMembers(g, meInGame, members))
|
|
107
|
+
.sort((a, b) => b.id - a.id)[0];
|
|
108
|
+
if (group)
|
|
109
|
+
return group.id;
|
|
110
|
+
// Message ids are decimal text, past a double's precision: the newest is the longest, then the greatest; else the last.
|
|
111
|
+
const newer = (a, b) => {
|
|
112
|
+
const [x, y] = [a.id ?? '', b.id ?? ''];
|
|
113
|
+
return x.length !== y.length ? x.length > y.length : x >= y;
|
|
114
|
+
};
|
|
115
|
+
// #682: a creation line only names the group by its name, which an older group may share. War.app numbers groups
|
|
116
|
+
// upwards (live: 11193, then 11194), so only the line of the game's highest group read, at or above the reply's id,
|
|
117
|
+
// can be the new group's: else the line is an older group's, and its players must not get the message.
|
|
118
|
+
const lines = readGameRefreshChat(bundle, env.body) ?? [];
|
|
119
|
+
const highest = Math.max(-Infinity, ...lines.flatMap((l) => (l.group !== undefined ? [l.group] : [])));
|
|
120
|
+
let line;
|
|
121
|
+
for (const l of lines) {
|
|
122
|
+
if (l.group !== undefined && l.sender === null && l.text.includes(name) && (!line || newer(l, line)))
|
|
123
|
+
line = l;
|
|
124
|
+
}
|
|
125
|
+
if (line?.group === undefined || line.group !== highest || (replyId !== undefined && line.group < replyId))
|
|
126
|
+
return undefined;
|
|
127
|
+
return line.group;
|
|
128
|
+
}
|
|
129
|
+
catch {
|
|
130
|
+
return undefined;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
40
133
|
/**
|
|
41
134
|
* The game's newest group holding exactly me and `members` (in-game ids), from one GameRefresh with the game details.
|
|
42
135
|
* `read: false` when the groups could not be read (a failed request, or a reply without them). Never throws.
|
|
43
136
|
*/
|
|
44
137
|
async function existingGroup(ctx, game, meInGame, members) {
|
|
138
|
+
// Which GameRefresh carries the groups is UNVERIFIED live (live, the details-only read did not): the chat read
|
|
139
|
+
// warapp_get_chat makes first, then the details read.
|
|
140
|
+
const read = async (chat) => {
|
|
141
|
+
try {
|
|
142
|
+
const env = await ctx.rpc.call('GameRefresh', Method.GameRefresh, (w) => writeGameRefreshParams(w, { gameId: game.id, chat, nonChat: !chat, lobby: game.state === 'WaitingForPlayers' }));
|
|
143
|
+
return readGameGroups(await ctx.bundle(), env.body);
|
|
144
|
+
}
|
|
145
|
+
catch {
|
|
146
|
+
return undefined;
|
|
147
|
+
}
|
|
148
|
+
};
|
|
45
149
|
try {
|
|
46
|
-
const
|
|
47
|
-
const groups = readGameGroups(await ctx.bundle(), env.body);
|
|
150
|
+
const groups = (await read(true)) ?? (await read(false));
|
|
48
151
|
if (!groups)
|
|
49
152
|
return { read: false };
|
|
50
|
-
const
|
|
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);
|
|
153
|
+
const same = groups.filter((g) => g.gameId === game.id && sameMembers(g, meInGame, members)).sort((a, b) => b.id - a.id);
|
|
54
154
|
return same[0] ? { read: true, group: same[0] } : { read: true };
|
|
55
155
|
}
|
|
56
156
|
catch {
|
|
@@ -351,6 +451,8 @@ export function shown(line, isNew, players, byInGame, me, map) {
|
|
|
351
451
|
channel: line.channel,
|
|
352
452
|
...(line.team !== undefined ? { team: line.team } : {}),
|
|
353
453
|
...(to ? { to } : {}),
|
|
454
|
+
// A game-group message's group id (warapp_send_chat's `group_id` sends into it).
|
|
455
|
+
...(line.group !== undefined ? { group: line.group } : {}),
|
|
354
456
|
// #387: a private message addressed to me, so a watcher can flag diplomacy the moment it arrives.
|
|
355
457
|
...(line.channel === 'private' && me !== undefined && line.to === me.inGameId ? { toMe: true } : {}),
|
|
356
458
|
// #634: what the sender shared and who reacted, all their own words (delimited).
|
|
@@ -471,7 +573,9 @@ export function registerChatTools(server, ctx, opts = {}) {
|
|
|
471
573
|
name: 'warapp_send_chat',
|
|
472
574
|
description: 'Post a chat message in a war.app (Warzone) game — to the whole game, to your team (`channel: "team"`, in ' +
|
|
473
575
|
'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
|
|
576
|
+
'group, reused when one of exactly you and them exists, else created first in the same call, named by `group_name` or ' +
|
|
577
|
+
"by default the members' names, yours first — war.app cannot rename or delete a group, so choose the name — and its id " +
|
|
578
|
+
'read back from the game chat before the message goes to it; UNVERIFIED live); ' +
|
|
475
579
|
'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 ' +
|
|
476
580
|
'(ContextMint Bridge); the game is read from GameFeed first, so the GameFeed credentials are needed too. ' +
|
|
477
581
|
"The result's `outcome` is `confirmed` when war.app's reply lists it as your newest message on that " +
|
|
@@ -481,12 +585,15 @@ export function registerChatTools(server, ctx, opts = {}) {
|
|
|
481
585
|
'orders already submitted) and the agreement ledger, a commitment they do not carry refuses the send, and once ' +
|
|
482
586
|
'the message is confirmed or accepted they are recorded in the ledger as yours (a propose or accept creates or ' +
|
|
483
587
|
'advances the agreement, a notice moves it to notice-by-me); warapp_submit_turn warns when later orders break one. ' +
|
|
588
|
+
'An n-way truce (a pact "p<n>"): propose or accept with `players`, or accept/notice by its id — every party must read ' +
|
|
589
|
+
'the message (a game group holding all of them, or public), and a notice on one of three or more needs `rest` (ask the owner). ' +
|
|
484
590
|
'Pass `automated: true` for a reply the owner did not tell you to send (e.g. an advice\'s `send`): it is refused ' +
|
|
485
591
|
'unless WARAPP_CHAT_AUTOMATION is on (off by default: the owner sends replies), and even then it is confirm-gated. ' +
|
|
486
592
|
'Link a territory or bonus as players see it in the official client with `[[t:<id or name>]]` / `[[b:<id or name>]]` ' +
|
|
487
593
|
'in the message, or set `link_territories` to link every territory name it mentions: names resolve against the ' +
|
|
488
594
|
"game's map (exact, case-insensitive; an unknown or shared name is refused, listing the ids), and the preview shows " +
|
|
489
|
-
'the message as rendered with its `links`. ' +
|
|
595
|
+
'the message as rendered with its `links`. Every send is confirmed with the two-step preview and `confirmToken`, ' +
|
|
596
|
+
'never an elicitation prompt (live, a client accepted one the owner never saw). ' +
|
|
490
597
|
`${CONFIRM_INJECTION_RULE}`,
|
|
491
598
|
annotations: toolAnnotations({
|
|
492
599
|
title: 'Send a war.app chat message',
|
|
@@ -524,8 +631,17 @@ export function registerChatTools(server, ctx, opts = {}) {
|
|
|
524
631
|
.min(1)
|
|
525
632
|
.max(MAX_GROUP_NAME)
|
|
526
633
|
.optional()
|
|
527
|
-
.describe(
|
|
528
|
-
|
|
634
|
+
.describe('A list `to` only (a list of one player with it makes a group of you and that player): the name of the game group if one has to be created (default: the members\' names, yours first, ' +
|
|
635
|
+
`e.g. "Ann, Bob and Cat", or "Ann, Bob and 2 more" past ${MAX_GROUP_NAME} characters). The members see it, and ` +
|
|
636
|
+
'war.app cannot rename or delete a group: choose it before confirming. An existing group of exactly these players ' +
|
|
637
|
+
'is reused, keeping its name.'),
|
|
638
|
+
group_id: z
|
|
639
|
+
.number()
|
|
640
|
+
.int()
|
|
641
|
+
.positive()
|
|
642
|
+
.optional()
|
|
643
|
+
.describe('A list `to` only (a list of one player with it sends to a group of you and that player): send into this existing game group (its id, as warapp_get_chat shows a group message\'s `group`) ' +
|
|
644
|
+
'instead of finding or creating one. war.app refuses it when you are not in that group.'),
|
|
529
645
|
commitments: commitmentsArg,
|
|
530
646
|
automated: z
|
|
531
647
|
.boolean()
|
|
@@ -533,7 +649,7 @@ export function registerChatTools(server, ctx, opts = {}) {
|
|
|
533
649
|
.describe('true when you send a reply the owner did not tell you to send (an automated reply). Refused unless ' +
|
|
534
650
|
'WARAPP_CHAT_AUTOMATION is on; default false (a send the owner asked for).'),
|
|
535
651
|
}),
|
|
536
|
-
async plan({ game_id, message, channel, to, group_name, commitments, automated, link_territories }) {
|
|
652
|
+
async plan({ game_id, message, channel, to, group_name, group_id, commitments, automated, link_territories }) {
|
|
537
653
|
// #415: an automated reply is refused with the gate off, before any request.
|
|
538
654
|
const auto = automated === true;
|
|
539
655
|
if (auto && (ctx.chatAutomation ?? chatAutomationMode(opts.env ?? process.env)) !== 'on') {
|
|
@@ -542,9 +658,10 @@ export function registerChatTools(server, ctx, opts = {}) {
|
|
|
542
658
|
});
|
|
543
659
|
}
|
|
544
660
|
const gameId = parseGameId(game_id);
|
|
545
|
-
// A list `to` of two or more players is a game group; a list of one is a private message to that player
|
|
661
|
+
// A list `to` of two or more players is a game group; a list of one is a private message to that player,
|
|
662
|
+
// unless `group_name` or `group_id` asks for a game group (of me and that player).
|
|
546
663
|
const toList = Array.isArray(to) ? to.filter((x) => String(x).trim() !== '') : undefined;
|
|
547
|
-
const grouped = toList !== undefined && toList.length >= 2;
|
|
664
|
+
const grouped = toList !== undefined && (toList.length >= 2 || (toList.length === 1 && (group_name !== undefined || group_id !== undefined)));
|
|
548
665
|
const single = toList ? (toList.length === 1 ? toList[0] : undefined) : Array.isArray(to) ? undefined : to;
|
|
549
666
|
const privately = grouped || (single !== undefined && String(single).trim() !== '');
|
|
550
667
|
if (toList !== undefined && toList.length === 0) {
|
|
@@ -555,6 +672,16 @@ export function registerChatTools(server, ctx, opts = {}) {
|
|
|
555
672
|
hint: 'Pass `to` as a list of the players to message together, or drop `group_name`.',
|
|
556
673
|
});
|
|
557
674
|
}
|
|
675
|
+
if (group_id !== undefined && !grouped) {
|
|
676
|
+
throw new McpToolError('`group_id` names a game group, which only a list of two or more players in `to` uses: nothing was sent.', {
|
|
677
|
+
hint: 'Pass `to` as the list of the players in that group (not you), or drop `group_id`.',
|
|
678
|
+
});
|
|
679
|
+
}
|
|
680
|
+
if (group_id !== undefined && group_name !== undefined) {
|
|
681
|
+
throw new McpToolError('`group_name` is for a group this call creates, and `group_id` sends into an existing one: nothing was sent.', {
|
|
682
|
+
hint: 'Drop `group_name` (the group keeps its name) or drop `group_id`.',
|
|
683
|
+
});
|
|
684
|
+
}
|
|
558
685
|
if (privately && channel === 'team') {
|
|
559
686
|
throw new McpToolError('A private message (`to`) cannot also go to the team channel: nothing was sent.', {
|
|
560
687
|
hint: 'Omit `to` to message your team, or omit `channel` to message one player privately.',
|
|
@@ -621,13 +748,25 @@ export function registerChatTools(server, ctx, opts = {}) {
|
|
|
621
748
|
}
|
|
622
749
|
kind = 'group';
|
|
623
750
|
const members = people.map((p) => inGameId(p));
|
|
624
|
-
const
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
751
|
+
const recipients = people.map((p) => ({ id: p.id, name: untrustedText(p.name) }));
|
|
752
|
+
if (group_id !== undefined) {
|
|
753
|
+
// The caller names the group: no read, nothing created; war.app checks I am in it.
|
|
754
|
+
group = { id: group_id, name: '', members, recipients, given: true };
|
|
755
|
+
}
|
|
756
|
+
else {
|
|
757
|
+
const found = await existingGroup(ctx, game, meInGame, members);
|
|
758
|
+
groupsRead = found.read;
|
|
759
|
+
// A new group's name: the one given, else the members' names, mine first (raw: war.app shows it).
|
|
760
|
+
const given = group_name === undefined ? '' : cleanName(group_name);
|
|
761
|
+
const name = given || defaultGroupName([seat?.name ?? '', ...people.map((p) => p.name)]);
|
|
762
|
+
group = {
|
|
763
|
+
...(found.group
|
|
764
|
+
? { id: found.group.id, name: untrustedText(found.group.name) }
|
|
765
|
+
: { name, lobby: game.state === 'WaitingForPlayers' }),
|
|
766
|
+
members,
|
|
767
|
+
recipients,
|
|
768
|
+
};
|
|
769
|
+
}
|
|
631
770
|
}
|
|
632
771
|
else if (privately) {
|
|
633
772
|
const p = resolvePlayer(game.players, single);
|
|
@@ -670,7 +809,7 @@ export function registerChatTools(server, ctx, opts = {}) {
|
|
|
670
809
|
}
|
|
671
810
|
const groupIds = group ? listIds(group.recipients.map((r) => r.id)) : '';
|
|
672
811
|
const words = kind === 'group'
|
|
673
|
-
? `privately to players ${groupIds} only, in a game group (${group.id !== undefined ? `group ${group.id}, which exists` : 'created first'})`
|
|
812
|
+
? `privately to ${group.recipients.length === 1 ? 'player' : 'players'} ${groupIds} only, in a game group (${group.id !== undefined ? `group ${group.id}, which exists` : 'created first'})`
|
|
674
813
|
: kind === 'private'
|
|
675
814
|
? `privately to player ${shownRecipient.id} only`
|
|
676
815
|
: kind === 'team'
|
|
@@ -680,8 +819,11 @@ export function registerChatTools(server, ctx, opts = {}) {
|
|
|
680
819
|
return {
|
|
681
820
|
gate: {
|
|
682
821
|
action: 'warapp.send_chat',
|
|
822
|
+
// Live 2026-11-30 a client accepted the elicitation with no prompt shown to the owner: every send is the
|
|
823
|
+
// two-step preview + confirmToken, never an elicitation (every other confirm setting still applies).
|
|
824
|
+
env: { ...(opts.env ?? process.env), MCP_CONFIRM_ELICITATION: 'off' },
|
|
683
825
|
summary: kind === 'group'
|
|
684
|
-
? `Send a group chat message to players ${groupIds} in game ${gameId}`
|
|
826
|
+
? `Send a group chat message to ${group.recipients.length === 1 ? 'player' : 'players'} ${groupIds} in game ${gameId}`
|
|
685
827
|
: kind === 'private'
|
|
686
828
|
? `Send a private chat message to player ${shownRecipient.id} in game ${gameId}`
|
|
687
829
|
: kind === 'team'
|
|
@@ -719,15 +861,23 @@ export function registerChatTools(server, ctx, opts = {}) {
|
|
|
719
861
|
...(group
|
|
720
862
|
? {
|
|
721
863
|
recipients: group.recipients,
|
|
722
|
-
group: group.
|
|
723
|
-
? { id: group.id,
|
|
724
|
-
:
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
864
|
+
group: group.given
|
|
865
|
+
? { id: group.id, given: true }
|
|
866
|
+
: group.id !== undefined
|
|
867
|
+
? { id: group.id, name: group.name, reused: true }
|
|
868
|
+
: { create: true, name: untrustedText(group.name) },
|
|
869
|
+
groupNote: (group.given
|
|
870
|
+
? `The message goes into game group ${group.id}, as given (its members are not read here: war.app refuses it when you are not in that group).`
|
|
871
|
+
: group.id !== undefined
|
|
872
|
+
? `The game's group ${group.id} holds exactly you and these players: the message goes there.`
|
|
873
|
+
: groupsRead
|
|
874
|
+
? 'No game group of exactly you and these players exists: one is created first, named as shown, and the message goes to it.'
|
|
875
|
+
: "The game's groups could not be read, so a new group is created first, named as shown, and the message goes to it, even if one of exactly these players exists.") +
|
|
876
|
+
(group.id === undefined
|
|
877
|
+
? " The new group's id is read back from the game's chat before the message goes (war.app's reply's id was refused live)."
|
|
878
|
+
: '') +
|
|
730
879
|
` ${GROUP_UNVERIFIED}`,
|
|
880
|
+
...(group.id === undefined ? { nameNote: GROUP_NAME_NOTE } : {}),
|
|
731
881
|
}
|
|
732
882
|
: {}),
|
|
733
883
|
...(links
|
|
@@ -778,8 +928,20 @@ export function registerChatTools(server, ctx, opts = {}) {
|
|
|
778
928
|
await requireApprovedAccount(ctx, account);
|
|
779
929
|
const to = group?.recipients ?? recipient?.name ?? (kind === 'team' ? `your team (team ${channel})` : 'everyone in the game');
|
|
780
930
|
const marked = automated ? { automated: true } : {};
|
|
781
|
-
//
|
|
931
|
+
// Like an unconfirmed send, a result whose message never left says what became of the commitments.
|
|
932
|
+
const withNotSentCommitments = (r) => commitments
|
|
933
|
+
? {
|
|
934
|
+
...r,
|
|
935
|
+
commitments: {
|
|
936
|
+
recorded: [],
|
|
937
|
+
why: 'The message was NOT sent (the game group could not be confirmed), so its commitments were not made: nothing to record.',
|
|
938
|
+
},
|
|
939
|
+
}
|
|
940
|
+
: r;
|
|
941
|
+
// A group message: the group first (created when none of exactly these players exists), its id read back from
|
|
942
|
+
// the game's chat, then the message to it.
|
|
782
943
|
let groupId = group?.id;
|
|
944
|
+
let created;
|
|
783
945
|
if (group && groupId === undefined) {
|
|
784
946
|
let createReply;
|
|
785
947
|
const notSent = (warning) => ({
|
|
@@ -789,54 +951,97 @@ export function registerChatTools(server, ctx, opts = {}) {
|
|
|
789
951
|
channel: kind,
|
|
790
952
|
to,
|
|
791
953
|
...marked,
|
|
792
|
-
group: { id: null, created: 'unknown' },
|
|
954
|
+
group: { id: null, created: 'unknown', name: untrustedText(group.name) },
|
|
793
955
|
warning,
|
|
794
956
|
});
|
|
957
|
+
const findIt = 'Look for it with warapp_get_chat (a group message, or its creation line, shows its `group`), then send with ' +
|
|
958
|
+
'`group_id` and the same `to`, so no other group is made.';
|
|
795
959
|
const made = await sendAndVerify({
|
|
796
960
|
send: async () => {
|
|
797
961
|
createReply = await ctx.rpc.call('CreateGameGroup', Method.CreateGameGroup, (w) => writeCreateGameGroupParams(w, { gameId, name: group.name, members: group.members }));
|
|
798
962
|
},
|
|
799
963
|
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
|
-
|
|
964
|
+
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. ${findIt}`),
|
|
965
|
+
// Both ids: the reply's, and the chat's (preferred: live 2026-11-30 the reply's was refused with 752).
|
|
802
966
|
readBack: async () => {
|
|
803
|
-
const
|
|
804
|
-
|
|
805
|
-
throw new Error('its reply named no group');
|
|
806
|
-
return id;
|
|
967
|
+
const replyId = createReply ? readCreateGameGroupReply(await ctx.bundle(), createReply.body) : undefined;
|
|
968
|
+
return { replyId, chatId: await createdGroupInChat(ctx, gameId, group.lobby ?? false, meInGame, group.members, group.name, replyId) };
|
|
807
969
|
},
|
|
808
|
-
unreadable: (failure) => notSent(`war.app accepted the game group's creation, but ${failure}, so the message was NOT sent. `
|
|
809
|
-
|
|
810
|
-
classify: (id) => id,
|
|
970
|
+
unreadable: (failure) => notSent(`war.app accepted the game group's creation, but ${failure}, so a group may now exist, but the message was NOT sent. ${findIt}`),
|
|
971
|
+
classify: (ids) => ids,
|
|
811
972
|
});
|
|
812
|
-
if (
|
|
813
|
-
|
|
814
|
-
|
|
973
|
+
if ('status' in made)
|
|
974
|
+
return withNotSentCommitments(made);
|
|
975
|
+
const { replyId, chatId } = made;
|
|
976
|
+
if (chatId === undefined && replyId === undefined) {
|
|
977
|
+
return withNotSentCommitments(notSent("war.app accepted the game group's creation, but neither its reply nor the game's chat names the group, so a group " +
|
|
978
|
+
`may now exist, but the message was NOT sent. ${findIt}`));
|
|
979
|
+
}
|
|
980
|
+
groupId = chatId ?? replyId;
|
|
981
|
+
created =
|
|
982
|
+
chatId === undefined
|
|
815
983
|
? {
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
why: 'The message was NOT sent (the game group could not be confirmed), so its commitments were not made: nothing to record.',
|
|
820
|
-
},
|
|
984
|
+
idFrom: 'reply',
|
|
985
|
+
warning: `The chat read did not show the new group, so the message went to the id war.app's reply named (${replyId}); ` +
|
|
986
|
+
'live 2026-11-30 a reply\'s id was refused. Check the group with warapp_get_chat.',
|
|
821
987
|
}
|
|
822
|
-
:
|
|
823
|
-
|
|
824
|
-
|
|
988
|
+
: replyId !== undefined && replyId !== chatId
|
|
989
|
+
? {
|
|
990
|
+
idFrom: 'chat',
|
|
991
|
+
replyId,
|
|
992
|
+
warning: `war.app's reply named group ${replyId}, but the game's chat shows group ${chatId} of exactly you and these ` +
|
|
993
|
+
`players under that name: the message went to group ${chatId}.`,
|
|
994
|
+
}
|
|
995
|
+
: { idFrom: 'chat' };
|
|
825
996
|
}
|
|
826
|
-
const groupOut = group
|
|
997
|
+
const groupOut = group
|
|
998
|
+
? {
|
|
999
|
+
group: created
|
|
1000
|
+
? { id: groupId, created: true, name: untrustedText(group.name), idFrom: created.idFrom, ...(created.replyId !== undefined ? { replyId: created.replyId } : {}) }
|
|
1001
|
+
: { id: groupId, created: false },
|
|
1002
|
+
}
|
|
1003
|
+
: {};
|
|
827
1004
|
const base = { status: 'sent', game: gameId, channel: kind, to, ...groupOut, ...marked };
|
|
828
1005
|
let reply;
|
|
1006
|
+
let retried = 0;
|
|
829
1007
|
const result = await sendAndVerify({
|
|
830
1008
|
send: async () => {
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
1009
|
+
for (;;) {
|
|
1010
|
+
try {
|
|
1011
|
+
reply = await ctx.rpc.call('SendChat', Method.SendChat, (w) => writeSendChatParams(w, {
|
|
1012
|
+
gameId,
|
|
1013
|
+
text,
|
|
1014
|
+
channel,
|
|
1015
|
+
...(recipient ? { recipient: recipient.id } : {}),
|
|
1016
|
+
...(groupId !== undefined ? { group: groupId } : {}),
|
|
1017
|
+
}));
|
|
1018
|
+
return;
|
|
1019
|
+
}
|
|
1020
|
+
catch (e) {
|
|
1021
|
+
// A group this call created refuses messages for a while (752): wait and send again. Only a refusal,
|
|
1022
|
+
// which posts nothing, is resent; never a group given by id or found, never any other failure.
|
|
1023
|
+
const delay = GROUP_SEND_RETRY.delaysMs[retried];
|
|
1024
|
+
if (!created || !(e instanceof WarappServerError) || e.code !== NOT_IN_GAME_GROUP || delay === undefined)
|
|
1025
|
+
throw e;
|
|
1026
|
+
retried += 1;
|
|
1027
|
+
await wait(delay);
|
|
1028
|
+
}
|
|
1029
|
+
}
|
|
838
1030
|
},
|
|
839
|
-
// A refusal is rethrown (nothing was posted; 36, too many messages, is never retried).
|
|
1031
|
+
// A refusal is rethrown (nothing was posted; 36, too many messages, is never retried). A group's refusal names
|
|
1032
|
+
// the group, and says so when this call created it (it stays).
|
|
1033
|
+
...(groupId !== undefined
|
|
1034
|
+
? {
|
|
1035
|
+
refused: (e) => new McpToolError(`war.app refused the message to game group ${groupId} (${GROUP_REFUSALS[e.code] ?? e.message}; war.app error ${e.code})` +
|
|
1036
|
+
(group?.id === undefined
|
|
1037
|
+
? '. The group was created and stays (its members see it), but nothing was sent.'
|
|
1038
|
+
: ': nothing was sent.'), {
|
|
1039
|
+
hint: group?.id === undefined
|
|
1040
|
+
? `To try again in that group, pass \`group_id: ${groupId}\` with the same \`to\`, so no other group is made.`
|
|
1041
|
+
: 'Check the group id with warapp_get_chat (a group message shows its `group`).',
|
|
1042
|
+
}),
|
|
1043
|
+
}
|
|
1044
|
+
: {}),
|
|
840
1045
|
unanswered: (failure) => ({
|
|
841
1046
|
status: 'unknown',
|
|
842
1047
|
outcome: 'unknown',
|
|
@@ -877,15 +1082,19 @@ export function registerChatTools(server, ctx, opts = {}) {
|
|
|
877
1082
|
};
|
|
878
1083
|
},
|
|
879
1084
|
});
|
|
1085
|
+
// How the new group's id was read, before anything the send itself warns of.
|
|
1086
|
+
const warning = [created?.warning, 'warning' in result ? result.warning : undefined].filter(Boolean).join(' ');
|
|
1087
|
+
const sent = retried ? { ...result, retriedAfterCreate: retried } : result;
|
|
1088
|
+
const out = warning ? { ...sent, warning } : sent;
|
|
880
1089
|
if (!commitments)
|
|
881
|
-
return
|
|
1090
|
+
return out;
|
|
882
1091
|
// B4: a message war.app confirmed or accepted made its promises: record them as mine. Otherwise
|
|
883
1092
|
// whether it went out is open, and so is whether the promises were made.
|
|
884
|
-
if (
|
|
885
|
-
return { ...
|
|
1093
|
+
if (out.outcome === 'confirmed' || out.outcome === 'accepted') {
|
|
1094
|
+
return { ...out, commitments: { recorded: await recordSent(gameId, Number(account), commitments), note: COMMITMENTS_NOTE } };
|
|
886
1095
|
}
|
|
887
1096
|
return {
|
|
888
|
-
...
|
|
1097
|
+
...out,
|
|
889
1098
|
commitments: {
|
|
890
1099
|
recorded: [],
|
|
891
1100
|
why: 'The message is not confirmed sent, so its commitments were not recorded. Check warapp_get_chat: if it went out, ' +
|
package/dist/tools/check-plan.js
CHANGED
|
@@ -28,8 +28,9 @@ import { loadLiveGame, standInLine, standInOf } from './live-context.js';
|
|
|
28
28
|
import { BRIDGE_NOTE, playerArg, resolveMe } from './live.js';
|
|
29
29
|
import { mapOf } from './map.js';
|
|
30
30
|
import { resolvePlayer, resolveTerritory } from './resolve.js';
|
|
31
|
-
import { BELOW_PLAN_BASIS, boardHistory, bordersBelowPlan, currentTurn, truceRelations, friendsOf, guardOffWarnings, modsWarning, plannerSettings, requirePlayingSeat, requireTurnPhase, turnOrdersArg, } from './turn.js';
|
|
31
|
+
import { BELOW_PLAN_BASIS, boardHistory, bordersBelowPlan, currentTurn, truceRelations, foePacts, friendsOf, guardOffWarnings, modsWarning, plannerSettings, requirePlayingSeat, requireTurnPhase, turnOrdersArg, } from './turn.js';
|
|
32
32
|
import { resolveTeamsFor } from './team-source.js';
|
|
33
|
+
import { pactPairs } from '../analysis/pacts.js';
|
|
33
34
|
import { stressOpponents } from './stress-opponents.js';
|
|
34
35
|
import { observedLowWarning } from '../analysis/opponents.js';
|
|
35
36
|
import { statedShiftWarning } from '../analysis/plan/estimates.js';
|
|
@@ -92,7 +93,8 @@ export function registerCheckPlanTool(server, ctx) {
|
|
|
92
93
|
'`movedIn` names each), or every stack attacking at once; a stack you attack moving out ' +
|
|
93
94
|
'first (a dodge: into its own territory, or a neutral or one of yours it can take — `dodges` lists each ' +
|
|
94
95
|
'with the armies that got away and what your strike then hit); two opponents striking one of your ' +
|
|
95
|
-
'territories together (teammates always;
|
|
96
|
+
'territories together (teammates always; two at peace by a pact you are not in — a reported pact, a Diplomacy ' +
|
|
97
|
+
'card or a Diplomacy 2 alliance between them, marked `pact`; any two in a free-for-all when you lead — `jointFalls` gives the ' +
|
|
96
98
|
'armies each such territory needs to hold); and, under Multi-Attack, each stack\'s most damaging chain ' +
|
|
97
99
|
'of captures. Under Local Deployment each deploy is bounded by where its bonus armies may land. Each ' +
|
|
98
100
|
'reply is tried with you moving first and with the opponent moving first unless `first_mover` says ' +
|
|
@@ -429,7 +431,13 @@ export function registerCheckPlanTool(server, ctx) {
|
|
|
429
431
|
// PLAN-TEAMS D3: a Diplomacy card in effect that the decoder is sure of is a truce here in any format
|
|
430
432
|
// (T9: the game enforces it). Its player stays among the opponents too: the decoder is unverified.
|
|
431
433
|
// T9 too: a Diplomacy 2 mod alliance (read only in a game that runs the mod) is a truce the game enforces.
|
|
432
|
-
const resolvedTruces = await truceRelations(ctx, {
|
|
434
|
+
const resolvedTruces = await truceRelations(ctx, {
|
|
435
|
+
game, me, turn, graph, board: seen, boards: history.boards, myIncome: income, tracks, diplomacy: effect.diplomacy, diplomacyOthers: effect.diplomacyOthers,
|
|
436
|
+
});
|
|
437
|
+
// #680: two opponents at peace by a pact I am not in (reported, a Diplomacy card, a Diplomacy 2 alliance) are
|
|
438
|
+
// tried striking one territory of mine together, as teammates are (counted in `safe` the same way).
|
|
439
|
+
const opponentIds = new Set(opponents.map((o) => o.id));
|
|
440
|
+
const pacts = pactPairs(foePacts(resolvedTruces?.pacts ?? [], game.players, me)).filter(([x, y]) => opponentIds.has(x) && opponentIds.has(y));
|
|
433
441
|
const truces = resolvedTruces?.relations ?? [];
|
|
434
442
|
const modRead = resolvedTruces?.mod;
|
|
435
443
|
const binding = truces.filter((r) => !friend(r.player) &&
|
|
@@ -467,6 +475,7 @@ export function registerCheckPlanTool(server, ctx) {
|
|
|
467
475
|
...(settings.localDeployments && (settings.bonusArmyPer ?? 0) > 0 ? { perTerritoryIncome: true } : {}),
|
|
468
476
|
leader,
|
|
469
477
|
...(binding.length ? { truces: binding.map((r) => ({ player: r.player, covered: r.coveredMine })) } : {}),
|
|
478
|
+
...(pacts.length ? { pacts } : {}),
|
|
470
479
|
});
|
|
471
480
|
// #274: my commander, by the check warapp_submit_turn refuses on (commander-check.ts): the same
|
|
472
481
|
// opponents, each reply at the larger of its estimate and my income (enemy_deploy only raises it,
|
|
@@ -604,7 +613,7 @@ export function registerCheckPlanTool(server, ctx) {
|
|
|
604
613
|
harmful: d.harmful,
|
|
605
614
|
});
|
|
606
615
|
/** #180: a territory two opponents take together, in a sentence. */
|
|
607
|
-
const jointText = (j) => `Players ${j.opponents[0]} and ${j.opponents[1]} together take territory ${j.territory} (${j.armies} there) with ${j.attackers[0]} from ` +
|
|
616
|
+
const jointText = (j) => `Players ${j.opponents[0]} and ${j.opponents[1]}${j.pact ? ' (at peace by a pact, #680)' : ''} together take territory ${j.territory} (${j.armies} there) with ${j.attackers[0]} from ` +
|
|
608
617
|
`territory ${j.from[0]} and ${j.attackers[1]} from territory ${j.from[1]}: it needs ${j.needs} to hold${j.bonusesLost.length ? `, or bonus${j.bonusesLost.length === 1 ? '' : 'es'} ${j.bonusesLost.map((b) => `${b.id} (${signed(b.value)})`).join(', ')} goes with it` : ''}.`;
|
|
609
618
|
const jointView = (j) => ({
|
|
610
619
|
text: jointText(j),
|
|
@@ -616,6 +625,7 @@ export function registerCheckPlanTool(server, ctx) {
|
|
|
616
625
|
attackers: j.attackers,
|
|
617
626
|
bonusesLost: j.bonusesLost.map((b) => bonusOf(b.id)),
|
|
618
627
|
incomeLost: j.incomeLost,
|
|
628
|
+
...(j.pact ? { pact: true } : {}),
|
|
619
629
|
});
|
|
620
630
|
/** One exposure in a sentence, by id. */
|
|
621
631
|
const exposure = (e) => `Next turn player ${e.opponent} can reach territory ${e.territory} (${e.armies} there) with ${e.attackers} from territory ${e.from} ` +
|