@chrischall/warapp-mcp 0.3.1 → 0.5.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.
- package/.claude-plugin/marketplace.json +2 -2
- package/.claude-plugin/plugin.json +1 -1
- package/README.md +4 -0
- package/dist/bundle.js +1312 -573
- package/dist/chat.js +11 -3
- package/dist/direct/transport.js +153 -11
- package/dist/my-games.js +1 -1
- package/dist/protocol/bundle.js +283 -20
- package/dist/protocol/codec.js +1 -1
- package/dist/protocol/dialect.js +371 -0
- package/dist/protocol/interp.js +143 -66
- package/dist/protocol/methods.js +35 -29
- package/dist/protocol/rpc.js +45 -4
- package/dist/push/socketio.js +2 -2
- package/dist/surrender-pending.js +4 -4
- package/dist/tools/begin-turn.js +3 -5
- package/dist/tools/chat-inbox.js +32 -3
- package/dist/tools/chat-read-mark.js +3 -1
- package/dist/tools/check-plan.js +3 -1
- package/dist/tools/healthcheck.js +64 -8
- package/dist/tools/index.js +2 -1
- package/dist/tools/live-context.js +71 -6
- package/dist/tools/my-games.js +10 -3
- package/dist/tools/notifications.js +2 -2
- package/dist/tools/push.js +2 -1
- package/dist/tools/session.js +20 -4
- package/dist/tools/surrender-pending.js +11 -6
- package/dist/tools/turn.js +9 -1
- package/dist/version.js +1 -1
- package/manifest.json +1 -1
- package/package.json +1 -1
- package/server.json +2 -2
package/dist/protocol/methods.js
CHANGED
|
@@ -1,37 +1,39 @@
|
|
|
1
1
|
// war.app web-client method ids (the int32 in every frame header) and the
|
|
2
|
-
// parameter writers this server uses. The
|
|
2
|
+
// parameter writers this server uses. The ids are protocol 243's: 243 inserted six methods
|
|
3
|
+
// (ChangeCommitConfirmation 26, TeamSurrender 70, TournamentGroup 94, UploadSharedImage 129,
|
|
4
|
+
// ChatRoomReactionsChanged 247, SetReaction 285) and renumbered everything after each. The name is also the `m=` query value of
|
|
3
5
|
// https://war.app/Services?m=<name>&js=1.
|
|
4
6
|
export const Method = {
|
|
5
7
|
/** Exists in the client's method table, but the web client never calls it (open games come from a page). */
|
|
6
8
|
GetOpenGames: 10,
|
|
7
|
-
GetGameDetails:
|
|
8
|
-
GameRefresh:
|
|
9
|
-
GetLatestGameInfo:
|
|
10
|
-
SendChat:
|
|
11
|
-
RegisterChatView:
|
|
12
|
-
GetGameSettings:
|
|
13
|
-
GetMyGames:
|
|
14
|
-
AcceptGame:
|
|
15
|
-
AcceptOpenSeat:
|
|
16
|
-
AcceptOpenAutoGame:
|
|
17
|
-
GetOpenAutoGame:
|
|
18
|
-
DeclineGame:
|
|
19
|
-
Surrender:
|
|
20
|
-
AcceptSurrender:
|
|
21
|
-
GetMapDetails:
|
|
22
|
-
SendOrders:
|
|
23
|
-
SendInProgressOrders:
|
|
24
|
-
SendTerritoryPicks:
|
|
25
|
-
SendInProgressPicks:
|
|
26
|
-
BeginFirstTurn:
|
|
27
|
-
GetTerritoryPicks:
|
|
28
|
-
UnCommit:
|
|
29
|
-
GetTurns:
|
|
30
|
-
Subscribe:
|
|
31
|
-
GameUpdated:
|
|
32
|
-
GetInAppNotifications:
|
|
33
|
-
DeleteInAppNotification:
|
|
34
|
-
AcknowledgeInAppNotifications:
|
|
9
|
+
GetGameDetails: 39,
|
|
10
|
+
GameRefresh: 40,
|
|
11
|
+
GetLatestGameInfo: 41,
|
|
12
|
+
SendChat: 43,
|
|
13
|
+
RegisterChatView: 44,
|
|
14
|
+
GetGameSettings: 49,
|
|
15
|
+
GetMyGames: 51,
|
|
16
|
+
AcceptGame: 61,
|
|
17
|
+
AcceptOpenSeat: 62,
|
|
18
|
+
AcceptOpenAutoGame: 63,
|
|
19
|
+
GetOpenAutoGame: 64,
|
|
20
|
+
DeclineGame: 65,
|
|
21
|
+
Surrender: 68,
|
|
22
|
+
AcceptSurrender: 69,
|
|
23
|
+
GetMapDetails: 75,
|
|
24
|
+
SendOrders: 76,
|
|
25
|
+
SendInProgressOrders: 77,
|
|
26
|
+
SendTerritoryPicks: 78,
|
|
27
|
+
SendInProgressPicks: 79,
|
|
28
|
+
BeginFirstTurn: 80,
|
|
29
|
+
GetTerritoryPicks: 81,
|
|
30
|
+
UnCommit: 82,
|
|
31
|
+
GetTurns: 83,
|
|
32
|
+
Subscribe: 242,
|
|
33
|
+
GameUpdated: 245,
|
|
34
|
+
GetInAppNotifications: 323,
|
|
35
|
+
DeleteInAppNotification: 324,
|
|
36
|
+
AcknowledgeInAppNotifications: 325,
|
|
35
37
|
};
|
|
36
38
|
const NAMES = new Map(Object.entries(Method).map(([name, id]) => [id, name]));
|
|
37
39
|
/** The method's name for a known id, or undefined. */
|
|
@@ -271,6 +273,8 @@ export function writeGameRefreshParams(w, p) {
|
|
|
271
273
|
.string(NO_CHAT_MARKER)
|
|
272
274
|
.bool(p.lobby)
|
|
273
275
|
.bool(false)
|
|
276
|
+
.bool(false)
|
|
277
|
+
// Protocol 243 added a last, optional value (a nullable number the client sends as text): absent.
|
|
274
278
|
.bool(false);
|
|
275
279
|
}
|
|
276
280
|
/** A chat read mark: a message id as decimal text, or `-1` (the client's "no mark"). */
|
|
@@ -317,6 +321,8 @@ export function writeSendChatParams(w, p) {
|
|
|
317
321
|
.string(null)
|
|
318
322
|
.string(null)
|
|
319
323
|
.bool(false)
|
|
324
|
+
.bool(false)
|
|
325
|
+
// Protocol 243 added a last, optional list of strings (the shared images a message carries): absent.
|
|
320
326
|
.bool(false);
|
|
321
327
|
}
|
|
322
328
|
// ---------------------------------------------------------------------------
|
package/dist/protocol/rpc.js
CHANGED
|
@@ -8,7 +8,7 @@ import { scrubSecrets } from '../redact.js';
|
|
|
8
8
|
import { decodeReplyEnvelope, encodeRequest, PROTOCOL_VERSION, fromHex, ProtocolError, toHex, } from './codec.js';
|
|
9
9
|
import { Method } from './methods.js';
|
|
10
10
|
/** The client version string the current web client sends. */
|
|
11
|
-
export const CLIENT_VERSION = 'v6.
|
|
11
|
+
export const CLIENT_VERSION = 'v6.08.0.2';
|
|
12
12
|
/** EnumSerialization_Platform: the website. */
|
|
13
13
|
export const PLATFORM_WEBSITE = 15;
|
|
14
14
|
/**
|
|
@@ -32,6 +32,8 @@ export function methodTakesAuth(methodId) {
|
|
|
32
32
|
* 51 (`MustUseCard`, verified live) has no client wording; this is ours.
|
|
33
33
|
*/
|
|
34
34
|
export const SERVER_ERROR_MESSAGES = {
|
|
35
|
+
// AuthFailed (live 2026-11-17): war.app's answer when the request's session is not signed in.
|
|
36
|
+
3: 'war.app refused the request as not signed in (AuthFailed): the war.app session this server uses is signed out.',
|
|
35
37
|
10: 'war.app refused the order sequence — card plays must come in turn-phase order.',
|
|
36
38
|
11: 'Your orders deploy more or fewer armies than you are receiving this turn. Please verify your orders deploy the correct number.',
|
|
37
39
|
51: 'You hold more cards than this game allows, so war.app requires you to play or discard one this turn.',
|
|
@@ -46,12 +48,27 @@ export const SERVER_ERROR_MESSAGES = {
|
|
|
46
48
|
};
|
|
47
49
|
/** The longest slice of an unmapped server message shown to the caller. */
|
|
48
50
|
const MAX_SERVER_MESSAGE = 200;
|
|
51
|
+
/**
|
|
52
|
+
* war.app answered in another protocol version than the one every reader here reads: a reply framed for
|
|
53
|
+
* another version would decode into wrong values, not an error (#131), so it is never decoded.
|
|
54
|
+
*/
|
|
55
|
+
export class ProtocolVersionError extends McpToolError {
|
|
56
|
+
answered;
|
|
57
|
+
name = 'ProtocolVersionError';
|
|
58
|
+
constructor(methodName, answered) {
|
|
59
|
+
super(`war.app answered ${methodName} in protocol version ${answered}; this server reads version ${PROTOCOL_VERSION}.`, {
|
|
60
|
+
kind: 'unknown',
|
|
61
|
+
hint: 'The war.app client may have changed; this server needs an update to read it.',
|
|
62
|
+
});
|
|
63
|
+
this.answered = answered;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
49
66
|
/** A ServerException reply (envelope kind 5). */
|
|
50
67
|
export class WarappServerError extends McpToolError {
|
|
51
68
|
code;
|
|
52
69
|
name = 'WarappServerError';
|
|
53
|
-
constructor(code, message) {
|
|
54
|
-
super(message, { kind: 'unknown' });
|
|
70
|
+
constructor(code, message, hint) {
|
|
71
|
+
super(message, { kind: 'unknown', ...(hint ? { hint } : {}) });
|
|
55
72
|
this.code = code;
|
|
56
73
|
}
|
|
57
74
|
}
|
|
@@ -141,7 +158,7 @@ export class WarappRpc {
|
|
|
141
158
|
if (env.version !== PROTOCOL_VERSION) {
|
|
142
159
|
// Every reader (the bundle's, and methods.ts) reads the layout of PROTOCOL_VERSION: a reply
|
|
143
160
|
// framed for another version would decode into wrong values, not an error (#131).
|
|
144
|
-
throw new
|
|
161
|
+
throw new ProtocolVersionError(methodName, env.version);
|
|
145
162
|
}
|
|
146
163
|
if (env.method !== methodId) {
|
|
147
164
|
throw new McpToolError(`war.app answered ${methodName} (method ${methodId}) with method ${env.method}.`, {
|
|
@@ -185,7 +202,31 @@ export class WarappRpc {
|
|
|
185
202
|
this.state.kFa = down.unreadMail.kFa;
|
|
186
203
|
}
|
|
187
204
|
}
|
|
205
|
+
/** war.app's `ClientOutOfDate`: the protocol this server speaks is older than war.app still accepts. */
|
|
206
|
+
export const CLIENT_OUT_OF_DATE = 48;
|
|
207
|
+
/** war.app's `ClientVersionTooHigh`: the client version this server sends is newer than war.app knows. */
|
|
208
|
+
export const CLIENT_VERSION_TOO_HIGH = 49;
|
|
209
|
+
/**
|
|
210
|
+
* war.app refused this server's client as out of date (48) or too new (49). Probed live 2026-11-17: war.app
|
|
211
|
+
* keeps answering about 21 older protocols, and a request below that window gets 48 — the sign that war.app
|
|
212
|
+
* has retired the protocol this server speaks, which no retry or relink fixes: only the update in
|
|
213
|
+
* docs/CLIENT-RELEASES.md ("Updating to a new client") does.
|
|
214
|
+
*/
|
|
215
|
+
export class ClientOutOfDateError extends WarappServerError {
|
|
216
|
+
name = 'ClientOutOfDateError';
|
|
217
|
+
constructor(methodName, code) {
|
|
218
|
+
super(code, code === CLIENT_OUT_OF_DATE
|
|
219
|
+
? `war.app refused ${methodName} as ClientOutOfDate (war.app error 48): it no longer accepts protocol ` +
|
|
220
|
+
`${PROTOCOL_VERSION}, the one this server speaks, so every war.app call through the web protocol will fail ` +
|
|
221
|
+
'until this server is updated to war.app’s current client.'
|
|
222
|
+
: `war.app refused ${methodName} as ClientVersionTooHigh (war.app error 49): it does not know client ` +
|
|
223
|
+
`${CLIENT_VERSION}, the version this server sends.`, 'This server needs an update to war.app’s current client: see docs/CLIENT-RELEASES.md, "Updating to a new ' +
|
|
224
|
+
'client". Retrying or signing in again will not help.');
|
|
225
|
+
}
|
|
226
|
+
}
|
|
188
227
|
function serverError(methodName, code, message, email) {
|
|
228
|
+
if (code === CLIENT_OUT_OF_DATE || code === CLIENT_VERSION_TOO_HIGH)
|
|
229
|
+
return new ClientOutOfDateError(methodName, code);
|
|
189
230
|
const known = SERVER_ERROR_MESSAGES[code];
|
|
190
231
|
if (known)
|
|
191
232
|
return new WarappServerError(code, `${known} (war.app error ${code})`);
|
package/dist/push/socketio.js
CHANGED
|
@@ -4,7 +4,7 @@ import { parseHandshake, parsePacket, SOCKET_URL, splitPayload } from './packets
|
|
|
4
4
|
import { realSetTimer, runWebSocketSession, WebSocketUnavailableError } from './websocket.js';
|
|
5
5
|
export { parseHandshake, parsePacket, SOCKET_URL, splitPayload } from './packets.js';
|
|
6
6
|
export const POST_CONTENT_TYPE = 'text/plain;charset=UTF-8';
|
|
7
|
-
/** A Subscribe frame (method
|
|
7
|
+
/** A Subscribe frame (method 242 in protocol 243, no auth block) as the uppercase hex a message packet carries. */
|
|
8
8
|
export function subscribeFrameHex(topics, msgNum, extras) {
|
|
9
9
|
return toHex(encodeRequest({
|
|
10
10
|
method: Method.Subscribe,
|
|
@@ -16,7 +16,7 @@ export function subscribeFrameHex(topics, msgNum, extras) {
|
|
|
16
16
|
}
|
|
17
17
|
/**
|
|
18
18
|
* Decode a frame from a message packet. A server push is a request-shaped
|
|
19
|
-
* frame (MessageExtrasUp, no auth): GameUpdated (
|
|
19
|
+
* frame (MessageExtrasUp, no auth): GameUpdated (245 in protocol 243) starts with the game id,
|
|
20
20
|
* then two bools the client logs as `chat` and `nonChat` (read from the bundle's
|
|
21
21
|
* handler; UNVERIFIED live), then an optional dict this server does not read.
|
|
22
22
|
* The flags are read only when present: a push without them is a plain update.
|
|
@@ -2,10 +2,10 @@
|
|
|
2
2
|
// UNVERIFIED live (docs/WEB-PROTOCOL.md, "Accepting a surrender").
|
|
3
3
|
//
|
|
4
4
|
// GameFeed keeps a player who asked to surrender `Playing`, and neither GetMyGames nor
|
|
5
|
-
// LatestGameInfo says anything about it: only the game details do. GameRefresh (
|
|
5
|
+
// LatestGameInfo says anything about it: only the game details do. GameRefresh (40) asked with
|
|
6
6
|
// `nonChat` answers `warlight.shared.GameDetailsAndChat`, whose second field is the game
|
|
7
7
|
// (`warlight.shared.GameWL`); the game's eighth field is its players, a dict of in-game id →
|
|
8
|
-
// `warlight.shared.GamePlayer`. Of a player's
|
|
8
|
+
// `warlight.shared.GamePlayer`. Of a player's 37 fields this reads the AI id, "human turned into
|
|
9
9
|
// an AI", the in-game id, who accepted its surrender, its state and the `Surrendered` flag.
|
|
10
10
|
//
|
|
11
11
|
// The client's player reader first sets a link back to the game being read (only when it is read
|
|
@@ -22,8 +22,8 @@ export const GAME_PLAYER = 'warlight.shared.GamePlayer';
|
|
|
22
22
|
/** GameWL: its field count and where the players are, in read order. */
|
|
23
23
|
export const GAME_WL_FIELDS = 14;
|
|
24
24
|
const GW_PLAYERS = 7;
|
|
25
|
-
/** GamePlayer: its field count and the positions read, in read order. */
|
|
26
|
-
export const GAME_PLAYER_FIELDS =
|
|
25
|
+
/** GamePlayer: its field count (protocol 243 added an int32 at 31) and the positions read, in read order. */
|
|
26
|
+
export const GAME_PLAYER_FIELDS = 37;
|
|
27
27
|
const GPL = { aiId: 0, turnedAI: 14, id: 20, accepted: 21, state: 28, surrendered: 29 };
|
|
28
28
|
/** Whether a details seat is still playing (GamePlayerState `Playing`, src/player-states.ts). */
|
|
29
29
|
export const seatPlaying = (s) => playerStateName(s.state) === 'Playing';
|
package/dist/tools/begin-turn.js
CHANGED
|
@@ -9,11 +9,10 @@
|
|
|
9
9
|
import { CONFIRM_INJECTION_RULE, toolAnnotations } from '@chrischall/mcp-utils';
|
|
10
10
|
import { z } from 'zod';
|
|
11
11
|
import { parseGameId } from '../client.js';
|
|
12
|
-
import {
|
|
13
|
-
import { Method, writeBeginFirstTurnParams, writeGetLatestGameInfoParams } from '../protocol/methods.js';
|
|
12
|
+
import { Method, writeBeginFirstTurnParams } from '../protocol/methods.js';
|
|
14
13
|
import { gameIdArg, shownAccount, UNTRUSTED_PREVIEW_NOTE, untrustedText } from './common.js';
|
|
15
14
|
import { mintMeta } from './hints.js';
|
|
16
|
-
import { requireApprovedAccount, SPEED_FIRST_TURN_MOVE_ORDER, writeAccount } from './live-context.js';
|
|
15
|
+
import { readLatestBoard, requireApprovedAccount, SPEED_FIRST_TURN_MOVE_ORDER, writeAccount } from './live-context.js';
|
|
17
16
|
import { defineGatedWrite, mySeat, refuse, requireMe, requirePlaying, sendAndVerify } from './write-kit.js';
|
|
18
17
|
const PLAYING = 'Playing';
|
|
19
18
|
const DISTRIBUTING = 'DistributingTerritories';
|
|
@@ -42,8 +41,7 @@ function beginnable(game, me) {
|
|
|
42
41
|
}
|
|
43
42
|
/** The live board, or undefined while war.app withholds it. */
|
|
44
43
|
async function liveBoard(ctx, gameId) {
|
|
45
|
-
|
|
46
|
-
return standingFromInfo(readLatestGameInfo(await ctx.bundle(), env.body)) ?? undefined;
|
|
44
|
+
return (await readLatestBoard(ctx, gameId)).territories ?? undefined;
|
|
47
45
|
}
|
|
48
46
|
export function registerBeginTurnTool(server, ctx) {
|
|
49
47
|
defineGatedWrite(server, {
|
package/dist/tools/chat-inbox.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
2
|
import { CHAT_CHANNELS } from '../chat.js';
|
|
3
|
-
import { chatGameIds, unflaggedFinished } from '../my-games.js';
|
|
3
|
+
import { chatGameIds, GAME_FINISHED, unflaggedFinished } from '../my-games.js';
|
|
4
4
|
import { playersByInGameId } from '../live.js';
|
|
5
5
|
import { CHAT_SOURCE_NOTES, chatMe, chatUnread, feedFillFields, markChatSeen, readChat, shown } from './chat.js';
|
|
6
6
|
import { parseGameId } from '../client.js';
|
|
@@ -8,6 +8,23 @@ import { gameIdArg, readAnnotations, respond, untrustedDescription, untrustedTex
|
|
|
8
8
|
import { mintMeta } from './hints.js';
|
|
9
9
|
import { BRIDGE_NOTE } from './live.js';
|
|
10
10
|
import { fetchMyGames } from './my-games.js';
|
|
11
|
+
/**
|
|
12
|
+
* #322: a finished game whose chat flags read clear is still read when it is among this many newest finished games
|
|
13
|
+
* (by id) in the list. A message GameFeed alone holds (a surrender "gg" sent as the game ended) leaves war.app's unread
|
|
14
|
+
* flag clear, and such a message comes as a game ends, so the newest finished games are where it hides; older ones stay
|
|
15
|
+
* judged by the flag. A bound, not a scan: at most this many extra reads over a whole sweep.
|
|
16
|
+
*/
|
|
17
|
+
export const FINISHED_CLEAR_WINDOW = 3;
|
|
18
|
+
/** The newest `FINISHED_CLEAR_WINDOW` finished games (by id) whose flags read clear, which `chatGameIds` leaves out. */
|
|
19
|
+
export function recentClearFinished(games) {
|
|
20
|
+
const listed = new Set(chatGameIds(games));
|
|
21
|
+
return games
|
|
22
|
+
.filter((g) => g.stateCode === GAME_FINISHED && !listed.has(g.id))
|
|
23
|
+
.map((g) => g.id)
|
|
24
|
+
.sort((a, b) => b - a)
|
|
25
|
+
.slice(0, FINISHED_CLEAR_WINDOW)
|
|
26
|
+
.sort((a, b) => a - b);
|
|
27
|
+
}
|
|
11
28
|
/** Games read per call, at most (each costs a GameFeed read and a GameRefresh). */
|
|
12
29
|
export const MAX_INBOX_GAMES = 10;
|
|
13
30
|
/** The most game ids a call may name. */
|
|
@@ -77,7 +94,8 @@ export function registerChatInboxTool(server, ctx) {
|
|
|
77
94
|
const list = given ? undefined : await fetchMyGames(ctx);
|
|
78
95
|
const me = await chatMe(ctx);
|
|
79
96
|
const after = cursor === undefined ? undefined : Number(cursor);
|
|
80
|
-
const
|
|
97
|
+
const clearFinished = list ? recentClearFinished(list.games) : [];
|
|
98
|
+
const ids = (given ?? [...chatGameIds(list.games), ...clearFinished].sort((a, b) => a - b)).filter((id) => after === undefined || id > after);
|
|
81
99
|
const batch = ids.slice(0, max_games ?? MAX_INBOX_GAMES);
|
|
82
100
|
const n = limit ?? DEFAULT_INBOX_LIMIT;
|
|
83
101
|
const channels = [...CHAT_CHANNELS];
|
|
@@ -107,9 +125,12 @@ export function registerChatInboxTool(server, ctx) {
|
|
|
107
125
|
}
|
|
108
126
|
sources.add(read.source);
|
|
109
127
|
const messages = fresh_.slice(-n).map((l) => shown(l, true, game.players, byInGame, me));
|
|
128
|
+
const name = game.name === undefined ? null : untrustedText(game.name);
|
|
110
129
|
withNew.push({
|
|
130
|
+
// #322/#323: the game as warapp_get_chat nests it; the top-level keys stay for existing callers.
|
|
131
|
+
game: { id: game.id, name, state: game.state },
|
|
111
132
|
id: game.id,
|
|
112
|
-
name
|
|
133
|
+
name,
|
|
113
134
|
state: game.state,
|
|
114
135
|
source: read.source,
|
|
115
136
|
...feedFillFields(read),
|
|
@@ -152,6 +173,14 @@ export function registerChatInboxTool(server, ctx) {
|
|
|
152
173
|
'are read like the rest rather than left out (the flags are not yet verified against war.app).',
|
|
153
174
|
}
|
|
154
175
|
: {}),
|
|
176
|
+
...(clearFinished.length
|
|
177
|
+
? {
|
|
178
|
+
finishedClearChecked: clearFinished.length,
|
|
179
|
+
finishedClearNote: `${clearFinished.length} recent finished game(s) are read although war.app's unread flag for their chat ` +
|
|
180
|
+
'is clear: a message GameFeed alone holds (a surrender line, say) leaves that flag clear (#322). Only the ' +
|
|
181
|
+
`${FINISHED_CLEAR_WINDOW} newest finished games are read so; older ones go by the flag.`,
|
|
182
|
+
}
|
|
183
|
+
: {}),
|
|
155
184
|
...(sources.size ? { sourceNotes: Object.fromEntries([...sources].map((s) => [s, CHAT_SOURCE_NOTES[s]])) } : {}),
|
|
156
185
|
}));
|
|
157
186
|
});
|
|
@@ -79,7 +79,9 @@ export function registerMarkChatReadTool(server, ctx) {
|
|
|
79
79
|
const read = await readChat(ctx, game, me);
|
|
80
80
|
// A filled web read (#313) still carries the web messages' ids; GameFeed's added lines carry none and mark nothing.
|
|
81
81
|
if (!read || read.source === 'gamefeed') {
|
|
82
|
-
refuse(`The chat of game ${game.id} could be read only from GameFeed, which gives no message ids, so nothing was sent.`, '
|
|
82
|
+
refuse(`The chat of game ${game.id} could be read only from GameFeed, which gives no message ids, so nothing was sent.`, 'A message read from GameFeed carries no id, so war.app has nothing to mark for it. Read the game with ' +
|
|
83
|
+
'warapp_get_chat: if its `source` is `web`, those messages can be marked; if it stays `gamefeed`, the web ' +
|
|
84
|
+
'read failed or the signed-in account could not be read, and marking waits until it reads.');
|
|
83
85
|
}
|
|
84
86
|
// #313: the web read answered with no message at all while GameFeed holds some (a finished game's chat,
|
|
85
87
|
// seen live). Every line is then GameFeed's, with no id; a retry reads the same, so it says why instead.
|
package/dist/tools/check-plan.js
CHANGED
|
@@ -17,7 +17,7 @@ import { assumedWarning, awardView, loadAward, openingThreat } from './award.js'
|
|
|
17
17
|
import { gameIdArg, graphOf, namer, readAnnotations, respond, untrustedDescription, untrustedText, viewArg } from './common.js';
|
|
18
18
|
import { lookupMeta } from './hints.js';
|
|
19
19
|
import { HEADROOM_COMPACT, headroomView, readTripwires, safeHeadroom, teamsOf, tripwireWarnings, untrustedDeploy } from './survival.js';
|
|
20
|
-
import { loadLiveGame } from './live-context.js';
|
|
20
|
+
import { loadLiveGame, standInLine, standInOf } from './live-context.js';
|
|
21
21
|
import { BRIDGE_NOTE, playerArg, resolveMe } from './live.js';
|
|
22
22
|
import { mapOf } from './map.js';
|
|
23
23
|
import { resolveTerritory } from './resolve.js';
|
|
@@ -540,6 +540,8 @@ export function registerCheckPlanTool(server, ctx) {
|
|
|
540
540
|
// #275 pattern 3: each border these orders leave below what the default plan leaves there (one plan per call).
|
|
541
541
|
const belowPlan = await bordersBelowPlan(ctx, { game, map, me, turn, territories, info, history, teamsKnown, given: { deploys, moves } });
|
|
542
542
|
const warnings = [
|
|
543
|
+
// The owner, 2026-11-17: while an older build stands in for a client this server cannot read, say so first.
|
|
544
|
+
...[standInLine(standInOf(ctx))].filter((w) => w !== undefined),
|
|
543
545
|
// #275 (b): an untrusted estimate is the first thing said (not under an explicit enemy_deploy).
|
|
544
546
|
...(enemy_deploy === undefined ? tripwireWarnings(trip.tripwires, (w) => untrustedOf.get(w.player) ?? untrustedDeploy(w, income), (p) => estimates.find((x) => x.playerId === p)?.estimate) : []),
|
|
545
547
|
...(award ? assumedWarning(award) : []),
|
|
@@ -3,6 +3,7 @@ import { registerAdaptiveHealthcheckTool, } from '@chrischall/mcp-utils/fetchpro
|
|
|
3
3
|
import { AUTH_FAILED_HINT, PROBE_GAME_ID, WarappClient } from '../client.js';
|
|
4
4
|
import { readCredentials, TOKEN_URL, WarappConfigError } from '../config.js';
|
|
5
5
|
import { readSessionSync } from '../direct/session.js';
|
|
6
|
+
import { HOST_SIGN_IN_ADVICE, SessionExpiredError } from '../direct/transport.js';
|
|
6
7
|
/**
|
|
7
8
|
* `warapp_healthcheck` — does war.app accept the configured email + token?
|
|
8
9
|
*
|
|
@@ -21,11 +22,24 @@ import { readSessionSync } from '../direct/session.js';
|
|
|
21
22
|
* which is the whole time the direct leg is serving calls ("on direct, the
|
|
22
23
|
* credential probe"). Either way the result carries which leg is active and
|
|
23
24
|
* whether a direct session is linked and how old it is — never the token.
|
|
25
|
+
*
|
|
26
|
+
* with a direct session (linked, or captured by mcp-host when hosted) the
|
|
27
|
+
* credential arm also asks war.app whether that SESSION is signed in — one GET
|
|
28
|
+
* of the invite-token page with it (`sessionCheck`: signed-in / signed-out /
|
|
29
|
+
* unknown) — and reports the router's `wall` (why it left the direct leg, when,
|
|
30
|
+
* and when it tries again). A session war.app shows signed out fails the check
|
|
31
|
+
* as `session_expired`, even when the API token is fine: before, a hosted
|
|
32
|
+
* healthcheck said ok while every live tool failed.
|
|
24
33
|
*/
|
|
25
34
|
export { PROBE_GAME_ID };
|
|
26
35
|
const PROBE_PATH = `/API/GameFeed?GameID=${PROBE_GAME_ID}&GetMap=false`;
|
|
27
36
|
/** The page the bridge arm round-trips through the user's war.app tab. */
|
|
28
37
|
export const BRIDGE_PROBE_PATH = '/';
|
|
38
|
+
/** `health` with the open stand-in window beside it, when one is open. */
|
|
39
|
+
function withStandIn(health, deps) {
|
|
40
|
+
const w = deps.standIn?.();
|
|
41
|
+
return w ? { ...health, standIn: w } : health;
|
|
42
|
+
}
|
|
29
43
|
/**
|
|
30
44
|
* The non-secret facts about the linked direct session — never the token. The
|
|
31
45
|
* session mcp-host captured at sign-in (hosted, #333) is `linked: true` with `linkedBy: 'host'` (`linked` stays a boolean), with
|
|
@@ -46,6 +60,33 @@ function transportHealth(status, env, now) {
|
|
|
46
60
|
}
|
|
47
61
|
export function registerHealthcheckTool(server, bridge, direct, deps = {}) {
|
|
48
62
|
const now = deps.now ?? Date.now;
|
|
63
|
+
/** What this call's session check found, echoed in the result; reset at each check. */
|
|
64
|
+
let lastCheck = {};
|
|
65
|
+
/** Check the direct session when there is one and the router may use it; never throws. */
|
|
66
|
+
const checkSession = async () => {
|
|
67
|
+
lastCheck = {};
|
|
68
|
+
if (!direct.checkSession || direct.status().mode === 'fetchproxy')
|
|
69
|
+
return undefined;
|
|
70
|
+
if (!readSessionSync(deps.env))
|
|
71
|
+
return undefined;
|
|
72
|
+
const verdict = await direct.checkSession().catch(() => 'unknown');
|
|
73
|
+
if (verdict === 'none')
|
|
74
|
+
return undefined;
|
|
75
|
+
const wall = direct.wall?.() ?? null;
|
|
76
|
+
lastCheck = { sessionCheck: verdict, ...(wall ? { wall } : {}) };
|
|
77
|
+
return verdict;
|
|
78
|
+
};
|
|
79
|
+
const health = () => withStandIn({ ...transportHealth(direct.status(), deps.env, now), ...lastCheck }, deps);
|
|
80
|
+
const signedOut = () => new SessionExpiredError({ hostSignIn: readSessionSync(deps.env)?.origin === 'host' });
|
|
81
|
+
const classifySignedOut = (err) => err instanceof SessionExpiredError
|
|
82
|
+
? {
|
|
83
|
+
kind: 'session_expired',
|
|
84
|
+
hint: 'war.app shows the session the live tools use as signed out. ' +
|
|
85
|
+
(err.hostSignIn ? HOST_SIGN_IN_ADVICE : 'Run warapp_link_session to relink.'),
|
|
86
|
+
}
|
|
87
|
+
: undefined;
|
|
88
|
+
/** The session check this call's resolver made, read by its probe. */
|
|
89
|
+
let resolvedVerdict;
|
|
49
90
|
registerAdaptiveHealthcheckTool({
|
|
50
91
|
server,
|
|
51
92
|
prefix: 'warapp',
|
|
@@ -60,36 +101,51 @@ export function registerHealthcheckTool(server, bridge, direct, deps = {}) {
|
|
|
60
101
|
bridge: {
|
|
61
102
|
probePath: BRIDGE_PROBE_PATH,
|
|
62
103
|
transport: () => bridge.transport(),
|
|
63
|
-
path:
|
|
104
|
+
path: health,
|
|
64
105
|
probeFn: async (path) => {
|
|
65
|
-
|
|
106
|
+
// Off the direct leg with a session: ask war.app about the session first. Signed
|
|
107
|
+
// out is the answer; signed in lifts the wall, and the probe then rides the direct leg.
|
|
108
|
+
const verdict = await checkSession();
|
|
109
|
+
if (verdict === 'signed-out')
|
|
110
|
+
throw signedOut();
|
|
111
|
+
const viaRouter = verdict === 'signed-in' && direct.ready !== undefined;
|
|
112
|
+
const leg = viaRouter ? await direct.ready() : await bridge.ready();
|
|
113
|
+
const res = await leg.fetch({ method: 'GET', path });
|
|
66
114
|
if (res.status !== 200) {
|
|
67
|
-
throw new McpToolError(`war.app answered HTTP ${res.status} through the bridge.`, {
|
|
115
|
+
throw new McpToolError(`war.app answered HTTP ${res.status}${viaRouter ? '' : ' through the bridge'}.`, {
|
|
68
116
|
status: res.status,
|
|
69
117
|
kind: 'http',
|
|
70
118
|
});
|
|
71
119
|
}
|
|
72
120
|
return res.body;
|
|
73
121
|
},
|
|
122
|
+
classifyThrown: classifySignedOut,
|
|
74
123
|
},
|
|
75
124
|
credential: {
|
|
76
125
|
probePath: PROBE_PATH,
|
|
77
126
|
resolveCredential: async () => {
|
|
78
|
-
|
|
127
|
+
resolvedVerdict = await checkSession();
|
|
128
|
+
const detail = health();
|
|
79
129
|
try {
|
|
80
130
|
readCredentials(deps.env);
|
|
81
|
-
return { source: 'env', detail
|
|
131
|
+
return { source: 'env', detail };
|
|
82
132
|
}
|
|
83
133
|
catch (e) {
|
|
84
134
|
if (e instanceof WarappConfigError)
|
|
85
|
-
return { source: null, detail: { ...
|
|
135
|
+
return { source: null, detail: { ...detail, reason: e.message } };
|
|
86
136
|
throw e;
|
|
87
137
|
}
|
|
88
138
|
},
|
|
89
|
-
probeFn: () =>
|
|
139
|
+
probeFn: async () => {
|
|
140
|
+
const res = await new WarappClient(deps).probeAuth();
|
|
141
|
+
// The API token works; the live tools ride the session, which war.app says is signed out.
|
|
142
|
+
if (resolvedVerdict === 'signed-out')
|
|
143
|
+
throw signedOut();
|
|
144
|
+
return res;
|
|
145
|
+
},
|
|
90
146
|
classifyThrown: (err) => err instanceof McpToolError && err.kind === 'credential_rejected'
|
|
91
147
|
? { kind: 'credential_rejected', hint: AUTH_FAILED_HINT }
|
|
92
|
-
:
|
|
148
|
+
: classifySignedOut(err),
|
|
93
149
|
hints: { no_credential: `Set WARAPP_EMAIL and WARAPP_API_TOKEN (token from ${TOKEN_URL}).` },
|
|
94
150
|
},
|
|
95
151
|
});
|
package/dist/tools/index.js
CHANGED
|
@@ -77,7 +77,7 @@ export function registerAllTools(server, deps = {}) {
|
|
|
77
77
|
// The cached signed-in account is discarded whenever the account behind the router may have changed.
|
|
78
78
|
identity: () => bridge.identityState(),
|
|
79
79
|
});
|
|
80
|
-
registerHealthcheckTool(server, fetchproxy, bridge, deps);
|
|
80
|
+
registerHealthcheckTool(server, fetchproxy, bridge, { ...deps, standIn: () => live.decoderReport()?.standIn });
|
|
81
81
|
// The signed-in account names a finished game's player for its end-of-game pass when no board was cached (#312).
|
|
82
82
|
registerGameTool(server, client, () => dataDir(deps.env), deps.env, () => live.myInviteToken());
|
|
83
83
|
registerMapTool(server, client, live);
|
|
@@ -142,6 +142,7 @@ export function registerAllTools(server, deps = {}) {
|
|
|
142
142
|
transport: {
|
|
143
143
|
activeLeg: () => bridge.status().transport,
|
|
144
144
|
sessionStale: () => bridge.sessionStale(),
|
|
145
|
+
wall: () => bridge.wall(),
|
|
145
146
|
sessionLinked: () => bridge.sessionLinked(),
|
|
146
147
|
},
|
|
147
148
|
pushTransport: () => push.status().transport,
|
|
@@ -3,10 +3,12 @@
|
|
|
3
3
|
// and the client bundle whose readers decode the board.
|
|
4
4
|
import { McpToolError } from '@chrischall/mcp-utils';
|
|
5
5
|
import { dataDir } from '../config.js';
|
|
6
|
-
import { inGameId, readLatestGameInfo, standingFromInfo } from '../live.js';
|
|
6
|
+
import { inGameId, LiveBoardFormatError, readLatestGameInfo, standingFromInfo } from '../live.js';
|
|
7
7
|
import { BUNDLE_FETCH_TIMEOUT_MS, BUNDLE_MAX_BYTES, BundleProvider } from '../protocol/bundle.js';
|
|
8
|
+
import { ProtocolError } from '../protocol/codec.js';
|
|
9
|
+
import { InterpError } from '../protocol/interp.js';
|
|
8
10
|
import { Method, readTerritoryPicks, writeGetLatestGameInfoParams, writeGetTerritoryPicksParams, } from '../protocol/methods.js';
|
|
9
|
-
import { WarappRpc } from '../protocol/rpc.js';
|
|
11
|
+
import { ProtocolVersionError, WarappRpc } from '../protocol/rpc.js';
|
|
10
12
|
import { BRIDGE_DOMAINS } from '../transport-bridge.js';
|
|
11
13
|
import { hostedSession } from '../direct/session.js';
|
|
12
14
|
import { isHosted } from '../hosted.js';
|
|
@@ -319,12 +321,75 @@ function beginFirstError(game) {
|
|
|
319
321
|
export async function loadLiveTerritories(ctx, game) {
|
|
320
322
|
return (await loadLiveGame(ctx, game)).territories;
|
|
321
323
|
}
|
|
324
|
+
/** The issue tracking the move to the client war.app now serves (protocol 243), named in the window-closed error. */
|
|
325
|
+
export const PROTOCOL_UPDATE_ISSUE = 'https://github.com/chrischall/warapp-mcp/issues/340';
|
|
326
|
+
/**
|
|
327
|
+
* One line for a tool's warnings while a stand-in decodes: war.app ships a client this server cannot read
|
|
328
|
+
* yet, so an older build it still answers is decoding, since when. `undefined` without a stand-in.
|
|
329
|
+
*/
|
|
330
|
+
export function standInLine(w) {
|
|
331
|
+
if (!w)
|
|
332
|
+
return undefined;
|
|
333
|
+
return (`war.app ships a client this server cannot read yet (${w.refusedVersion}), so the client build ${w.version}, ` +
|
|
334
|
+
`which war.app still answers, stands in and decodes the board (since ${w.since}). Boards still decode exactly; ` +
|
|
335
|
+
`war.app may stop answering the old build at any time, and this server then needs its update (#340, ${PROTOCOL_UPDATE_ISSUE}).`);
|
|
336
|
+
}
|
|
337
|
+
/** The stand-in window of the bundle this process decodes with, if one stands in (never loads one). */
|
|
338
|
+
export function standInOf(ctx) {
|
|
339
|
+
return ctx.decoderReport()?.standIn;
|
|
340
|
+
}
|
|
341
|
+
/**
|
|
342
|
+
* war.app no longer answers the build that stands in: its reply did not decode with it (bytes left over, an
|
|
343
|
+
* unknown frame) or came in another protocol version. Nothing was decoded.
|
|
344
|
+
*/
|
|
345
|
+
export class StandInClosedError extends McpToolError {
|
|
346
|
+
window;
|
|
347
|
+
name = 'StandInClosedError';
|
|
348
|
+
constructor(window, cause) {
|
|
349
|
+
const why = cause instanceof Error ? cause.message : String(cause);
|
|
350
|
+
super(`war.app no longer answers the client build ${window.version} this server has decoded with since ${window.since} ` +
|
|
351
|
+
`(standing in for ${window.refusedVersion}, which this server cannot read yet): ${why} Nothing was decoded; ` +
|
|
352
|
+
'the old client is no longer accepted, so this server needs the protocol update (#340).', {
|
|
353
|
+
kind: 'unknown',
|
|
354
|
+
hint: `The old client is no longer accepted: this server needs the protocol update (${PROTOCOL_UPDATE_ISSUE}). Play in the war.app web client until then.`,
|
|
355
|
+
cause,
|
|
356
|
+
});
|
|
357
|
+
this.window = window;
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
/** A failure that says the reply and the decoder disagree on the layout (or the protocol). */
|
|
361
|
+
const isLayoutFailure = (e) => e instanceof ProtocolVersionError || e instanceof LiveBoardFormatError || e instanceof ProtocolError || e instanceof InterpError;
|
|
362
|
+
/** `e`, or the window-closed error when it is a layout failure while a stand-in decodes. */
|
|
363
|
+
async function windowClosed(ctx, bundle, e) {
|
|
364
|
+
if (!isLayoutFailure(e))
|
|
365
|
+
return e;
|
|
366
|
+
const b = bundle ?? (await ctx.bundle().catch(() => undefined));
|
|
367
|
+
const w = b?.report?.().standIn;
|
|
368
|
+
return w ? new StandInClosedError(w, e) : e;
|
|
369
|
+
}
|
|
370
|
+
/**
|
|
371
|
+
* GetLatestGameInfo for a game, decoded: the info (`null` when war.app sent none) and its current standing.
|
|
372
|
+
* A standing that decodes with every byte read records the bundle as a build that works; a layout failure
|
|
373
|
+
* while a stand-in decodes is the window-closed error.
|
|
374
|
+
*/
|
|
375
|
+
export async function readLatestBoard(ctx, gameId) {
|
|
376
|
+
let bundle;
|
|
377
|
+
try {
|
|
378
|
+
const env = await ctx.rpc.call('GetLatestGameInfo', Method.GetLatestGameInfo, (w) => writeGetLatestGameInfoParams(w, gameId));
|
|
379
|
+
bundle = await ctx.bundle();
|
|
380
|
+
const info = readLatestGameInfo(bundle, env.body);
|
|
381
|
+
const territories = standingFromInfo(info);
|
|
382
|
+
if (territories)
|
|
383
|
+
await bundle.markDecoded?.();
|
|
384
|
+
return { info, territories };
|
|
385
|
+
}
|
|
386
|
+
catch (e) {
|
|
387
|
+
throw await windowClosed(ctx, bundle, e);
|
|
388
|
+
}
|
|
389
|
+
}
|
|
322
390
|
/** The live board plus the decoded LatestGameInfo (cards live there); throws when war.app has no board. */
|
|
323
391
|
export async function loadLiveGame(ctx, game) {
|
|
324
|
-
const
|
|
325
|
-
const bundle = await ctx.bundle();
|
|
326
|
-
const info = readLatestGameInfo(bundle, env.body);
|
|
327
|
-
const territories = standingFromInfo(info);
|
|
392
|
+
const { info, territories } = await readLatestBoard(ctx, game.id);
|
|
328
393
|
if (!territories) {
|
|
329
394
|
if (awaitsBegin(game))
|
|
330
395
|
throw beginFirstError(game);
|
package/dist/tools/my-games.js
CHANGED
|
@@ -83,7 +83,9 @@ export const MAX_SURRENDER_READS = 20;
|
|
|
83
83
|
const SURRENDER_READ_BATCH = 4;
|
|
84
84
|
/**
|
|
85
85
|
* #317: each game's pending surrenders, by game id: read for a game being played or picked where my seat
|
|
86
|
-
* still plays (at most {@link MAX_SURRENDER_READS}, war.app's order
|
|
86
|
+
* still plays (at most {@link MAX_SURRENDER_READS}, war.app's order; `null` when unreadable, and absent —
|
|
87
|
+
* so `null` — past the bound); every other game is an empty list, read from nothing (#327: a lobby or a
|
|
88
|
+
* finished game has none, and a game I am out of owes none from me).
|
|
87
89
|
* GetMyGames carries no GameFeed id, so `player` is `null`; the name is the list's, untrusted.
|
|
88
90
|
*/
|
|
89
91
|
export async function myGamesSurrenders(ctx, games, me) {
|
|
@@ -92,6 +94,9 @@ export async function myGamesSurrenders(ctx, games, me) {
|
|
|
92
94
|
const mine = g.players.find((p) => p.id === me);
|
|
93
95
|
return surrenderMayBePending(gameStateName(g.stateCode), mine ? playerStateName(mine.stateCode) : undefined);
|
|
94
96
|
});
|
|
97
|
+
for (const g of games)
|
|
98
|
+
if (!eligible.includes(g))
|
|
99
|
+
byGame.set(g.id, []);
|
|
95
100
|
const read = eligible.slice(0, MAX_SURRENDER_READS);
|
|
96
101
|
for (let i = 0; i < read.length; i += SURRENDER_READ_BATCH) {
|
|
97
102
|
const batch = read.slice(i, i + SURRENDER_READ_BATCH);
|
|
@@ -129,7 +134,8 @@ export function registerMyGamesTool(server, ctx, deps = {}) {
|
|
|
129
134
|
'they have committed this turn) and waitingOnYou — true when the game is being played or distributing ' +
|
|
130
135
|
'territories, you are still playing, and you have not committed — and surrenderPending: the surrenders other ' +
|
|
131
136
|
'players asked for that are still pending, each with owedByMe (true: waiting for you to accept it), read from ' +
|
|
132
|
-
'the game details (unverified live; null when not read or unreadable, never "none"
|
|
137
|
+
'the game details (unverified live; null when not read or unreadable, never "none"; empty without a read ' +
|
|
138
|
+
'for a lobby, a finished game or a game you no longer play in, where none can wait on you); the top-level ' +
|
|
133
139
|
'surrenderPending counts the games where one waits on you, and those games come first too. ' +
|
|
134
140
|
'Finished games are left out unless ' +
|
|
135
141
|
'`include_finished` (`finishedLeftOut` counts them). `listed` is how many games war.app returned and ' +
|
|
@@ -163,7 +169,8 @@ export function registerMyGamesTool(server, ctx, deps = {}) {
|
|
|
163
169
|
if (view === 'brief')
|
|
164
170
|
return briefResult(summary, partial ? raw.length : undefined);
|
|
165
171
|
const finishedLeftOut = raw.length - kept.length;
|
|
166
|
-
// #317: the surrenders pending in each game (the game details; null: not read or unreadable, never "none"
|
|
172
|
+
// #317: the surrenders pending in each game (the game details; null: not read or unreadable, never "none";
|
|
173
|
+
// #327: [] without a read where none can wait on me).
|
|
167
174
|
const { byGame, skipped } = await myGamesSurrenders(ctx, kept, me);
|
|
168
175
|
const withSurrenders = summary.map((g) => ({ ...g, surrenderPending: byGame.get(g.id) ?? null }));
|
|
169
176
|
// A game waiting on my acceptance waits on me too: it goes first with the turns waiting on me.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// warapp_get_notifications, warapp_dismiss_notification and warapp_delete_notification (#311): war.app's
|
|
2
|
-
// in-app notifications (the client's "In App Notifications" screen), read with GetInAppNotifications (
|
|
3
|
-
// marked read with AcknowledgeInAppNotifications (
|
|
2
|
+
// in-app notifications (the client's "In App Notifications" screen), read with GetInAppNotifications (323),
|
|
3
|
+
// marked read with AcknowledgeInAppNotifications (325) and deleted with DeleteInAppNotification (324, the
|
|
4
4
|
// client's Delete button). All read from the client bundle, UNVERIFIED live (docs/WEB-PROTOCOL.md,
|
|
5
5
|
// Notifications and read marks).
|
|
6
6
|
//
|