@chrischall/warapp-mcp 0.0.0 → 0.2.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 (194) hide show
  1. package/.claude-plugin/marketplace.json +4 -4
  2. package/.claude-plugin/plugin.json +2 -2
  3. package/README.md +211 -9
  4. package/dist/analysis/accept-surrender.js +56 -0
  5. package/dist/analysis/award.js +159 -0
  6. package/dist/analysis/bonuses.js +98 -0
  7. package/dist/analysis/breach.js +62 -0
  8. package/dist/analysis/calibrate.js +239 -0
  9. package/dist/analysis/card-support.js +329 -0
  10. package/dist/analysis/card-threats.js +234 -0
  11. package/dist/analysis/cards-in-effect.js +130 -0
  12. package/dist/analysis/chains.js +59 -0
  13. package/dist/analysis/chokepoints.js +140 -0
  14. package/dist/analysis/combat.js +231 -0
  15. package/dist/analysis/commander-safety.js +149 -0
  16. package/dist/analysis/commitments.js +338 -0
  17. package/dist/analysis/exchange.js +155 -0
  18. package/dist/analysis/finished-game.js +136 -0
  19. package/dist/analysis/game-lessons.js +217 -0
  20. package/dist/analysis/graph.js +82 -0
  21. package/dist/analysis/guard-off.js +54 -0
  22. package/dist/analysis/guess.js +351 -0
  23. package/dist/analysis/headroom.js +241 -0
  24. package/dist/analysis/hold-diff.js +64 -0
  25. package/dist/analysis/how-lost.js +130 -0
  26. package/dist/analysis/index.js +14 -0
  27. package/dist/analysis/local-deploy.js +179 -0
  28. package/dist/analysis/lookahead.js +108 -0
  29. package/dist/analysis/opponent-profile.js +552 -0
  30. package/dist/analysis/opponents.js +1253 -0
  31. package/dist/analysis/outlook.js +695 -0
  32. package/dist/analysis/overrides.js +60 -0
  33. package/dist/analysis/picks.js +1879 -0
  34. package/dist/analysis/plan/after-leftover.js +140 -0
  35. package/dist/analysis/plan/cap-spend.js +242 -0
  36. package/dist/analysis/plan/captures.js +1195 -0
  37. package/dist/analysis/plan/commander.js +236 -0
  38. package/dist/analysis/plan/completed.js +29 -0
  39. package/dist/analysis/plan/conceded-out.js +131 -0
  40. package/dist/analysis/plan/estimates.js +715 -0
  41. package/dist/analysis/plan/guard-off.js +232 -0
  42. package/dist/analysis/plan/holds.js +1631 -0
  43. package/dist/analysis/plan/leftover.js +760 -0
  44. package/dist/analysis/plan/move-order.js +319 -0
  45. package/dist/analysis/plan/orders.js +317 -0
  46. package/dist/analysis/plan/relations.js +702 -0
  47. package/dist/analysis/plan/report.js +672 -0
  48. package/dist/analysis/plan/shared.js +1405 -0
  49. package/dist/analysis/plan/stand-still.js +823 -0
  50. package/dist/analysis/plan/state.js +44 -0
  51. package/dist/analysis/plan/strike.js +1416 -0
  52. package/dist/analysis/plan/targets.js +651 -0
  53. package/dist/analysis/plan/team.js +299 -0
  54. package/dist/analysis/plan/threats.js +1001 -0
  55. package/dist/analysis/plan/transfers.js +328 -0
  56. package/dist/analysis/plan/util.js +5 -0
  57. package/dist/analysis/plan/vacated.js +285 -0
  58. package/dist/analysis/planner.js +2927 -0
  59. package/dist/analysis/player-record.js +144 -0
  60. package/dist/analysis/player.js +268 -0
  61. package/dist/analysis/profile.js +347 -0
  62. package/dist/analysis/relations.js +1030 -0
  63. package/dist/analysis/schedule.js +88 -0
  64. package/dist/analysis/since-last.js +50 -0
  65. package/dist/analysis/static-seats.js +71 -0
  66. package/dist/analysis/stress.js +584 -0
  67. package/dist/analysis/team-brief.js +151 -0
  68. package/dist/analysis/tripwire.js +644 -0
  69. package/dist/analysis/turn-sim.js +259 -0
  70. package/dist/analysis/whereabouts.js +1112 -0
  71. package/dist/board.js +105 -0
  72. package/dist/bundle.js +121082 -36148
  73. package/dist/calibration-source.js +75 -0
  74. package/dist/cards.js +435 -0
  75. package/dist/chat-cursor.js +135 -0
  76. package/dist/chat.js +265 -0
  77. package/dist/client.js +439 -0
  78. package/dist/config.js +62 -0
  79. package/dist/direct/link.js +102 -0
  80. package/dist/direct/session.js +267 -0
  81. package/dist/direct/transport.js +424 -0
  82. package/dist/finished-store.js +357 -0
  83. package/dist/guess-salt.js +65 -0
  84. package/dist/hosted.js +24 -0
  85. package/dist/index.js +33 -0
  86. package/dist/join-color.js +140 -0
  87. package/dist/lessons-store.js +356 -0
  88. package/dist/live.js +287 -0
  89. package/dist/map-details.js +127 -0
  90. package/dist/map-stats.js +160 -0
  91. package/dist/map-store.js +242 -0
  92. package/dist/move-order.js +141 -0
  93. package/dist/my-games.js +218 -0
  94. package/dist/normalize.js +443 -0
  95. package/dist/notifications.js +143 -0
  96. package/dist/open-games.js +537 -0
  97. package/dist/outlook-log.js +165 -0
  98. package/dist/path-lock.js +22 -0
  99. package/dist/pick-list.js +193 -0
  100. package/dist/player-record-store.js +231 -0
  101. package/dist/player-states.js +31 -0
  102. package/dist/profile-store.js +727 -0
  103. package/dist/protocol/bundle.js +375 -0
  104. package/dist/protocol/codec.js +556 -0
  105. package/dist/protocol/decoded.js +12 -0
  106. package/dist/protocol/interp.js +1904 -0
  107. package/dist/protocol/methods.js +615 -0
  108. package/dist/protocol/rpc.js +202 -0
  109. package/dist/push/listener.js +393 -0
  110. package/dist/push/packets.js +66 -0
  111. package/dist/push/socketio.js +333 -0
  112. package/dist/push/websocket.js +179 -0
  113. package/dist/redact.js +62 -0
  114. package/dist/relations-store.js +242 -0
  115. package/dist/replay.js +227 -0
  116. package/dist/scalars.js +28 -0
  117. package/dist/scout.js +346 -0
  118. package/dist/stats.js +291 -0
  119. package/dist/strategy/card-clock.js +185 -0
  120. package/dist/strategy/map-notes.js +128 -0
  121. package/dist/strategy/notes.js +2223 -0
  122. package/dist/surrender-pending.js +126 -0
  123. package/dist/team-cards.js +84 -0
  124. package/dist/team-orders.js +150 -0
  125. package/dist/teams.js +19 -0
  126. package/dist/tools/accept-surrender.js +311 -0
  127. package/dist/tools/award.js +206 -0
  128. package/dist/tools/begin-turn.js +162 -0
  129. package/dist/tools/board.js +77 -0
  130. package/dist/tools/card-advice.js +256 -0
  131. package/dist/tools/card-effects.js +49 -0
  132. package/dist/tools/card-plays.js +434 -0
  133. package/dist/tools/card-support-advice.js +140 -0
  134. package/dist/tools/chat-inbox.js +158 -0
  135. package/dist/tools/chat-read-mark.js +179 -0
  136. package/dist/tools/chat.js +525 -0
  137. package/dist/tools/check-plan.js +689 -0
  138. package/dist/tools/commander-check.js +103 -0
  139. package/dist/tools/commitments.js +216 -0
  140. package/dist/tools/common.js +143 -0
  141. package/dist/tools/diplomacy.js +342 -0
  142. package/dist/tools/end-of-game.js +384 -0
  143. package/dist/tools/game.js +151 -0
  144. package/dist/tools/guess-view.js +56 -0
  145. package/dist/tools/healthcheck.js +90 -0
  146. package/dist/tools/hints.js +34 -0
  147. package/dist/tools/how-lost.js +154 -0
  148. package/dist/tools/index.js +152 -0
  149. package/dist/tools/join-game.js +327 -0
  150. package/dist/tools/leave-game.js +181 -0
  151. package/dist/tools/live-context.js +339 -0
  152. package/dist/tools/live.js +404 -0
  153. package/dist/tools/map-details.js +88 -0
  154. package/dist/tools/map-stats.js +130 -0
  155. package/dist/tools/map.js +141 -0
  156. package/dist/tools/my-games.js +193 -0
  157. package/dist/tools/notifications.js +484 -0
  158. package/dist/tools/open-games.js +104 -0
  159. package/dist/tools/opponents.js +163 -0
  160. package/dist/tools/order-options.js +135 -0
  161. package/dist/tools/past-games.js +94 -0
  162. package/dist/tools/picks.js +305 -0
  163. package/dist/tools/profile-hook.js +156 -0
  164. package/dist/tools/profile-opponents.js +121 -0
  165. package/dist/tools/profile-reads.js +99 -0
  166. package/dist/tools/push.js +445 -0
  167. package/dist/tools/relations.js +611 -0
  168. package/dist/tools/resolve.js +45 -0
  169. package/dist/tools/route.js +36 -0
  170. package/dist/tools/scout.js +87 -0
  171. package/dist/tools/session.js +163 -0
  172. package/dist/tools/strategy.js +257 -0
  173. package/dist/tools/stress-opponents.js +83 -0
  174. package/dist/tools/surrender-pending.js +74 -0
  175. package/dist/tools/surrender.js +247 -0
  176. package/dist/tools/survival.js +189 -0
  177. package/dist/tools/team-brief.js +266 -0
  178. package/dist/tools/team-source.js +222 -0
  179. package/dist/tools/team.js +178 -0
  180. package/dist/tools/turn.js +2825 -0
  181. package/dist/tools/uncommit.js +160 -0
  182. package/dist/tools/where.js +300 -0
  183. package/dist/tools/write-kit.js +164 -0
  184. package/dist/transport-bridge.js +33 -0
  185. package/dist/trend.js +577 -0
  186. package/dist/version.js +4 -0
  187. package/manifest.json +194 -4
  188. package/mint.yaml +106 -14
  189. package/package.json +11 -6
  190. package/server.json +40 -3
  191. package/skills/warapp-api/SKILL.md +95 -4
  192. package/skills/warapp-api/references/scout.mjs +348 -0
  193. package/skills/warapp-api/scripts/warapp.sh +69 -8
  194. package/skills/warapp-mcp/SKILL.md +1096 -21
package/dist/chat.js ADDED
@@ -0,0 +1,265 @@
1
+ // Game chat as data: one line shape for both sources, with the channel each message was sent on.
2
+ //
3
+ // - The web client's GameRefresh (method 39) answers `warlight.shared.GameDetailsAndChat`, whose first
4
+ // field is the chat: a list of `warlight.shared.GameMessage`. Both are decoded by the client bundle's
5
+ // own readers, found by their stable registered type names; fields are taken by read order and
6
+ // checked by type, never by their minified names (docs/WEB-PROTOCOL.md, Chat). The SendChat reply is
7
+ // the same message list. UNVERIFIED live: the field meanings come from how the client's chat UI uses
8
+ // them (the sender, the channel, -1 public, else a team; the private counterpart; the turn).
9
+ // - GameFeed's `GetChat=true` list is read loosely: it is not documented, and whether it carries team
10
+ // or private messages, or any channel field, is unknown. A message with no channel field is `unknown`.
11
+ //
12
+ // Readers here never throw: a reply in a shape they do not understand is `undefined`, and the caller
13
+ // falls back (GameRefresh to GameFeed) or reports the outcome as unreadable.
14
+ import { fields, isObj } from './protocol/decoded.js';
15
+ import { parseFeedTime } from './normalize.js';
16
+ import { asInt } from './scalars.js';
17
+ export const GAME_DETAILS_AND_CHAT = 'warlight.shared.GameDetailsAndChat';
18
+ export const GAME_MESSAGE = 'warlight.shared.GameMessage';
19
+ /** GameMessage field positions in read order, and its whole field count. */
20
+ const GM = { date: 0, sender: 1, group: 2, id: 4, text: 5, channel: 6, to: 7, turn: 9 };
21
+ export const GAME_MESSAGE_FIELDS = 10;
22
+ /** The public channel's value (any other is a team). */
23
+ export const PUBLIC_CHANNEL = -1;
24
+ export const CHAT_CHANNELS = ['public', 'team', 'private', 'unknown'];
25
+ const isInt = (v) => typeof v === 'number' && Number.isInteger(v);
26
+ const optInt = (v) => v === null || isInt(v);
27
+ /** One decoded GameMessage as a line; `undefined` when a field is not what it should be. */
28
+ function webLine(m) {
29
+ if (!isObj(m) || m.$type !== GAME_MESSAGE)
30
+ return undefined;
31
+ const f = fields(m);
32
+ if (f.length !== GAME_MESSAGE_FIELDS)
33
+ return undefined;
34
+ const date = f[GM.date];
35
+ const sender = f[GM.sender];
36
+ const group = f[GM.group];
37
+ const id = f[GM.id];
38
+ const text = f[GM.text];
39
+ const channel = f[GM.channel];
40
+ const to = f[GM.to];
41
+ const turn = f[GM.turn];
42
+ if (!(date === null || date instanceof Date) || !optInt(sender) || !optInt(group) || !optInt(to) || !optInt(turn))
43
+ return undefined;
44
+ if (!(id === null || typeof id === 'string' || isInt(id)) || typeof text !== 'string' || !isInt(channel))
45
+ return undefined;
46
+ const line = { sender, text, turn, channel: 'unknown' };
47
+ if (id !== null)
48
+ line.id = String(id);
49
+ if (date !== null && Number.isFinite(date.getTime())) {
50
+ line.time = date.toISOString();
51
+ line.timeMs = date.getTime();
52
+ }
53
+ // The client sorts a message into a tab the same way: a private counterpart first, then a game
54
+ // group (no channel of ours), then the channel (-1 public, else the team).
55
+ if (to !== null) {
56
+ line.channel = 'private';
57
+ line.to = to;
58
+ }
59
+ else if (group !== null) {
60
+ line.channel = 'unknown';
61
+ line.group = group;
62
+ }
63
+ else if (channel === PUBLIC_CHANNEL) {
64
+ line.channel = 'public';
65
+ }
66
+ else {
67
+ line.channel = 'team';
68
+ line.team = channel;
69
+ }
70
+ return line;
71
+ }
72
+ const numericId = (id) => {
73
+ const n = id === undefined ? Number.NaN : Number(id);
74
+ return Number.isFinite(n) ? n : Number.POSITIVE_INFINITY;
75
+ };
76
+ /** Oldest first: by time where both have one, else by id. */
77
+ function byAge(a, b) {
78
+ if (a.timeMs !== undefined && b.timeMs !== undefined && a.timeMs !== b.timeMs)
79
+ return a.timeMs - b.timeMs;
80
+ return numericId(a.id) - numericId(b.id);
81
+ }
82
+ /** A decoded message list as lines, oldest first; `undefined` when any message is unreadable. */
83
+ function webLines(list) {
84
+ if (!Array.isArray(list))
85
+ return undefined;
86
+ const out = [];
87
+ for (const m of list) {
88
+ if (m === null)
89
+ continue;
90
+ const line = webLine(m);
91
+ if (!line)
92
+ return undefined;
93
+ out.push(line);
94
+ }
95
+ return out.sort(byAge);
96
+ }
97
+ /**
98
+ * The chat of a GameRefresh reply (the body positioned at the result-present flag), oldest first;
99
+ * `undefined` when there is no result, no chat list, or a shape this server does not understand.
100
+ */
101
+ export function readGameRefreshChat(bundle, body) {
102
+ try {
103
+ if (!body.bool())
104
+ return undefined;
105
+ const ret = bundle.readClass(GAME_DETAILS_AND_CHAT, body);
106
+ if (!isObj(ret) || ret.$type !== GAME_DETAILS_AND_CHAT)
107
+ return undefined;
108
+ const list = fields(ret)[0];
109
+ return list === null ? undefined : webLines(list);
110
+ }
111
+ catch {
112
+ return undefined;
113
+ }
114
+ }
115
+ /**
116
+ * The SendChat reply: the updated message list, read straight after the result-present flag (each
117
+ * message behind its own present flag), oldest first; `undefined` when it cannot be read.
118
+ */
119
+ export function readSendChatReply(bundle, body) {
120
+ try {
121
+ if (!body.bool())
122
+ return undefined;
123
+ const list = body.list((r) => (r.bool() ? bundle.readClass(GAME_MESSAGE, r) : null));
124
+ return list === null ? undefined : webLines(list);
125
+ }
126
+ catch {
127
+ return undefined;
128
+ }
129
+ }
130
+ const MESSAGE_ID = /^\d{1,20}$/;
131
+ const higher = (a, b) => (a === undefined || BigInt(b) > BigInt(a) ? b : a);
132
+ /**
133
+ * The read marks of web-client `lines` on `channels` (pure): per channel the highest message id among
134
+ * them, mine included, as the client keeps it. A private conversation is keyed by its counterpart — the
135
+ * recipient of a message I sent, else its sender — and a game group (`unknown`) by its group. Lines
136
+ * without a message id (GameFeed's) mark nothing. `undefined` when nothing would be marked.
137
+ */
138
+ export function chatViewMarks(lines, meInGame, channels) {
139
+ const want = new Set(channels);
140
+ const out = { private: new Map(), groups: new Map(), channels: [] };
141
+ for (const l of lines) {
142
+ if (l.id === undefined || !MESSAGE_ID.test(l.id) || !want.has(l.channel))
143
+ continue;
144
+ if (l.channel === 'public')
145
+ out.public = higher(out.public, l.id);
146
+ else if (l.channel === 'team')
147
+ out.team = higher(out.team, l.id);
148
+ else if (l.channel === 'private') {
149
+ const other = l.sender === meInGame ? l.to : l.sender;
150
+ if (other === undefined || other === null)
151
+ continue;
152
+ out.private.set(other, higher(out.private.get(other), l.id));
153
+ }
154
+ else if (l.group !== undefined)
155
+ out.groups.set(l.group, higher(out.groups.get(l.group), l.id));
156
+ }
157
+ const has = {
158
+ public: out.public !== undefined,
159
+ team: out.team !== undefined,
160
+ private: out.private.size > 0,
161
+ unknown: out.groups.size > 0,
162
+ };
163
+ out.channels = CHAT_CHANNELS.filter((c) => has[c]);
164
+ return out.channels.length ? out : undefined;
165
+ }
166
+ const isRec = (v) => typeof v === 'object' && v !== null && !Array.isArray(v);
167
+ const pick = (r, keys) => {
168
+ for (const k of keys)
169
+ if (r[k] !== undefined && r[k] !== null)
170
+ return r[k];
171
+ return undefined;
172
+ };
173
+ const SENDER_KEYS = ['playerID', 'playerId', 'sender', 'senderID', 'from', 'player'];
174
+ const TEXT_KEYS = ['message', 'text', 'chat', 'msg', 'body'];
175
+ const TIME_KEYS = ['time', 'date', 'dateTime', 'created', 'sent', 'when'];
176
+ const LIST_KEYS = ['chat', 'messages', 'Chat'];
177
+ const TURN_KEYS = ['turn', 'turnNumber', 'Turn'];
178
+ // None of these has been seen in a GameFeed reply (V2 in docs/PLAN-TEAMS.md): read only to be tolerant.
179
+ const CHANNEL_KEYS = ['channel', 'Channel', 'teamID', 'teamId', 'team', 'Team'];
180
+ const RECIPIENT_KEYS = ['recipientID', 'recipientId', 'recipient', 'toPlayerID', 'toPlayerId', 'privateTo', 'to'];
181
+ /**
182
+ * GameFeed's chat as lines, in the order sent (most recent last): a message is anything with a text
183
+ * field, its sender an id (GameFeed's `playerID` is the in-game id) or a name. `undefined` when
184
+ * nothing recognisable is there, so the caller can pass the raw value through instead.
185
+ */
186
+ export function feedChatLines(raw) {
187
+ let list = raw;
188
+ if (isRec(list))
189
+ list = pick(list, LIST_KEYS);
190
+ if (!Array.isArray(list))
191
+ return undefined;
192
+ const out = [];
193
+ for (const item of list) {
194
+ if (!isRec(item))
195
+ return undefined;
196
+ const text = pick(item, TEXT_KEYS);
197
+ if (typeof text !== 'string')
198
+ return undefined;
199
+ const from = pick(item, SENDER_KEYS);
200
+ const id = asInt(from);
201
+ const line = { sender: id ?? null, text, turn: asInt(pick(item, TURN_KEYS)) ?? null, channel: 'unknown' };
202
+ if (id === undefined && typeof from === 'string' && from !== '')
203
+ line.senderName = from;
204
+ const time = pick(item, TIME_KEYS);
205
+ if (typeof time === 'string' || typeof time === 'number') {
206
+ line.time = String(time);
207
+ // A feed time with no zone is UTC, as every other GameFeed time (parseFeedTime); Date.parse would read it as local time.
208
+ const ms = typeof time === 'string' ? (parseFeedTime(time) ?? Date.parse(time)) : Number.NaN;
209
+ if (Number.isFinite(ms))
210
+ line.timeMs = ms;
211
+ }
212
+ const to = asInt(pick(item, RECIPIENT_KEYS));
213
+ const channel = asInt(pick(item, CHANNEL_KEYS));
214
+ if (to !== undefined) {
215
+ line.channel = 'private';
216
+ line.to = to;
217
+ }
218
+ else if (channel !== undefined) {
219
+ if (channel === PUBLIC_CHANNEL)
220
+ line.channel = 'public';
221
+ else {
222
+ line.channel = 'team';
223
+ line.team = channel;
224
+ }
225
+ }
226
+ out.push(line);
227
+ }
228
+ return out;
229
+ }
230
+ // ---------- A short web read, filled from GameFeed (#313) ----------
231
+ /** Two times this close (ms) are one message's: GameFeed may give whole seconds where the web client gives ms. */
232
+ const SAME_MESSAGE_MS = 1000;
233
+ const sameMessage = (web, feed) => {
234
+ if (web.sender !== feed.sender)
235
+ return false;
236
+ if (web.timeMs !== undefined && feed.timeMs !== undefined)
237
+ return Math.abs(web.timeMs - feed.timeMs) < SAME_MESSAGE_MS;
238
+ return web.text === feed.text;
239
+ };
240
+ /**
241
+ * The web client's `web` lines with GameFeed's `feed` lines that no web line matches (same sender, and
242
+ * times within a second — or the same text when either has no time), each match used once. The added
243
+ * lines keep GameFeed's `unknown` channel and go in by time (after every web line of the same or an
244
+ * earlier time); one with no time goes last. Pure: `added` is how many GameFeed lines were added.
245
+ */
246
+ export function fillFromFeed(web, feed) {
247
+ const used = new Set();
248
+ const extra = [];
249
+ for (const f of feed) {
250
+ const k = web.findIndex((w, i) => !used.has(i) && sameMessage(w, f));
251
+ if (k >= 0)
252
+ used.add(k);
253
+ else
254
+ extra.push({ ...f, channel: 'unknown' });
255
+ }
256
+ const lines = [...web];
257
+ for (const e of extra) {
258
+ const at = e.timeMs === undefined ? -1 : lines.findIndex((l) => l.timeMs !== undefined && l.timeMs > e.timeMs);
259
+ if (at < 0)
260
+ lines.push(e);
261
+ else
262
+ lines.splice(at, 0, e);
263
+ }
264
+ return { lines, added: extra.length };
265
+ }