@chrischall/warapp-mcp 0.0.0 → 0.1.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 (177) hide show
  1. package/.claude-plugin/marketplace.json +4 -4
  2. package/.claude-plugin/plugin.json +2 -2
  3. package/README.md +199 -8
  4. package/dist/analysis/award.js +159 -0
  5. package/dist/analysis/bonuses.js +98 -0
  6. package/dist/analysis/breach.js +62 -0
  7. package/dist/analysis/card-support.js +329 -0
  8. package/dist/analysis/card-threats.js +234 -0
  9. package/dist/analysis/cards-in-effect.js +130 -0
  10. package/dist/analysis/chains.js +59 -0
  11. package/dist/analysis/chokepoints.js +140 -0
  12. package/dist/analysis/combat.js +231 -0
  13. package/dist/analysis/commander-safety.js +149 -0
  14. package/dist/analysis/commitments.js +338 -0
  15. package/dist/analysis/exchange.js +155 -0
  16. package/dist/analysis/graph.js +82 -0
  17. package/dist/analysis/guard-off.js +54 -0
  18. package/dist/analysis/guess.js +351 -0
  19. package/dist/analysis/headroom.js +241 -0
  20. package/dist/analysis/hold-diff.js +64 -0
  21. package/dist/analysis/how-lost.js +130 -0
  22. package/dist/analysis/index.js +14 -0
  23. package/dist/analysis/local-deploy.js +159 -0
  24. package/dist/analysis/lookahead.js +108 -0
  25. package/dist/analysis/opponent-profile.js +551 -0
  26. package/dist/analysis/opponents.js +1245 -0
  27. package/dist/analysis/outlook.js +633 -0
  28. package/dist/analysis/overrides.js +60 -0
  29. package/dist/analysis/picks.js +1879 -0
  30. package/dist/analysis/plan/after-leftover.js +140 -0
  31. package/dist/analysis/plan/cap-spend.js +242 -0
  32. package/dist/analysis/plan/captures.js +1195 -0
  33. package/dist/analysis/plan/commander.js +236 -0
  34. package/dist/analysis/plan/completed.js +29 -0
  35. package/dist/analysis/plan/conceded-out.js +131 -0
  36. package/dist/analysis/plan/estimates.js +715 -0
  37. package/dist/analysis/plan/guard-off.js +232 -0
  38. package/dist/analysis/plan/holds.js +1631 -0
  39. package/dist/analysis/plan/leftover.js +760 -0
  40. package/dist/analysis/plan/move-order.js +319 -0
  41. package/dist/analysis/plan/orders.js +317 -0
  42. package/dist/analysis/plan/relations.js +702 -0
  43. package/dist/analysis/plan/report.js +672 -0
  44. package/dist/analysis/plan/shared.js +1218 -0
  45. package/dist/analysis/plan/stand-still.js +823 -0
  46. package/dist/analysis/plan/state.js +44 -0
  47. package/dist/analysis/plan/strike.js +1416 -0
  48. package/dist/analysis/plan/targets.js +651 -0
  49. package/dist/analysis/plan/team.js +299 -0
  50. package/dist/analysis/plan/threats.js +927 -0
  51. package/dist/analysis/plan/transfers.js +328 -0
  52. package/dist/analysis/plan/util.js +5 -0
  53. package/dist/analysis/plan/vacated.js +285 -0
  54. package/dist/analysis/planner.js +2922 -0
  55. package/dist/analysis/player-record.js +144 -0
  56. package/dist/analysis/player.js +268 -0
  57. package/dist/analysis/profile.js +347 -0
  58. package/dist/analysis/relations.js +1030 -0
  59. package/dist/analysis/schedule.js +88 -0
  60. package/dist/analysis/since-last.js +50 -0
  61. package/dist/analysis/static-seats.js +71 -0
  62. package/dist/analysis/stress.js +577 -0
  63. package/dist/analysis/team-brief.js +151 -0
  64. package/dist/analysis/tripwire.js +644 -0
  65. package/dist/analysis/turn-sim.js +259 -0
  66. package/dist/analysis/whereabouts.js +1109 -0
  67. package/dist/board.js +105 -0
  68. package/dist/bundle.js +117959 -36172
  69. package/dist/cards.js +435 -0
  70. package/dist/chat-cursor.js +135 -0
  71. package/dist/chat.js +192 -0
  72. package/dist/client.js +361 -0
  73. package/dist/config.js +62 -0
  74. package/dist/direct/link.js +102 -0
  75. package/dist/direct/session.js +267 -0
  76. package/dist/direct/transport.js +424 -0
  77. package/dist/guess-salt.js +65 -0
  78. package/dist/hosted.js +24 -0
  79. package/dist/index.js +33 -0
  80. package/dist/join-color.js +140 -0
  81. package/dist/live.js +278 -0
  82. package/dist/map-stats.js +152 -0
  83. package/dist/map-store.js +204 -0
  84. package/dist/move-order.js +141 -0
  85. package/dist/my-games.js +180 -0
  86. package/dist/normalize.js +411 -0
  87. package/dist/open-games.js +537 -0
  88. package/dist/outlook-log.js +138 -0
  89. package/dist/path-lock.js +22 -0
  90. package/dist/pick-list.js +193 -0
  91. package/dist/player-record-store.js +229 -0
  92. package/dist/player-states.js +31 -0
  93. package/dist/profile-store.js +677 -0
  94. package/dist/protocol/bundle.js +375 -0
  95. package/dist/protocol/codec.js +556 -0
  96. package/dist/protocol/decoded.js +12 -0
  97. package/dist/protocol/interp.js +1904 -0
  98. package/dist/protocol/methods.js +531 -0
  99. package/dist/protocol/rpc.js +202 -0
  100. package/dist/push/listener.js +393 -0
  101. package/dist/push/packets.js +66 -0
  102. package/dist/push/socketio.js +333 -0
  103. package/dist/push/websocket.js +179 -0
  104. package/dist/redact.js +62 -0
  105. package/dist/relations-store.js +242 -0
  106. package/dist/replay.js +215 -0
  107. package/dist/scalars.js +28 -0
  108. package/dist/scout.js +346 -0
  109. package/dist/stats.js +269 -0
  110. package/dist/strategy/card-clock.js +185 -0
  111. package/dist/strategy/map-notes.js +128 -0
  112. package/dist/strategy/notes.js +2168 -0
  113. package/dist/team-cards.js +84 -0
  114. package/dist/team-orders.js +150 -0
  115. package/dist/teams.js +19 -0
  116. package/dist/tools/award.js +206 -0
  117. package/dist/tools/begin-turn.js +162 -0
  118. package/dist/tools/board.js +77 -0
  119. package/dist/tools/card-advice.js +256 -0
  120. package/dist/tools/card-effects.js +49 -0
  121. package/dist/tools/card-plays.js +434 -0
  122. package/dist/tools/card-support-advice.js +140 -0
  123. package/dist/tools/chat-inbox.js +146 -0
  124. package/dist/tools/chat.js +483 -0
  125. package/dist/tools/check-plan.js +688 -0
  126. package/dist/tools/commander-check.js +102 -0
  127. package/dist/tools/commitments.js +216 -0
  128. package/dist/tools/common.js +143 -0
  129. package/dist/tools/diplomacy.js +342 -0
  130. package/dist/tools/game.js +126 -0
  131. package/dist/tools/guess-view.js +56 -0
  132. package/dist/tools/healthcheck.js +90 -0
  133. package/dist/tools/hints.js +34 -0
  134. package/dist/tools/how-lost.js +154 -0
  135. package/dist/tools/index.js +142 -0
  136. package/dist/tools/join-game.js +327 -0
  137. package/dist/tools/leave-game.js +181 -0
  138. package/dist/tools/live-context.js +339 -0
  139. package/dist/tools/live.js +404 -0
  140. package/dist/tools/map-stats.js +117 -0
  141. package/dist/tools/map.js +133 -0
  142. package/dist/tools/my-games.js +123 -0
  143. package/dist/tools/open-games.js +104 -0
  144. package/dist/tools/opponents.js +151 -0
  145. package/dist/tools/order-options.js +135 -0
  146. package/dist/tools/picks.js +292 -0
  147. package/dist/tools/profile-hook.js +156 -0
  148. package/dist/tools/profile-opponents.js +121 -0
  149. package/dist/tools/profile-reads.js +99 -0
  150. package/dist/tools/push.js +385 -0
  151. package/dist/tools/relations.js +611 -0
  152. package/dist/tools/resolve.js +45 -0
  153. package/dist/tools/route.js +36 -0
  154. package/dist/tools/scout.js +87 -0
  155. package/dist/tools/session.js +163 -0
  156. package/dist/tools/strategy.js +200 -0
  157. package/dist/tools/stress-opponents.js +83 -0
  158. package/dist/tools/surrender.js +240 -0
  159. package/dist/tools/survival.js +189 -0
  160. package/dist/tools/team-brief.js +266 -0
  161. package/dist/tools/team-source.js +222 -0
  162. package/dist/tools/team.js +182 -0
  163. package/dist/tools/turn.js +2761 -0
  164. package/dist/tools/uncommit.js +160 -0
  165. package/dist/tools/where.js +275 -0
  166. package/dist/tools/write-kit.js +158 -0
  167. package/dist/transport-bridge.js +33 -0
  168. package/dist/trend.js +452 -0
  169. package/dist/version.js +4 -0
  170. package/manifest.json +174 -4
  171. package/mint.yaml +101 -14
  172. package/package.json +11 -6
  173. package/server.json +40 -3
  174. package/skills/warapp-api/SKILL.md +95 -4
  175. package/skills/warapp-api/references/scout.mjs +348 -0
  176. package/skills/warapp-api/scripts/warapp.sh +69 -8
  177. package/skills/warapp-mcp/SKILL.md +969 -21
@@ -0,0 +1,232 @@
1
+ import { armiesToTake } from '../combat.js';
2
+ import { neighborsOf } from '../graph.js';
3
+ import { byNum } from './util.js';
4
+ /** #276: a stack of at least this many times my income within two moves calls for a second line. */
5
+ export const SECOND_LINE_STACK_INCOMES = 1;
6
+ /** #276: the armies a raid one step deeper sends: one stays on the near territory, one goes on next turn. */
7
+ export const RAID_ARMIES = 2;
8
+ /** The most a second-line garrison is ever sized at (a kill rate letting one army take more is not a game). */
9
+ const MAX_GARRISON = 3;
10
+ /** #276: the fewest defenders one attacking army cannot take, luck-free (1 at 60/70). */
11
+ export function garrisonSize(rates) {
12
+ for (let d = 1; d <= MAX_GARRISON; d++) {
13
+ const take = armiesToTake(d, rates);
14
+ if (take === null || take > 1)
15
+ return d;
16
+ }
17
+ return MAX_GARRISON;
18
+ }
19
+ /**
20
+ * #276 (1): the interior members of my held bonuses within two moves of an enemy stack of at least
21
+ * {@link SECOND_LINE_STACK_INCOMES} × my income, with the garrison each keeps. Empty with the guard
22
+ * on, under No-Split, or with no such stack. Pure.
23
+ */
24
+ export function secondLineOf(pc) {
25
+ const { g, territories: state, mine, mineSet, myCommanders, foe, allies, guard, noSplit, armiesOf, unitsAt, income, toTake } = pc;
26
+ const out = new Map();
27
+ if (guard || noSplit)
28
+ return out;
29
+ const bar = Math.max(1, SECOND_LINE_STACK_INCOMES * income);
30
+ const stacks = [...state.values()]
31
+ .filter((t) => t.owner.kind === 'player' && foe(t.owner.playerId) && t.armies !== null)
32
+ .map((t) => ({ id: t.territoryId, armies: armiesOf(t.territoryId) + unitsAt(t.territoryId), player: t.owner.playerId }))
33
+ .filter((x) => x.armies >= bar);
34
+ if (!stacks.length)
35
+ return out;
36
+ const friendly = (id) => {
37
+ const o = state.get(id)?.owner;
38
+ return mineSet.has(id) || (o?.kind === 'player' && allies.has(o.playerId));
39
+ };
40
+ const held = [...g.bonusById.values()]
41
+ .filter((b) => b.value > 0 && b.territoryIds.length > 0 && b.territoryIds.every((x) => mineSet.has(x)))
42
+ .sort((a, b) => b.value - a.value || a.id - b.id);
43
+ let size = null;
44
+ for (let d = 1; d <= MAX_GARRISON && size === null; d++) {
45
+ const take = toTake(d);
46
+ if (take === null || take > 1)
47
+ size = d;
48
+ }
49
+ const garrison = size ?? MAX_GARRISON;
50
+ for (const id of [...mine].sort(byNum)) {
51
+ if (myCommanders.has(id))
52
+ continue;
53
+ const bonus = held.find((b) => b.territoryIds.includes(id));
54
+ if (!bonus)
55
+ continue;
56
+ const near = neighborsOf(g, id);
57
+ if (!near.every(friendly))
58
+ continue;
59
+ const within = new Set([...near, ...near.flatMap((n) => neighborsOf(g, n))]);
60
+ const stack = stacks
61
+ .filter((s) => within.has(s.id))
62
+ .sort((a, b) => b.armies - a.armies || a.id - b.id)[0];
63
+ if (stack)
64
+ out.set(id, { size: garrison, stack, bonusId: bonus.id });
65
+ }
66
+ return out;
67
+ }
68
+ /**
69
+ * #276 (1): pay the second line's shortfall (the garrison less what stands there) from what the
70
+ * holds and captures left, before the leftover deploy; say what it keeps, and warn on what the
71
+ * income cannot reach.
72
+ */
73
+ export function fillSecondLine(pc, ps, book) {
74
+ const { label, bonusName, reserve } = pc;
75
+ const { rationale, warnings, avail } = ps;
76
+ const { secondLine, secondLineKept, deploy, roomAt } = book;
77
+ if (!secondLine.size)
78
+ return;
79
+ const paid = [];
80
+ const short = [];
81
+ for (const [id, e] of [...secondLine].sort((a, b) => a[0] - b[0])) {
82
+ const owed = e.size - secondLineKept.get(id);
83
+ if (owed <= 0)
84
+ continue;
85
+ const k = Math.min(owed, Math.max(0, ps.budget - reserve), roomAt(id));
86
+ if (k > 0) {
87
+ deploy(id, k);
88
+ // The deployed armies join the garrison: they stay, as the guard would.
89
+ avail.set(id, avail.get(id) - k);
90
+ secondLineKept.set(id, secondLineKept.get(id) + k);
91
+ paid.push(id);
92
+ }
93
+ if (k < owed)
94
+ short.push(id);
95
+ }
96
+ const kept = [...secondLine.keys()].filter((id) => secondLineKept.get(id) > 0).sort(byNum);
97
+ const bonuses = [...new Set([...secondLine.values()].map((e) => e.bonusId))].sort(byNum);
98
+ const big = [...secondLine.values()].sort((a, b) => b.stack.armies - a.stack.armies || a.stack.id - b.stack.id)[0].stack;
99
+ if (kept.length)
100
+ rationale.push(`Second line (#276): One Army Must Stand Guard is off, and player ${big.player}'s ${big.armies} on ${label(big.id)} can reach the interior of ${bonuses.map(bonusName).join(', ')} within two moves and split into single armies there, so ${kept
101
+ .map((id) => `${label(id)} keeps ${secondLineKept.get(id)}`)
102
+ .join(', ')} (one army cannot take ${kept.length === 1 ? 'it' : 'them'})${paid.length ? `; deployed on ${paid.map(label).join(', ')}, which stood short` : ''}.`);
103
+ if (short.length)
104
+ warnings.push(`Second line (#276): ${short.map(label).join(', ')} ${short.length === 1 ? 'stands' : 'stand'} below the garrison one army cannot take, inside a held bonus within two moves of player ${big.player}'s ${big.armies}, and this turn's deploy cannot reach ${short.length === 1 ? 'it' : 'them'}: a single raider past the border takes ${short.length === 1 ? 'it' : 'them'}.`);
105
+ }
106
+ /** #276 (2), (3): raids one step deeper and free retakes, after #165's breaks. */
107
+ export function guardOffRaids(pc, ps, book, hd, tgt, threats, worstCase, previousBoard) {
108
+ const { g, me, territories: state, reserve, label, bonusName, mineSet, unitsAt, uncounted, guard, chanceOf, costAt, noSplit, foe } = pc;
109
+ const { rationale, warnings, avail, spared, captured, moves, survivorsAt, captureOrder, captureUndo } = ps;
110
+ const { reinforcementAt } = threats;
111
+ const { coverOf, gainWith, deploy, roomAt } = book;
112
+ const { conceded, keepFor, twoStepKeep } = hd;
113
+ const { targets, repulsed } = tgt;
114
+ if (guard || noSplit)
115
+ return;
116
+ const enemyOf = (id) => {
117
+ const o = state.get(id)?.owner;
118
+ return o?.kind === 'player' && foe(o.playerId) ? o.playerId : undefined;
119
+ };
120
+ /** In view at 0 with no special unit: one army takes it, losing none. */
121
+ const empty = (id) => {
122
+ const t = state.get(id);
123
+ return !!t && t.armies === 0 && !t.specialUnits?.length && (t.owner.kind === 'neutral' || enemyOf(id) !== undefined);
124
+ };
125
+ /** Free to take now: not taken this turn, nothing the plan keeps off, never one lowering income. */
126
+ const takeable = (n) => !captured.has(n) && !spared.has(n) && !uncounted(n) && unitsAt(n) === 0 && gainWith([n]) >= 0 && !pc.truce.noTarget(n) && !repulsed.has(n);
127
+ /**
128
+ * One attack on `n` of `armies` (its bare size: what takes it at 0, plus what goes on next turn),
129
+ * from the neighbour with the most to spare, else deployed. On a player's territory it is sized
130
+ * first for what its owner may deploy there before it lands (#120: the sure size, the extra armies
131
+ * kept on top), from spare armies, else topped up with a deploy; only when neither covers it does
132
+ * it go at its bare size, with #120's "assumes its owner does not reinforce" warning.
133
+ */
134
+ const attack = (n, armies, reason, head) => {
135
+ const near = neighborsOf(g, n).filter((x) => mineSet.has(x));
136
+ const spareOf = (x) => Math.max(0, avail.get(x) - Math.max(keepFor(x, (y) => y === n), twoStepKeep(x, (y) => y === n), coverOf(x)));
137
+ const extra = enemyOf(n) !== undefined ? reinforcementAt(n) : 0;
138
+ const sureCost = extra > 0 ? costAt(n, extra) : null;
139
+ const sure = sureCost === null ? null : Math.max(armies, sureCost + armies - 1);
140
+ const free = Math.max(0, ps.budget - reserve);
141
+ const bySpare = near.map((x) => ({ x, spare: spareOf(x) })).sort((a, b) => b.spare - a.spare || a.x - b.x);
142
+ const deployable = (x) => !conceded.has(x) && avail.get(x) >= 0;
143
+ /** The source, the armies sent and the deploy bought there, for an attack of `size`. */
144
+ const fund = (size) => {
145
+ const spared = bySpare.find((o) => o.spare >= size);
146
+ if (spared)
147
+ return { src: spared.x, bought: 0 };
148
+ // Top up the source with the most to spare (the most standing there on a tie) with a deploy.
149
+ const top = bySpare
150
+ .filter((o) => deployable(o.x))
151
+ .map((o) => ({ ...o, need: size - o.spare }))
152
+ .filter((o) => o.need <= free && roomAt(o.x) >= o.need)
153
+ .sort((a, b) => a.need - b.need || avail.get(b.x) - avail.get(a.x) || a.x - b.x)[0];
154
+ return top ? { src: top.x, bought: top.need } : undefined;
155
+ };
156
+ const sized = sure !== null ? fund(sure) : undefined;
157
+ const funded = sized ?? fund(armies);
158
+ if (!funded)
159
+ return false;
160
+ const size = sized ? sure : armies;
161
+ const { src: from, bought } = funded;
162
+ if (bought)
163
+ deploy(from, bought);
164
+ avail.set(from, avail.get(from) - size);
165
+ captured.add(n);
166
+ survivorsAt.set(n, size);
167
+ captureOrder.push(n);
168
+ captureUndo.set(n, () => avail.set(from, avail.get(from) + size));
169
+ if (!targets.has(n))
170
+ targets.set(n, { id: n, cost: size, enemy: enemyOf(n) !== undefined, sources: near });
171
+ moves.push({ from, to: n, armies: size, kind: 'attack', reason, winChance: chanceOf(size, 0) });
172
+ if (sized)
173
+ worstCase.set(n, extra);
174
+ else if (extra > 0)
175
+ warnings.push(`Attack on enemy ${label(n)} assumes its owner does not reinforce it first.`);
176
+ rationale.push(`${head} from ${label(from)} with ${size}${bought ? ` (deploy ${bought} there)` : ''}${sized ? `, which take it even if player ${enemyOf(n)} deploys its ~${extra} there first` : ''}: ${reason}.`);
177
+ return true;
178
+ };
179
+ // (3) Free retakes: an enemy territory beside me at 0 that was mine on the previous board.
180
+ if (previousBoard) {
181
+ const before = new Map(previousBoard.territories.map((t) => [t.territoryId, t]));
182
+ const retakes = [...state.values()]
183
+ .map((t) => t.territoryId)
184
+ .filter((id) => {
185
+ const was = before.get(id)?.owner;
186
+ return (was?.kind === 'player' &&
187
+ was.playerId === me &&
188
+ enemyOf(id) !== undefined &&
189
+ empty(id) &&
190
+ neighborsOf(g, id).some((x) => mineSet.has(x)));
191
+ })
192
+ .sort(byNum);
193
+ for (const n of retakes) {
194
+ if (!takeable(n))
195
+ continue;
196
+ const reason = `One Army Must Stand Guard is off and player ${enemyOf(n)}'s stack left ${label(n)}, taken from me, at 0: a retake, one army if it stays empty (#276)`;
197
+ attack(n, 1, reason, `Retake ${label(n)}`);
198
+ }
199
+ }
200
+ // (2) Raids one step deeper: an empty enemy territory not beside me whose loss breaks its owner's
201
+ // bonus, behind an empty territory beside me.
202
+ const breaksOf = (id) => {
203
+ const owner = enemyOf(id);
204
+ if (owner === undefined)
205
+ return undefined;
206
+ return [...g.bonusById.values()]
207
+ .filter((b) => b.value > 0 &&
208
+ b.territoryIds.includes(id) &&
209
+ b.territoryIds.every((x) => {
210
+ const o = state.get(x)?.owner;
211
+ return o?.kind === 'player' && o.playerId === owner;
212
+ }))
213
+ .sort((a, b) => b.value - a.value || a.id - b.id)[0];
214
+ };
215
+ const deep = [...state.values()]
216
+ .map((t) => t.territoryId)
217
+ .filter((id) => empty(id) && enemyOf(id) !== undefined && !captured.has(id) && !neighborsOf(g, id).some((x) => mineSet.has(x)))
218
+ .map((id) => ({ id, bonus: breaksOf(id) }))
219
+ .filter((x) => x.bonus !== undefined)
220
+ .sort((a, b) => b.bonus.value - a.bonus.value || a.id - b.id);
221
+ for (const far of deep) {
222
+ if (pc.truce.noTarget(far.id))
223
+ continue;
224
+ const step = neighborsOf(g, far.id)
225
+ .filter((n) => empty(n) && neighborsOf(g, n).some((x) => mineSet.has(x)) && takeable(n))
226
+ .sort(byNum)[0];
227
+ if (step === undefined)
228
+ continue;
229
+ const reason = `a raid: One Army Must Stand Guard is off and ${label(step)} stands at 0, behind it ${label(far.id)} too, and taking ${label(far.id)} breaks player ${enemyOf(far.id)}'s bonus ${bonusName(far.bonus.id)} (+${far.bonus.value}); the survivors hold ${label(step)} and one takes ${label(far.id)} next turn if it still stands at 0 (#276)`;
230
+ attack(step, RAID_ARMIES, reason, `Raid ${label(step)}`);
231
+ }
232
+ }