@chrischall/warapp-mcp 0.1.0 → 0.3.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 (86) hide show
  1. package/.claude-plugin/marketplace.json +3 -3
  2. package/.claude-plugin/plugin.json +1 -1
  3. package/README.md +49 -20
  4. package/dist/analysis/accept-surrender.js +56 -0
  5. package/dist/analysis/calibrate.js +239 -0
  6. package/dist/analysis/finished-game.js +136 -0
  7. package/dist/analysis/game-lessons.js +217 -0
  8. package/dist/analysis/local-deploy.js +37 -17
  9. package/dist/analysis/opponent-profile.js +6 -5
  10. package/dist/analysis/opponents.js +10 -2
  11. package/dist/analysis/outlook.js +63 -1
  12. package/dist/analysis/plan/shared.js +194 -7
  13. package/dist/analysis/plan/threats.js +103 -29
  14. package/dist/analysis/planner.js +10 -5
  15. package/dist/analysis/stress.js +14 -7
  16. package/dist/analysis/whereabouts.js +3 -0
  17. package/dist/bundle.js +13214 -9759
  18. package/dist/calibration-source.js +75 -0
  19. package/dist/chat.js +73 -0
  20. package/dist/client.js +85 -7
  21. package/dist/direct/link.js +9 -5
  22. package/dist/direct/session.js +60 -6
  23. package/dist/direct/sign-in.js +296 -0
  24. package/dist/direct/transport.js +59 -24
  25. package/dist/finished-store.js +357 -0
  26. package/dist/hosted.js +6 -4
  27. package/dist/index.js +1 -1
  28. package/dist/lessons-store.js +356 -0
  29. package/dist/live.js +9 -0
  30. package/dist/map-details.js +127 -0
  31. package/dist/map-stats.js +14 -6
  32. package/dist/map-store.js +44 -6
  33. package/dist/my-games.js +44 -6
  34. package/dist/normalize.js +34 -2
  35. package/dist/notifications.js +143 -0
  36. package/dist/outlook-log.js +28 -1
  37. package/dist/player-record-store.js +2 -0
  38. package/dist/profile-store.js +61 -11
  39. package/dist/protocol/methods.js +86 -2
  40. package/dist/replay.js +16 -4
  41. package/dist/stats.js +26 -4
  42. package/dist/strategy/notes.js +64 -9
  43. package/dist/surrender-pending.js +126 -0
  44. package/dist/tools/accept-surrender.js +311 -0
  45. package/dist/tools/chat-inbox.js +17 -5
  46. package/dist/tools/chat-read-mark.js +179 -0
  47. package/dist/tools/chat.js +50 -8
  48. package/dist/tools/check-plan.js +1 -0
  49. package/dist/tools/commander-check.js +1 -0
  50. package/dist/tools/end-of-game.js +384 -0
  51. package/dist/tools/game.js +31 -6
  52. package/dist/tools/healthcheck.js +7 -1
  53. package/dist/tools/index.js +24 -8
  54. package/dist/tools/join-game.js +1 -1
  55. package/dist/tools/live-context.js +3 -1
  56. package/dist/tools/map-details.js +88 -0
  57. package/dist/tools/map-stats.js +15 -2
  58. package/dist/tools/map.js +10 -2
  59. package/dist/tools/my-games.js +78 -8
  60. package/dist/tools/notifications.js +484 -0
  61. package/dist/tools/open-games.js +5 -2
  62. package/dist/tools/opponents.js +14 -2
  63. package/dist/tools/past-games.js +94 -0
  64. package/dist/tools/picks.js +15 -2
  65. package/dist/tools/profile-opponents.js +1 -1
  66. package/dist/tools/profile-reads.js +3 -3
  67. package/dist/tools/push.js +72 -12
  68. package/dist/tools/session.js +50 -18
  69. package/dist/tools/sign-in.js +56 -0
  70. package/dist/tools/strategy.js +65 -8
  71. package/dist/tools/stress-opponents.js +1 -1
  72. package/dist/tools/surrender-pending.js +74 -0
  73. package/dist/tools/surrender.js +10 -3
  74. package/dist/tools/team-brief.js +1 -1
  75. package/dist/tools/team.js +2 -6
  76. package/dist/tools/turn.js +79 -15
  77. package/dist/tools/where.js +42 -17
  78. package/dist/tools/write-kit.js +16 -3
  79. package/dist/trend.js +145 -20
  80. package/dist/version.js +1 -1
  81. package/docs/examples/warapp-auth-flow.json +31 -0
  82. package/manifest.json +22 -2
  83. package/mint.yaml +44 -22
  84. package/package.json +3 -2
  85. package/server.json +2 -2
  86. package/skills/warapp-mcp/SKILL.md +141 -14
@@ -12,6 +12,7 @@ import { gameIdArg, graphOf, namer, readAnnotations, respond, round2, untrustedD
12
12
  import { lookupMeta } from './hints.js';
13
13
  import { loadLiveGame } from './live-context.js';
14
14
  import { BRIDGE_NOTE, playerArg, resolveMe } from './live.js';
15
+ import { dealtMode, modeStarts } from './map-details.js';
15
16
  import { mapOf } from './map.js';
16
17
  import { recordProfile } from './profile-hook.js';
17
18
  import { boardHistory, currentTurn, plannerSettings, requireTurnPhase } from './turn.js';
@@ -43,15 +44,28 @@ export async function keepPickable(ctx, game, pickable, neutrals) {
43
44
  }
44
45
  /**
45
46
  * Where a player could have started, and how the candidates weigh: the pickable territories kept
46
- * during distribution, else (statistics on) every territory a player started on in the finished
47
- * games cached for the map; the prior counts those starts, plus one, when statistics are on and
48
- * some game is cached. Only files this server already wrote are read.
47
+ * during distribution; else, in a game that dealt its starts automatically from a map distribution
48
+ * mode, that mode's territories (#328: read once from war.app's map details and kept with the map);
49
+ * else (statistics on) every territory a player started on in the finished games cached for the map.
50
+ * The prior counts those starts, plus one, when statistics are on and some game is cached. Only files
51
+ * this server already wrote are read, and war.app only for the map details. `warnings` says when the
52
+ * mode's territories are unknown. Never throws on the map details.
49
53
  */
50
54
  async function startKnowledge(ctx, env, game, map, me) {
51
- if (!ctx.dataDir)
52
- return {};
53
55
  const onMap = new Set(map.territories.map((t) => t.id));
54
- const kept = (await readPickRecord(ctx.dataDir, game.id, me))?.pickable?.filter((t) => onMap.has(t)) ?? [];
56
+ const kept = ctx.dataDir ? ((await readPickRecord(ctx.dataDir, game.id, me))?.pickable?.filter((t) => onMap.has(t)) ?? []) : [];
57
+ const warnings = [];
58
+ let candidates = kept.length ? { territories: kept, source: 'pickable' } : undefined;
59
+ const dealt = candidates ? undefined : dealtMode(game.settings, map);
60
+ if (dealt) {
61
+ const read = await modeStarts(ctx, map, dealt.id);
62
+ if (read.territories)
63
+ candidates = { territories: read.territories, source: 'distribution-mode', mode: dealt.id };
64
+ else
65
+ warnings.push(...read.warnings);
66
+ }
67
+ if (!ctx.dataDir)
68
+ return { ...(candidates ? { candidates } : {}), warnings };
55
69
  const records = statsGate(env).enabled ? await cachedRecords(ctx.dataDir, map.id) : [];
56
70
  /** Territory → the players who started on it, over the cached games. */
57
71
  const started = new Map();
@@ -60,15 +74,11 @@ async function startKnowledge(ctx, env, game, map, me) {
60
74
  for (const t of new Set(p.starts))
61
75
  if (onMap.has(t))
62
76
  started.set(t, (started.get(t) ?? 0) + 1);
63
- const candidates = kept.length
64
- ? { territories: kept, source: 'pickable' }
65
- : started.size
66
- ? { territories: [...started.keys()].sort((a, b) => a - b), source: 'statistics' }
67
- : undefined;
77
+ candidates ??= started.size ? { territories: [...started.keys()].sort((a, b) => a - b), source: 'statistics' } : undefined;
68
78
  if (!candidates)
69
- return {};
79
+ return { warnings };
70
80
  if (!records.length)
71
- return { candidates };
81
+ return { candidates, warnings };
72
82
  return {
73
83
  candidates,
74
84
  prior: {
@@ -78,6 +88,7 @@ async function startKnowledge(ctx, env, game, map, me) {
78
88
  sample: records.length,
79
89
  weak: records.length < MIN_SAMPLE,
80
90
  },
91
+ warnings,
81
92
  };
82
93
  }
83
94
  export function registerWhereTool(server, ctx, deps = {}) {
@@ -102,14 +113,16 @@ export function registerWhereTool(server, ctx, deps = {}) {
102
113
  'them as guesses, and `seen` as what is known. The model assumes one capture per turn along a path, pooled ' +
103
114
  'armies when it grows a start, that a start is never abandoned, and ignores cards (the full view lists its ' +
104
115
  'assumptions). The start candidates are the territories the live board showed as pickable, kept by ' +
105
- 'warapp_plan_picks and by warapp_submit_picks; with none kept and no statistics, no start is guessed ' +
106
- '(`starts.source` is "none") and the rest works from what was seen. The start prior is uniform, unless the ' +
116
+ 'warapp_plan_picks and by warapp_submit_picks; in a game that dealt its starts automatically from a map ' +
117
+ 'distribution mode, that mode\'s territories (`starts.source` "distribution-mode"; read once from war.app\'s ' +
118
+ 'map details and kept with the map, and `warnings` says when they are unknown; `startCandidates` names the source, the count and the mode by id and name); with neither and no ' +
119
+ 'statistics, no start is guessed (`starts.source` is "none") and the rest works from what was seen. The start prior is uniform, unless the ' +
107
120
  `server runs locally with ${STATS_ENV}=1: then each candidate weighs by how often players started on it in the ` +
108
121
  'finished games warapp_map_stats already cached for the map (the sample is reported, and called weak under ' +
109
122
  `${MIN_SAMPLE} games), and with no pickable territories kept those starts are the candidates. It reads only boards ` +
110
123
  `this server already saw (the last ${CACHED_TURNS} turns warapp_plan_turn, warapp_track_opponents and this tool cached, ` +
111
124
  'or the game history when war.app sends it) plus those files: no war.app request beyond the live board and ' +
112
- `the game feed warapp_track_opponents reads. Refuses outside a turn phase. ${BRIDGE_NOTE} Read-only on war.app; it ` +
125
+ `the game feed warapp_track_opponents reads, and the map details once per map for a mode's territories. Refuses outside a turn phase. ${BRIDGE_NOTE} Read-only on war.app; it ` +
113
126
  'caches the board it read. warapp_plan_turn does not use these guesses yet.'),
114
127
  _meta: lookupMeta(['where is my opponent', 'locate opponents', 'where did they start', 'what is my opponent doing', 'what should i prepare for']),
115
128
  annotations: readAnnotations('Locate war.app opponents'),
@@ -142,7 +155,7 @@ export function registerWhereTool(server, ctx, deps = {}) {
142
155
  const proven = new Map();
143
156
  if (award?.opponent && award.reading.opponentStarts.length)
144
157
  proven.set(award.opponent.id, award.reading.opponentStarts);
145
- const { candidates, prior } = await startKnowledge(ctx, deps.env, game, map, me.id);
158
+ const { candidates, prior, warnings: startWarnings } = await startKnowledge(ctx, deps.env, game, map, me.id);
146
159
  const s = game.settings;
147
160
  const whereSettings = {
148
161
  ...settings,
@@ -268,6 +281,18 @@ export function registerWhereTool(server, ctx, deps = {}) {
268
281
  turns: boards.map((b) => b.turn).sort((a, b) => a - b),
269
282
  opponents: result.opponents.map(opponentView),
270
283
  prepare: result.prepare.map(prepareView),
284
+ // #328: where the start candidates came from, and the distribution mode that dealt them, by id and name.
285
+ startCandidates: candidates
286
+ ? {
287
+ source: candidates.source,
288
+ count: candidates.territories.length,
289
+ ...(candidates.mode !== undefined
290
+ ? { mode: { id: candidates.mode, name: map.distributionModes.find((d) => d.id === candidates.mode)?.name ?? null } }
291
+ : {}),
292
+ }
293
+ : { source: 'none', count: 0 },
294
+ // #328: the distribution mode's territories could not be had (they are no start candidates then).
295
+ ...(startWarnings.length ? { warnings: startWarnings } : {}),
271
296
  ...(full ? { assumptions: result.assumptions } : {}),
272
297
  };
273
298
  });
@@ -22,25 +22,38 @@
22
22
  // warapp_leave_game left → confirmed; unconfirmed; unknown
23
23
  // warapp_surrender surrendered → confirmed; pending, still_playing → accepted;
24
24
  // unchanged → unconfirmed; unknown
25
+ // warapp_accept_surrender accepted, pending (my acceptance read back, others still owe
26
+ // theirs) → confirmed; unconfirmed; unknown
25
27
  // warapp_uncommit_turn uncommitted → confirmed; unconfirmed; unknown
26
28
  // warapp_submit_turn resolved, committed → confirmed; unknown after a send war.app
27
29
  // accepted (read-back failed or shows nothing yet) → unconfirmed;
28
30
  // unknown (no answer) → unknown
29
31
  // warapp_submit_picks verified → confirmed; unconfirmed; unknown
30
32
  // warapp_send_chat sent → accepted; unknown
33
+ // warapp_dismiss_notification dismissed → confirmed; unconfirmed; unknown
34
+ // warapp_delete_notification deleted → confirmed; unconfirmed (also after a refusal past the
35
+ // first id); unknown
36
+ // warapp_mark_chat_read read → confirmed; unconfirmed; unknown
31
37
  // warapp_link_session linked → confirmed
32
38
  import { defineWrite, McpToolError, registerWrite, } from '@chrischall/mcp-utils';
33
39
  import { notSent, WarappServerError } from '../protocol/rpc.js';
34
40
  import { respond, untrustedText } from './common.js';
35
41
  import { withToolConfig } from './hints.js';
42
+ import { HOST_SIGN_IN_ADVICE } from '../direct/transport.js';
36
43
  import { failureText } from './live-context.js';
37
44
  import { resolvePlayer } from './resolve.js';
38
45
  /** Refuse a write (or a read) before anything is sent. */
39
46
  export function refuse(message, hint) {
40
47
  throw new McpToolError(message, { kind: 'unknown', hint });
41
48
  }
42
- /** The hint when the signed-in account cannot be told: linking a session is suggested only locally. */
43
- function signedInHint(hosted) {
49
+ /**
50
+ * The hint when the signed-in account cannot be told: linking a session is suggested only locally, and a
51
+ * hosted connection mcp-host signed in to war.app is pointed at its "Sign in" (a paired tab meanwhile).
52
+ */
53
+ function signedInHint(view) {
54
+ const { hosted, hostSignIn } = typeof view === 'object' ? view : { hosted: view, hostSignIn: false };
55
+ if (hosted && hostSignIn)
56
+ return `${HOST_SIGN_IN_ADVICE} Then retry.`;
44
57
  return hosted
45
58
  ? 'Make sure a war.app tab signed in to your account is open and paired (reload or focus it if it is frozen), then retry.'
46
59
  : 'Make sure a war.app tab signed in to your account is open and paired (reload or focus it if it is frozen), or link ' +
@@ -61,7 +74,7 @@ export function accountUnknown(hosted, consequence = 'nothing was sent') {
61
74
  export async function requireMe(ctx, opts = {}) {
62
75
  const token = await ctx.myInviteToken({ fresh: opts.fresh ?? true });
63
76
  if (token === undefined)
64
- throw accountUnknown(ctx.hosted, opts.consequence);
77
+ throw accountUnknown(ctx, opts.consequence);
65
78
  return token;
66
79
  }
67
80
  /** The seat of account `token` in `game`; refused when it holds none. */
package/dist/trend.js CHANGED
@@ -29,6 +29,10 @@ import { asInt } from './scalars.js';
29
29
  const isRec = (v) => typeof v === 'object' && v !== null && !Array.isArray(v);
30
30
  const STANDING_KEYS = ['standing', 'standings', 'latestStanding', 'Standing'];
31
31
  const NUMBER_KEYS = ['turnNumber', 'turn', 'number', 'TurnNumber'];
32
+ /** Keys that wrap a history's turns (#302: GameFeed's spelling is unverified). */
33
+ const WRAPPER_KEYS = ['turns', 'Turns', 'history', 'History', 'standings', 'Standings'];
34
+ const DISTRIBUTION_KEYS = ['distributionStanding', 'DistributionStanding'];
35
+ const STANDING_KEY = /^standing_?(\d+)$/i;
32
36
  function standingOf(entry) {
33
37
  if (!isRec(entry))
34
38
  return entry;
@@ -37,41 +41,117 @@ function standingOf(entry) {
37
41
  return entry[k];
38
42
  return entry;
39
43
  }
40
- /** History entries as (completed turns, raw standing), in any of the plausible layouts. */
41
- function entriesOf(history, out = []) {
44
+ /** Whether a raw standing shows any territory held by a player (a pre-pick board shows none). */
45
+ const playerLand = (raw) => boardFromStanding(standingOf(raw))?.territories.some((t) => t.owner.kind === 'player') ?? false;
46
+ const ORDER_LIST_KEYS = ['orders', 'Orders'];
47
+ const ORDER_TYPE_KEYS = ['type', 'Type', 'orderType', 'OrderType'];
48
+ /**
49
+ * Whether a history entry carries a turn's orders rather than a standing: a record with an `orders`
50
+ * list and no standing key, or a list whose records name an order type (`type` / `orderType`).
51
+ */
52
+ function carriesOrders(entry) {
53
+ if (Array.isArray(entry))
54
+ return entry.some((e) => isRec(e) && ORDER_TYPE_KEYS.some((k) => typeof e[k] === 'string'));
55
+ if (!isRec(entry))
56
+ return false;
57
+ return ORDER_LIST_KEYS.some((k) => entry[k] !== undefined) && !STANDING_KEYS.some((k) => entry[k] !== undefined);
58
+ }
59
+ /** History entries in any of the plausible layouts (#302). Throws only on a hostile getter (callers catch). */
60
+ function parseHistory(history, opts = {}) {
61
+ if (typeof history === 'string') {
62
+ let parsed;
63
+ try {
64
+ parsed = JSON.parse(history);
65
+ }
66
+ catch {
67
+ return { entries: [], layout: 'none', shape: 'string' };
68
+ }
69
+ const inner = parseHistory(parsed, opts);
70
+ return { ...inner, layout: `json>${inner.layout}` };
71
+ }
42
72
  if (Array.isArray(history)) {
43
- history.forEach((e, i) => {
73
+ const entries = history.map((e, i) => {
44
74
  let n;
45
75
  if (isRec(e))
46
76
  for (const k of NUMBER_KEYS)
47
77
  n ??= asInt(e[k]);
48
- out.push([n ?? i, standingOf(e)]);
78
+ return [n ?? i, standingOf(e)];
49
79
  });
50
- return out;
80
+ return { entries, layout: 'array', shape: 'array' };
51
81
  }
52
82
  if (!isRec(history))
53
- return out;
54
- const turns = history.turns ?? history.Turns;
55
- if (turns !== undefined)
56
- return entriesOf(turns, out);
83
+ return { entries: [], layout: 'none', shape: history === null ? 'null' : typeof history };
84
+ for (const k of WRAPPER_KEYS) {
85
+ const v = history[k];
86
+ if (v === undefined)
87
+ continue;
88
+ const inner = parseHistory(v, opts);
89
+ return { ...inner, layout: `wrapper:${k}>${inner.layout}`, shape: 'object' };
90
+ }
91
+ let dist;
92
+ for (const k of DISTRIBUTION_KEYS)
93
+ dist ??= history[k];
94
+ const standings = [];
57
95
  for (const [k, v] of Object.entries(history)) {
58
- const m = /^(?:turn|standing)?_?(\d+)$/i.exec(k);
96
+ const m = STANDING_KEY.exec(k);
59
97
  if (m)
60
- out.push([Number(m[1]), standingOf(v)]);
98
+ standings.push([Number(m[1]), standingOf(v)]);
61
99
  }
62
- return out;
100
+ if (standings.length) {
101
+ // Top-level `standing<N>` keys (#302), `turn<N>` beside them being orders: is standing0 the
102
+ // start, or the board after the first turn? UNVERIFIED. A distribution standing beside them
103
+ // decides: one on which no player holds land is the board before picks, so standing0 is the
104
+ // start (the board after picks); one with player land is the start itself, so standing0 is one
105
+ // turn on. Without one, the game's completed turns decide when the last N reaches them or
106
+ // falls one short.
107
+ const last = Math.max(...standings.map(([n]) => n));
108
+ const t = opts.numberOfTurns;
109
+ const offset = dist !== undefined
110
+ ? playerLand(dist)
111
+ ? 1
112
+ : 0
113
+ : t !== undefined && last === t - 1
114
+ ? 1
115
+ : 0;
116
+ const entries = standings.map(([n, v]) => [n + offset, v]);
117
+ if (dist !== undefined && !entries.some(([n]) => n === 0))
118
+ entries.push([0, standingOf(dist)]);
119
+ return {
120
+ entries,
121
+ layout: `standing-keys${offset ? '+1' : ''}${dist !== undefined ? '+distribution' : ''}`,
122
+ shape: 'object',
123
+ };
124
+ }
125
+ // Turn-numbered keys (`turn<N>` / `<N>`): an entry that carries orders is never a board (the
126
+ // Warlight-era `turn<N>` is the turn's orders). A distribution standing is entry 0 only when a
127
+ // player holds land on it: a land-free one is the board before picks, never turn 1's previous board.
128
+ const entries = [];
129
+ for (const [k, v] of Object.entries(history)) {
130
+ const m = /^(?:turn)?_?(\d+)$/i.exec(k);
131
+ if (m && !carriesOrders(v))
132
+ entries.push([Number(m[1]), standingOf(v)]);
133
+ }
134
+ if (dist !== undefined && playerLand(dist) && !entries.some(([n]) => n === 0))
135
+ entries.push([0, standingOf(dist)]);
136
+ return { entries, layout: 'numbered-keys', shape: 'object' };
63
137
  }
64
138
  /**
65
139
  * The standing after `completedTurns` turns from a raw `GetHistory` payload,
66
140
  * with owners keyed by GameFeed player id; `undefined` when it is absent or
67
141
  * unusable. An entry's number is read as the count of completed turns its
68
- * standing reflects (an assumption: the in-progress shape is unverified).
69
- * Never throws.
142
+ * standing reflects (an assumption: the shape is unverified, #302). The first
143
+ * entry of that number that parses wins. Never throws.
70
144
  */
71
- export function boardFromHistory(history, completedTurns, players) {
145
+ export function boardFromHistory(history, completedTurns, players, opts = {}) {
72
146
  try {
73
- const raw = entriesOf(history).find(([n]) => n === completedTurns)?.[1];
74
- return feedOwners(boardFromStanding(raw), players);
147
+ for (const [n, raw] of parseHistory(history, opts).entries) {
148
+ if (n !== completedTurns)
149
+ continue;
150
+ const board = feedOwners(boardFromStanding(raw), players);
151
+ if (board)
152
+ return board;
153
+ }
154
+ return undefined;
75
155
  }
76
156
  catch {
77
157
  return undefined;
@@ -97,13 +177,13 @@ function feedOwners(board, players) {
97
177
  * Every usable standing in a raw `GetHistory` payload, ascending by entry
98
178
  * number (completed turns, as {@link boardFromHistory} reads it), owners keyed
99
179
  * by GameFeed player id. Entries that do not parse are left out; the first of
100
- * two entries with one number wins. Never throws.
180
+ * two entries with one number that parses wins. Never throws.
101
181
  */
102
- export function historyBoards(history, players) {
182
+ export function historyBoards(history, players, opts = {}) {
103
183
  try {
104
184
  const seen = new Set();
105
185
  const out = [];
106
- for (const [turn, raw] of entriesOf(history)) {
186
+ for (const [turn, raw] of parseHistory(history, opts).entries) {
107
187
  if (seen.has(turn))
108
188
  continue;
109
189
  const board = feedOwners(boardFromStanding(raw), players);
@@ -118,6 +198,51 @@ export function historyBoards(history, players) {
118
198
  return [];
119
199
  }
120
200
  }
201
+ /** At most this many key names go into a report (#302). */
202
+ const MAX_REPORTED_KEYS = 40;
203
+ /** A key name that may be reported: an identifier, never free text. */
204
+ const SAFE_KEY = /^[A-Za-z][A-Za-z0-9_]{0,39}$/;
205
+ /** The key names of a reply or entry worth reporting: identifiers only, capped (#302). */
206
+ export function safeKeys(keys) {
207
+ return keys.filter((k) => SAFE_KEY.test(k)).slice(0, MAX_REPORTED_KEYS);
208
+ }
209
+ /**
210
+ * Whether a game's history reads, and if not why (#302): one live call then shows GameFeed's real
211
+ * shape. `needPlayerLand` (map statistics) also asks that some board shows a player of the game
212
+ * holding land. Name-free; never throws.
213
+ */
214
+ export function historyReport(game, opts = {}) {
215
+ const keys = safeKeys(game.feedKeys ?? []);
216
+ if (game.history === undefined)
217
+ return { unreadable: { reason: 'absent', keys } };
218
+ let parsed;
219
+ try {
220
+ parsed = parseHistory(game.history, game.numberOfTurns !== undefined ? { numberOfTurns: game.numberOfTurns } : {});
221
+ }
222
+ catch {
223
+ parsed = { entries: [], layout: 'none', shape: 'object' };
224
+ }
225
+ const { entries, shape, layout } = parsed;
226
+ if (shape === 'string')
227
+ return { unreadable: { reason: 'not-json', keys, shape } };
228
+ if (!entries.length) {
229
+ const own = isRec(game.history) ? { historyKeys: safeKeys(Object.keys(game.history)) } : {};
230
+ return { unreadable: { reason: 'no-turns', keys, shape, ...own } };
231
+ }
232
+ const boards = historyBoards(game.history, game.players, game.numberOfTurns !== undefined ? { numberOfTurns: game.numberOfTurns } : {});
233
+ if (!boards.length) {
234
+ const first = entries[0][1];
235
+ const entryKeys = isRec(first) ? { entryKeys: safeKeys(Object.keys(first)) } : {};
236
+ return { unreadable: { reason: 'no-standing', keys, shape, turns: entries.length, ...entryKeys } };
237
+ }
238
+ if (opts.needPlayerLand) {
239
+ const ids = new Set(game.players.map((p) => p.id));
240
+ const land = boards.some(({ board }) => board.territories.some((t) => t.owner.kind === 'player' && ids.has(t.owner.playerId)));
241
+ if (!land)
242
+ return { unreadable: { reason: 'no-player-land', keys, shape, turns: boards.length } };
243
+ }
244
+ return { read: { turns: boards.length, first: boards[0].turn, last: boards[boards.length - 1].turn, layout } };
245
+ }
121
246
  /** Where the last planned boards of a game are cached. */
122
247
  export const boardCachePath = (dir, gameId) => join(dir, 'boards', `${gameId}.json`);
123
248
  /**
package/dist/version.js CHANGED
@@ -1,4 +1,4 @@
1
1
  // Single source of truth for the server version. release-please bumps the
2
2
  // literal on the marked line (registered in release-please-config.json
3
3
  // extra-files); every other module imports VERSION from here.
4
- export const VERSION = '0.1.0'; // x-release-please-version
4
+ export const VERSION = '0.3.0'; // x-release-please-version
@@ -0,0 +1,31 @@
1
+ {
2
+ "steps": [
3
+ {
4
+ "tool": "warapp_session_status",
5
+ "args": {},
6
+ "prompt": [
7
+ {
8
+ "name": "password",
9
+ "label": "war.app password",
10
+ "type": "password",
11
+ "help": "Used once to sign in, never stored: it goes to war.app once, with the war.app email you gave above, and only the session war.app gives back is kept. If it stops working (a changed password, say), use Sign in on this connection again, or reconnect it."
12
+ }
13
+ ],
14
+ "title": "Sign in to war.app",
15
+ "description": "This lets the connector reach war.app directly, without your browser. Connecting needs this sign-in to succeed: if war.app refuses it (a wrong password, a bot check, an outage, or an account that signs in only through Facebook), the connection is not made. Your password is sent to war.app once, with your war.app email, and then discarded; what is kept is the session war.app gives back, a full-account credential stored as your own secret on this connection. A refused sign-in is not retried for you, because war.app may count failed attempts."
16
+ }
17
+ ],
18
+ "capture": {
19
+ "tool": "warapp_sign_in",
20
+ "args": {
21
+ "email": {
22
+ "from": "WARAPP_EMAIL"
23
+ },
24
+ "password": {
25
+ "from": "password"
26
+ }
27
+ },
28
+ "path": "authToken",
29
+ "into": "WARAPP_AUTH_TOKEN"
30
+ }
31
+ }
package/manifest.json CHANGED
@@ -3,8 +3,8 @@
3
3
  "manifest_version": "0.3",
4
4
  "name": "warapp-mcp",
5
5
  "display_name": "war.app (Warzone)",
6
- "version": "0.1.0",
7
- "description": "war.app (Warzone) game advisor for Claude — your games, maps, bonuses, board analysis and routes via the GameFeed API, plus your games list (waiting on you first), opponent scouting with your head-to-head, the live board, territory picks, cards, turn planning and submission, turn notifications, and chat through your signed-in war.app tab (ContextMint Bridge). Joining, leaving or surrendering a game, Begin on a speed first turn, picks, turn orders, withdrawing them, chat sends and linking a session (local only) are confirm-gated.",
6
+ "version": "0.3.0",
7
+ "description": "war.app (Warzone) game advisor for Claude — your games, maps, bonuses, board analysis and routes via the GameFeed API, plus your games list (waiting on you first), opponent scouting with your head-to-head, the live board, territory picks, cards, turn planning and submission, turn notifications, and chat through your signed-in war.app tab (ContextMint Bridge). Joining, leaving or surrendering a game, accepting another player's surrender, Begin on a speed first turn, picks, turn orders, withdrawing them, chat sends, marking notifications and chat read, deleting notifications and linking a session (local only) are confirm-gated.",
8
8
  "author": {
9
9
  "name": "Chris Hall",
10
10
  "email": "chris.c.hall@gmail.com",
@@ -119,6 +119,10 @@
119
119
  "name": "warapp_surrender",
120
120
  "description": "Surrender a war.app game you are playing, or take back a pending surrender (confirm-gated)"
121
121
  },
122
+ {
123
+ "name": "warapp_accept_surrender",
124
+ "description": "Accept another player's pending surrender in a war.app game, after a preview of what it does (confirm-gated)"
125
+ },
122
126
  {
123
127
  "name": "warapp_begin_turn",
124
128
  "description": "Press Begin in a speed-first-turn game to reveal the board and start your turn timer (confirm-gated)"
@@ -203,6 +207,22 @@
203
207
  "name": "warapp_chat_inbox",
204
208
  "description": "Read the unseen chat across all your games in one call"
205
209
  },
210
+ {
211
+ "name": "warapp_get_notifications",
212
+ "description": "List your war.app in-app notifications by id, kind and game (read-only)"
213
+ },
214
+ {
215
+ "name": "warapp_dismiss_notification",
216
+ "description": "Mark war.app notifications read by id (confirm-gated)"
217
+ },
218
+ {
219
+ "name": "warapp_delete_notification",
220
+ "description": "Delete war.app notifications by id, for good (confirm-gated)"
221
+ },
222
+ {
223
+ "name": "warapp_mark_chat_read",
224
+ "description": "Mark a game's chat read on war.app itself (confirm-gated)"
225
+ },
206
226
  {
207
227
  "name": "warapp_get_team",
208
228
  "description": "Read your team in a team game: teammates (human or AI, committed or not, visible income, entered orders or picks), the team hand and unread team chat"
package/mint.yaml CHANGED
@@ -10,23 +10,32 @@ slug: warapp
10
10
  # `bridgePortEnv: WARAPP_WS_PORT` (with a runtime that supports a bridge) —
11
11
  # registration fields this manifest has no schema for.
12
12
  #
13
- # Direct transport is LOCAL-ONLY. A local install can link the signed-in
14
- # war.app session (warapp_link_session) and then talk to war.app directly
15
- # without a browser (WARAPP_TRANSPORT=auto/direct). That stores a full-account
16
- # AuthToken on the machine, so hosting never uses it: a hosted child keeps the
17
- # browser bridge above and stores no session token — enforced in code
18
- # (src/hosted.ts): when hosted, warapp_link_session is not registered, the
19
- # session store reads as empty and the transport is pinned to the bridge.
20
- # Nothing in this manifest enables direct mode.
13
+ # Direct transport. A local install can link the signed-in war.app session
14
+ # (warapp_link_session, stored on that machine) and then talk to war.app
15
+ # directly without a browser (WARAPP_TRANSPORT=auto/direct). A hosted child
16
+ # never stores a session and never registers warapp_link_session (src/hosted.ts):
17
+ # it rides the direct leg only from the session captured at sign-in — the
18
+ # AuthToken mcp-host's authFlow (`auth.flow` below) captures into the per-user
19
+ # secret WARAPP_AUTH_TOKEN (#333: the war.app password is asked once and never
20
+ # stored; the token is held in memory) — with the bridge above as its fallback
21
+ # on the same registration. Without that token it is pinned to the bridge, as
22
+ # before. THE TRADE-OFF: once the registration carries the flow, every NEW
23
+ # connection needs one successful war.app password sign-in. mcp-host ends the
24
+ # login with no grant on any warapp_sign_in refusal — a captcha, an outage or
25
+ # a network fault as well as a wrong password — and may clear the fields
26
+ # already entered; an account with no war.app password (Facebook sign-in)
27
+ # cannot connect. The bridge is the fallback only for connections made before
28
+ # the flow was added and for a session that expires later. Adding the flow is
29
+ # the owner's decision (docs/PLAN-DIRECT.md, "Registration change", step 2). The flow is docs/examples/warapp-auth-flow.json (shipped in the npm
30
+ # package): one masked password prompt, then warapp_sign_in with WARAPP_EMAIL
31
+ # and that password as the capture, path authToken into WARAPP_AUTH_TOKEN.
32
+ # WARAPP_AUTH_TOKEN is deliberately not in `env`: a capture into a host-set
33
+ # variable is refused.
21
34
  summary: >-
22
- war.app (Warzone) game advisor — your games, players and settings, map
23
- bonuses and chokepoints, board analysis and route planning through war.app's
24
- GameFeed API, plus the games waiting on you, opponent scouting (their record and
25
- your head-to-head), the live board, territory picks, turn planning and game chat
26
- through your signed-in war.app tab, with card plays and a wait for your turn on
27
- war.app's push notifications. Joining, leaving or surrendering a game, Begin on a
28
- speed first turn, picks, turn orders, withdrawing them and chat messages are sent only
29
- after you confirm.
35
+ war.app (Warzone) advisor: games waiting on you, maps, scouting, chat and
36
+ turn plans in your war.app tab. Joining, leaving or surrendering games,
37
+ accepting surrenders, Begin, picks, turn orders and withdrawals, chat sends,
38
+ chat read and notification marks and deletes happen only after you confirm.
30
39
  examples:
31
40
  - prompt: Which of my war.app games are waiting on me?
32
41
  note: Lists your games through your war.app tab, the ones waiting on you first.
@@ -46,10 +55,11 @@ identity:
46
55
  perUserChild: true
47
56
 
48
57
  auth:
49
- # Collected once on the connector's authorize page. There is no `flow`:
50
- # GameFeed takes the email + token on every request (form body), with no
51
- # login exchange, MFA or session to mint. Every auth field is stored as a
52
- # per-user secret (the field schema has no separate `secret` flag).
58
+ # Collected once on the connector's authorize page: GameFeed takes the email
59
+ # + token on every request (form body), with no login exchange. Every auth
60
+ # field is stored as a per-user secret (the field schema has no separate
61
+ # `secret` flag). The `flow` then signs in to war.app once for the direct
62
+ # transport (see the header): a path inside the package, read at the pin.
53
63
  fields:
54
64
  - name: WARAPP_EMAIL
55
65
  label: war.app email
@@ -64,6 +74,7 @@ auth:
64
74
  Your API token, shown at https://war.app/API/GetAPIToken while signed
65
75
  in to war.app. Stored as a per-user secret and never shown again.
66
76
  Changing your war.app password rotates it — reconnect with the new one.
77
+ flow: docs/examples/warapp-auth-flow.json
67
78
 
68
79
  # WARAPP_EMAIL / WARAPP_API_TOKEN are collected per user above, and an auth
69
80
  # field may not name a host-set variable, so they are not in `env`. Set them in
@@ -86,7 +97,9 @@ env:
86
97
  help: >-
87
98
  How the live-game tools reach war.app on a LOCAL install: auto (default —
88
99
  the chrome-less direct transport when a session is linked, else the
89
- browser bridge), direct, or fetchproxy. A hosted child keeps the bridge.
100
+ browser bridge), direct, or fetchproxy. A hosted child keeps the bridge
101
+ unless mcp-host captured a war.app session at sign-in (WARAPP_AUTH_TOKEN);
102
+ then it reads this as a local install does.
90
103
  - name: WARAPP_PLAYER_RECORD
91
104
  required: false
92
105
  help: >-
@@ -121,7 +134,16 @@ state:
121
134
  WARAPP_PLAYER_RECORD=off switches it off), and the opponent profile turns
122
135
  ($MCP_DATA_DIR/profiles/games: gameplay counts per game, owner decision P4,
123
136
  on hosted as well, folded when a game finishes into the name-free
124
- profiles/players.json and population.json, keyed by the same salt; WARAPP_PLAYER_PROFILE=off switches it off). GameFeed maps are kept at
137
+ profiles/players.json and population.json, keyed by the same salt; WARAPP_PLAYER_PROFILE=off switches it off), and the
138
+ end-of-game records ($MCP_DATA_DIR/finished: once per finished game the
139
+ account played, its history read once and kept name-free under the same
140
+ salt, its boards and final outlook line included, at most 500, and a lasting hashed mark per game in
141
+ finished/processed.json (5000 keys) so a game is never read twice; a read whose record cannot be
142
+ written is remembered in-process and not repeated; each captured history is
143
+ then folded into the profiles, the per-map record at
144
+ $MCP_DATA_DIR/maps-record/<mapId>.json and the lessons at
145
+ $MCP_DATA_DIR/lessons.json, both name-free and bounded, read back only to be
146
+ reported beside the picks, plans and tracks, never planned on). GameFeed maps are kept at
125
147
  $MCP_DATA_DIR/maps/<mapId>.json (public map data, base bonus values, at most
126
148
  40, re-downloaded after 30 days) with maps/games.json naming each game's map,
127
149
  so a known game is not downloaded with its map again after a cold start; and
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@chrischall/warapp-mcp",
3
- "version": "0.1.0",
3
+ "version": "0.3.0",
4
4
  "mcpName": "io.github.chrischall/warapp-mcp",
5
5
  "description": "war.app (Warzone) game advisor MCP server for Claude — games, maps, bonuses and board analysis via the GameFeed API, plus your games list, opponent scouting, the live board, territory picks, cards, turn planning and submission, turn notifications and chat through your signed-in war.app tab. Developed and maintained by AI (Claude Code).",
6
6
  "author": "Claude Code (AI) <https://www.anthropic.com/claude>",
@@ -33,7 +33,8 @@
33
33
  "server.json",
34
34
  "manifest.json",
35
35
  "skills",
36
- "mint.yaml"
36
+ "mint.yaml",
37
+ "docs/examples/warapp-auth-flow.json"
37
38
  ],
38
39
  "scripts": {
39
40
  "build": "tsc && npm run bundle",
package/server.json CHANGED
@@ -6,12 +6,12 @@
6
6
  "url": "https://github.com/chrischall/warapp-mcp",
7
7
  "source": "github"
8
8
  },
9
- "version": "0.1.0",
9
+ "version": "0.3.0",
10
10
  "packages": [
11
11
  {
12
12
  "registryType": "npm",
13
13
  "identifier": "@chrischall/warapp-mcp",
14
- "version": "0.1.0",
14
+ "version": "0.3.0",
15
15
  "transport": {
16
16
  "type": "stdio"
17
17
  },