@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,88 @@
1
+ // Move scheduling within one turn (#127). Pure; no I/O.
2
+ //
3
+ // war.app runs both players' moves zigzag: the first mover's 1st order, the second mover's 1st
4
+ // and 2nd, the first mover's 2nd and 3rd, and so on. So where an order sits in my list decides
5
+ // what it meets: an early order runs before most of the opponent's, a late one after them.
6
+ /** Where a move belongs in the list, earliest first. */
7
+ export const MoveSlot = {
8
+ /** The one order Order Priority puts ahead of the opponent's first. */
9
+ Protected: 0,
10
+ /** Withdrawals (they only run while the border is mine) and transfers into a border the enemy can break. */
11
+ Early: 1,
12
+ /** Attacks that capture even if the owner's whole deploy lands there first; contested neutrals whose survivors hold. */
13
+ Sure: 2,
14
+ /** Uncontested neutral captures and interior transfers: filler. */
15
+ Filler: 3,
16
+ /**
17
+ * Attacks into a stack that can fight back, and contested neutrals taken at their exact cost:
18
+ * last, so they meet what is left once the opponent's own attacks have run (a defender kills
19
+ * 70% per army, an attacker 60%: the side that attacks second fights survivors).
20
+ */
21
+ Last: 4,
22
+ };
23
+ /**
24
+ * Whether move `j` must stay after move `i` (i listed before j in decision order):
25
+ * - attacks on one target keep their order (softeners before the finisher);
26
+ * - a move out of a territory another move went into earlier (a capture, a transfer) stays
27
+ * after it (its armies may be the ones moving on) — not my commander's walk when it carries no
28
+ * armies (#274: nothing it lists can be waiting to arrive);
29
+ * - a transfer into a territory captured this turn stays after the capture;
30
+ * - (#274 review 2) every other move out of my commander's territory stays after its walk, wherever
31
+ * it was listed (the armies there hold the commander until it leaves), unless `beforeWalk` lets it
32
+ * go first (a strike that ends a player: {@link scheduleMoves}).
33
+ */
34
+ function dependsOn(i, j) {
35
+ if (i.kind === 'attack' && j.kind === 'attack' && i.to === j.to)
36
+ return true;
37
+ if (j.from === i.to && !(j.commander === true && j.armies === 0))
38
+ return true;
39
+ return i.kind === 'attack' && j.kind === 'transfer' && j.to === i.to;
40
+ }
41
+ /**
42
+ * The moves in the order to send them: each in its slot (earliest first), within a slot the
43
+ * higher `rankOf` first (ties keep decision order), never ahead of a move it depends on (see
44
+ * {@link dependsOn}). Stable and deterministic.
45
+ */
46
+ export function scheduleMoves(moves, slotOf, rankOf = () => 0, beforeWalk = () => false) {
47
+ const slot = moves.map((m, i) => slotOf(m, i));
48
+ const rank = moves.map((m) => rankOf(m));
49
+ const walks = moves.flatMap((m, i) => (m.commander === true ? [i] : []));
50
+ const deps = moves.map((m, j) => [
51
+ ...moves.slice(0, j).flatMap((p, i) => (dependsOn(p, m) ? [i] : [])),
52
+ ...(m.commander === true || beforeWalk(m) ? [] : walks.filter((w) => moves[w].from === m.from)),
53
+ ]);
54
+ const done = new Set();
55
+ const out = [];
56
+ while (out.length < moves.length) {
57
+ let pick = -1;
58
+ for (let j = 0; j < moves.length; j++) {
59
+ if (done.has(j) || !deps[j].every((i) => done.has(i)))
60
+ continue;
61
+ if (pick < 0 || slot[j] < slot[pick] || (slot[j] === slot[pick] && rank[j] > rank[pick]))
62
+ pick = j;
63
+ }
64
+ done.add(pick);
65
+ out.push(moves[pick]);
66
+ }
67
+ return out;
68
+ }
69
+ /**
70
+ * How many of the opponent's orders run before my `k`-th (1-based) in a two-player turn. The
71
+ * interleave is F S S F F S S …: the first mover's k-th runs after 2·floor(k/2) of the other's,
72
+ * the second mover's after 2·ceil(k/2) − 1. (Once the opponent's list runs out, mine run in a row.)
73
+ */
74
+ export function opponentOrdersBefore(k, mover) {
75
+ return mover === 'first' ? 2 * Math.floor(k / 2) : 2 * Math.ceil(k / 2) - 1;
76
+ }
77
+ /**
78
+ * The first index (1-based) of mine that runs after all `n` of the opponent's orders: the
79
+ * smallest even number ≥ n moving first, the smallest odd number ≥ n moving second, n + 1 when
80
+ * not known (it must hold either way). Never below 1.
81
+ */
82
+ export function indexAfterAll(n, mover) {
83
+ if (mover === 'unknown')
84
+ return n + 1;
85
+ const parity = mover === 'first' ? 0 : 1;
86
+ const k = n % 2 === parity ? n : n + 1;
87
+ return Math.max(1, k);
88
+ }
@@ -0,0 +1,50 @@
1
+ // Since last turn (#194): this turn's income against the next income the plan of the previous
2
+ // turn expected, and what changed hands since the previous board — the positive bonuses I held
3
+ // that are broken now, and the territories I held that are no longer mine (taken by a player,
4
+ // neutral again, or out of view). Pure and deterministic (ascending ids); no I/O.
5
+ //
6
+ // The expected figure is the plan's `expected.nextIncome` as it stood when the previous turn was
7
+ // planned: it assumed the plan's orders were sent and every kept border held, so a shortfall says
8
+ // either an order was not sent as planned or a border fell — the lists say which borders.
9
+ import { bonusTerritories } from './bonuses.js';
10
+ const byNum = (a, b) => a - b;
11
+ function heldBy(b, me, g) {
12
+ const out = new Set();
13
+ for (const t of b.territories)
14
+ if (g.territoryById.has(t.territoryId) && t.owner.kind === 'player' && t.owner.playerId === me)
15
+ out.add(t.territoryId);
16
+ return out;
17
+ }
18
+ export function sinceLastTurn(input) {
19
+ const { graph, previous, current, me, income } = input;
20
+ const expected = input.expected ?? null;
21
+ const out = {
22
+ income,
23
+ expected,
24
+ expectedTurn: expected === null ? null : (input.expectedTurn ?? null),
25
+ shortfall: expected === null ? null : Math.max(0, expected - income),
26
+ };
27
+ const c = input.armyCap;
28
+ if (c?.cut)
29
+ out.capCut = { uncapped: c.uncapped, cut: c.uncapped - c.received };
30
+ if (!previous)
31
+ return out;
32
+ const before = heldBy(previous, me, graph);
33
+ const now = heldBy(current, me, graph);
34
+ const holds = (held, ts) => ts.length > 0 && ts.every((t) => held.has(t));
35
+ out.bonusesBroken = [...graph.bonusById.values()]
36
+ .filter((b) => b.value > 0)
37
+ .map((b) => ({ b, ts: bonusTerritories(graph, b.id) }))
38
+ .filter(({ ts }) => holds(before, ts) && !holds(now, ts))
39
+ .map(({ b }) => ({ bonusId: b.id, value: b.value }))
40
+ .sort((x, y) => x.bonusId - y.bonusId);
41
+ const ownerNow = new Map(current.territories.map((t) => [t.territoryId, t.owner]));
42
+ out.territoriesLost = [...before]
43
+ .filter((id) => !now.has(id))
44
+ .sort(byNum)
45
+ .map((territoryId) => {
46
+ const o = ownerNow.get(territoryId);
47
+ return { territoryId, to: o?.kind === 'player' ? o.playerId : null };
48
+ });
49
+ return out;
50
+ }
@@ -0,0 +1,71 @@
1
+ // #270: a player who is out of the game and whose seat no AI plays. Pure, no I/O.
2
+ //
3
+ // war.app keeps such a player's territories on the board (a surrender without
4
+ // SurrenderedPlayersTurnIntoAIs, a boot without BootedPlayersTurnIntoAIs, a vote to end), but
5
+ // nobody deploys there or orders anything from there: the armies stand still. Every analysis that
6
+ // reads a player as an opponent (the planner's estimates, threats, standing and strike stack, the
7
+ // stress test's replies, the tracker, the outlook) reads those territories as neutrals instead —
8
+ // static armies, priced like a wasteland — through `neutralizeSeats`. An AI that replaced a player
9
+ // (`humanTurnedIntoAI`, or the game's turn-into-AI setting for that ending) stays an opponent.
10
+ import { carriesTeam } from '../teams.js';
11
+ /** GameFeed states of a player who no longer plays the game (PLAYER_STATE_NAMES, src/player-states.ts). */
12
+ export const OUT_STATES = new Set(['SurrenderAccepted', 'Booted', 'Eliminated', 'EndedByVote']);
13
+ /**
14
+ * Whether `p` is out and its seat static: an out state, no AI playing it (`humanTurnedIntoAI`), and
15
+ * not a surrender or boot the game turns into an AI.
16
+ */
17
+ export function isStaticSeat(p, endRules) {
18
+ const state = p.state ?? 'Playing';
19
+ if (!OUT_STATES.has(state) || p.humanTurnedIntoAI)
20
+ return false;
21
+ if (state === 'SurrenderAccepted' && endRules?.surrenderedTurnIntoAI === true)
22
+ return false;
23
+ if (state === 'Booted' && endRules?.bootedTurnIntoAI === true)
24
+ return false;
25
+ return true;
26
+ }
27
+ /**
28
+ * The static seats among `players`, by id, with the state that put each out. Never `me`, nor a
29
+ * teammate of mine: a teammate's land is not a neutral to attack (an order into it is a transfer
30
+ * unless it sets attack_teammates), and the planner never targets it anyway.
31
+ */
32
+ export function staticSeats(players, endRules, me) {
33
+ const myTeam = players?.find((p) => p.id === me)?.team;
34
+ const ally = (p) => p.id === me || (carriesTeam(myTeam) && p.team === myTeam);
35
+ const out = new Map();
36
+ for (const p of players ?? [])
37
+ if (!ally(p) && isStaticSeat(p, endRules))
38
+ out.set(p.id, p.state ?? 'Playing');
39
+ return out;
40
+ }
41
+ /**
42
+ * `board` with every territory a static seat holds read as neutral, its armies (and any special unit
43
+ * standing there, which still defends) unchanged. The same object when nothing changes.
44
+ */
45
+ export function neutralizeSeats(board, seats) {
46
+ if (!seats.size)
47
+ return board;
48
+ const held = (t) => t.owner.kind === 'player' && seats.has(t.owner.playerId);
49
+ if (!board.territories.some(held))
50
+ return board;
51
+ return {
52
+ ...board,
53
+ territories: board.territories.map((t) => (held(t) ? { ...t, owner: { kind: 'neutral' } } : t)),
54
+ };
55
+ }
56
+ /** Per static seat, the territories it holds on `board` (only seats holding some). */
57
+ export function seatTerritories(board, seats) {
58
+ const n = new Map();
59
+ for (const t of board.territories)
60
+ if (t.owner.kind === 'player' && seats.has(t.owner.playerId))
61
+ n.set(t.owner.playerId, (n.get(t.owner.playerId) ?? 0) + 1);
62
+ return n;
63
+ }
64
+ /** The end rules a plan reads (`PlanGameContext.endRules`) from `Game.endRules`: only the fields set. */
65
+ export function seatEndRules(r) {
66
+ return {
67
+ ...(r.aisSurrenderWhenOneHumanRemains !== undefined ? { aisSurrenderWhenOneHumanRemains: r.aisSurrenderWhenOneHumanRemains } : {}),
68
+ ...(r.surrenderedTurnIntoAI !== undefined ? { surrenderedTurnIntoAI: r.surrenderedTurnIntoAI } : {}),
69
+ ...(r.bootedTurnIntoAI !== undefined ? { bootedTurnIntoAI: r.bootedTurnIntoAI } : {}),
70
+ };
71
+ }