@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,182 @@
1
+ // warapp_get_team (C1, docs/PLAN-TEAMS.md): my team in a team game — who is on it, human or AI, committed or
2
+ // not, each teammate's visible income and the orders or picks they have entered, the team's shared hand and
3
+ // unread team chat. Read-only.
4
+ //
5
+ // UNVERIFIED live: GameFeed's player `team` (V1; without it the team comes from GetMyGames' GameInfoPlayer,
6
+ // read from the bundle), the teammate orders in LatestGameInfo (V5), GetTerritoryPicks with a teammate's id
7
+ // (V6) and how a team's hand is keyed (#163, V8). Every read here is tolerant: what cannot be read is
8
+ // unknown (`null`), never an error — except a game that is not a team game, which is refused.
9
+ import { McpToolError } from '@chrischall/mcp-utils';
10
+ import { z } from 'zod';
11
+ import { visibleIncomeFor } from '../analysis/plan/shared.js';
12
+ import { cardRules, handReadable, readHand } from '../cards.js';
13
+ import { parseGameId } from '../client.js';
14
+ import { boardStateFromLive, playersByInGameId } from '../live.js';
15
+ import { withTeammateOrders } from '../team-orders.js';
16
+ import { carriesTeam, teammatesOf } from '../teams.js';
17
+ import { handOwners } from './card-advice.js';
18
+ import { chatUnread, readChat } from './chat.js';
19
+ import { gameIdArg, graphOf, namer, readAnnotations, respond, untrustedDescription, untrustedText } from './common.js';
20
+ import { lookupMeta } from './hints.js';
21
+ import { loadLiveGame, loadPicks } from './live-context.js';
22
+ import { BRIDGE_NOTE } from './live.js';
23
+ import { mapOf } from './map.js';
24
+ import { resolveTeams } from './team-source.js';
25
+ import { currentTurn } from './turn.js';
26
+ import { accountUnknown } from './write-kit.js';
27
+ const NOTES = [
28
+ "GameFeed's player team is UNVERIFIED (V1); when it sends none, the team comes from GetMyGames (from the client bundle).",
29
+ "Teammate orders and picks come from the live board's TeammateOrders (client bundle, UNVERIFIED live, V5): `null` " +
30
+ 'means unknown — none entered, or war.app did not send them — never "nothing entered".',
31
+ "While distributing, a teammate's picks not in the board are asked with GetTerritoryPicks and the teammate's id " +
32
+ '(UNVERIFIED, V6); a refusal reads as unknown.',
33
+ "The team's hand is every card under me and my teammates; how war.app keys a team's hand is UNVERIFIED (#163).",
34
+ ];
35
+ const DISTRIBUTING = 'DistributingTerritories';
36
+ const BOARD_STATES = new Set(['Playing', DISTRIBUTING]);
37
+ /** A teammate's in-game id; `undefined` for a seat without a GameFeed player id (an AI). */
38
+ function inGameOf(p) {
39
+ return [...playersByInGameId([p]).keys()][0];
40
+ }
41
+ /**
42
+ * A teammate's pick list: the live board's TeammateOrders entry first (V5), else GetTerritoryPicks with the
43
+ * teammate's in-game id (V6). `null` is unknown — an AI seat, or a read war.app refused. Never throws.
44
+ */
45
+ export async function readTeammatePicks(ctx, gameId, mate, entry) {
46
+ if (entry?.picks)
47
+ return { source: 'teammate-orders', territories: entry.picks };
48
+ const inGame = inGameOf(mate);
49
+ if (inGame === undefined)
50
+ return null;
51
+ try {
52
+ return { source: 'territory-picks', territories: await loadPicks(ctx, gameId, inGame) };
53
+ }
54
+ catch {
55
+ return null; // refused or unreadable (V6): unknown
56
+ }
57
+ }
58
+ export function registerTeamTool(server, ctx) {
59
+ server.registerTool('warapp_get_team', {
60
+ title: 'Read my team in a war.app team game',
61
+ description: untrustedDescription('Your team in a war.app (Warzone) team game: your team id (and whether GameFeed or your game list gave it), ' +
62
+ 'each teammate (GameFeed id, name, human or ai, state, whether they have committed this turn, their visible ' +
63
+ 'income on the live board, the orders they have entered this turn — deploys, moves, card plays — or, while ' +
64
+ 'picking, their picks), the opponents by team, the team\'s shared hand ({ inPlay: false } in a game without cards), and unread team chat (a count, no text). ' +
65
+ 'A field that cannot be read is null: unknown, never "none". Teammate orders, picks and the team hand are read ' +
66
+ `from the client's own structures and are UNVERIFIED live. Refuses outside a team game. ${BRIDGE_NOTE} Read-only.`),
67
+ _meta: lookupMeta(['my team', 'teammates', 'team game', 'teammate orders', 'teammate picks', 'team hand']),
68
+ annotations: readAnnotations('Read my war.app team'),
69
+ inputSchema: z.object({ game_id: gameIdArg }),
70
+ }, async ({ game_id }) => {
71
+ const gameId = parseGameId(game_id);
72
+ const identity = await ctx.myIdentity().catch(() => undefined);
73
+ if (!identity)
74
+ throw accountUnknown(ctx.hosted, 'your team cannot be read');
75
+ const read = await ctx.client.getGame(gameId, { settings: true, chat: true });
76
+ const { game, source } = await resolveTeams(ctx, read);
77
+ const me = game.players.find((p) => p.id === identity.token);
78
+ if (!me) {
79
+ throw new McpToolError(`The signed-in war.app account is not a player in game ${game.id}.`, {
80
+ hint: 'Check the game id with warapp_my_games.',
81
+ });
82
+ }
83
+ if (source === 'none' || !carriesTeam(me.team)) {
84
+ throw new McpToolError(`Game ${game.id} is not a team game, or your team there is unknown.`, {
85
+ hint: "GameFeed's team field is unverified and your game list did not name a team either. Outside a team game " +
86
+ 'every other player is an opponent: warapp_track_opponents reads them.',
87
+ });
88
+ }
89
+ const team = me.team;
90
+ const mates = teammatesOf(game.players, me);
91
+ const map = mapOf(game);
92
+ const name = namer(map);
93
+ const warnings = [];
94
+ let board;
95
+ let info;
96
+ if (BOARD_STATES.has(game.state)) {
97
+ try {
98
+ const live = await loadLiveGame(ctx, game);
99
+ info = live.info;
100
+ board = withTeammateOrders(boardStateFromLive(live.territories, me, game.players), info, me, game.players);
101
+ }
102
+ catch (e) {
103
+ warnings.push(`The live board could not be read (${e.message}): incomes, orders, picks and the hand are unknown.`);
104
+ }
105
+ }
106
+ const rules = cardRules(game.settings);
107
+ const ordersView = (o) => ({
108
+ deploys: o.deploys.map((d) => ({ territory: name(d.territoryId), armies: d.armies })),
109
+ moves: o.moves.map((m) => ({
110
+ from: name(m.from),
111
+ to: name(m.to),
112
+ armies: m.armies,
113
+ mode: m.mode,
114
+ ...(m.percent ? { percent: true } : {}),
115
+ ...(m.attackTeammates ? { attackTeammates: true } : {}),
116
+ ...(m.commander ? { commander: true } : {}),
117
+ })),
118
+ cards: o.cards.map((c) => ({ ...(c.cardId ? { card: c.cardId } : {}), type: c.name })),
119
+ ...(o.discards.length ? { discards: o.discards.map((d) => (d.cardId ? { card: d.cardId } : {})) } : {}),
120
+ ...(o.unread.length ? { unread: o.unread } : {}),
121
+ });
122
+ const teammates = [];
123
+ for (const p of mates) {
124
+ const inGame = inGameOf(p);
125
+ const entry = board?.teammateOrders?.find((e) => e.playerId === p.id);
126
+ let picks = null;
127
+ if (game.state === DISTRIBUTING && board) {
128
+ const read = await readTeammatePicks(ctx, game.id, p, entry);
129
+ picks = read && { source: read.source, territories: read.territories.map(name) };
130
+ }
131
+ teammates.push({
132
+ id: p.id,
133
+ name: untrustedText(p.name),
134
+ kind: p.isAI || p.humanTurnedIntoAI ? 'ai' : 'human',
135
+ state: p.state ?? null,
136
+ committed: p.hasCommittedOrders,
137
+ visibleIncome: board && inGame !== undefined ? visibleIncomeFor(graphOf(map), board, p.id, game.settings) : null,
138
+ orders: entry?.orders ? ordersView(entry.orders) : null,
139
+ picks,
140
+ });
141
+ }
142
+ const owners = handOwners(game, me);
143
+ // No card in play is known from the settings, board or not; `null` is a hand that could not be read.
144
+ const hand = game.settings && !rules.inPlay.length
145
+ ? { inPlay: false }
146
+ : info === undefined || !rules.inPlay.length
147
+ ? null
148
+ : {
149
+ readable: handReadable(info, owners),
150
+ cards: readHand(info, owners).map((c) => ({ id: c.id, name: c.name, ...(c.armies !== undefined ? { armies: c.armies } : {}) })),
151
+ ...(rules.maxCardsHold !== undefined ? { limit: rules.maxCardsHold } : {}),
152
+ };
153
+ const chatMeOf = identity;
154
+ let chat = { unreadTeam: null, source: null };
155
+ try {
156
+ const lines = await readChat(ctx, game, chatMeOf);
157
+ if (lines) {
158
+ const { unread } = await chatUnread(ctx, game.id, chatMeOf, lines.lines);
159
+ chat =
160
+ lines.source === 'web'
161
+ ? { unreadTeam: unread.team, source: 'web' }
162
+ : { unreadTeam: null, source: 'gamefeed', note: 'GameFeed names no channel: read team chat with warapp_get_chat.' };
163
+ }
164
+ }
165
+ catch {
166
+ // unknown
167
+ }
168
+ return respond(undefined, ['compact'], () => ({
169
+ game: { id: game.id, state: game.state, turn: currentTurn(game) },
170
+ team: { id: team, source },
171
+ me: { id: me.id, name: untrustedText(me.name) },
172
+ teammates,
173
+ opponents: game.players
174
+ .filter((p) => p.id !== me.id && p.team !== team)
175
+ .map((p) => ({ id: p.id, name: untrustedText(p.name), team: carriesTeam(p.team) ? p.team : null })),
176
+ hand,
177
+ chat,
178
+ notes: NOTES,
179
+ ...(warnings.length ? { warnings } : {}),
180
+ }));
181
+ });
182
+ }