@chrischall/warapp-mcp 0.9.0 → 0.11.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.
@@ -3,6 +3,7 @@
3
3
  // opponent could make with its estimated deploy, and the replies that cost something are
4
4
  // reported, worst first (src/analysis/stress.ts, on the turn resolver src/analysis/turn-sim.ts).
5
5
  // Read-only on war.app, and it writes nothing but its verdict to the decision log (#437): not the board cache.
6
+ import { bonusDelayWarning } from '../analysis/bonus-delay.js';
6
7
  import { gameBaseIncome } from '../analysis/player.js';
7
8
  import { McpToolError } from '@chrischall/mcp-utils';
8
9
  import { z } from 'zod';
@@ -106,7 +107,8 @@ export function registerCheckPlanTool(server, ctx) {
106
107
  'differ from the default plan by design. ' +
107
108
  'In a free-for-all with a truce in force (the agreement ledger), its partner is still tried — `safe` is safe ' +
108
109
  'against a break too — each reply that attacks a territory a truce covers is marked `breaksTruce`, and ' +
109
- '`safeIfTruceHolds` is the verdict over the other replies (null when every reply is a break). ' +
110
+ '`safeIfTruceHolds` is the verdict over the other replies (null when every reply is a break); a partner-approved ' +
111
+ 'truce exception on this turn opens its territories (no break) and is listed under `relations`. ' +
110
112
  `Refuses outside a turn phase. ${BRIDGE_NOTE} Read-only on ` +
111
113
  'war.app; it never submits orders.'),
112
114
  _meta: lookupMeta(['check my plan', 'stress test my orders', 'what can my opponent do to this turn', 'is this plan safe']),
@@ -613,6 +615,8 @@ export function registerCheckPlanTool(server, ctx) {
613
615
  ? [`These orders use ${[...refused].join(', ')}: war.app would refuse them in this game, and warapp_submit_turn does; the test ran them anyway.`]
614
616
  : []),
615
617
  ...sanction.warnings,
618
+ // #505: orders that delay the nearest bonus say by how many turns (advice only).
619
+ ...[bonusDelayWarning(belowPlan?.bonusDelay)].filter((w) => w !== undefined),
616
620
  ...effect.unsure,
617
621
  ...[claimedCardWarning(claimedCardUses(uses, claimed))].filter((w) => w !== undefined),
618
622
  ...unsimulatedCards,
@@ -643,6 +647,18 @@ export function registerCheckPlanTool(server, ctx) {
643
647
  }
644
648
  : {}),
645
649
  summary,
650
+ // Partner-approved truce exceptions on this turn: normal targets (mine), or open to the partner (theirs).
651
+ ...(binding.some((r) => r.exceptions?.length)
652
+ ? {
653
+ relations: binding
654
+ .filter((r) => r.exceptions?.length)
655
+ .map((r) => ({
656
+ player: who(r.player),
657
+ ...(r.agreement ? { agreement: r.agreement } : {}),
658
+ exceptions: r.exceptions.map((e) => ({ direction: e.direction, territories: e.territories.map(name) })),
659
+ })),
660
+ }
661
+ : {}),
646
662
  exact: report.exact,
647
663
  // Where the teams came from (GameFeed, else the game list), in a team game only.
648
664
  ...(teamSource !== 'none' ? { teamSource } : {}),
@@ -722,6 +738,17 @@ export function registerCheckPlanTool(server, ctx) {
722
738
  .map((r) => ({ territory: name(r.territory), planLeaves: r.planLeaves, left: r.left, short: r.short })),
723
739
  ...(belowPlan.rows.length > LIST_MAX ? { belowPlanMore: belowPlan.rows.length - LIST_MAX } : {}),
724
740
  belowPlanAgainst: belowPlan.against,
741
+ ...(belowPlan.bonusDelay
742
+ ? {
743
+ bonusDelay: {
744
+ bonus: belowPlan.bonusDelay.bonus,
745
+ bonusId: belowPlan.bonusDelay.bonusId,
746
+ dropped: belowPlan.bonusDelay.dropped.map((t) => name(t)),
747
+ plannedTurn: belowPlan.bonusDelay.plannedTurn,
748
+ givenTurn: belowPlan.bonusDelay.givenTurn,
749
+ },
750
+ }
751
+ : {}),
725
752
  ...(rung === 'full' ? { belowPlanBasis: BELOW_PLAN_BASIS } : {}),
726
753
  }
727
754
  : {}),
@@ -137,6 +137,10 @@ export function registerMyGamesTool(server, ctx, deps = {}) {
137
137
  'the game details (unverified live; null when not read or unreadable, never "none"; empty without a read ' +
138
138
  'for a lobby, a finished game or a game you no longer play in, where none can wait on you); the top-level ' +
139
139
  'surrenderPending counts the games where one waits on you, and those games come first too. ' +
140
+ 'Each game also carries unreadChat, from the game list itself (no extra request): whether war.app shows unread ' +
141
+ 'chat per channel (public, team, private, group) and toMe (unread private chat is addressed to you) — flags, ' +
142
+ 'not counts; null when they did not read. Games with unread private chat come right after the ones waiting on ' +
143
+ 'you, and the top-level unreadPrivateGames counts them; read them with warapp_chat_inbox. ' +
140
144
  'Finished games are left out unless ' +
141
145
  '`include_finished` (`finishedLeftOut` counts them). `listed` is how many games war.app returned and ' +
142
146
  '`complete` false (with a `warning`) means the list may be partial. Use the id with the other warapp tools. ' +
@@ -150,7 +154,8 @@ export function registerMyGamesTool(server, ctx, deps = {}) {
150
154
  .enum(VIEWS)
151
155
  .optional()
152
156
  .describe('"compact" (default): the games as described. "brief": one line per game — name — "turn N" (or the ' +
153
- 'state when not being played) — "waiting on you" or "waiting on others", inside the untrusted-data ' +
157
+ 'state when not being played) — "waiting on you" or "waiting on others", then " — unread private" and ' +
158
+ '" — unread public, team, group" when war.app shows unread chat there, inside the untrusted-data ' +
154
159
  'envelope as data: string[]; "-- none" when there are no games, and a last "-- the list may be ' +
155
160
  'partial…" line when it may be. Brief reads no game details, so it says nothing of pending surrenders.'),
156
161
  include_finished: z
@@ -181,6 +186,7 @@ export function registerMyGamesTool(server, ctx, deps = {}) {
181
186
  games,
182
187
  count: games.length,
183
188
  waitingOnYou: games.filter((g) => g.waitingOnYou).length,
189
+ unreadPrivateGames: games.filter((g) => g.unreadChat?.private === true).length,
184
190
  surrenderPending: games.filter((g) => surrenderOwed(g.surrenderPending)).length,
185
191
  surrenderNote: SURRENDER_PENDING_NOTE +
186
192
  (unread ? ` The details of ${unread} game(s) could not be read.` : '') +
@@ -10,7 +10,7 @@ import { z } from 'zod';
10
10
  import { boardIncome, incomeRules, trackGame, trackOpponents } from '../analysis/index.js';
11
11
  import { agreementChange } from '../analysis/commitments.js';
12
12
  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';
13
+ 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
14
  import { AVOID_REASONS, emptyIntel, INCOME_STALE_TURNS, intelIsEmpty } from '../analysis/intel.js';
15
15
  import { boardStateFromLive } from '../live.js';
16
16
  import { entryKey, legacyEntryKey, playerRecordEnabled, playerRecordState, readPlayerRecord, updatePlayerRecord } from '../player-record-store.js';
@@ -27,6 +27,7 @@ import { recordProfile } from './profile-hook.js';
27
27
  import { resolveBonus, resolvePlayer, resolveTerritory } from './resolve.js';
28
28
  import { boardHistory, plannerSettings } from './turn.js';
29
29
  import { captureObservation } from './decision-capture.js';
30
+ import { scrubNames } from '../decision-log.js';
30
31
  import { resolveTeamsFor } from './team-source.js';
31
32
  const VIEWS = ['compact', 'full'];
32
33
  const MAX_SCOPE_ITEMS = 200;
@@ -165,9 +166,27 @@ function agreementView(a, game, map, turn, rung) {
165
166
  },
166
167
  ...(a.enforced !== undefined ? { enforced: a.enforced } : {}),
167
168
  ...(a.retaliated !== undefined ? { retaliated: a.retaliated } : {}),
169
+ ...(a.exceptions?.length
170
+ ? {
171
+ exceptions: a.exceptions.map((e) => ({
172
+ id: e.id,
173
+ direction: e.direction,
174
+ territories: e.territories.map(name),
175
+ turns: [e.fromTurn, e.toTurn],
176
+ inForce: e.fromTurn <= turn && turn <= e.toTurn,
177
+ recordedTurn: e.recordedTurn,
178
+ ...(e.note !== undefined ? { note: untrustedText(e.note) } : {}),
179
+ })),
180
+ }
181
+ : {}),
168
182
  ...(rung === 'full' ? { history: a.history } : {}),
169
183
  };
170
184
  }
185
+ /** An exception's note as stored: trimmed, player names scrubbed (`Player <id>`), capped; absent when empty. */
186
+ export function exceptionNote(note, game) {
187
+ const t = note?.trim();
188
+ return t ? scrubNames(t, game.players).slice(0, MAX_EXCEPTION_NOTE) : undefined;
189
+ }
171
190
  /** An entry as a result shows it: everything but its key. */
172
191
  const entryView = ({ key: _key, ...rest }) => rest;
173
192
  /** The reliability facts on record for `partner` (and its entries), or why there are none. */
@@ -266,6 +285,48 @@ export async function recordBrokenByMe(o) {
266
285
  return o.agreements.map((agreement) => ({ agreement, ledger: 'refused', why: e.message }));
267
286
  }
268
287
  }
288
+ /**
289
+ * `warapp_submit_turn`'s `partner_approved`: record, once the orders are committed, a one-turn `mine`
290
+ * exception on each agreement the orders hit (its territories hit, the note already scrubbed) — under the
291
+ * ledger's lock, then the partner's player record (D5: an exception, never a break). Never throws.
292
+ */
293
+ export async function recordPartnerApproved(o) {
294
+ const { dir, env, game, me, map, turn } = o;
295
+ const graph = graphOf(map);
296
+ const refused = (why) => o.exceptions.map((x) => ({ agreement: x.agreement, territories: [...x.territories], ledger: 'refused', why }));
297
+ try {
298
+ return await withLedgerLock(dir, game.id, me.id, async () => {
299
+ const read = await readLedgerForWrite(dir, game.id, me.id);
300
+ if (read === null || read === 'unreadable')
301
+ return refused(read === null ? 'no ledger for this game' : 'the ledger exists but cannot be read');
302
+ let ledger = read;
303
+ const out = [];
304
+ for (const x of o.exceptions) {
305
+ const territories = [...new Set(x.territories)].sort((a, b) => a - b);
306
+ const found = ledger.agreements.find((a) => a.id === x.agreement);
307
+ if (!found) {
308
+ out.push({ agreement: x.agreement, territories, ledger: 'refused', why: 'not in the ledger' });
309
+ continue;
310
+ }
311
+ const ex = { direction: 'mine', territories, fromTurn: turn, toTurn: turn, recordedTurn: turn, ...(x.note ? { note: x.note } : {}) };
312
+ const moved = withExceptions(found, [ex]);
313
+ const rest = ledger.agreements.filter((a) => a.id !== found.id);
314
+ const next = { ...ledger, agreements: [...rest, moved] };
315
+ if (!(await writeLedger(dir, next))) {
316
+ out.push({ agreement: x.agreement, territories, ledger: 'refused', why: 'the ledger could not be written' });
317
+ continue;
318
+ }
319
+ ledger = next;
320
+ const playerRecord = await updateAgreementRecord({ dir, env, game, me, map, graph, agreement: moved, before: found, created: false, others: rest });
321
+ out.push({ agreement: x.agreement, territories, ledger: 'recorded', id: moved.exceptions.at(-1).id, playerRecord });
322
+ }
323
+ return out;
324
+ });
325
+ }
326
+ catch (e) {
327
+ return refused(e.message);
328
+ }
329
+ }
269
330
  /**
270
331
  * B4 (warapp_send_chat, once a message is sent): record its declared commitments in the ledger as
271
332
  * mine, under the ledger's lock — a propose, accept or notice re-applied to the ledger as it now stands
@@ -336,7 +397,7 @@ export function registerRelationsTools(server, ctx, opts = {}) {
336
397
  'its state this turn (`proposed`, `active`, in `notice` with the turn it ends, or `over` and why: ended, broken, ' +
337
398
  'the partner eliminated or turned AI, only two players left, its end condition met, its notice run), and for a ' +
338
399
  '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 ' +
400
+ '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
401
  'armies near the covered border grew two turns running, or an event the fog leaves ambiguous), `outgrowing` (its ' +
341
402
  `estimated income above ${TRUCE_OUTGROW_RATIO}× yours) and \`kept\` (quiet turns) — and \`trust\`: \`clear\`, or \`watch\` ` +
342
403
  'on any flag but kept, on their notice, and in the endgame (no other opponent still a match for either of you). ' +
@@ -439,7 +500,7 @@ export function registerRelationsTools(server, ctx, opts = {}) {
439
500
  });
440
501
  server.registerTool('warapp_record_agreement', {
441
502
  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']),
503
+ _meta: mintMeta('change', ['record a truce', 'we agreed a truce', 'they broke the truce', 'give notice', 'truce exception']),
443
504
  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
505
  "machine's agreement ledger. Nothing is sent to war.app or to any player (so there is no confirmation " +
445
506
  'step): it records what was agreed, so warapp_get_relations can watch the board for it. Create one with ' +
@@ -449,7 +510,12 @@ export function registerRelationsTools(server, ctx, opts = {}) {
449
510
  'new `status`: agreed, notice-by-me, notice-by-them, ended, broken-by-them, broken-by-me (terms change only ' +
450
511
  'while proposed; an ended or broken agreement takes nothing more but `retaliated` after broken-by-me). Refused ' +
451
512
  '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. An agreement exists only because you record it here: chat is never read ' +
513
+ 'a territory or bonus not on the map. `exceptions` records partner-approved exceptions that are no break, in any ' +
514
+ 'status (agreed included): each lists `territories`, `turns` (one turn or [from, to], inclusive), `direction` ' +
515
+ '(mine: the partner agreed I may attack its covered territories there — warapp_plan_turn targets them and ' +
516
+ 'warapp_submit_turn sends the attack without break_agreement; theirs: I agreed it may attack or take mine — ' +
517
+ 'warapp_get_relations raises no `broken` flag for it) and an optional `note` (player names scrubbed). The player ' +
518
+ 'record counts exceptions apart from breaks. An agreement exists only because you record it here: chat is never read ' +
453
519
  'into one. With the cross-game player record on (owner decision D5: on unless WARAPP_PLAYER_RECORD=off, local and ' +
454
520
  'hosted), each agreement is also kept per partner under a salted hash, name-free (no id, no name, no game, no ' +
455
521
  'message): the format, the turns agreed and ended, the shape of the terms, the outcome, a break\'s turn, flag and ' +
@@ -470,6 +536,21 @@ export function registerRelationsTools(server, ctx, opts = {}) {
470
536
  until_player_out: playerRef.optional().describe('It ends when this player (name or id) is out of the game.'),
471
537
  against: playerRef.optional().describe('The player (name or id) it is aimed at, when it names one.'),
472
538
  retaliated: z.boolean().optional().describe('After broken-by-me: whether the partner retaliated.'),
539
+ exceptions: z
540
+ .array(z.object({
541
+ territories: z.array(playerRef).min(1).max(MAX_SCOPE_ITEMS).describe('The territories (names or ids) the exception opens.'),
542
+ turns: z
543
+ .union([z.coerce.number().int().min(1), z.array(z.coerce.number().int().min(1)).length(2)])
544
+ .describe('One turn, or [from, to] (inclusive).'),
545
+ direction: z
546
+ .enum(EXCEPTION_DIRECTIONS)
547
+ .optional()
548
+ .describe('mine (default): the partner agreed I may attack these; theirs: I agreed the partner may attack or take these of mine.'),
549
+ note: z.string().max(MAX_EXCEPTION_NOTE).optional().describe("The owner's own words on what was agreed (player names are scrubbed)."),
550
+ }))
551
+ .max(10)
552
+ .optional()
553
+ .describe('Partner-approved exceptions to add: attacks the partner agreed to, which are no break. Any status.'),
473
554
  }),
474
555
  }, async (args) => {
475
556
  if (!ctx.dataDir) {
@@ -530,6 +611,21 @@ export function registerRelationsTools(server, ctx, opts = {}) {
530
611
  t.against = against;
531
612
  return t;
532
613
  };
614
+ /** The exceptions `args` add, resolved and checked: territories by id, turns in order, the note scrubbed. */
615
+ const exceptionsFrom = () => (args.exceptions ?? []).map((x) => {
616
+ const [fromTurn, toTurn] = typeof x.turns === 'number' ? [x.turns, x.turns] : [x.turns[0], x.turns[1]];
617
+ if (fromTurn > toTurn)
618
+ refuse(`An exception's turns [${fromTurn}, ${toTurn}] run backwards`, 'Give [from, to] with from ≤ to, or one turn.');
619
+ const note = exceptionNote(x.note, game);
620
+ return {
621
+ direction: x.direction ?? 'mine',
622
+ territories: [...new Set(x.territories.map((t) => resolveTerritory(map, t).id))].sort((a, b) => a - b),
623
+ fromTurn,
624
+ toTurn,
625
+ recordedTurn: turn,
626
+ ...(note ? { note } : {}),
627
+ };
628
+ });
533
629
  /** The change `args` make to `ledger`: the agreement after it, and as it stood. Refuses what cannot be recorded. */
534
630
  const change = (ledger) => {
535
631
  let agreement;
@@ -560,8 +656,8 @@ export function registerRelationsTools(server, ctx, opts = {}) {
560
656
  before = found;
561
657
  if (args.with !== undefined && resolvePlayer(game.players, args.with).id !== agreement.with)
562
658
  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 `retaliated`', 'Pass the status the agreement moved to.');
659
+ if (args.status === undefined && !termsGiven && args.retaliated === undefined && !args.exceptions?.length)
660
+ refuse('Nothing to record: give a new `status`, terms, `retaliated` or `exceptions`', 'Pass the status the agreement moved to.');
565
661
  if (termsGiven) {
566
662
  if (agreement.status !== 'proposed-by-me' && agreement.status !== 'proposed-by-them')
567
663
  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 +681,8 @@ export function registerRelationsTools(server, ctx, opts = {}) {
585
681
  agreement = { ...agreement, retaliated: args.retaliated };
586
682
  }
587
683
  }
684
+ if (args.exceptions?.length)
685
+ agreement = withExceptions(agreement, exceptionsFrom());
588
686
  return { agreement, before, created };
589
687
  };
590
688
  const updateRecord = (agreement, before, created, others) => updateAgreementRecord({ dir, env, game, me, map, graph, agreement, before, created, others });
@@ -8,6 +8,7 @@ import { chargeDeploys, DEFAULT_OFFENSIVE_KILL_RATE, deployPools, expectedKills,
8
8
  import { parseGameId } from '../client.js';
9
9
  import { COMMANDER_STRENGTH, luckFraction, straightKills } from '../analysis/combat.js';
10
10
  import { guardOffExposure } from '../analysis/guard-off.js';
11
+ import { bonusDelay, bonusDelayWarning } from '../analysis/bonus-delay.js';
11
12
  import { BELOW_PLAN_MIN_SHORT, holdsBelowPlan } from '../analysis/hold-diff.js';
12
13
  import { guardCase } from '../analysis/profile.js';
13
14
  import { boardStateFromLive, inGameId, playersByInGameId } from '../live.js';
@@ -22,7 +23,7 @@ import { boardCardsInEffect, CARDS_IN_EFFECT_UNVERIFIED, sanctionMyIncome } from
22
23
  import { adviseCards, cardGame, cardPieceOption, giftInOrders, intelOrders, handOwners, lastTurnPlays, opponentCanHold, opponentReinforcement, reinforcementPlaysShown, seenReinforcementPlays, TEAM_HAND } from './card-advice.js';
23
24
  import { currentTurn, turnsCompleted, gameIdArg, knownIncomeArg, avoidPlayersArg, avoidTerritoriesArg, graphOf, namer, readAnnotations, respond, shownAccount, UNTRUSTED_PREVIEW_NOTE, untrustedDescription, untrustedText, viewArg, } from './common.js';
24
25
  import { lookupMeta, mintMeta } from './hints.js';
25
- import { chatSummary } from './chat.js';
26
+ import { chatSummary, privateToMeUnread, privateToMeWarning } from './chat.js';
26
27
  import { blockedLog, CHAT_BLOCKS_NOTE, chatSeats, planChatView, planStanding, turnChatBlocks, withBlocks } from './chat-advice.js';
27
28
  import { chatBlockLine } from '../analysis/chat-blocks.js';
28
29
  import { chatAutomationMode, chatBlocksTurnMode } from '../chat-automation.js';
@@ -55,8 +56,8 @@ import { chatTruces } from '../analysis/chat-read.js';
55
56
  import { readDecisionLog, scrubNames } from '../decision-log.js';
56
57
  import { readPickRecord } from '../pick-list.js';
57
58
  import { commitmentWarnings } from '../analysis/commitments.js';
58
- import { planRelationsFrom, truceBreaksIn } from '../analysis/relations.js';
59
- import { recordBrokenByMe } from './relations.js';
59
+ import { MAX_EXCEPTION_NOTE, planRelationsFrom, truceBreaksIn } from '../analysis/relations.js';
60
+ import { exceptionNote, recordBrokenByMe, recordPartnerApproved } from './relations.js';
60
61
  import { readPlayerRecord } from '../player-record-store.js';
61
62
  import { withTeammateOrders } from '../team-orders.js';
62
63
  import { claimedCardUses, claimedCardWarning, teamCardClaims, teamCardLimit, teamCardRoles, teamHandLeft, unclaimedFirst, } from '../team-cards.js';
@@ -1728,7 +1729,15 @@ export async function bordersBelowPlan(ctx, a) {
1728
1729
  .filter((k) => !held.has(k))
1729
1730
  .sort((x, y) => x - y)
1730
1731
  : [];
1731
- return { rows, against: guess ? 'guess' : 'plan', ...(historyGap.length ? { historyGap } : {}) };
1732
+ // #505: the same default plan, compared for the nearest bonus's finish turn (one more plan per order set, only when a capture toward it is dropped).
1733
+ let delay;
1734
+ try {
1735
+ delay = bonusDelay({ input: setup.input, plan, given });
1736
+ }
1737
+ catch {
1738
+ delay = undefined;
1739
+ }
1740
+ return { rows, against: guess ? 'guess' : 'plan', ...(historyGap.length ? { historyGap } : {}), ...(delay ? { bonusDelay: delay } : {}) };
1732
1741
  }
1733
1742
  catch {
1734
1743
  return undefined;
@@ -1773,6 +1782,29 @@ export function registerTurnTools(server, ctx, opts = {}) {
1773
1782
  return notRecorded(`re-reading the game failed (${failureText(e)}): record it with warapp_record_agreement (status broken-by-me)`);
1774
1783
  }
1775
1784
  };
1785
+ /**
1786
+ * `warapp_submit_turn` with `partner_approved`: record a one-turn exception on each agreement its orders
1787
+ * hit — only once the orders are confirmed committed; otherwise say how to record it by hand. Never throws.
1788
+ */
1789
+ const recordApproved = async (st, committed) => {
1790
+ const list = st.exceptions ?? [];
1791
+ const notRecorded = (why) => list.map((x) => ({ agreement: x.agreement, territories: x.territories, ledger: 'not-recorded', why }));
1792
+ const byHand = `record it with warapp_record_agreement (exceptions: territories, turns ${st.turnNumber})`;
1793
+ if (!committed)
1794
+ return notRecorded(`the orders are not confirmed committed: once warapp_get_game shows them in, ${byHand}`);
1795
+ if (!ctx.dataDir)
1796
+ return notRecorded('this server keeps no data directory');
1797
+ try {
1798
+ const { game } = await resolveTeams(ctx, await ctx.client.getGame(st.gameId, { settings: true }));
1799
+ const me = game.players.find((p) => p.id === st.feedPlayerId);
1800
+ if (!me)
1801
+ return notRecorded('you are no longer listed in the game');
1802
+ return await recordPartnerApproved({ dir: ctx.dataDir, env: opts.env, game, me, map: mapOf(game), exceptions: list, turn: st.turnNumber });
1803
+ }
1804
+ catch (e) {
1805
+ return notRecorded(`re-reading the game failed (${failureText(e)}): ${byHand}`);
1806
+ }
1807
+ };
1776
1808
  server.registerTool('warapp_plan_turn', {
1777
1809
  title: 'Plan my turn in a war.app game',
1778
1810
  description: untrustedDescription('Plan one turn for you in an in-progress war.app (Warzone) game from the live board, the map and the ' +
@@ -1843,7 +1875,8 @@ export function registerTurnTools(server, ctx, opts = {}) {
1843
1875
  'In a free-for-all, `relations` reports each truce recorded with warapp_record_agreement as the plan treated it ' +
1844
1876
  '(no covered territory of the partner attacked while it is active or in notice; a covered border facing only ' +
1845
1877
  'the partner held against its stacks with no deploy, except your commander\'s, a valuable border, or while trust ' +
1846
- 'is watch; a border cap kept), `advice` says `give-notice` when the endgame or the partner outgrowing you made ' +
1878
+ 'is watch; a border cap kept; a partner-approved truce exception on this turn makes its territories normal ' +
1879
+ 'targets, listed under the truce as `exceptions`), `advice` says `give-notice` when the endgame or the partner outgrowing you made ' +
1847
1880
  'the trust watch, a truce the board shows broken is planned as an ordinary opponent, and `tacit` lists quiet ' +
1848
1881
  'borders with no agreement (a report, never a truce). The plan never reads what your chat promised ' +
1849
1882
  "(warapp_send_chat's `commitments`): a warning says when its moves would break one still in force. " +
@@ -2342,6 +2375,11 @@ export function registerTurnTools(server, ctx, opts = {}) {
2342
2375
  const standInNote = standInLine(standInOf(ctx));
2343
2376
  if (standInNote)
2344
2377
  warnings.unshift(standInNote);
2378
+ // Unread private chat to me leads every warning (report only: read after the plan, no order reads it). From
2379
+ // GameFeed's chat, else one GameRefresh only when GameFeed shows unread messages of others with no channel.
2380
+ const privateLine = chat ? privateToMeWarning(await privateToMeUnread(ctx, game, chat)) : undefined;
2381
+ if (privateLine)
2382
+ warnings.unshift(privateLine);
2345
2383
  // #312 E3: after turns 4 and 8, my income beside the pace my finished games on this map set
2346
2384
  // (reported only: read after the plan is made, never an input to it).
2347
2385
  const paceRecord = PACE_TURNS.includes(turnsCompleted(game))
@@ -2617,6 +2655,7 @@ export function registerTurnTools(server, ctx, opts = {}) {
2617
2655
  fullHold: r.fullHold.map((f) => ({ territory: name(f.territory), why: f.why })),
2618
2656
  ...(r.capMoved ? { capMoved: r.capMoved.map((m) => ({ from: name(m.from), to: name(m.to), armies: m.armies })) } : {}),
2619
2657
  ...(r.breach ? { breach: { ...r.breach, territories: r.breach.territories.map(name) } } : {}),
2658
+ ...(r.exceptions ? { exceptions: r.exceptions.map((e) => ({ direction: e.direction, territories: e.territories.map(name) })) } : {}),
2620
2659
  lossIfBroken: r.lossIfBroken
2621
2660
  ? {
2622
2661
  ...r.lossIfBroken,
@@ -2769,7 +2808,19 @@ export function registerTurnTools(server, ctx, opts = {}) {
2769
2808
  .optional()
2770
2809
  .describe('Only when an order attacks (or a Bomb hits) a territory an active or in-notice truce covers (warapp_get_relations): true breaks ' +
2771
2810
  'it on purpose — the preview names the agreement, and once the orders are committed the ledger records it ' +
2772
- 'broken-by-me (the partner\'s player record too). Without it such orders are refused. Ask the owner first.'),
2811
+ 'broken-by-me (the partner\'s player record too). Without it such orders are refused. Ask the owner first. ' +
2812
+ 'Not with partner_approved.'),
2813
+ partner_approved: z
2814
+ .boolean()
2815
+ .optional()
2816
+ .describe('The truce partner agreed to these attacks: true records a one-turn exception (the agreement and the territories ' +
2817
+ 'hit) instead of refusing, and nothing is broken — no broken-by-me, the player record counts an exception. ' +
2818
+ 'Ignored (a preview note) when no order hits a covered territory. Not with break_agreement.'),
2819
+ note: z
2820
+ .string()
2821
+ .max(MAX_EXCEPTION_NOTE)
2822
+ .optional()
2823
+ .describe("With partner_approved: the owner's own words on what the partner agreed, kept on the exception (player names scrubbed)."),
2773
2824
  accept_commander_risk: z
2774
2825
  .boolean()
2775
2826
  .optional()
@@ -2846,7 +2897,9 @@ export function registerTurnTools(server, ctx, opts = {}) {
2846
2897
  'a border below what the default plan made now (warapp_plan_turn with no options, or its border guess when the deploys ' +
2847
2898
  'are the guess\'s) leaves standing there, naming each with the difference (the plan\'s figure carries its surplus). An order that attacks (or a Bomb that hits) a territory an active or in-notice truce ' +
2848
2899
  'covers (the agreement ledger) is refused unless `break_agreement` is true; then the preview names the agreement ' +
2849
- 'and, once the orders are committed, the ledger records it broken-by-me. In a Commanders game, orders that ' +
2900
+ 'and, once the orders are committed, the ledger records it broken-by-me. When the partner agreed to it, ' +
2901
+ '`partner_approved: true` (optional `note`) records a one-turn truce exception instead — no break; an exception ' +
2902
+ 'already recorded (warapp_record_agreement `exceptions`) lets the attack through by itself. In a Commanders game, orders that ' +
2850
2903
  'leave your commander takeable by one opponent\'s single deploy, or two striking together when you lead a ' +
2851
2904
  'free-for-all (each reply sized at the larger of its estimate and your income, on the live board; your Airlifts counted, ' +
2852
2905
  'after the deploys and before the moves) are refused with the armies that would hold, and so is a Blockade or Gift ' +
@@ -2864,7 +2917,12 @@ export function registerTurnTools(server, ctx, opts = {}) {
2864
2917
  openWorld: true,
2865
2918
  }),
2866
2919
  inputSchema: submitSchema,
2867
- async plan({ game_id, player, orders, income: givenIncome, break_agreement, accept_commander_risk, cities, override_reason, override_by, chat_reviewed }) {
2920
+ async plan({ game_id, player, orders, income: givenIncome, break_agreement, partner_approved, note, accept_commander_risk, cities, override_reason, override_by, chat_reviewed }) {
2921
+ if (partner_approved === true && break_agreement === true) {
2922
+ throw new McpToolError('break_agreement and partner_approved are both true, so it is unclear whether this breaks the truce or is an exception the partner agreed to: nothing was sent.', {
2923
+ hint: 'Pass partner_approved: true when the partner agreed to these attacks (no break), or break_agreement: true to break it on purpose — not both.',
2924
+ });
2925
+ }
2868
2926
  // #415 task 4b: the chat comes in the same GameFeed read (GetChat=true), so the chat block check adds no request.
2869
2927
  const feed = await ctx.client.getGame(parseGameId(game_id), { settings: true, chat: true });
2870
2928
  requireTurnPhase(feed);
@@ -3068,11 +3126,24 @@ export function registerTurnTools(server, ctx, opts = {}) {
3068
3126
  bombs: bombs.map((x) => x.target),
3069
3127
  })
3070
3128
  : [];
3071
- if (breaks.length && break_agreement !== true) {
3129
+ // `partner_approved`: each hit becomes a one-turn exception on its agreement, recorded once committed — no break.
3130
+ const approved = partner_approved === true
3131
+ ? breaks.map((b) => {
3132
+ const n = exceptionNote(note, game);
3133
+ return {
3134
+ agreement: b.agreement,
3135
+ with: b.with,
3136
+ territories: [...new Set([...b.moves.map((m) => m.to), ...(b.bombs ?? []).map((x) => x.target)])].sort((x, y) => x - y),
3137
+ ...(n ? { note: n } : {}),
3138
+ };
3139
+ })
3140
+ : [];
3141
+ if (breaks.length && break_agreement !== true && partner_approved !== true) {
3072
3142
  throw new McpToolError(`${breaksText(breaks, moves, bombPlays)}: nothing was sent.`, {
3073
3143
  hint: 'Drop those orders, or give notice (warapp_record_agreement status notice-by-me) and wait until it runs. ' +
3074
3144
  'If the partner broke it first, record broken-by-them with warapp_record_agreement. To break it on purpose ' +
3075
- '(ask the owner first), resend with break_agreement: true — the ledger then records it broken-by-me.',
3145
+ '(ask the owner first), resend with break_agreement: true — the ledger then records it broken-by-me. If the ' +
3146
+ 'partner agreed to these attacks, resend with partner_approved: true — a one-turn exception, no break.',
3076
3147
  });
3077
3148
  }
3078
3149
  const { warnings } = validateTurn({
@@ -3115,7 +3186,15 @@ export function registerTurnTools(server, ctx, opts = {}) {
3115
3186
  else if (givenIncome === undefined && incomeOnBoard.capUnknown)
3116
3187
  warnings.unshift(`Deploys checked against income ${modelled}, not cut by the army cap: an army count of yours is unreadable on the board, ` +
3117
3188
  "so the cap's cut could not be worked out (pass the game's own number as income if it differs).");
3118
- if (breaks.length)
3189
+ if (partner_approved === true && !breaks.length)
3190
+ warnings.unshift('partner_approved is ignored: no order attacks (or Bomb hits) a territory an active or in-notice truce covers, so there is no exception to record.');
3191
+ else if (note !== undefined && partner_approved !== true)
3192
+ warnings.unshift('note is ignored: it is kept only on an exception recorded with partner_approved: true.');
3193
+ if (approved.length)
3194
+ warnings.unshift(`partner_approved is true: once these orders are committed the ledger records a one-turn exception (turn ${turnNumber}, no break) on ` +
3195
+ approved.map((x) => `agreement ${x.agreement} with player ${x.with} for ${x.territories.join(', ')}`).join('; ') +
3196
+ '. Nothing is recorded broken-by-me; the player record counts an exception.');
3197
+ else if (breaks.length)
3119
3198
  warnings.unshift(`${breaksText(breaks, moves, bombPlays)}. break_agreement is true: once these orders are committed the ledger records ` +
3120
3199
  `${breaks.length === 1 ? 'it' : 'them'} broken-by-me, and the partner's player record says so. That is final: ` +
3121
3200
  'withdrawing the orders afterwards (warapp_uncommit_turn) does not undo it.');
@@ -3260,6 +3339,10 @@ export function registerTurnTools(server, ctx, opts = {}) {
3260
3339
  const belowPlan = belowPlanWarning(belowRows);
3261
3340
  if (belowPlan)
3262
3341
  warnings.push(belowPlan);
3342
+ // #505: orders that delay the nearest bonus say by how many turns (advice only, never a refusal).
3343
+ const delayLine = bonusDelayWarning(belowRows?.bonusDelay);
3344
+ if (delayLine)
3345
+ warnings.push(delayLine);
3263
3346
  // #437: what was checked on these orders, for the decision log (ids and numbers only).
3264
3347
  const checks = submitChecksLog({
3265
3348
  commander: commanderChecked ? { ...commanderChecked, ...(commanderRisk && accept_commander_risk === true ? { accepted: true } : {}) } : undefined,
@@ -3344,6 +3427,10 @@ export function registerTurnTools(server, ctx, opts = {}) {
3344
3427
  account: shownAccount(me.name, me.id),
3345
3428
  note: 'These orders reach the game; once the turn resolves, other players see the results.',
3346
3429
  ...(attacks.length ? { attacks: attacks.map((a) => ({ ...a, from: shownPlace(a.from), to: shownPlace(a.to) })) } : {}),
3430
+ // `partner_approved`: the truce exceptions recorded once committed (agreement, partner by id, territories).
3431
+ ...(approved.length
3432
+ ? { truceExceptions: approved.map((x) => ({ agreement: x.agreement, with: x.with, turn: turnNumber, territories: x.territories.map((t) => shownPlace(resolveTerritory(map, t))) })) }
3433
+ : {}),
3347
3434
  ...(warnings.length ? { warnings } : {}),
3348
3435
  ...(chatWarnings.length ? { chatWarnings } : {}),
3349
3436
  untrusted: UNTRUSTED_PREVIEW_NOTE,
@@ -3361,7 +3448,8 @@ export function registerTurnTools(server, ctx, opts = {}) {
3361
3448
  ...(givenIncome !== undefined ? { incomeGiven: true } : {}),
3362
3449
  ...(placedDelays.length ? { orderDelayCheck: orderDelayCheck(placedDelays.map((p) => placedAt(p))) } : {}),
3363
3450
  ...(unverifiedPlays.length ? { cardPlayCheck: cardPlayCheck(unverifiedPlays) } : {}),
3364
- ...(breaks.length ? { breaks: breaks.map((b) => b.agreement) } : {}),
3451
+ ...(breaks.length && !approved.length ? { breaks: breaks.map((b) => b.agreement) } : {}),
3452
+ ...(approved.length ? { exceptions: approved.map(({ with: _with, ...x }) => x) } : {}),
3365
3453
  ...(commanderRisk ? { commanderRisk: commanderRisk.risk } : {}),
3366
3454
  checks,
3367
3455
  ...(chat_reviewed === true ? { chatReviewed: { blocks: blocks.map((b) => ({ case: b.case, intent: b.intent, from: b.from, messageIds: b.messageIds })) } } : {}),
@@ -3447,9 +3535,10 @@ export function registerTurnTools(server, ctx, opts = {}) {
3447
3535
  });
3448
3536
  const withChat = st.chatReviewed ? { ...result, chatReviewed: st.chatReviewed } : result;
3449
3537
  const withRisk = st.commanderRisk ? { ...withChat, commanderRiskAccepted: st.commanderRisk } : withChat;
3538
+ const withExceptions = st.exceptions?.length ? { ...withRisk, exceptionsRecorded: await recordApproved(st, result.outcome === 'confirmed') } : withRisk;
3450
3539
  if (!st.breaks?.length)
3451
- return withRisk;
3452
- return { ...withRisk, agreementsBroken: await recordBreaks(st, result.outcome === 'confirmed') };
3540
+ return withExceptions;
3541
+ return { ...withExceptions, agreementsBroken: await recordBreaks(st, result.outcome === 'confirmed') };
3453
3542
  },
3454
3543
  });
3455
3544
  }
package/dist/version.js CHANGED
@@ -1,4 +1,4 @@
1
1
  // Single source of truth for the server version. release-please bumps the
2
2
  // literal on the marked line (registered in release-please-config.json
3
3
  // extra-files); every other module imports VERSION from here.
4
- export const VERSION = '0.9.0'; // x-release-please-version
4
+ export const VERSION = '0.11.0'; // x-release-please-version
package/manifest.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "manifest_version": "0.3",
4
4
  "name": "warapp-mcp",
5
5
  "display_name": "war.app (Warzone)",
6
- "version": "0.9.0",
6
+ "version": "0.11.0",
7
7
  "description": "war.app (Warzone) game advisor for Claude — your games, maps, bonuses, board analysis and routes via the GameFeed API, plus your games list (waiting on you first), opponent scouting with your head-to-head, the live board, territory picks, cards, turn planning and submission, turn notifications, and chat through your signed-in war.app tab (ContextMint Bridge). Joining, leaving or surrendering a game, accepting another player's surrender, Begin on a speed first turn, picks, turn orders, withdrawing them, chat sends, marking notifications and chat read, deleting notifications, importing local history into a hosted server and linking a session (local only) are confirm-gated.",
8
8
  "author": {
9
9
  "name": "Chris Hall",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@chrischall/warapp-mcp",
3
- "version": "0.9.0",
3
+ "version": "0.11.0",
4
4
  "mcpName": "io.github.chrischall/warapp-mcp",
5
5
  "description": "war.app (Warzone) game advisor MCP server for Claude — games, maps, bonuses and board analysis via the GameFeed API, plus your games list, opponent scouting, the live board, territory picks, cards, turn planning and submission, turn notifications and chat through your signed-in war.app tab. Developed and maintained by AI (Claude Code).",
6
6
  "author": "Claude Code (AI) <https://www.anthropic.com/claude>",
package/server.json CHANGED
@@ -6,12 +6,12 @@
6
6
  "url": "https://github.com/chrischall/warapp-mcp",
7
7
  "source": "github"
8
8
  },
9
- "version": "0.9.0",
9
+ "version": "0.11.0",
10
10
  "packages": [
11
11
  {
12
12
  "registryType": "npm",
13
13
  "identifier": "@chrischall/warapp-mcp",
14
- "version": "0.9.0",
14
+ "version": "0.11.0",
15
15
  "transport": {
16
16
  "type": "stdio"
17
17
  },