@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
|
@@ -12,8 +12,8 @@ import { McpToolError } from '@chrischall/mcp-utils';
|
|
|
12
12
|
import { z } from 'zod';
|
|
13
13
|
import { checkCommitments, MAX_MESSAGE_COMMITMENTS, MAX_NO_ATTACK_TURNS, } from '../analysis/commitments.js';
|
|
14
14
|
import { planTurn } from '../analysis/index.js';
|
|
15
|
-
import { MAX_NOTICE_TURNS } from '../analysis/relations.js';
|
|
16
|
-
import { nextAgreementId, readLedger } from '../relations-store.js';
|
|
15
|
+
import { MAX_NOTICE_TURNS, MAX_PARTIES, PACT_RESTS } from '../analysis/relations.js';
|
|
16
|
+
import { nextAgreementId, nextPactId, readLedger } from '../relations-store.js';
|
|
17
17
|
import { readCachedOrders } from '../trend.js';
|
|
18
18
|
import { currentTurn } from './common.js';
|
|
19
19
|
import { loadLiveGame } from './live-context.js';
|
|
@@ -29,6 +29,14 @@ const scopeArgs = {
|
|
|
29
29
|
territories: z.array(ref).max(MAX_SCOPE_ITEMS).optional().describe("Only these territories (names or ids); omit with `bonuses` for all of the player's."),
|
|
30
30
|
bonuses: z.array(ref).max(MAX_SCOPE_ITEMS).optional().describe("Only these bonuses' territories (names or ids)."),
|
|
31
31
|
};
|
|
32
|
+
/** #685: a pact's other parties: two or more players besides you. */
|
|
33
|
+
const playersArg = z
|
|
34
|
+
.array(ref)
|
|
35
|
+
.min(2)
|
|
36
|
+
.max(MAX_PARTIES - 1)
|
|
37
|
+
.optional()
|
|
38
|
+
.describe(`#685: an n-way truce — the other parties (names or GameFeed ids, 2–${MAX_PARTIES - 1}; you make ${MAX_PARTIES} at most), instead of \`player\`. ` +
|
|
39
|
+
'One pact `p<n>` with you in it. Every party must read the message: a game group holding all of them, or the public channel.');
|
|
32
40
|
const termsArgs = {
|
|
33
41
|
...scopeArgs,
|
|
34
42
|
notice_turns: z.coerce.number().int().min(0).max(MAX_NOTICE_TURNS).optional().describe('Turns of notice before the truce ends (default 1).'),
|
|
@@ -56,7 +64,12 @@ export const commitmentArg = z.discriminatedUnion('kind', [
|
|
|
56
64
|
z
|
|
57
65
|
.object({
|
|
58
66
|
kind: z.literal('notice').describe('I am ending our truce.'),
|
|
59
|
-
agreement: z.string().trim().min(1).max(20).describe('The agreement (e.g. "a1") notice is given on.'),
|
|
67
|
+
agreement: z.string().trim().min(1).max(20).describe('The agreement (e.g. "a1") or pact ("p1") notice is given on.'),
|
|
68
|
+
rest: z
|
|
69
|
+
.enum(PACT_RESTS)
|
|
70
|
+
.optional()
|
|
71
|
+
.describe('A pact only, and required while three or more parties are bound: what becomes of the rest of the truce — ask the owner, it is ' +
|
|
72
|
+
'never decided automatically. `continue`: you leave once your notice has run, the others stay bound; `end`: the whole pact ends then.'),
|
|
60
73
|
ends_turn: z.coerce
|
|
61
74
|
.number()
|
|
62
75
|
.int()
|
|
@@ -68,15 +81,17 @@ export const commitmentArg = z.discriminatedUnion('kind', [
|
|
|
68
81
|
z
|
|
69
82
|
.object({
|
|
70
83
|
kind: z.literal('propose').describe('I propose a truce on these terms.'),
|
|
71
|
-
player: ref.describe('The partner (name or GameFeed id).'),
|
|
84
|
+
player: ref.optional().describe('The partner (name or GameFeed id); or `players` for an n-way truce.'),
|
|
85
|
+
players: playersArg,
|
|
72
86
|
...termsArgs,
|
|
73
87
|
})
|
|
74
88
|
.describe('A truce proposed (or a counter-offer).'),
|
|
75
89
|
z
|
|
76
90
|
.object({
|
|
77
91
|
kind: z.literal('accept').describe('I accept this truce.'),
|
|
78
|
-
agreement: z.string().trim().min(1).max(20).optional().describe('The recorded proposal accepted (e.g. "a1").'),
|
|
92
|
+
agreement: z.string().trim().min(1).max(20).optional().describe('The recorded proposal accepted (e.g. "a1", or a pact "p1").'),
|
|
79
93
|
player: ref.optional().describe('The partner (name or GameFeed id), when no agreement id is given.'),
|
|
94
|
+
players: playersArg,
|
|
80
95
|
...termsArgs,
|
|
81
96
|
})
|
|
82
97
|
.describe('A truce accepted: a recorded proposal (any terms given must match it; those left out are not compared), or terms ' +
|
|
@@ -134,14 +149,28 @@ export function resolveCommitments(game, map, args) {
|
|
|
134
149
|
...(a.turn !== undefined ? { turn: a.turn } : {}),
|
|
135
150
|
};
|
|
136
151
|
case 'notice':
|
|
137
|
-
return {
|
|
152
|
+
return {
|
|
153
|
+
kind: 'notice',
|
|
154
|
+
agreement: a.agreement,
|
|
155
|
+
...(a.ends_turn !== undefined ? { endsTurn: a.ends_turn } : {}),
|
|
156
|
+
...(a.rest !== undefined ? { rest: a.rest } : {}),
|
|
157
|
+
};
|
|
138
158
|
case 'propose':
|
|
139
|
-
|
|
159
|
+
if ((a.player === undefined) === (a.players === undefined))
|
|
160
|
+
throw new McpToolError(`A propose names \`player\` (a two-party truce) or \`players\` (an n-way truce), one of them: ${NOTHING_SENT}.`, {
|
|
161
|
+
hint: 'Give `player` for one partner, or `players` for two or more.',
|
|
162
|
+
});
|
|
163
|
+
return a.players !== undefined
|
|
164
|
+
? { kind: 'propose', players: a.players.map(pid), terms: termsOf(map, a) }
|
|
165
|
+
: { kind: 'propose', with: pid(a.player), terms: termsOf(map, a) };
|
|
140
166
|
case 'accept':
|
|
167
|
+
if (a.player !== undefined && a.players !== undefined)
|
|
168
|
+
throw new McpToolError(`An accept names \`player\` or \`players\`, not both: ${NOTHING_SENT}.`, { hint: 'Give `players` for an n-way truce.' });
|
|
141
169
|
return {
|
|
142
170
|
kind: 'accept',
|
|
143
171
|
...(a.agreement !== undefined ? { agreement: a.agreement } : {}),
|
|
144
172
|
...(a.player !== undefined ? { with: pid(a.player) } : {}),
|
|
173
|
+
...(a.players !== undefined ? { players: a.players.map(pid) } : {}),
|
|
145
174
|
...(termsGiven(a) ? { terms: givenTermsOf(map, a) } : {}),
|
|
146
175
|
};
|
|
147
176
|
}
|
|
@@ -197,6 +226,8 @@ teamsKnown = true) {
|
|
|
197
226
|
players,
|
|
198
227
|
agreements: ledger?.agreements ?? [],
|
|
199
228
|
nextAgreementId: (agreements) => nextAgreementId({ agreements }),
|
|
229
|
+
pacts: ledger?.pacts ?? [],
|
|
230
|
+
nextPactId: (pacts) => nextPactId({ pacts }),
|
|
200
231
|
commitments,
|
|
201
232
|
moves,
|
|
202
233
|
source,
|
|
@@ -209,7 +240,8 @@ teamsKnown = true) {
|
|
|
209
240
|
hint: 'Promise only what the plan does: change or drop the commitment, and drop the promise from the message (an undeclared ' +
|
|
210
241
|
'promise is not allowed). To promise an attack the plan does not make, submit those orders first (warapp_submit_turn); ' +
|
|
211
242
|
'to change a truce, record it with warapp_record_agreement. A proposal, an acceptance or a notice goes to the ' +
|
|
212
|
-
'partner: privately to that player, or to the whole game
|
|
243
|
+
'partner: privately to that player, or to the whole game; on an n-way truce (`players`, a pact "p<n>") to every party — ' +
|
|
244
|
+
'a game group holding all of them, or the whole game. A notice on a pact of three or more needs `rest`: ask the owner.',
|
|
213
245
|
});
|
|
214
246
|
}
|
|
215
247
|
return { turn, source, commitments, checks, players };
|
package/dist/tools/diplomacy.js
CHANGED
|
@@ -14,7 +14,8 @@ import { McpToolError } from '@chrischall/mcp-utils';
|
|
|
14
14
|
import { z } from 'zod';
|
|
15
15
|
import { findChokepoints, planTurn } from '../analysis/index.js';
|
|
16
16
|
import { diplomacyFacts, MAX_NOTICE_TURNS, offerChecks, partyRefusal, priceTruce, scopeRefusal, sharedBorder, agreementState, suggestedTerms, TERMINAL_STATUSES, truceEndgame, truceVerdict, } from '../analysis/relations.js';
|
|
17
|
-
import { readLedger } from '../relations-store.js';
|
|
17
|
+
import { ledgerTruces, readLedger } from '../relations-store.js';
|
|
18
|
+
import { atPeaceWith, pactLabel, pactsInForce } from '../analysis/pacts.js';
|
|
18
19
|
import { isTeamGame } from '../teams.js';
|
|
19
20
|
import { bonusNamer, currentTurn, gameIdArg, graphOf, namer, readAnnotations, respond, untrustedDescription, untrustedText, viewArg } from './common.js';
|
|
20
21
|
import { lookupMeta } from './hints.js';
|
|
@@ -80,7 +81,11 @@ export function registerDiplomacyTool(server, ctx, opts = {}) {
|
|
|
80
81
|
'proposed — never parsed from chat), the same price and three checks: do I gain only if they keep it, do I ' +
|
|
81
82
|
'lose if I comply and they do not, do they gain from my compliance; all three true means run warapp_check_plan ' +
|
|
82
83
|
'first. `facts`: true statements about third players you may cite to each neighbour, each with whether it can ' +
|
|
83
|
-
|
|
84
|
+
"see them under the game's fog. #680: `pactsBetweenOthers` lists the pacts between other players binding this " +
|
|
85
|
+
'turn (reported, one you left, a Diplomacy card or a Diplomacy 2 alliance between two others), and a neighbour ' +
|
|
86
|
+
'already at peace with another player carries `atPeaceWith` and a reason saying so — report only, no price reads it. ' +
|
|
87
|
+
'#686: a pact a party broke in view on your boards carries `broken: true` and its `flags`, and no longer counts as peace. ' +
|
|
88
|
+
`Refused outside a free-for-all. ${BRIDGE_NOTE} Sends nothing and records ` +
|
|
84
89
|
'nothing: record an agreement with warapp_record_agreement, and send a message with warapp_send_chat.'),
|
|
85
90
|
_meta: lookupMeta(['truce advice', 'should i make a truce', 'diplomacy', 'price a deal', 'they offered a truce', 'alliance']),
|
|
86
91
|
annotations: readAnnotations('Advise on war.app truces'),
|
|
@@ -254,7 +259,8 @@ export function registerDiplomacyTool(server, ctx, opts = {}) {
|
|
|
254
259
|
continue;
|
|
255
260
|
}
|
|
256
261
|
const border = sharedBorder(graph, board, me.id, partner, chokepoints);
|
|
257
|
-
|
|
262
|
+
// #680: a pact I am in counts per partner, as the same truce recorded apart would.
|
|
263
|
+
const open = ledgerTruces(ledger).find((a) => a.with === partner && !TERMINAL_STATUSES.has(a.status));
|
|
258
264
|
const terms = open ? open.terms : suggestedTerms(border, turn);
|
|
259
265
|
const { priced, verdict, recordState, related: rel } = await price(partner, terms, open?.id);
|
|
260
266
|
built.push({ partner, ...(open ? { agreement: open.id } : {}), border, terms, priced, verdict, recordState, related: rel, facts });
|
|
@@ -267,11 +273,22 @@ export function registerDiplomacyTool(server, ctx, opts = {}) {
|
|
|
267
273
|
: undefined;
|
|
268
274
|
const description = game.description !== undefined ? untrustedText(game.description, DESCRIPTION_MAX) : null;
|
|
269
275
|
// The Diplomacy 2 mod's alliances beside the ledger (the read warapp_plan_turn's setup made; none without the mod).
|
|
270
|
-
const liveAgreements = (ledger
|
|
276
|
+
const liveAgreements = ledgerTruces(ledger).filter((a) => {
|
|
271
277
|
const st = agreementState(a, turn ?? 0, players);
|
|
272
278
|
return st.phase === 'active' || st.phase === 'notice';
|
|
273
279
|
});
|
|
274
280
|
const modView = setup.truces ? modRelationsView(setup.truces.mod, liveAgreements, playerRef) : undefined;
|
|
281
|
+
// #680: the pacts between other players this turn (report only): who each neighbour is already at peace with.
|
|
282
|
+
const pacts = setup.truces?.pacts ?? [];
|
|
283
|
+
const peaceOf = (partner) => {
|
|
284
|
+
// #686: a broken pact no longer counts as peace.
|
|
285
|
+
const with_ = pactsInForce(pacts).filter((k) => k.parties.includes(partner));
|
|
286
|
+
if (!with_.length)
|
|
287
|
+
return undefined;
|
|
288
|
+
return `Player ${partner} is already at peace with ${with_
|
|
289
|
+
.map((k) => `player${k.parties.length > 2 ? 's' : ''} ${k.parties.filter((x) => x !== partner).join(', ')} (${pactLabel(k)})`)
|
|
290
|
+
.join('; ')}: a truce with it does not free it from them, and they may act together (#680, report only).`;
|
|
291
|
+
};
|
|
275
292
|
return respond(view, VIEWS, (rung) => {
|
|
276
293
|
const neighbours = built.map((b) => ({
|
|
277
294
|
player: playerRef(b.partner),
|
|
@@ -291,7 +308,8 @@ export function registerDiplomacyTool(server, ctx, opts = {}) {
|
|
|
291
308
|
terms: { ...termsView(b.terms), source: b.agreement ? 'recorded' : 'suggested' },
|
|
292
309
|
price: priceView(b.priced, rung),
|
|
293
310
|
verdict: b.verdict.verdict,
|
|
294
|
-
reasons: b.verdict.reasons,
|
|
311
|
+
reasons: peaceOf(b.partner) ? [...b.verdict.reasons, peaceOf(b.partner)] : b.verdict.reasons,
|
|
312
|
+
...(atPeaceWith(pacts, b.partner).length ? { atPeaceWith: atPeaceWith(pacts, b.partner).map(playerRef) } : {}),
|
|
295
313
|
record: b.recordState,
|
|
296
314
|
...(habitsOf(b.partner) ? { habits: habitsOf(b.partner) } : {}),
|
|
297
315
|
}),
|
|
@@ -307,6 +325,20 @@ export function registerDiplomacyTool(server, ctx, opts = {}) {
|
|
|
307
325
|
description,
|
|
308
326
|
},
|
|
309
327
|
...(modView ? { modAlliances: modView } : {}),
|
|
328
|
+
...(pacts.length
|
|
329
|
+
? {
|
|
330
|
+
pactsBetweenOthers: pacts.map((k) => ({
|
|
331
|
+
parties: k.parties.map(playerRef),
|
|
332
|
+
source: k.source,
|
|
333
|
+
...(k.agreement ? { agreement: k.agreement } : {}),
|
|
334
|
+
...(k.untilTurn !== undefined ? { untilTurn: k.untilTurn } : {}),
|
|
335
|
+
...(k.endsTurn !== undefined ? { endsTurn: k.endsTurn } : {}),
|
|
336
|
+
// #686: a party broke it in view: it no longer counts (report only).
|
|
337
|
+
...(k.broken ? { broken: true } : {}),
|
|
338
|
+
...(k.flags?.length ? { flags: k.flags.map((f) => ({ ...f, by: playerRef(f.by), against: playerRef(f.against), territories: f.territories.map(name) })) } : {}),
|
|
339
|
+
})),
|
|
340
|
+
}
|
|
341
|
+
: {}),
|
|
310
342
|
income: setup.income,
|
|
311
343
|
neighbours,
|
|
312
344
|
...(offerResult
|
|
@@ -9,7 +9,7 @@ import { z } from 'zod';
|
|
|
9
9
|
import { inGameOf, playersByInGameId } from '../live.js';
|
|
10
10
|
import { Method, writeGameRefreshParams } from '../protocol/methods.js';
|
|
11
11
|
import { readMyOrderList } from '../my-orders.js';
|
|
12
|
-
import { allianceMismatches, allyAttacksIn, breakAlerts, breaksInOrders, diplomacy2From, modPairs, myAllies, readModData, runsDiplomacy2, } from '../mod-alliances.js';
|
|
12
|
+
import { allianceMismatches, allyAttacksIn, breakAlerts, breaksInOrders, diplomacy2From, modPairs, myAllies, othersAlliances, readModData, runsDiplomacy2, } from '../mod-alliances.js';
|
|
13
13
|
import { currentTurn, gameIdArg, readAnnotations, respond, untrustedDescription, untrustedText } from './common.js';
|
|
14
14
|
import { lookupMeta } from './hints.js';
|
|
15
15
|
import { readLatestBoard } from './live-context.js';
|
|
@@ -50,6 +50,18 @@ export async function readModAlliances(ctx, game, me) {
|
|
|
50
50
|
const allies = ids.map(feedOf).filter((x) => x !== null);
|
|
51
51
|
return { status: 'read', state, me: mine, allies, unmapped: ids.length - allies.length, feedOf };
|
|
52
52
|
}
|
|
53
|
+
/**
|
|
54
|
+
* #680: the Diplomacy 2 alliances between two other players, by GameFeed id (each pair ascending): pacts between
|
|
55
|
+
* them, report only. Only a read that worked; a player whose in-game id maps to no GameFeed player is left out.
|
|
56
|
+
*/
|
|
57
|
+
export function modPacts(read) {
|
|
58
|
+
if (read.status !== 'read')
|
|
59
|
+
return [];
|
|
60
|
+
return othersAlliances(read.state, read.me).flatMap(([x, y]) => {
|
|
61
|
+
const [a, b] = [read.feedOf(x), read.feedOf(y)];
|
|
62
|
+
return a === null || b === null || a === b ? [] : [[a, b].sort((p, q) => p - q)];
|
|
63
|
+
});
|
|
64
|
+
}
|
|
53
65
|
/** The warnings a turn tool adds for a mod-191 game (none for `no-mod`). */
|
|
54
66
|
export function modAllianceWarnings(read) {
|
|
55
67
|
if (read.status === 'no-mod')
|