@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
@@ -140,6 +140,31 @@ export function deployBook(ctx, ps, previousBoard) {
140
140
  }
141
141
  return cost <= paybackTurns * value && worst <= WASTELAND_FACTOR * value;
142
142
  };
143
+ /**
144
+ * #425 (owner decision of 2026-11-22): the bonus `ts` a lone foothold is my only way into still earns
145
+ * its share unless an enemy holds a missing member (which an enemy stack roaming inside it, #298, does
146
+ * too). Unlike {@link building} a member the fog hides keeps the share: it is passed over, not refused,
147
+ * and only the members in view are priced on #122's economy tests. A member a teammate holds is no
148
+ * bonus of mine to build, as in `building`.
149
+ */
150
+ const footholdBuilding = (ts, value) => {
151
+ let cost = 0;
152
+ let worst = 0;
153
+ for (const x of ts) {
154
+ if (ps.holdings.has(x))
155
+ continue;
156
+ const st = state.get(x);
157
+ const o = st?.owner;
158
+ if (o?.kind === 'player')
159
+ return false;
160
+ if (st === undefined || o?.kind !== 'neutral' || st.armies === null)
161
+ continue;
162
+ const c = econCostAt(x);
163
+ cost += c;
164
+ worst = Math.max(worst, c);
165
+ }
166
+ return cost <= paybackTurns * value && worst <= WASTELAND_FACTOR * value;
167
+ };
143
168
  /**
144
169
  * #298: a foe's stack arrived on `x` since `previousBoard`: it took `x` from me, or its armies there
145
170
  * grew, both read only where that board showed `x` (owner and armies). No previous board: none.
@@ -325,9 +350,18 @@ export function deployBook(ctx, ps, previousBoard) {
325
350
  continue;
326
351
  }
327
352
  // An incomplete bonus I am working on (T is in it): lost access if T is my only way in.
353
+ // #425: the only way in carries the share #122 gives a member of a bonus being built (value ×
354
+ // members held ÷ size: T alone here), and nothing when an enemy holds or roams a member
355
+ // (`footholdBuilding`; a fogged member keeps the share, owner decision of 2026-11-22). It used to
356
+ // carry the whole bonus whatever stood on the rest, so a lone foothold in a bonus an enemy holds
357
+ // part of drew a full bonus's hold (on the finished games' truth boards 276 of 285 such borders
358
+ // were in a bonus an enemy held part of; 7 of the 285 bonuses were ever completed).
328
359
  const access = (has) => ts.some((x) => has(x) || neighborsOf(g, x).some(has));
329
360
  if (!access(mineWithout)) {
330
- v += b.value;
361
+ if (footholdBuilding(ts, b.value)) {
362
+ const held = ts.filter((x) => ps.holdings.has(x) || x === t).length;
363
+ v += Math.round(((b.value * held) / ts.length) * 10) / 10;
364
+ }
331
365
  continue;
332
366
  }
333
367
  // #122: a member of a bonus I am building carries its share of the bonus — value × the
@@ -39,7 +39,8 @@
39
39
  import { bonusTerritories } from '../bonuses.js';
40
40
  import { bfsDistances, neighborsOf } from '../graph.js';
41
41
  import { simTerritories, simulateTurn } from '../turn-sim.js';
42
- import { CONCEDE_FACTOR, } from './shared.js';
42
+ import { armiesToTake, DEFAULT_DEFENSIVE_KILL_RATE, straightKills } from '../combat.js';
43
+ import { captureCost, CONCEDE_FACTOR, } from './shared.js';
43
44
  import { byNum } from './util.js';
44
45
  /** T3: a covered border protecting more than this share of my income keeps its full hold. */
45
46
  export const TRUCE_RELAX_VALUE = 0.25;
@@ -75,6 +76,75 @@ export function avoidedBy(input) {
75
76
  owner.set(t.territoryId, t.owner.playerId);
76
77
  return (t) => territories.has(t) || players.has(owner.get(t) ?? Number.NaN);
77
78
  }
79
+ /**
80
+ * #441: the neutrals an avoided player is visibly collecting — its only enemy neighbour is that player, or it
81
+ * sits in a bonus whose members that player visibly holds more than half of — which the plan skips like the
82
+ * player's own territories: taking one beside its stack reads as a provocation and is conceded next turn.
83
+ * Not skipped: a neutral whose capture completes a bonus of mine on its own (every other member mine at the
84
+ * start), or one the capture would hold next turn with what it leaves there alone (the fewest attackers that
85
+ * take it, less the defenders' kills) against every enemy stack beside it plus its owner's deploy.
86
+ * #457: a truce partner's (`truce`, `Truce.keptWith`) the same way — its enemy neighbours counting the partner
87
+ * even when a card makes it no foe — except that holding is no reason to take one: to the partner it reads as a
88
+ * breach either way; only completing a bonus of mine is (`truce: true` on the skirt). Empty with no avoided
89
+ * player and no truce partner, so every other plan is unchanged.
90
+ */
91
+ export function skirtedNeutrals(input, o) {
92
+ const out = new Map();
93
+ const avoid = new Set(input.options?.avoid?.players ?? []);
94
+ const partners = o.truce ?? new Set();
95
+ if (!avoid.size && !partners.size)
96
+ return out;
97
+ const watched = [...new Set([...avoid, ...partners])].sort(byNum);
98
+ const { graph: g, board, me } = input;
99
+ const state = new Map(board.territories.map((t) => [t.territoryId, t]));
100
+ const ownerOf = (t) => {
101
+ const st = state.get(t);
102
+ return st?.owner.kind === 'player' ? st.owner.playerId : undefined;
103
+ };
104
+ const rates = o.settings;
105
+ for (const st of [...board.territories].sort((a, b) => a.territoryId - b.territoryId)) {
106
+ const n = st.territoryId;
107
+ if (st.owner.kind !== 'neutral' || !g.territoryById.has(n))
108
+ continue;
109
+ const bonuses = g.map.bonuses.filter((b) => bonusTerritories(g, b.id).includes(n));
110
+ // It completes a bonus of mine: always worth taking.
111
+ if (bonuses.some((b) => b.value > 0 && bonusTerritories(g, b.id).every((x) => x === n || ownerOf(x) === me)))
112
+ continue;
113
+ const foes = [...new Set(neighborsOf(g, n).flatMap((x) => {
114
+ const p = ownerOf(x);
115
+ return p !== undefined && (o.foe(p) || partners.has(p)) ? [p] : [];
116
+ }))];
117
+ const of = (player, why) => ({ player, why, ...(partners.has(player) ? { truce: true } : {}) });
118
+ let skirt;
119
+ if (foes.length === 1 && (avoid.has(foes[0]) || partners.has(foes[0])))
120
+ skirt = of(foes[0], 'stack');
121
+ else
122
+ for (const b of [...bonuses].sort((x, y) => x.id - y.id)) {
123
+ const ts = bonusTerritories(g, b.id);
124
+ const p = watched.find((a) => ts.filter((x) => ownerOf(x) === a).length * 2 > ts.length);
125
+ if (p !== undefined) {
126
+ skirt = of(p, 'bonus');
127
+ break;
128
+ }
129
+ }
130
+ if (!skirt)
131
+ continue;
132
+ // #457: a truce partner's is skipped whether or not the capture would hold.
133
+ if (skirt.truce) {
134
+ out.set(n, skirt);
135
+ continue;
136
+ }
137
+ // It holds next turn with its survivors alone: no provocation that costs it.
138
+ const defenders = st.armies ?? 0;
139
+ const sent = captureCost(defenders, o.settings);
140
+ const survivors = sent === null ? 0 : sent - straightKills(defenders, rates.defensiveKillRate ?? DEFAULT_DEFENSIVE_KILL_RATE);
141
+ const threat = Math.max(0, ...foes.map((p) => neighborsOf(g, n).reduce((sum, x) => sum + (ownerOf(x) === p ? Math.max(0, (state.get(x).armies ?? 0) - 1) : 0), 0) + o.deployOf(p)));
142
+ if (survivors > 0 && (armiesToTake(survivors, rates) ?? Number.POSITIVE_INFINITY) > threat)
143
+ continue;
144
+ out.set(n, skirt);
145
+ }
146
+ return out;
147
+ }
78
148
  function withAvoid(truce, input) {
79
149
  const avoided = avoidedBy(input);
80
150
  return { ...truce, avoided, noTarget: (t) => avoided(t) || truce.noTarget(t) };
@@ -116,11 +186,15 @@ function truceFrom(input, o) {
116
186
  const partners = new Set();
117
187
  const enforced = new Set();
118
188
  const lookAheadFoes = new Set();
189
+ /** #457: the players an agreement (not only a card) binds this turn, in any format. */
190
+ const keptWith = new Set();
119
191
  /** Per partner whose agreement binds (in any format), the territories of theirs covered. */
120
192
  const theirs = new Map();
121
193
  given.forEach((r, i) => {
122
194
  if (!kept[i])
123
195
  return;
196
+ if (!r.card)
197
+ keptWith.add(r.player);
124
198
  // T2–T5 and T9 only in a free-for-all; T1 (never a surprise break, D3) wherever the agreement binds.
125
199
  if (binds[i]) {
126
200
  partners.add(r.player);
@@ -153,7 +227,19 @@ function truceFrom(input, o) {
153
227
  if (binds[i] && enforcedNow[i] && (r.enforcedUntil === undefined || (o.turnNow !== null && r.enforcedUntil > o.turnNow + 1)))
154
228
  lookAheadFoes.delete(r.player);
155
229
  });
156
- return { given, status, binds, partners, enforced, lookAheadFoes, noTarget, avoided: () => false, noFront, format: o.format };
230
+ return {
231
+ given,
232
+ status,
233
+ binds,
234
+ partners,
235
+ ...(keptWith.size ? { keptWith } : {}),
236
+ enforced,
237
+ lookAheadFoes,
238
+ noTarget,
239
+ avoided: () => false,
240
+ noFront,
241
+ format: o.format,
242
+ };
157
243
  }
158
244
  /**
159
245
  * T4 for rule 0p.2: the binding partners the game profile counts among my opponents — on the
@@ -698,6 +784,33 @@ export function truceBreakLosses(pc, plan) {
698
784
  return best;
699
785
  });
700
786
  }
787
+ /**
788
+ * #457: a neutral the plan's final orders attack beside a territory (at the start) of a player an agreement binds
789
+ * (`Truce.keptWith`): a warning per neutral that it may read as a breach to that player, so the owner can tell it
790
+ * first. Ascending territory id; nothing with no such agreement.
791
+ */
792
+ export function warnTruceNeutrals(pc, plan) {
793
+ const kept = pc.truce.keptWith;
794
+ if (!kept?.size)
795
+ return;
796
+ const ownerOf = (t) => {
797
+ const o = pc.territories.get(t)?.owner;
798
+ return o?.kind === 'player' ? o.playerId : undefined;
799
+ };
800
+ const taken = [...new Set(plan.moves.filter((m) => m.kind === 'attack').map((m) => m.to))].sort(byNum);
801
+ for (const t of taken) {
802
+ if (pc.territories.get(t)?.owner.kind !== 'neutral')
803
+ continue;
804
+ const beside = [...new Set(neighborsOf(pc.g, t).flatMap((x) => {
805
+ const p = ownerOf(x);
806
+ return p !== undefined && kept.has(p) ? [p] : [];
807
+ }))].sort(byNum);
808
+ if (!beside.length)
809
+ continue;
810
+ const who = beside.map((p) => `player ${p}`).join(' and ');
811
+ plan.warnings.push(`Taking ${pc.label(t)}, a neutral beside ${beside.map((p) => `player ${p}'s`).join(' and ')} land, may read as a breach to ${who} (a truce binds you): tell ${who} first (#457).`);
812
+ }
813
+ }
701
814
  /**
702
815
  * T6's report: each binding truce's {@link truceBreakLosses} on its view, and a rationale line that
703
816
  * says what a break would take. Nothing with no relations.
@@ -12,6 +12,7 @@ import { bonusTerritories } from '../bonuses.js';
12
12
  import { DEFAULT_DEFENSIVE_KILL_RATE, DEFAULT_OFFENSIVE_KILL_RATE, straightKills } from '../combat.js';
13
13
  import { classifyExchange } from '../exchange.js';
14
14
  import { neighborsOf } from '../graph.js';
15
+ import { poolShortfall } from '../local-deploy.js';
15
16
  import { bonusesAtRisk, captureCost, CITE_OPEN, CITE_RE, ETA_HORIZON, NOT_ATTACKING_REASONS, SECOND_FRONT_LEAD, SLOT_NAMES, } from './shared.js';
16
17
  import { knownFirst, lateArrivals, lateNet, withdrawnInto } from './holds.js';
17
18
  import { relaxedFor } from './relations.js';
@@ -28,7 +29,7 @@ export function reportExpected(pc, ps, book, threats, hd, tgt, caps) {
28
29
  const { warnings, rationale, absorbLines, captured, moves, survivorsAt } = ps;
29
30
  const { heldNow } = book;
30
31
  const { borders } = threats;
31
- const { conceded, heldAgainst, keptIncome, stayAt, twoStepBound, twoStepCited, twoStepHold, twoStepNote } = hd;
32
+ const { conceded, heldAgainst, keptIncome, keptHeld, stayAt, twoStepBound, twoStepCited, twoStepHold, twoStepNote } = hd;
32
33
  const { frontierOf, startHold } = tgt;
33
34
  const { notCompleted, stopped, stoppedLine, denied } = caps;
34
35
  // ---- expected ----
@@ -88,12 +89,17 @@ export function reportExpected(pc, ps, book, threats, hd, tgt, caps) {
88
89
  const need = list.reduce((n, g) => n + g.needs, 0);
89
90
  const onGates = list.reduce((n, g) => n + g.armies, 0);
90
91
  const deficit = list.reduce((n, g) => n + Math.max(0, g.needs - g.armies), 0);
91
- return { player, gates: list, need, onGates, deficit, income: frontier.income, short: Math.max(0, deficit - frontier.income) };
92
+ if (!pc.s.localDeployments)
93
+ return { player, gates: list, need, onGates, deficit, income: frontier.income, short: Math.max(0, deficit - frontier.income) };
94
+ // #433: under Local Deployment a bonus's pool pays only for the gates in it; the rest falls on the free income.
95
+ const lacks = new Map(list.map((x) => [x.id, Math.max(0, x.needs - x.armies)]));
96
+ const { short, deployable } = poolShortfall(g, keptHeld(after), frontier.income, lacks);
97
+ return { player, gates: list, need, onGates, deficit, income: frontier.income, short, deployable };
92
98
  })();
93
99
  // Warned only when this plan's own captures open a gate the budget cannot pay for (the shortfall alone is in the report).
94
100
  const opened = gates ? gates.gates.filter((x) => captured.has(x.id)).map((x) => x.id) : [];
95
101
  if (gates && gates.short > 0 && opened.length)
96
- warnings.push(`Gate budget (#297): this plan's capture of ${opened.map(label).join(', ')} opens ${opened.length === 1 ? 'a gate' : 'gates'} the income cannot hold — ${gates.gates.length} gates facing player ${gates.player}${gates.gates.some((x) => x.conceded) ? ` (${gates.gates.filter((x) => x.conceded).length} conceded)` : ''} need ${gates.need} against its one floating deploy; ${gates.onGates} stand on them, ${gates.deficit} short across them, and the next income is ${gates.income}: ${gates.short} short.`);
102
+ warnings.push(`Gate budget (#297): this plan's capture of ${opened.map(label).join(', ')} opens ${opened.length === 1 ? 'a gate' : 'gates'} the income cannot hold — ${gates.gates.length} gates facing player ${gates.player}${gates.gates.some((x) => x.conceded) ? ` (${gates.gates.filter((x) => x.conceded).length} conceded)` : ''} need ${gates.need} against its one floating deploy; ${gates.onGates} stand on them, ${gates.deficit} short across them, and the next income is ${gates.income}${gates.deployable !== undefined ? ` (${gates.deployable} of it deployable on them under Local Deployment)` : ''}: ${gates.short} short.`);
97
103
  const startCost = startHold();
98
104
  const outgrown = frontier.holdCost > frontier.income && frontier.holdCost > startCost;
99
105
  // A capture stopped by one pass but taken by a later one (the next income grew in between) is
@@ -110,7 +116,7 @@ export function reportExpected(pc, ps, book, threats, hd, tgt, caps) {
110
116
  rationale.push(denied.get(t));
111
117
  if (outgrown || notTaken.length) {
112
118
  const stop = notTaken.length
113
- ? ` Expansion that adds enemy borders without completing a bonus is stopped: ${notTaken.map((x) => `${label(x.t)} (the frontier would need ${x.holdCost}, next income ${x.income})`).join(', ')} not taken.`
119
+ ? ` Expansion that adds enemy borders without completing a bonus is stopped: ${notTaken.map((x) => `${label(x.t)} (the frontier would need ${x.holdCost}, next income ${x.income}${x.deployable !== undefined ? `, ${x.deployable} of it deployable on the gates under Local Deployment` : ''})`).join(', ')} not taken.`
114
120
  : '';
115
121
  warnings.push(outgrown
116
122
  ? `Frontier grows faster than income: holding its ${frontier.enemyBorders} enemy-facing borders next turn needs ${frontier.holdCost} at the expected deploy, more than ${frontier.income < nextIncome