@chrischall/warapp-mcp 0.6.0 → 0.8.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.
Files changed (111) hide show
  1. package/.claude-plugin/marketplace.json +2 -2
  2. package/.claude-plugin/plugin.json +1 -1
  3. package/README.md +100 -7
  4. package/dist/analysis/accept-surrender.js +20 -2
  5. package/dist/analysis/calibrate.js +1 -0
  6. package/dist/analysis/card-support.js +187 -20
  7. package/dist/analysis/card-threats.js +68 -3
  8. package/dist/analysis/chat-advice.js +182 -0
  9. package/dist/analysis/chat-blocks.js +106 -0
  10. package/dist/analysis/chat-intent.js +559 -0
  11. package/dist/analysis/chat-read.js +159 -0
  12. package/dist/analysis/coalition.js +55 -0
  13. package/dist/analysis/decision-replay.js +279 -0
  14. package/dist/analysis/decision-truth.js +146 -0
  15. package/dist/analysis/finished-game.js +62 -3
  16. package/dist/analysis/game-lessons.js +12 -6
  17. package/dist/analysis/local-deploy.js +14 -0
  18. package/dist/analysis/opponent-profile.js +46 -3
  19. package/dist/analysis/opponents.js +246 -19
  20. package/dist/analysis/outlook.js +323 -17
  21. package/dist/analysis/picks.js +270 -37
  22. package/dist/analysis/plan/after-leftover.js +28 -3
  23. package/dist/analysis/plan/captures.js +80 -16
  24. package/dist/analysis/plan/completed.js +8 -1
  25. package/dist/analysis/plan/conceded-out.js +16 -11
  26. package/dist/analysis/plan/deploy-estimates.js +513 -0
  27. package/dist/analysis/plan/doomed-out.js +135 -0
  28. package/dist/analysis/plan/estimates.js +73 -7
  29. package/dist/analysis/plan/free-capture.js +34 -0
  30. package/dist/analysis/plan/guard-off.js +2 -1
  31. package/dist/analysis/plan/holds.js +85 -313
  32. package/dist/analysis/plan/horizon.js +42 -0
  33. package/dist/analysis/plan/leftover.js +188 -10
  34. package/dist/analysis/plan/observe.js +896 -0
  35. package/dist/analysis/plan/orders.js +35 -1
  36. package/dist/analysis/plan/relations.js +115 -2
  37. package/dist/analysis/plan/report.js +10 -4
  38. package/dist/analysis/plan/shared.js +7 -1189
  39. package/dist/analysis/plan/stand-still.js +7 -5
  40. package/dist/analysis/plan/state.js +12 -0
  41. package/dist/analysis/plan/stockpile.js +104 -0
  42. package/dist/analysis/plan/strike-stack.js +467 -0
  43. package/dist/analysis/plan/strike.js +8 -441
  44. package/dist/analysis/plan/targets.js +374 -72
  45. package/dist/analysis/plan/threats.js +120 -9
  46. package/dist/analysis/plan/transfers.js +35 -1
  47. package/dist/analysis/plan/two-move.js +70 -0
  48. package/dist/analysis/plan/vacated.js +124 -2
  49. package/dist/analysis/plan/withdraw.js +316 -0
  50. package/dist/analysis/planner.js +356 -53
  51. package/dist/analysis/player.js +4 -0
  52. package/dist/analysis/relations.js +8 -2
  53. package/dist/analysis/since-last.js +18 -5
  54. package/dist/analysis/stress.js +1 -1
  55. package/dist/board.js +36 -2
  56. package/dist/build-id.js +106 -0
  57. package/dist/bundle.js +15863 -10242
  58. package/dist/chat-automation.js +22 -0
  59. package/dist/client.js +14 -0
  60. package/dist/decision-log.js +1093 -0
  61. package/dist/finished-store.js +5 -1
  62. package/dist/lessons-store.js +322 -21
  63. package/dist/my-games.js +2 -0
  64. package/dist/open-games.js +122 -18
  65. package/dist/outlook-log.js +42 -1
  66. package/dist/protocol/methods.js +4 -2
  67. package/dist/review-export.js +198 -0
  68. package/dist/state-bundle.js +62 -3
  69. package/dist/state-cli.js +5 -3
  70. package/dist/strategy/notes.js +56 -0
  71. package/dist/tools/accept-surrender.js +23 -9
  72. package/dist/tools/award.js +5 -1
  73. package/dist/tools/card-advice.js +102 -33
  74. package/dist/tools/card-support-advice.js +53 -8
  75. package/dist/tools/chat-advice.js +330 -0
  76. package/dist/tools/chat-inbox.js +15 -4
  77. package/dist/tools/chat.js +41 -11
  78. package/dist/tools/check-plan.js +16 -3
  79. package/dist/tools/commander-check.js +2 -1
  80. package/dist/tools/decision-capture.js +461 -0
  81. package/dist/tools/end-of-game.js +146 -18
  82. package/dist/tools/game-kind.js +92 -0
  83. package/dist/tools/how-lost.js +7 -2
  84. package/dist/tools/index.js +3 -0
  85. package/dist/tools/join-game.js +51 -9
  86. package/dist/tools/live-context.js +6 -0
  87. package/dist/tools/live.js +43 -6
  88. package/dist/tools/map-curves.js +73 -0
  89. package/dist/tools/notifications.js +4 -3
  90. package/dist/tools/open-games.js +2 -2
  91. package/dist/tools/opponents.js +2 -0
  92. package/dist/tools/past-games.js +74 -8
  93. package/dist/tools/picks.js +169 -57
  94. package/dist/tools/profile-hook.js +62 -3
  95. package/dist/tools/profile-opponents.js +2 -0
  96. package/dist/tools/push.js +2 -2
  97. package/dist/tools/relations.js +2 -0
  98. package/dist/tools/scout.js +16 -2
  99. package/dist/tools/state.js +6 -1
  100. package/dist/tools/strategy.js +3 -3
  101. package/dist/tools/stress-opponents.js +2 -0
  102. package/dist/tools/surrender-pending.js +10 -1
  103. package/dist/tools/surrender.js +18 -3
  104. package/dist/tools/turn.js +353 -19
  105. package/dist/tools/where.js +3 -1
  106. package/dist/version.js +1 -1
  107. package/manifest.json +23 -2
  108. package/mint.yaml +23 -0
  109. package/package.json +1 -1
  110. package/server.json +20 -2
  111. package/skills/warapp-mcp/SKILL.md +42 -8
@@ -5,6 +5,7 @@
5
5
  // rationale and warnings that state them. Pure: it reads the input and writes only
6
6
  // `state.warnings` / `state.rationale`.
7
7
  import { siegeFit, siegeOf } from './siege.js';
8
+ import { pileOf, strikeShareOf } from './stockpile.js';
8
9
  import { armiesForGold } from '../../commerce.js';
9
10
  import { holdsSeat } from '../../player-states.js';
10
11
  import { isTeamGame, teammatesOf } from '../../teams.js';
@@ -19,10 +20,11 @@ import { AHEAD_PRESSURE_FACTOR, captureCost, combatSettings, DECIDED_PAYBACK_MIN
19
20
  import { AHEAD_RATIO, BEHIND_RATIO, gameProfile } from '../profile.js';
20
21
  import { byNum } from './util.js';
21
22
  import { sanctionedIncome } from '../cards-in-effect.js';
22
- import { truceOf } from './relations.js';
23
+ import { skirtedNeutrals, truceOf } from './relations.js';
23
24
  import { teamFocusOf } from './team.js';
24
25
  import { neutralizeSeats, staticSeats } from '../static-seats.js';
25
26
  import { commanderPlace } from './commander.js';
27
+ import { fogVacated, VACATED_FOG_ARMIES } from './vacated.js';
26
28
  /**
27
29
  * The fog prior to apply (#119, {@link EnemyIncomePrior}): only when the game says the start was
28
30
  * symmetric (`symmetricStart`), with no teams — a 1v1 (one opponent), or (#226) a free-for-all, where
@@ -58,6 +60,8 @@ function fogPrior(board, me, ctx, myIncome, seats = new Map()) {
58
60
  ...(opponents > 1 || out.length ? { format: 'ffa', opponents } : {}),
59
61
  ...(out.length ? { out } : {}),
60
62
  ...(ctx.opening ? { opening: ctx.opening } : {}),
63
+ // #419: the past winners' pace, thin evidence's upper bound when above the prior.
64
+ ...(ctx.mapPace ? { winnerPace: ctx.mapPace } : {}),
61
65
  },
62
66
  };
63
67
  }
@@ -84,7 +88,9 @@ export function planEnemyEstimates(input) {
84
88
  const previousBoard = input.previousBoard ? neutralizeSeats(input.previousBoard, seats) : undefined;
85
89
  const tracks = input.tracks?.filter((t) => !seats.has(t.playerId));
86
90
  const capCut = input.incomeCap ? Math.max(0, Math.floor(input.incomeCap.uncapped - input.incomeCap.received)) : 0;
87
- const { prior, skipped } = fogPrior(board, input.me, ctx, input.income + capCut, seats);
91
+ const fog = fogPrior(board, input.me, ctx, input.income + capCut, seats);
92
+ const prior = statedScale(fog.prior, board, input.me, input.known ?? []);
93
+ const skipped = fog.skipped;
88
94
  const turn = input.turn ?? ctx.turn ?? null;
89
95
  const estimates = enemyDeployEstimates(input.graph, board, input.me, input.settings ?? {}, previousBoard, tracks, prior, {
90
96
  turn,
@@ -95,6 +101,22 @@ export function planEnemyEstimates(input) {
95
101
  const priced = applyKnown(applyArmyPrice(applySanctions(estimates, input.sanctions ?? []), input.settings?.armyCostMultiplier ?? 0), input.known ?? []);
96
102
  return { estimates: priced, prior, ...(skipped ? { priorSkipped: skipped } : {}) };
97
103
  }
104
+ /**
105
+ * #444: the incomes stated in chat (`known`) for players in view (not me) scale the prior of every other
106
+ * opponent when their mean is below my income: `EnemyIncomePrior.stated`. The prior unchanged otherwise.
107
+ */
108
+ function statedScale(prior, board, me, known) {
109
+ if (!prior || !known.length || prior.myIncome <= 0)
110
+ return prior;
111
+ const inView = new Set(board.territories.flatMap((t) => (t.owner.kind === 'player' ? [t.owner.playerId] : [])));
112
+ const players = known
113
+ .filter((k) => k.player !== me && inView.has(k.player))
114
+ .map((k) => ({ id: k.player, income: Math.max(0, Math.floor(k.income)) }));
115
+ if (!players.length)
116
+ return prior;
117
+ const ratio = players.reduce((n, x) => n + x.income, 0) / players.length / prior.myIncome;
118
+ return ratio < 1 ? { ...prior, stated: { players, mine: prior.myIncome, ratio } } : prior;
119
+ }
98
120
  /**
99
121
  * #368: each estimate whose player the user gave a known income for (what it said in chat, say): that
100
122
  * income replaces the estimate's, whatever its source; a Reinforcement card the clock adds stays on top.
@@ -210,7 +232,8 @@ function opponentsCtx(input) {
210
232
  ...(ctx.turn !== undefined ? { turn: ctx.turn } : {}),
211
233
  ...(ctx.picking !== undefined ? { picking: ctx.picking } : {}),
212
234
  ...(ctx.endRules ? { endRules: ctx.endRules } : {}),
213
- income: earnedIncome,
235
+ // #427: my Reinforcement card is a one-off deploy like an opponent's, so the standing reads income without it.
236
+ income: earnedIncome - Math.max(0, Math.floor(input.cardArmies ?? 0)),
214
237
  // #164 x #167: an opponent's Reinforcement card is a one-off deploy, not income: the standing
215
238
  // and the FFA ranking read each estimate less its card. PLAN-TEAMS C3: teammates' estimates go
216
239
  // too, for the team standing (the profile keeps them off the opponents' side).
@@ -321,9 +344,19 @@ function opponentsCtx(input) {
321
344
  const heldLand = new Set(held
322
345
  ? board.territories.flatMap((t) => t.owner.kind === 'player' && t.owner.playerId === held.target && !held.breakMembers.has(t.territoryId) ? [t.territoryId] : [])
323
346
  : []);
324
- const truceNow = held
347
+ const withSiege = held
325
348
  ? { ...truce, siegeHeld: (t) => heldLand.has(t), noTarget: (t) => truce.noTarget(t) || heldLand.has(t) }
326
349
  : truce;
350
+ // #441: the neutrals an avoided player is visibly collecting are no targets either; #457: nor a truce partner's.
351
+ const skirted = skirtedNeutrals({ ...input, board }, { foe, deployOf, settings: s, ...(truce.keptWith ? { truce: truce.keptWith } : {}) });
352
+ const truceNow = skirted.size
353
+ ? {
354
+ ...withSiege,
355
+ skirted,
356
+ avoided: (t) => skirted.has(t) || withSiege.avoided(t),
357
+ noTarget: (t) => skirted.has(t) || withSiege.noTarget(t),
358
+ }
359
+ : withSiege;
327
360
  /**
328
361
  * #201: the planning horizon. Once the outlook (#178) says the game is decided — winning or losing
329
362
  * for OUTLOOK_TURNS turns running — every payback test counts the turns the game has left instead
@@ -395,6 +428,7 @@ function opponentsCtx(input) {
395
428
  untrustedAt,
396
429
  decidedGame,
397
430
  paybackTurns,
431
+ capturePaybackTurns: paybackTurns,
398
432
  };
399
433
  }
400
434
  /** The territories as the board shows them, and what holding them is worth (#70, #85, #125). */
@@ -451,8 +485,11 @@ function boardCtx(input, o) {
451
485
  */
452
486
  const uncounted = (id) => (state.get(id)?.specialUnits ?? []).some((u) => u.kind !== 'commander');
453
487
  const uncountedKind = (id) => [...new Set((state.get(id)?.specialUnits ?? []).filter((u) => u.kind !== 'commander').map((u) => (u.kind === 'boss' ? 'a boss' : u.kind === 'custom' ? 'a custom unit' : 'a special unit')))].join(' and ');
454
- /** What a territory defends as now: its armies plus its special units. */
455
- const defenceAt = (id) => armiesOf(id) + unitsAt(id);
488
+ /**
489
+ * What a territory defends as now: its armies plus its special units. #417 (the breach force): land a
490
+ * static seat left whose armies the fog hides stands on {@link VACATED_FOG_ARMIES} at most.
491
+ */
492
+ const defenceAt = (id) => (fogVacated(input.vacated, state.get(id), id) ? VACATED_FOG_ARMIES : armiesOf(id)) + unitsAt(id);
456
493
  // ---- income change (#70): the one computation nextIncome, R3 and the negative-bonus rules use ----
457
494
  const bonusTs = new Map(g.map.bonuses.map((b) => [b.id, bonusTerritories(g, b.id)]));
458
495
  /** The bonuses each territory is in (superbonuses through their members included). */
@@ -733,7 +770,28 @@ function standingCtx(o, b) {
733
770
  export function planContext(input) {
734
771
  const o = opponentsCtx(input);
735
772
  const b = boardCtx(input, o);
736
- return { ...o, ...b, ...combatCtx(o, b), ...standingCtx(o, b) };
773
+ const c = combatCtx(o, b);
774
+ // #421 (owner decision, 2026-11-20): in contact on a flat income the strike share is held out of
775
+ // captures (the reserve holds back captures only, so holds keep their exact need first).
776
+ const contact = new Set();
777
+ for (const id of b.mine)
778
+ for (const n of neighborsOf(o.g, id)) {
779
+ const st = b.territories.get(n);
780
+ if (st?.owner.kind === 'player' && st.armies !== null && o.foe(st.owner.playerId))
781
+ contact.add(st.owner.playerId);
782
+ }
783
+ const pileArgs = {
784
+ territories: b.territories, mineSet: b.mineSet, unitsAt: b.unitsAt, foe: o.foe, income: o.income,
785
+ ...(o.incomeTrend ? { incomeTrend: o.incomeTrend } : {}), auto: o.auto, goal: o.goal, noSplit: c.noSplit,
786
+ };
787
+ const strikeShare = o.opts.strikeShare === false ? 0 : strikeShareOf({ ...pileArgs, format: o.profile.format, siege: o.siege?.target, contact });
788
+ const reserve = Math.min(o.income, o.reserve + strikeShare);
789
+ // #421: the pile itself, for the break and all-in spends.
790
+ const pile = pileOf(pileArgs);
791
+ return {
792
+ ...o, ...b, ...c, ...standingCtx(o, b), reserve, strikeShare: reserve - o.reserve,
793
+ ...(pile ? { pile: { my: pile.my, turns: pile.turns } } : {}),
794
+ };
737
795
  }
738
796
  /**
739
797
  * The rationale and warnings that state what the estimates phase decided: the goal and the profile
@@ -797,6 +855,14 @@ export function noteEstimates(ctx, state) {
797
855
  rationale.push('An opponent may hold a Bomb (#163): it halves one territory of mine next to it after the deploys and before any move, so every hold here is sized as if its stack were halved first (my commander unharmed), and the leftover goes to two stacks, not one, unless it concentrates for an attack.');
798
856
  if (s.multiAttack)
799
857
  rationale.push(`Multi-attack is on: the plan does not chain its own attacks from captured territories, but an enemy stack's chain — a capture, then the survivors on from it, through territories not mine — counts as a threat to the territory of mine, or the capture, it reaches (luck-free, at most ${CHAIN_MAX_STEPS} attacks deep).`);
858
+ // #441: a neutral skipped for an avoided player, beside my land (one the plan could reach this turn); #457: or a truce partner.
859
+ for (const [n, k] of ctx.truce.skirted ?? [])
860
+ if (neighborsOf(ctx.g, n).some((x) => ctx.mineSet.has(x))) {
861
+ const why = k.why === 'stack' ? `its only enemy neighbour is player ${k.player}` : `it sits in a bonus player ${k.player} visibly holds most of`;
862
+ rationale.push(k.truce
863
+ ? `Not taking ${ctx.label(n)}: ${why}, with whom a truce binds you, and taking it may read as a breach to player ${k.player} — raise it with player ${k.player} instead (it is taken only when it completes a bonus of mine) (#457).`
864
+ : `Not taking ${ctx.label(n)}: ${why}, whom the plan avoids, and its capture would not hold next turn, so taking it would only provoke that player (#441).`);
865
+ }
800
866
  if (noSplit) {
801
867
  rationale.push('No-Split: each territory issues at most one attack or transfer this turn, and it sends the whole stack (every army there, this turn\'s deploys included, less the guard); a territory that would split keeps its first (best) order, and one that must hold issues none.');
802
868
  }
@@ -0,0 +1,34 @@
1
+ import { neighborsOf } from '../graph.js';
2
+ import { noLossNeutral } from './after-leftover.js';
3
+ import { byNum } from './util.js';
4
+ export function warnIdleBesideFree(pc, ps, tgt, previousBoard) {
5
+ if (!previousBoard)
6
+ return;
7
+ const { g, territories: state, label, mineSet, me, guard, myCommanders } = pc;
8
+ const { captured, moves, warnings } = ps;
9
+ const before = new Map(previousBoard.territories.map((t) => [t.territoryId, t]));
10
+ const mineBefore = (x) => {
11
+ const t = before.get(x);
12
+ return t?.owner.kind === 'player' && t.owner.playerId === me ? t : undefined;
13
+ };
14
+ for (const x of [...mineSet].sort(byNum)) {
15
+ // Idle this turn: the plan sends nothing out of it. My commander's stack stays by rule 1k's choice.
16
+ if (myCommanders.has(x) || moves.some((m) => m.from === x))
17
+ continue;
18
+ const now = state.get(x)?.armies;
19
+ const was = mineBefore(x)?.armies;
20
+ // It had armies to move last turn and has no fewer now.
21
+ if (now == null || was == null || was - guard < 1 || now < was)
22
+ continue;
23
+ // Each neutral its own movable armies take (the guard stays), with no deploy.
24
+ const free = neighborsOf(g, x)
25
+ .filter((n) => {
26
+ const cost = tgt.targets.get(n)?.cost;
27
+ return !captured.has(n) && cost !== undefined && cost <= now - guard && noLossNeutral(pc, tgt, n) && before.get(n)?.owner.kind === 'neutral';
28
+ })
29
+ .sort(byNum);
30
+ if (!free.length)
31
+ continue;
32
+ warnings.push(`${label(x)} has stood idle two turns with ${now} armies beside ${free.map(label).join(', ')}, which ${free.length === 1 ? 'is a no-loss capture (its defenders kill none of the attackers)' : 'are no-loss captures (their defenders kill none of the attackers)'}, and this plan leaves it idle again (#426).`);
33
+ }
34
+ }
@@ -82,7 +82,8 @@ export function fillSecondLine(pc, ps, book) {
82
82
  const owed = e.size - secondLineKept.get(id);
83
83
  if (owed <= 0)
84
84
  continue;
85
- const k = Math.min(owed, Math.max(0, ps.budget - reserve), roomAt(id));
85
+ // #421: the strike share holds back captures only, never the second line's exact need.
86
+ const k = Math.min(owed, Math.max(0, ps.budget - (reserve - pc.strikeShare)), roomAt(id));
86
87
  if (k > 0) {
87
88
  deploy(id, k);
88
89
  // The deployed armies join the garrison: they stay, as the guard would.