@chrischall/warapp-mcp 0.10.0 → 0.12.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude-plugin/marketplace.json +3 -3
- package/.claude-plugin/plugin.json +1 -1
- package/README.md +10 -8
- package/dist/analysis/cards-in-effect.js +10 -1
- package/dist/analysis/chat-mentions.js +17 -0
- package/dist/analysis/commander-fog.js +126 -0
- package/dist/analysis/end-game-stats.js +149 -0
- package/dist/analysis/local-deploy.js +3 -2
- package/dist/analysis/outlook.js +133 -55
- package/dist/analysis/picks.js +125 -0
- package/dist/analysis/plan/commander.js +3 -2
- package/dist/analysis/plan/deploy-estimates.js +11 -7
- package/dist/analysis/plan/estimates.js +63 -9
- package/dist/analysis/plan/relations.js +29 -14
- package/dist/analysis/plan/shared.js +21 -0
- package/dist/analysis/plan/threats.js +74 -5
- package/dist/analysis/player-record.js +31 -1
- package/dist/analysis/player.js +23 -10
- package/dist/analysis/relations.js +83 -9
- package/dist/analysis/scale.js +71 -0
- package/dist/analysis/single-pick.js +356 -0
- package/dist/bundle.js +3099 -809
- package/dist/chat-links.js +141 -0
- package/dist/finished-store.js +30 -0
- package/dist/index.js +1 -1
- package/dist/known-mods.js +33 -0
- package/dist/map-stats.js +24 -2
- package/dist/mod-alliances.js +217 -0
- package/dist/mod-data.js +160 -0
- package/dist/my-games.js +53 -2
- package/dist/normalize.js +7 -0
- package/dist/outlook-log.js +13 -0
- package/dist/player-record-store.js +5 -3
- package/dist/protocol/methods.js +14 -2
- package/dist/relations-store.js +29 -1
- package/dist/tools/card-advice.js +29 -9
- package/dist/tools/card-effects.js +3 -1
- package/dist/tools/card-support-advice.js +1 -1
- package/dist/tools/chat-advice.js +1 -1
- package/dist/tools/chat-inbox.js +67 -10
- package/dist/tools/chat.js +46 -8
- package/dist/tools/check-plan.js +115 -11
- package/dist/tools/close-finished-game.js +110 -0
- package/dist/tools/commander-check.js +80 -1
- package/dist/tools/diplomacy.js +11 -2
- package/dist/tools/end-of-game.js +57 -3
- package/dist/tools/game.js +7 -3
- package/dist/tools/how-lost.js +68 -5
- package/dist/tools/index.js +21 -1
- package/dist/tools/map.js +50 -1
- package/dist/tools/mod-alliances.js +191 -0
- package/dist/tools/my-games.js +12 -1
- package/dist/tools/pace.js +44 -0
- package/dist/tools/picks.js +41 -1
- package/dist/tools/relations.js +120 -7
- package/dist/tools/session.js +20 -6
- package/dist/tools/stress-opponents.js +25 -2
- package/dist/tools/turn.js +338 -42
- package/dist/tools/write-kit.js +1 -0
- package/dist/version.js +1 -1
- package/manifest.json +10 -2
- package/mint.yaml +3 -4
- package/package.json +1 -1
- package/server.json +2 -2
- package/skills/warapp-mcp/SKILL.md +73 -11
package/dist/tools/my-games.js
CHANGED
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
// games together and that the server honours a count above 10.
|
|
11
11
|
import { untrustedEnvelope } from '@chrischall/mcp-utils';
|
|
12
12
|
import { z } from 'zod';
|
|
13
|
-
import { briefGameLine, gameStateName, isFinished, readMyGames, summarizeMyGames } from '../my-games.js';
|
|
13
|
+
import { BOOT_NOTE, briefGameLine, gameStateName, isFinished, readMyGames, summarizeMyGames } from '../my-games.js';
|
|
14
14
|
import { Method, MY_GAMES_DEFAULT_SORT, MyGamesFilterType, writeGetMyGamesParams } from '../protocol/methods.js';
|
|
15
15
|
import { readAnnotations, respond, untrustedDescription, untrustedText, WARAPP_UNTRUSTED_NOTE } from './common.js';
|
|
16
16
|
import { canonicalMeta } from './hints.js';
|
|
@@ -18,6 +18,7 @@ import { BRIDGE_NOTE } from './live.js';
|
|
|
18
18
|
import { holdsSeat, playerStateName } from '../player-states.js';
|
|
19
19
|
import { sweepFinished } from './end-of-game.js';
|
|
20
20
|
import { accountUnknown } from './write-kit.js';
|
|
21
|
+
import { rememberPace } from './pace.js';
|
|
21
22
|
import { pendingSurrenders, surrenderOwed } from '../surrender-pending.js';
|
|
22
23
|
import { readDetailsSeats, SURRENDER_PENDING_NOTE, surrenderMayBePending } from './surrender-pending.js';
|
|
23
24
|
const VIEWS = ['compact', 'brief'];
|
|
@@ -75,6 +76,8 @@ export async function fetchMyGames(ctx) {
|
|
|
75
76
|
return readMyGames(await ctx.bundle(), env.body);
|
|
76
77
|
};
|
|
77
78
|
const [me, list] = await Promise.all([myInGameId(ctx), listMyGames(read)]);
|
|
79
|
+
// Pace: keep the boot clocks for warapp_session_status (no request of its own).
|
|
80
|
+
rememberPace(ctx, summarizeMyGames(list.games, me), Date.now());
|
|
78
81
|
return { me, ...list };
|
|
79
82
|
}
|
|
80
83
|
/** #317: the most games whose details one call reads for a pending surrender (the rest are `null`). */
|
|
@@ -141,6 +144,10 @@ export function registerMyGamesTool(server, ctx, deps = {}) {
|
|
|
141
144
|
'chat per channel (public, team, private, group) and toMe (unread private chat is addressed to you) — flags, ' +
|
|
142
145
|
'not counts; null when they did not read. Games with unread private chat come right after the ones waiting on ' +
|
|
143
146
|
'you, and the top-level unreadPrivateGames counts them; read them with warapp_chat_inbox. ' +
|
|
147
|
+
'A multi-day game being played or picked with your seat playing carries `boot` (pace, from the game list: its boot ' +
|
|
148
|
+
'time, your banked time, their sum, and while it waits on you `leftMinutes`, the sum less how long your turn has ' +
|
|
149
|
+
'run, with `soon` under 6 hours; unverified live); `bootSoon` counts the games close to a boot, and brief adds ' +
|
|
150
|
+
'" — boot in …" to them. ' +
|
|
144
151
|
'Finished games are left out unless ' +
|
|
145
152
|
'`include_finished` (`finishedLeftOut` counts them). `listed` is how many games war.app returned and ' +
|
|
146
153
|
'`complete` false (with a `warning`) means the list may be partial. Use the id with the other warapp tools. ' +
|
|
@@ -187,6 +194,10 @@ export function registerMyGamesTool(server, ctx, deps = {}) {
|
|
|
187
194
|
count: games.length,
|
|
188
195
|
waitingOnYou: games.filter((g) => g.waitingOnYou).length,
|
|
189
196
|
unreadPrivateGames: games.filter((g) => g.unreadChat?.private === true).length,
|
|
197
|
+
// Pace: multi-day games whose boot is under six hours away (boot time plus bank, less my turn so far).
|
|
198
|
+
...(games.some((g) => g.boot)
|
|
199
|
+
? { bootSoon: games.filter((g) => g.boot?.soon).length, bootNote: BOOT_NOTE }
|
|
200
|
+
: {}),
|
|
190
201
|
surrenderPending: games.filter((g) => surrenderOwed(g.surrenderPending)).length,
|
|
191
202
|
surrenderNote: SURRENDER_PENDING_NOTE +
|
|
192
203
|
(unread ? ` The details of ${unread} game(s) could not be read.` : '') +
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
// Pace: the boot clocks of my multi-day games, as the last game-list read in this process saw them
|
|
2
|
+
// (warapp_my_games, warapp_chat_inbox and every other tool that lists my games through `fetchMyGames`), so
|
|
3
|
+
// warapp_session_status can warn of a boot close by without a war.app request of its own.
|
|
4
|
+
import { BOOT_WARN_MINUTES, minutesText } from '../my-games.js';
|
|
5
|
+
import { untrustedText } from './common.js';
|
|
6
|
+
const snapshots = new WeakMap();
|
|
7
|
+
/** Keep the boot clocks of `games` (summarized for me) as read at `at`, for the context `owner`. */
|
|
8
|
+
export function rememberPace(owner, games, at) {
|
|
9
|
+
snapshots.set(owner, {
|
|
10
|
+
at,
|
|
11
|
+
games: games.flatMap((g) => (g.boot?.leftMinutes != null ? [{ id: g.id, name: g.name, leftMinutes: g.boot.leftMinutes }] : [])),
|
|
12
|
+
});
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* #532: drop one game from the kept snapshot — warapp_submit_turn calls it once war.app confirms my orders, since
|
|
16
|
+
* the game no longer waits on me and the snapshot would keep naming it until the list is read again.
|
|
17
|
+
*/
|
|
18
|
+
export function forgetPaceGame(owner, gameId) {
|
|
19
|
+
const s = snapshots.get(owner);
|
|
20
|
+
if (s)
|
|
21
|
+
snapshots.set(owner, { ...s, games: s.games.filter((g) => g.id !== gameId) });
|
|
22
|
+
}
|
|
23
|
+
export const PACE_NOTE = `Read from the last game list this server read (warapp_my_games and the chat inbox read it): each game waiting on you ` +
|
|
24
|
+
`whose boot time plus your banked time, less how long your turn has run, is under ${BOOT_WARN_MINUTES / 60} hours ` +
|
|
25
|
+
'away now. Unverified live; call warapp_my_games for a fresh read.';
|
|
26
|
+
export function paceStatus(owner, now) {
|
|
27
|
+
const s = snapshots.get(owner);
|
|
28
|
+
if (!s)
|
|
29
|
+
return undefined;
|
|
30
|
+
const ago = Math.max(0, Math.floor((now - s.at) / 60_000));
|
|
31
|
+
const bootSoon = s.games
|
|
32
|
+
.map((g) => ({ ...g, leftMinutes: Math.max(0, g.leftMinutes - ago) }))
|
|
33
|
+
.filter((g) => g.leftMinutes < BOOT_WARN_MINUTES)
|
|
34
|
+
.sort((a, b) => a.leftMinutes - b.leftMinutes || a.id - b.id)
|
|
35
|
+
.map((g) => ({ id: g.id, name: untrustedText(g.name), leftMinutes: g.leftMinutes, left: minutesText(g.leftMinutes) }));
|
|
36
|
+
return { listReadMinutesAgo: ago, bootSoon, note: PACE_NOTE };
|
|
37
|
+
}
|
|
38
|
+
/** The warning line for the games close to a boot, or undefined. */
|
|
39
|
+
export function paceWarning(p) {
|
|
40
|
+
if (!p?.bootSoon.length)
|
|
41
|
+
return undefined;
|
|
42
|
+
return (`Boot close: ${p.bootSoon.map((g) => `game ${g.id} in ${g.left}`).join(', ')} — take ${p.bootSoon.length === 1 ? 'that turn' : 'those turns'} ` +
|
|
43
|
+
`(under ${BOOT_WARN_MINUTES / 60} hours left, boot time plus bank).`);
|
|
44
|
+
}
|
package/dist/tools/picks.js
CHANGED
|
@@ -164,6 +164,12 @@ export function registerPickTools(server, ctx, deps = {}) {
|
|
|
164
164
|
'On a very large map (over 400 pickable territories) only the territories that score best alone are ranked, 400 at the default budget and more with a larger one (`candidates` says how many); ' +
|
|
165
165
|
'the plan has a time budget (20 s; `WARAPP_PICKS_BUDGET_MS` sets it, 0 for none) and, when it runs out, answers `partial: true` with a valid list; ' +
|
|
166
166
|
'the compact view caps its reasons, threats, coverage and warning lists (counts say what was cut; `submitPicks` is never cut). ' +
|
|
167
|
+
'In a game that overrides bonus values, with a territory limit of 1 on a huge map (1,000+ territories, 3+ players, not a team game) it ranks single starts instead of groups: ' +
|
|
168
|
+
'`startRanking` shows 25 starts per `page`, each scored on income at the game\'s bonus values (overrides applied; a bonus worth 0 ' +
|
|
169
|
+
'is crossed, never counted) over a 5-turn flood opening, the turn its income first exceeds the base income, the nearest paying bonus, ' +
|
|
170
|
+
'wastelands within 2 hops (blocking a paying bonus or shielding an approach) and commander safety (open approaches, entries into its ' +
|
|
171
|
+
'2-hop pocket, the nearest other start and the rival starts expected within 3 hops), with reasons; `submitPicks` is the ranking in ' +
|
|
172
|
+
'priority order, cut at the client\'s max (players × 1). The ranking is cached per map, so the next page costs nothing. ' +
|
|
167
173
|
'In a team game only the players off your team are threats, `team` names your teammates, and the list is judged by both award ' +
|
|
168
174
|
"orders that fit (`award.orders`; a team game's is unverified). When a teammate's pick list can be read (unverified), each " +
|
|
169
175
|
"teammate carries `picks`, and `team.coordination` reports the overlap with your list, the bonuses their top picks into " +
|
|
@@ -179,13 +185,21 @@ export function registerPickTools(server, ctx, deps = {}) {
|
|
|
179
185
|
inputSchema: z.object({
|
|
180
186
|
game_id: gameIdArg,
|
|
181
187
|
view: viewArg(VIEWS, 'compact (default) gives the ranked picks with reasons, the groups and submitPicks (and the first start bonuses of `mapRecord`); "full" adds the settings the plan assumed and every start bonus.'),
|
|
188
|
+
page: z.coerce
|
|
189
|
+
.number()
|
|
190
|
+
.int()
|
|
191
|
+
.min(1)
|
|
192
|
+
.max(200)
|
|
193
|
+
.optional()
|
|
194
|
+
.describe('Single-pick ranking only (a territory limit of 1 on a huge map): the page of 25 ranked starts to detail (default 1). ' +
|
|
195
|
+
'The submit list is the same on every page.'),
|
|
182
196
|
spread: z
|
|
183
197
|
.boolean()
|
|
184
198
|
.optional()
|
|
185
199
|
.describe('In a 1v1, spread the primary across bonuses against a counter-pick instead of one compact cluster ' +
|
|
186
200
|
'(default false); usually worse on large maps. Ignored with three or more players.'),
|
|
187
201
|
}),
|
|
188
|
-
}, async ({ game_id, view, spread }) => {
|
|
202
|
+
}, async ({ game_id, view, spread, page }) => {
|
|
189
203
|
const feed = await ctx.client.getGame(game_id, { settings: true });
|
|
190
204
|
requirePickPhase(feed);
|
|
191
205
|
const { territories, info } = await loadLiveGame(ctx, feed);
|
|
@@ -248,6 +262,8 @@ export function registerPickTools(server, ctx, deps = {}) {
|
|
|
248
262
|
...(team ? { team: { teammates: team.length, ...(lists.some((l) => l.length) ? { lists } : {}) } } : {}),
|
|
249
263
|
...(budgetMs !== undefined ? { budgetMs } : {}),
|
|
250
264
|
...(limitRead.fullDeal ? { fullDeal: true } : {}),
|
|
265
|
+
...(page !== undefined ? { singlePage: page } : {}),
|
|
266
|
+
...((game.settings?.overriddenBonuses?.size ?? 0) > 0 ? { overridden: true } : {}),
|
|
251
267
|
});
|
|
252
268
|
}
|
|
253
269
|
catch (e) {
|
|
@@ -400,6 +416,30 @@ export function registerPickTools(server, ctx, deps = {}) {
|
|
|
400
416
|
},
|
|
401
417
|
...(plan.partial ? { partial: true } : {}),
|
|
402
418
|
...(plan.candidates ? { candidates: plan.candidates } : {}),
|
|
419
|
+
...(plan.single
|
|
420
|
+
? {
|
|
421
|
+
// Mega-game spec part 2: the ranked single starts of a huge map, one page at a time.
|
|
422
|
+
startRanking: {
|
|
423
|
+
shown: plan.single.shown,
|
|
424
|
+
page: plan.single.page,
|
|
425
|
+
pages: plan.single.pages,
|
|
426
|
+
simulated: plan.single.simulated,
|
|
427
|
+
payingBonuses: plan.single.paying,
|
|
428
|
+
...(plan.single.cached ? { cached: true } : {}),
|
|
429
|
+
starts: plan.single.starts.map((x, i) => ({
|
|
430
|
+
rank: plan.single.shown.from + i,
|
|
431
|
+
territory: name(x.territoryId),
|
|
432
|
+
score: x.score,
|
|
433
|
+
firstIncomeTurn: x.firstIncomeTurn,
|
|
434
|
+
nearestPayingBonus: x.nearestPaying ? { ...bonusName(x.nearestPaying.bonusId), value: x.nearestPaying.value, hops: x.nearestPaying.hops } : null,
|
|
435
|
+
bonuses: x.bonuses.map((b) => ({ ...bonusName(b.bonusId), value: b.value, turn: b.turn, contest: b.contest })),
|
|
436
|
+
wastelands: { blocking: x.wastelands.blocking.map(name), shielding: x.wastelands.shielding.map(name) },
|
|
437
|
+
safety: x.safety,
|
|
438
|
+
reasons: x.reasons ?? [],
|
|
439
|
+
})),
|
|
440
|
+
},
|
|
441
|
+
}
|
|
442
|
+
: {}),
|
|
403
443
|
...cappedLines('warnings', [...warnings, ...plan.warnings], !lean(rung)),
|
|
404
444
|
...cappedLines('rationale', plan.rationale, !lean(rung)),
|
|
405
445
|
submitPicks: { game_id: game.id, territories: plan.picks.map((p) => p.territoryId) },
|
package/dist/tools/relations.js
CHANGED
|
@@ -5,12 +5,13 @@
|
|
|
5
5
|
// and hosted, name-free per-agreement entries and tallies) — nothing is sent to war.app or to any
|
|
6
6
|
// player, so it is not confirm-gated. An agreement exists only because the player recorded it here with
|
|
7
7
|
// structured terms: chat is never parsed into one, and words change no flag — only the board does.
|
|
8
|
+
import { modRelationsView, readModAlliances } from './mod-alliances.js';
|
|
8
9
|
import { McpToolError, toolAnnotations } from '@chrischall/mcp-utils';
|
|
9
10
|
import { z } from 'zod';
|
|
10
11
|
import { boardIncome, incomeRules, trackGame, trackOpponents } from '../analysis/index.js';
|
|
11
12
|
import { agreementChange } from '../analysis/commitments.js';
|
|
12
13
|
import { playerRecord, recordDelta, recordEntryFor } from '../analysis/player-record.js';
|
|
13
|
-
import { AGREEMENT_STATUSES, agreementState, breachWatch, MAX_NOTICE_TURNS, newAgreement, OPENING_STATUSES, partyRefusal, scopeRefusal, tacitTruces, TERMINAL_STATUSES, transitionAgreement, TRUCE_OUTGROW_RATIO, trust, truceEndgame, } from '../analysis/relations.js';
|
|
14
|
+
import { AGREEMENT_STATUSES, agreementState, breachWatch, EXCEPTION_DIRECTIONS, MAX_EXCEPTION_NOTE, MAX_NOTICE_TURNS, newAgreement, OPENING_STATUSES, partyRefusal, scopeRefusal, tacitTruces, TERMINAL_STATUSES, transitionAgreement, TRUCE_OUTGROW_RATIO, trust, truceEndgame, withExceptions, } from '../analysis/relations.js';
|
|
14
15
|
import { AVOID_REASONS, emptyIntel, INCOME_STALE_TURNS, intelIsEmpty } from '../analysis/intel.js';
|
|
15
16
|
import { boardStateFromLive } from '../live.js';
|
|
16
17
|
import { entryKey, legacyEntryKey, playerRecordEnabled, playerRecordState, readPlayerRecord, updatePlayerRecord } from '../player-record-store.js';
|
|
@@ -27,6 +28,7 @@ import { recordProfile } from './profile-hook.js';
|
|
|
27
28
|
import { resolveBonus, resolvePlayer, resolveTerritory } from './resolve.js';
|
|
28
29
|
import { boardHistory, plannerSettings } from './turn.js';
|
|
29
30
|
import { captureObservation } from './decision-capture.js';
|
|
31
|
+
import { scrubNames } from '../decision-log.js';
|
|
30
32
|
import { resolveTeamsFor } from './team-source.js';
|
|
31
33
|
const VIEWS = ['compact', 'full'];
|
|
32
34
|
const MAX_SCOPE_ITEMS = 200;
|
|
@@ -165,9 +167,27 @@ function agreementView(a, game, map, turn, rung) {
|
|
|
165
167
|
},
|
|
166
168
|
...(a.enforced !== undefined ? { enforced: a.enforced } : {}),
|
|
167
169
|
...(a.retaliated !== undefined ? { retaliated: a.retaliated } : {}),
|
|
170
|
+
...(a.exceptions?.length
|
|
171
|
+
? {
|
|
172
|
+
exceptions: a.exceptions.map((e) => ({
|
|
173
|
+
id: e.id,
|
|
174
|
+
direction: e.direction,
|
|
175
|
+
territories: e.territories.map(name),
|
|
176
|
+
turns: [e.fromTurn, e.toTurn],
|
|
177
|
+
inForce: e.fromTurn <= turn && turn <= e.toTurn,
|
|
178
|
+
recordedTurn: e.recordedTurn,
|
|
179
|
+
...(e.note !== undefined ? { note: untrustedText(e.note) } : {}),
|
|
180
|
+
})),
|
|
181
|
+
}
|
|
182
|
+
: {}),
|
|
168
183
|
...(rung === 'full' ? { history: a.history } : {}),
|
|
169
184
|
};
|
|
170
185
|
}
|
|
186
|
+
/** An exception's note as stored: trimmed, player names scrubbed (`Player <id>`), capped; absent when empty. */
|
|
187
|
+
export function exceptionNote(note, game) {
|
|
188
|
+
const t = note?.trim();
|
|
189
|
+
return t ? scrubNames(t, game.players).slice(0, MAX_EXCEPTION_NOTE) : undefined;
|
|
190
|
+
}
|
|
171
191
|
/** An entry as a result shows it: everything but its key. */
|
|
172
192
|
const entryView = ({ key: _key, ...rest }) => rest;
|
|
173
193
|
/** The reliability facts on record for `partner` (and its entries), or why there are none. */
|
|
@@ -266,6 +286,48 @@ export async function recordBrokenByMe(o) {
|
|
|
266
286
|
return o.agreements.map((agreement) => ({ agreement, ledger: 'refused', why: e.message }));
|
|
267
287
|
}
|
|
268
288
|
}
|
|
289
|
+
/**
|
|
290
|
+
* `warapp_submit_turn`'s `partner_approved`: record, once the orders are committed, a one-turn `mine`
|
|
291
|
+
* exception on each agreement the orders hit (its territories hit, the note already scrubbed) — under the
|
|
292
|
+
* ledger's lock, then the partner's player record (D5: an exception, never a break). Never throws.
|
|
293
|
+
*/
|
|
294
|
+
export async function recordPartnerApproved(o) {
|
|
295
|
+
const { dir, env, game, me, map, turn } = o;
|
|
296
|
+
const graph = graphOf(map);
|
|
297
|
+
const refused = (why) => o.exceptions.map((x) => ({ agreement: x.agreement, territories: [...x.territories], ledger: 'refused', why }));
|
|
298
|
+
try {
|
|
299
|
+
return await withLedgerLock(dir, game.id, me.id, async () => {
|
|
300
|
+
const read = await readLedgerForWrite(dir, game.id, me.id);
|
|
301
|
+
if (read === null || read === 'unreadable')
|
|
302
|
+
return refused(read === null ? 'no ledger for this game' : 'the ledger exists but cannot be read');
|
|
303
|
+
let ledger = read;
|
|
304
|
+
const out = [];
|
|
305
|
+
for (const x of o.exceptions) {
|
|
306
|
+
const territories = [...new Set(x.territories)].sort((a, b) => a - b);
|
|
307
|
+
const found = ledger.agreements.find((a) => a.id === x.agreement);
|
|
308
|
+
if (!found) {
|
|
309
|
+
out.push({ agreement: x.agreement, territories, ledger: 'refused', why: 'not in the ledger' });
|
|
310
|
+
continue;
|
|
311
|
+
}
|
|
312
|
+
const ex = { direction: 'mine', territories, fromTurn: turn, toTurn: turn, recordedTurn: turn, ...(x.note ? { note: x.note } : {}) };
|
|
313
|
+
const moved = withExceptions(found, [ex]);
|
|
314
|
+
const rest = ledger.agreements.filter((a) => a.id !== found.id);
|
|
315
|
+
const next = { ...ledger, agreements: [...rest, moved] };
|
|
316
|
+
if (!(await writeLedger(dir, next))) {
|
|
317
|
+
out.push({ agreement: x.agreement, territories, ledger: 'refused', why: 'the ledger could not be written' });
|
|
318
|
+
continue;
|
|
319
|
+
}
|
|
320
|
+
ledger = next;
|
|
321
|
+
const playerRecord = await updateAgreementRecord({ dir, env, game, me, map, graph, agreement: moved, before: found, created: false, others: rest });
|
|
322
|
+
out.push({ agreement: x.agreement, territories, ledger: 'recorded', id: moved.exceptions.at(-1).id, playerRecord });
|
|
323
|
+
}
|
|
324
|
+
return out;
|
|
325
|
+
});
|
|
326
|
+
}
|
|
327
|
+
catch (e) {
|
|
328
|
+
return refused(e.message);
|
|
329
|
+
}
|
|
330
|
+
}
|
|
269
331
|
/**
|
|
270
332
|
* B4 (warapp_send_chat, once a message is sent): record its declared commitments in the ledger as
|
|
271
333
|
* mine, under the ledger's lock — a propose, accept or notice re-applied to the ledger as it now stands
|
|
@@ -336,7 +398,7 @@ export function registerRelationsTools(server, ctx, opts = {}) {
|
|
|
336
398
|
'its state this turn (`proposed`, `active`, in `notice` with the turn it ends, or `over` and why: ended, broken, ' +
|
|
337
399
|
'the partner eliminated or turned AI, only two players left, its end condition met, its notice run), and for a ' +
|
|
338
400
|
'live one: watch `flags` from your own board history — `broken` (the partner took or attacked a covered territory ' +
|
|
339
|
-
'of yours), `cap-exceeded` (a partner stack on the covered border above the agreed cap), `massing` (its visible ' +
|
|
401
|
+
'of yours — not one a `theirs` exception you recorded allowed that turn), `cap-exceeded` (a partner stack on the covered border above the agreed cap), `massing` (its visible ' +
|
|
340
402
|
'armies near the covered border grew two turns running, or an event the fog leaves ambiguous), `outgrowing` (its ' +
|
|
341
403
|
`estimated income above ${TRUCE_OUTGROW_RATIO}× yours) and \`kept\` (quiet turns) — and \`trust\`: \`clear\`, or \`watch\` ` +
|
|
342
404
|
'on any flag but kept, on their notice, and in the endgame (no other opponent still a match for either of you). ' +
|
|
@@ -345,7 +407,10 @@ export function registerRelationsTools(server, ctx, opts = {}) {
|
|
|
345
407
|
'`record`: how it kept earlier agreements — tallies, a kept rate, its notices honoured or broken, its breaks in ' +
|
|
346
408
|
'the endgame or while leading, retaliation, proposing again and turns to a break (`full` adds the entries) — keyed ' +
|
|
347
409
|
'by a salted hash, never its id or name. `playerRecord` says on, off or unreadable. Words in chat never change a ' +
|
|
348
|
-
|
|
410
|
+
'flag or the trust: only the board does. Each agreement carries `source: "ledger"`; in a game running the Diplomacy 2 ' +
|
|
411
|
+
'mod (mod 191) `modAlliances` lists the mod\'s alliances with you (`source: "mod"`, UNVERIFIED live) with `mismatches` ' +
|
|
412
|
+
'(`mod-only`: allied with no agreement recorded; `ledger-only`: a truce the game does not enforce) and `notices` (an ' +
|
|
413
|
+
`ally's break, shown once it applied). ${BRIDGE_NOTE} Read-only on war.app; it caches the board it read.`),
|
|
349
414
|
_meta: lookupMeta(['my truces', 'agreements', 'is my truce holding', 'diplomacy', 'who kept their word']),
|
|
350
415
|
annotations: readAnnotations('Read war.app agreements'),
|
|
351
416
|
inputSchema: z.object({
|
|
@@ -415,6 +480,15 @@ export function registerRelationsTools(server, ctx, opts = {}) {
|
|
|
415
480
|
]);
|
|
416
481
|
const tacit = tacitTruces({ graph, boards, me: me.id, exclude: excluded });
|
|
417
482
|
const recordState = await playerRecordState(ctx.dataDir, env);
|
|
483
|
+
// The Diplomacy 2 mod's alliances beside the ledger's (a game without the mod: no request, no field).
|
|
484
|
+
const liveAgreements = ledger.agreements.filter((a) => {
|
|
485
|
+
const st = agreementState(a, turn, relationPlayers(game.players));
|
|
486
|
+
return st.phase === 'active' || st.phase === 'notice';
|
|
487
|
+
});
|
|
488
|
+
const modView = modRelationsView(await readModAlliances(ctx, game, me), liveAgreements, (id) => {
|
|
489
|
+
const p = game.players.find((x) => x.id === id);
|
|
490
|
+
return { id, name: p ? untrustedText(p.name) : null };
|
|
491
|
+
});
|
|
418
492
|
const name = namer(map);
|
|
419
493
|
const playerName = (id) => {
|
|
420
494
|
const p = game.players.find((x) => x.id === id);
|
|
@@ -424,6 +498,7 @@ export function registerRelationsTools(server, ctx, opts = {}) {
|
|
|
424
498
|
game: { id: game.id, name: game.name === undefined ? null : untrustedText(game.name), state: game.state, turn },
|
|
425
499
|
player: { id: me.id, name: untrustedText(me.name) },
|
|
426
500
|
agreements: agreements.map((x) => ({
|
|
501
|
+
source: 'ledger',
|
|
427
502
|
...agreementView(x.agreement, game, map, turn, rung),
|
|
428
503
|
...(x.trust ? { trust: x.trust, endgame: x.endgame } : {}),
|
|
429
504
|
flags: x.flags.map((f) => ({ ...f, territories: f.territories.map(name) })),
|
|
@@ -431,6 +506,7 @@ export function registerRelationsTools(server, ctx, opts = {}) {
|
|
|
431
506
|
...(rung === 'full' && x.entries ? { recordEntries: x.entries.map(entryView) } : {}),
|
|
432
507
|
})),
|
|
433
508
|
tacit: tacit.map((t) => ({ player: playerName(t.player), quietTurns: t.quietTurns, border: t.border.map(name) })),
|
|
509
|
+
...(modView ? { modAlliances: modView } : {}),
|
|
434
510
|
boards: { turns: boards.map((b) => b.turn).sort((a, b) => a - b), live },
|
|
435
511
|
incomes: { mine: incomes.mine, opponents: Object.fromEntries(incomes.opponents) },
|
|
436
512
|
playerRecord: recordState,
|
|
@@ -439,7 +515,7 @@ export function registerRelationsTools(server, ctx, opts = {}) {
|
|
|
439
515
|
});
|
|
440
516
|
server.registerTool('warapp_record_agreement', {
|
|
441
517
|
title: 'Record an agreement in a war.app game',
|
|
442
|
-
_meta: mintMeta('change', ['record a truce', 'we agreed a truce', 'they broke the truce', 'give notice']),
|
|
518
|
+
_meta: mintMeta('change', ['record a truce', 'we agreed a truce', 'they broke the truce', 'give notice', 'truce exception']),
|
|
443
519
|
description: untrustedDescription('Record a truce you made, proposed or received in a war.app (Warzone) free-for-all, or a change to one, in this ' +
|
|
444
520
|
"machine's agreement ledger. Nothing is sent to war.app or to any player (so there is no confirmation " +
|
|
445
521
|
'step): it records what was agreed, so warapp_get_relations can watch the board for it. Create one with ' +
|
|
@@ -449,7 +525,12 @@ export function registerRelationsTools(server, ctx, opts = {}) {
|
|
|
449
525
|
'new `status`: agreed, notice-by-me, notice-by-them, ended, broken-by-them, broken-by-me (terms change only ' +
|
|
450
526
|
'while proposed; an ended or broken agreement takes nothing more but `retaliated` after broken-by-me). Refused ' +
|
|
451
527
|
'for a partner who is you, an AI, out of the game or your teammate, in a 1v1 or once two players remain, and for ' +
|
|
452
|
-
'a territory or bonus not on the map.
|
|
528
|
+
'a territory or bonus not on the map. `exceptions` records partner-approved exceptions that are no break, in any ' +
|
|
529
|
+
'status (agreed included): each lists `territories`, `turns` (one turn or [from, to], inclusive), `direction` ' +
|
|
530
|
+
'(mine: the partner agreed I may attack its covered territories there — warapp_plan_turn targets them and ' +
|
|
531
|
+
'warapp_submit_turn sends the attack without break_agreement; theirs: I agreed it may attack or take mine — ' +
|
|
532
|
+
'warapp_get_relations raises no `broken` flag for it) and an optional `note` (player names scrubbed). The player ' +
|
|
533
|
+
'record counts exceptions apart from breaks. An agreement exists only because you record it here: chat is never read ' +
|
|
453
534
|
'into one. With the cross-game player record on (owner decision D5: on unless WARAPP_PLAYER_RECORD=off, local and ' +
|
|
454
535
|
'hosted), each agreement is also kept per partner under a salted hash, name-free (no id, no name, no game, no ' +
|
|
455
536
|
'message): the format, the turns agreed and ended, the shape of the terms, the outcome, a break\'s turn, flag and ' +
|
|
@@ -470,6 +551,21 @@ export function registerRelationsTools(server, ctx, opts = {}) {
|
|
|
470
551
|
until_player_out: playerRef.optional().describe('It ends when this player (name or id) is out of the game.'),
|
|
471
552
|
against: playerRef.optional().describe('The player (name or id) it is aimed at, when it names one.'),
|
|
472
553
|
retaliated: z.boolean().optional().describe('After broken-by-me: whether the partner retaliated.'),
|
|
554
|
+
exceptions: z
|
|
555
|
+
.array(z.object({
|
|
556
|
+
territories: z.array(playerRef).min(1).max(MAX_SCOPE_ITEMS).describe('The territories (names or ids) the exception opens.'),
|
|
557
|
+
turns: z
|
|
558
|
+
.union([z.coerce.number().int().min(1), z.array(z.coerce.number().int().min(1)).length(2)])
|
|
559
|
+
.describe('One turn, or [from, to] (inclusive).'),
|
|
560
|
+
direction: z
|
|
561
|
+
.enum(EXCEPTION_DIRECTIONS)
|
|
562
|
+
.optional()
|
|
563
|
+
.describe('mine (default): the partner agreed I may attack these; theirs: I agreed the partner may attack or take these of mine.'),
|
|
564
|
+
note: z.string().max(MAX_EXCEPTION_NOTE).optional().describe("The owner's own words on what was agreed (player names are scrubbed)."),
|
|
565
|
+
}))
|
|
566
|
+
.max(10)
|
|
567
|
+
.optional()
|
|
568
|
+
.describe('Partner-approved exceptions to add: attacks the partner agreed to, which are no break. Any status.'),
|
|
473
569
|
}),
|
|
474
570
|
}, async (args) => {
|
|
475
571
|
if (!ctx.dataDir) {
|
|
@@ -530,6 +626,21 @@ export function registerRelationsTools(server, ctx, opts = {}) {
|
|
|
530
626
|
t.against = against;
|
|
531
627
|
return t;
|
|
532
628
|
};
|
|
629
|
+
/** The exceptions `args` add, resolved and checked: territories by id, turns in order, the note scrubbed. */
|
|
630
|
+
const exceptionsFrom = () => (args.exceptions ?? []).map((x) => {
|
|
631
|
+
const [fromTurn, toTurn] = typeof x.turns === 'number' ? [x.turns, x.turns] : [x.turns[0], x.turns[1]];
|
|
632
|
+
if (fromTurn > toTurn)
|
|
633
|
+
refuse(`An exception's turns [${fromTurn}, ${toTurn}] run backwards`, 'Give [from, to] with from ≤ to, or one turn.');
|
|
634
|
+
const note = exceptionNote(x.note, game);
|
|
635
|
+
return {
|
|
636
|
+
direction: x.direction ?? 'mine',
|
|
637
|
+
territories: [...new Set(x.territories.map((t) => resolveTerritory(map, t).id))].sort((a, b) => a - b),
|
|
638
|
+
fromTurn,
|
|
639
|
+
toTurn,
|
|
640
|
+
recordedTurn: turn,
|
|
641
|
+
...(note ? { note } : {}),
|
|
642
|
+
};
|
|
643
|
+
});
|
|
533
644
|
/** The change `args` make to `ledger`: the agreement after it, and as it stood. Refuses what cannot be recorded. */
|
|
534
645
|
const change = (ledger) => {
|
|
535
646
|
let agreement;
|
|
@@ -560,8 +671,8 @@ export function registerRelationsTools(server, ctx, opts = {}) {
|
|
|
560
671
|
before = found;
|
|
561
672
|
if (args.with !== undefined && resolvePlayer(game.players, args.with).id !== agreement.with)
|
|
562
673
|
refuse(`Agreement ${agreement.id} is with player ${agreement.with}`, 'Omit `with` when updating, or record a new agreement.');
|
|
563
|
-
if (args.status === undefined && !termsGiven && args.retaliated === undefined)
|
|
564
|
-
refuse('Nothing to record: give a new `status`, terms, or `
|
|
674
|
+
if (args.status === undefined && !termsGiven && args.retaliated === undefined && !args.exceptions?.length)
|
|
675
|
+
refuse('Nothing to record: give a new `status`, terms, `retaliated` or `exceptions`', 'Pass the status the agreement moved to.');
|
|
565
676
|
if (termsGiven) {
|
|
566
677
|
if (agreement.status !== 'proposed-by-me' && agreement.status !== 'proposed-by-them')
|
|
567
678
|
refuse(`The terms of agreement ${agreement.id} (${agreement.status}) can no longer change`, 'End it and record a new agreement with the new terms.');
|
|
@@ -585,6 +696,8 @@ export function registerRelationsTools(server, ctx, opts = {}) {
|
|
|
585
696
|
agreement = { ...agreement, retaliated: args.retaliated };
|
|
586
697
|
}
|
|
587
698
|
}
|
|
699
|
+
if (args.exceptions?.length)
|
|
700
|
+
agreement = withExceptions(agreement, exceptionsFrom());
|
|
588
701
|
return { agreement, before, created };
|
|
589
702
|
};
|
|
590
703
|
const updateRecord = (agreement, before, created, others) => updateAgreementRecord({ dir, env, game, me, map, graph, agreement, before, created, others });
|
package/dist/tools/session.js
CHANGED
|
@@ -20,6 +20,7 @@
|
|
|
20
20
|
//
|
|
21
21
|
// SECURITY: the AuthToken is a full-account credential. Neither tool returns,
|
|
22
22
|
// logs, or previews it; the status output carries only `capturedAt`/`host`/age.
|
|
23
|
+
import { paceWarning } from './pace.js';
|
|
23
24
|
import { CONFIRM_INJECTION_RULE, toolAnnotations } from '@chrischall/mcp-utils';
|
|
24
25
|
import { z } from 'zod';
|
|
25
26
|
import { linkSession } from '../direct/link.js';
|
|
@@ -83,7 +84,7 @@ export function registerSessionTools(server, deps) {
|
|
|
83
84
|
};
|
|
84
85
|
server.registerTool('warapp_session_status', {
|
|
85
86
|
title: 'war.app direct-transport session status',
|
|
86
|
-
description: untrustedDescription(hosted && hostToken === 'ok'
|
|
87
|
+
description: untrustedDescription((hosted && hostToken === 'ok'
|
|
87
88
|
? 'Report which transport serves war.app calls on this hosted server (direct to war.app with the session ' +
|
|
88
89
|
'mcp-host captured at sign-in, or the browser bridge after that session stops working) and which ' +
|
|
89
90
|
'transport the turn-notification push socket rides (websocket or xhr-polling) once it has run, and, once ' +
|
|
@@ -100,11 +101,24 @@ export function registerSessionTools(server, deps) {
|
|
|
100
101
|
'which transport the turn-notification push socket rides (websocket or xhr-polling) once it has run, ' +
|
|
101
102
|
'and, once a live board has been read, which client bundle decodes boards (a cached stand-in or not) and ' +
|
|
102
103
|
'which of its reader helpers were verified. ' +
|
|
103
|
-
'Never shows the session cookie. Read-only; use warapp_link_session to link or relink.')
|
|
104
|
+
'Never shows the session cookie. Read-only; use warapp_link_session to link or relink.') +
|
|
105
|
+
' `pace` lists the multi-day games waiting on you whose boot is under 6 hours away (boot time plus your banked ' +
|
|
106
|
+
'time, less your turn so far), and `bootWarning` names them: from the game list this server last read ' +
|
|
107
|
+
'(warapp_my_games, the chat inbox), else it reads the list itself (one war.app request, over a working direct ' +
|
|
108
|
+
'session only — never by waiting on the browser bridge); `paceUnread` says why when it could not.'),
|
|
104
109
|
_meta: lookupMeta(['war.app session', 'is war.app linked', 'direct transport status']),
|
|
105
110
|
annotations: readAnnotations('war.app session status'),
|
|
106
111
|
inputSchema: z.object({}),
|
|
107
112
|
}, async () => {
|
|
113
|
+
// Pace: a boot close by in a multi-day game, from the last game list read; with none kept, the list is read now
|
|
114
|
+
// (one request) — only over a direct session that works, never by waiting on the browser bridge.
|
|
115
|
+
const session = hosted ? undefined : await read();
|
|
116
|
+
const direct = deps.transport.activeLeg() === 'direct' && !deps.transport.sessionStale() && (hosted ? hostToken === 'ok' : session !== undefined);
|
|
117
|
+
const activeTransport = deps.transport.activeLeg();
|
|
118
|
+
const pace = await deps.pace?.(now(), direct);
|
|
119
|
+
const paceRead = pace && !('error' in pace) ? pace : undefined;
|
|
120
|
+
const bootWarning = paceWarning(paceRead);
|
|
121
|
+
const paceFields = paceRead ? { pace: paceRead, ...(bootWarning ? { bootWarning } : {}) } : pace && 'error' in pace ? { paceUnread: pace.error } : {};
|
|
108
122
|
if (hosted && hostToken === 'ok') {
|
|
109
123
|
const pt = deps.pushTransport?.();
|
|
110
124
|
const wall = deps.transport.wall?.() ?? null;
|
|
@@ -112,10 +126,11 @@ export function registerSessionTools(server, deps) {
|
|
|
112
126
|
hosted: true,
|
|
113
127
|
linked: true,
|
|
114
128
|
linkedBy: 'host',
|
|
115
|
-
activeTransport
|
|
129
|
+
activeTransport,
|
|
116
130
|
...(wall ? { wall } : {}),
|
|
117
131
|
...(pt ? { pushTransport: pt } : {}),
|
|
118
132
|
...decoderView(),
|
|
133
|
+
...paceFields,
|
|
119
134
|
hostedNote: NOTE_HOSTED_DIRECT,
|
|
120
135
|
};
|
|
121
136
|
return respond(undefined, ['compact'], () => deps.transport.sessionStale() ? { ...base, sessionExpired: true, hint: HINT_HOST_EXPIRED } : base);
|
|
@@ -128,13 +143,12 @@ export function registerSessionTools(server, deps) {
|
|
|
128
143
|
activeTransport: 'fetchproxy',
|
|
129
144
|
...(pt ? { pushTransport: pt } : {}),
|
|
130
145
|
...decoderView(),
|
|
146
|
+
...paceFields,
|
|
131
147
|
hostedNote: hostToken === 'malformed' ? NOTE_HOSTED_MALFORMED : NOTE_HOSTED,
|
|
132
148
|
}));
|
|
133
149
|
}
|
|
134
|
-
const session = await read();
|
|
135
|
-
const activeTransport = deps.transport.activeLeg();
|
|
136
150
|
const pt = deps.pushTransport?.();
|
|
137
|
-
const push = { ...(pt ? { pushTransport: pt } : {}), ...decoderView() };
|
|
151
|
+
const push = { ...(pt ? { pushTransport: pt } : {}), ...decoderView(), ...paceFields };
|
|
138
152
|
return respond(undefined, ['compact'], () => {
|
|
139
153
|
if (!session)
|
|
140
154
|
return { linked: false, activeTransport, ...push, hint: HINT_NOT_LINKED };
|
|
@@ -7,6 +7,17 @@ import { carriesTeam } from '../teams.js';
|
|
|
7
7
|
import { opponentReinforcement } from './card-advice.js';
|
|
8
8
|
import { boardCardsInEffect } from './card-effects.js';
|
|
9
9
|
import { commerceDeployOf } from './commerce-deploy.js';
|
|
10
|
+
/**
|
|
11
|
+
* An opponent's deploy for the stress test and its card apart: the estimate (its card on top) under `clock`,
|
|
12
|
+
* the estimate without the card under `none`; `cardBonus` the card's armies, absent with no card.
|
|
13
|
+
*/
|
|
14
|
+
export function opponentDeploy(e, assume) {
|
|
15
|
+
const card = e.card?.armies ?? 0;
|
|
16
|
+
return {
|
|
17
|
+
deploy: assume === 'none' ? e.estimate - card : e.estimate,
|
|
18
|
+
...(card > 0 ? { cardBonus: card, ...(e.card?.basis ? { cardBonusBasis: e.card.basis } : {}) } : {}),
|
|
19
|
+
};
|
|
20
|
+
}
|
|
10
21
|
export function stressOpponents(input) {
|
|
11
22
|
const { graph, map, game, me, seen, turn, settings, hand, info } = input;
|
|
12
23
|
// #270: a player out of the game whose seat no AI plays deploys and attacks nothing: its
|
|
@@ -67,13 +78,25 @@ export function stressOpponents(input) {
|
|
|
67
78
|
const onBoard = new Set(board.territories.flatMap((t) => (t.owner.kind === 'player' ? [t.owner.playerId] : [])));
|
|
68
79
|
const stillIn = game.players.filter((p) => (p.state ?? 'Playing') === 'Playing').map((p) => p.id);
|
|
69
80
|
const base = settings.baseIncome ?? 0;
|
|
70
|
-
const estimateOf = (id) =>
|
|
81
|
+
const estimateOf = (id) => {
|
|
82
|
+
const e = estimates.find((x) => x.playerId === id);
|
|
83
|
+
return e ? opponentDeploy(e, input.assumeCards ?? 'clock').deploy : base;
|
|
84
|
+
};
|
|
71
85
|
const opponents = [...new Set([...onBoard, ...stillIn])]
|
|
72
86
|
.filter((id) => !friend(id))
|
|
73
87
|
.sort((a, b) => a - b)
|
|
74
88
|
.map((id) => {
|
|
75
89
|
const e = estimates.find((x) => x.playerId === id);
|
|
76
|
-
|
|
90
|
+
const sized = e ? opponentDeploy(e, input.assumeCards ?? 'clock') : { deploy: base };
|
|
91
|
+
return {
|
|
92
|
+
id,
|
|
93
|
+
deploy: input.enemyDeploy ?? sized.deploy,
|
|
94
|
+
base: e?.base ?? base,
|
|
95
|
+
...(e?.card ? { card: e.card.armies } : {}),
|
|
96
|
+
...(sized.cardBonus !== undefined ? { cardBonus: sized.cardBonus } : {}),
|
|
97
|
+
...(sized.cardBonusBasis !== undefined ? { cardBonusBasis: sized.cardBonusBasis } : {}),
|
|
98
|
+
...(e?.sanctioned ? { sanctioned: e.sanctioned } : {}),
|
|
99
|
+
};
|
|
77
100
|
});
|
|
78
101
|
const teams = new Map();
|
|
79
102
|
for (const p of game.players)
|