@chrischall/warapp-mcp 0.15.0 → 0.16.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/dist/bundle.js +118 -17
- package/dist/finished-store.js +41 -0
- package/dist/tools/end-of-game.js +86 -14
- package/dist/tools/state.js +30 -4
- package/dist/version.js +1 -1
- package/manifest.json +1 -1
- package/package.json +1 -1
- package/server.json +2 -2
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
},
|
|
8
8
|
"metadata": {
|
|
9
9
|
"description": "MCP server for war.app (Warzone) — your games, players, settings, map bonuses and chokepoints, board analysis and route planning through war.app's per-player GameFeed API, plus the live board, territory picks, cards, turn planning and submission, turn notifications and game chat through your signed-in war.app tab (joining, leaving or surrendering a game, closing out a finished 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, importing local history and linking a session are confirm-gated).",
|
|
10
|
-
"version": "0.
|
|
10
|
+
"version": "0.16.0"
|
|
11
11
|
},
|
|
12
12
|
"plugins": [
|
|
13
13
|
{
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
"displayName": "war.app (Warzone)",
|
|
16
16
|
"source": "./",
|
|
17
17
|
"description": "war.app (Warzone) game advisor for Claude — games, maps, bonuses, routes, live board, picks, turns, cards and chat",
|
|
18
|
-
"version": "0.
|
|
18
|
+
"version": "0.16.0",
|
|
19
19
|
"author": {
|
|
20
20
|
"name": "Chris Hall"
|
|
21
21
|
},
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "warapp-mcp",
|
|
3
3
|
"displayName": "war.app (Warzone)",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.16.0",
|
|
5
5
|
"description": "war.app (Warzone) game advisor for Claude — games, maps, bonuses, routes, live board, picks, turns, cards and chat",
|
|
6
6
|
"author": {
|
|
7
7
|
"name": "Chris Hall",
|
package/dist/bundle.js
CHANGED
|
@@ -115630,7 +115630,7 @@ function serverBuild() {
|
|
|
115630
115630
|
}
|
|
115631
115631
|
|
|
115632
115632
|
// src/version.ts
|
|
115633
|
-
var VERSION2 = "0.
|
|
115633
|
+
var VERSION2 = "0.16.0";
|
|
115634
115634
|
|
|
115635
115635
|
// src/decision-log.ts
|
|
115636
115636
|
var DECISION_LOG_VERSION = 1;
|
|
@@ -145010,6 +145010,7 @@ var finishedDir = (dir) => join24(dir, "finished");
|
|
|
145010
145010
|
var finishedPath = (dir, salt, me, gameId) => join24(finishedDir(dir), `${finishedGameKey(salt, me, gameId)}.json`);
|
|
145011
145011
|
var processedPath = (dir) => join24(finishedDir(dir), "processed.json");
|
|
145012
145012
|
var KEY = /^[0-9a-f]{32}$/;
|
|
145013
|
+
var COLLECTOR_VERSION = 1;
|
|
145013
145014
|
var END_STATS_VERSION = 3;
|
|
145014
145015
|
var OWNER_NEUTRAL2 = -1;
|
|
145015
145016
|
var OWNER_AVAILABLE = -2;
|
|
@@ -145032,6 +145033,33 @@ async function readFinishedState(path) {
|
|
|
145032
145033
|
return "unreadable";
|
|
145033
145034
|
}
|
|
145034
145035
|
}
|
|
145036
|
+
async function readFinishedSummary(path) {
|
|
145037
|
+
let text;
|
|
145038
|
+
try {
|
|
145039
|
+
text = await readFile19(path, "utf8");
|
|
145040
|
+
} catch (e) {
|
|
145041
|
+
return e.code === "ENOENT" ? "missing" : "unreadable";
|
|
145042
|
+
}
|
|
145043
|
+
try {
|
|
145044
|
+
const v = JSON.parse(text);
|
|
145045
|
+
if (!isRec20(v) || v.version !== VERSION4 || typeof v.status !== "string" || !STATUSES.has(v.status)) return "unreadable";
|
|
145046
|
+
const r = v;
|
|
145047
|
+
const f = isRec20(r.failure) ? r.failure : void 0;
|
|
145048
|
+
const stats = isRec20(r.stats) ? r.stats : void 0;
|
|
145049
|
+
return {
|
|
145050
|
+
status: r.status,
|
|
145051
|
+
collector: typeof r.collector === "number" && Number.isInteger(r.collector) && r.collector >= 0 ? r.collector : 0,
|
|
145052
|
+
...f && typeof f.reason === "string" ? { failure: { reason: f.reason, ..."kind" in f && typeof f.kind === "string" ? { kind: f.kind } : {} } } : {},
|
|
145053
|
+
...Array.isArray(r.turns) ? { turns: r.turns.length } : {},
|
|
145054
|
+
...Array.isArray(r.boards) ? { boards: r.boards.length } : {},
|
|
145055
|
+
...stats && typeof stats.version === "number" ? { statsVersion: stats.version } : {},
|
|
145056
|
+
...Array.isArray(r.kinds) ? { kinds: r.kinds.filter((k) => typeof k === "string") } : {},
|
|
145057
|
+
...isRec20(r.outcome) && typeof r.outcome.result === "string" ? { result: r.outcome.result } : {}
|
|
145058
|
+
};
|
|
145059
|
+
} catch {
|
|
145060
|
+
return "unreadable";
|
|
145061
|
+
}
|
|
145062
|
+
}
|
|
145035
145063
|
async function writeFinishedRecord(dir, path, body, keep = MAX_FINISHED_RECORDS, protect) {
|
|
145036
145064
|
await writeJsonAtomic(path, finishedDir(dir), body);
|
|
145037
145065
|
await pruneFinished(dir, keep, /* @__PURE__ */ new Set([...protect ?? [], path])).catch(() => void 0);
|
|
@@ -145110,6 +145138,7 @@ function finishedRecordOf(p) {
|
|
|
145110
145138
|
const stored = kept ? storeBoards(kept.boards, p.game?.players.map((x) => x.id) ?? [p.me], key) : void 0;
|
|
145111
145139
|
return {
|
|
145112
145140
|
version: VERSION4,
|
|
145141
|
+
collector: COLLECTOR_VERSION,
|
|
145113
145142
|
status: p.status,
|
|
145114
145143
|
...p.failure ? { failure: p.failure } : {},
|
|
145115
145144
|
...p.layout ? { layout: p.layout } : {},
|
|
@@ -156418,13 +156447,14 @@ async function endOfGame(deps, gameId, me, seen2, opts = {}) {
|
|
|
156418
156447
|
await closeOnly();
|
|
156419
156448
|
return { status: "record-unreadable" };
|
|
156420
156449
|
}
|
|
156421
|
-
|
|
156422
|
-
if (state !== "missing" &&
|
|
156450
|
+
const reread = opts.reread === true;
|
|
156451
|
+
if (state !== "missing" && state.status === "captured" && !reread) return await keptOrBackfilled(dataDir2, path, salt, me, opts.history ?? seen2, opts.history);
|
|
156452
|
+
if (state !== "missing" && !reread && (!opts.retry || !opts.history)) return { status: "already-processed" };
|
|
156423
156453
|
let game = opts.history;
|
|
156424
156454
|
let failure2;
|
|
156425
156455
|
if (!game) {
|
|
156426
|
-
if (state === "missing" && await isMarked(dataDir2, salt, me, gameId)) return { status: "already-processed" };
|
|
156427
|
-
const key = attemptKey(dataDir2, me, gameId)
|
|
156456
|
+
if (state === "missing" && !reread && await isMarked(dataDir2, salt, me, gameId)) return { status: "already-processed" };
|
|
156457
|
+
const key = `${attemptKey(dataDir2, me, gameId)}${reread ? "|reread" : ""}`;
|
|
156428
156458
|
if (attempted.has(key)) return { status: "attempted" };
|
|
156429
156459
|
remember(attempted, key);
|
|
156430
156460
|
try {
|
|
@@ -156446,6 +156476,8 @@ async function endOfGame(deps, gameId, me, seen2, opts = {}) {
|
|
|
156446
156476
|
read = game;
|
|
156447
156477
|
const shown2 = game ?? seen2;
|
|
156448
156478
|
const { record: record4, history } = await buildRecord(dataDir2, salt, me, gameId, game, shown2, failure2);
|
|
156479
|
+
if (reread && state !== "missing" && state.status === "captured" && record4.status !== "captured")
|
|
156480
|
+
return { status: record4.status, keptPrevious: true, ...record4.failure ? { failure: record4.failure } : {} };
|
|
156449
156481
|
kept = excludedKind(record4.kinds ?? []);
|
|
156450
156482
|
try {
|
|
156451
156483
|
const protect = opts.protectIds ? new Set(opts.protectIds.map((id) => finishedPath(dataDir2, salt, me, id))) : void 0;
|
|
@@ -156719,19 +156751,76 @@ var sweepWindow = (keep = MAX_FINISHED_RECORDS) => Math.max(1, Math.floor(keep /
|
|
|
156719
156751
|
async function sweepFinished(deps, me, gameIds, {
|
|
156720
156752
|
limit = END_OF_GAME_PER_CALL,
|
|
156721
156753
|
keep = MAX_FINISHED_RECORDS,
|
|
156722
|
-
window: size
|
|
156754
|
+
window: size,
|
|
156755
|
+
only,
|
|
156756
|
+
reread,
|
|
156757
|
+
report: report2
|
|
156723
156758
|
} = {}) {
|
|
156724
156759
|
const window = gameIds.slice(0, Math.max(1, Math.min(size ?? sweepWindow(keep), keep)));
|
|
156725
|
-
|
|
156760
|
+
const scope = only ? gameIds.filter((id) => only.includes(id)) : window;
|
|
156761
|
+
if (deps.dataDir && !profileEnabled(deps.env)) await finishDecisionLogs(deps.dataDir, scope, me, { mode: decisionLogModeOf(deps.env) });
|
|
156762
|
+
const before = /* @__PURE__ */ new Map();
|
|
156763
|
+
if (report2 || reread) for (const id of scope) before.set(id, await gameStanding(deps, me, id));
|
|
156726
156764
|
const todo = [];
|
|
156727
|
-
for (const id of
|
|
156765
|
+
for (const id of scope) {
|
|
156766
|
+
if (await needsEndOfGame(deps.dataDir, deps.env, id, me)) todo.push({ id, reread: false });
|
|
156767
|
+
else if (reread && rereadWanted(before.get(id), reread)) todo.push({ id, reread: true });
|
|
156768
|
+
}
|
|
156728
156769
|
await refreshProcessed(deps, me, window).catch(() => void 0);
|
|
156729
156770
|
const processed = [];
|
|
156730
|
-
|
|
156731
|
-
|
|
156732
|
-
|
|
156771
|
+
const protectIds = only ? [.../* @__PURE__ */ new Set([...window, ...scope])] : window;
|
|
156772
|
+
for (const t of todo.slice(0, limit)) {
|
|
156773
|
+
const r = await endOfGame(deps, t.id, me, void 0, { fold: true, keep, protectIds, ...t.reread ? { reread: true } : {} });
|
|
156774
|
+
processed.push({
|
|
156775
|
+
gameId: t.id,
|
|
156776
|
+
status: r.status,
|
|
156777
|
+
...t.reread ? { reread: true } : {},
|
|
156778
|
+
...r.turns !== void 0 ? { turns: r.turns } : {},
|
|
156779
|
+
...r.failure ? { failure: failureCode(r.failure) } : {},
|
|
156780
|
+
...r.keptPrevious ? { keptPrevious: true } : {}
|
|
156781
|
+
});
|
|
156782
|
+
}
|
|
156783
|
+
const out = { processed, pending: Math.max(0, todo.length - limit) };
|
|
156784
|
+
if (report2) {
|
|
156785
|
+
const thisCall = new Map(processed.map((p) => [p.gameId, p]));
|
|
156786
|
+
const waiting = new Set(todo.slice(limit).map((t) => t.id));
|
|
156787
|
+
const games = [];
|
|
156788
|
+
for (const id of scope) {
|
|
156789
|
+
const now = thisCall.has(id) ? await gameStanding(deps, me, id) : before.get(id);
|
|
156790
|
+
const p = thisCall.get(id);
|
|
156791
|
+
games.push({
|
|
156792
|
+
gameId: id,
|
|
156793
|
+
...now,
|
|
156794
|
+
...p ? { thisCall: p.reread ? "reread" : "read" } : waiting.has(id) ? { thisCall: "waiting" } : {}
|
|
156795
|
+
});
|
|
156796
|
+
}
|
|
156797
|
+
out.games = games;
|
|
156798
|
+
}
|
|
156799
|
+
return out;
|
|
156800
|
+
}
|
|
156801
|
+
async function gameStanding(deps, me, gameId) {
|
|
156802
|
+
const { dataDir: dataDir2, env } = deps;
|
|
156803
|
+
if (!dataDir2 || !profileEnabled(env)) return { state: "unknown" };
|
|
156804
|
+
try {
|
|
156805
|
+
const salt = await playerRecordSalt(dataDir2);
|
|
156806
|
+
if (!salt) return { state: "not-processed" };
|
|
156807
|
+
const summary = await readFinishedSummary(finishedPath(dataDir2, salt, me, gameId));
|
|
156808
|
+
if (summary === "unreadable") return { state: "record-unreadable" };
|
|
156809
|
+
if (summary !== "missing") return { state: "recorded", outdated: summary.collector < COLLECTOR_VERSION, ...summary };
|
|
156810
|
+
return await isMarked(dataDir2, salt, me, gameId) ? { state: "processed-record-pruned" } : { state: "not-processed" };
|
|
156811
|
+
} catch {
|
|
156812
|
+
return { state: "unknown" };
|
|
156733
156813
|
}
|
|
156734
|
-
|
|
156814
|
+
}
|
|
156815
|
+
function rereadWanted(s, scope) {
|
|
156816
|
+
if (s.state === "processed-record-pruned") return scope === "all";
|
|
156817
|
+
if (s.state !== "recorded") return false;
|
|
156818
|
+
if (scope === "all") return true;
|
|
156819
|
+
if (scope === "failed") return s.status !== "captured";
|
|
156820
|
+
return s.outdated;
|
|
156821
|
+
}
|
|
156822
|
+
function failureCode(f) {
|
|
156823
|
+
return { reason: f.reason, ..."kind" in f && f.kind ? { kind: f.kind } : {} };
|
|
156735
156824
|
}
|
|
156736
156825
|
async function refreshProcessed(deps, me, window) {
|
|
156737
156826
|
const { dataDir: dataDir2, env } = deps;
|
|
@@ -165127,14 +165216,18 @@ function registerBackfillTool(server, ctx, env) {
|
|
|
165127
165216
|
{
|
|
165128
165217
|
title: "Process more finished war.app games at once",
|
|
165129
165218
|
_meta: mintMeta("change", ["backfill my war.app history", "process finished games", "catch up past games"]),
|
|
165130
|
-
description: `Give the end-of-game pass to up to \`limit\` (default 10, at most 25) of your finished war.app games not yet processed, newest first: each game's history is read ONCE from GameFeed (never again, whatever comes of it) and kept name-free for the opponent profiles, map records and lessons \u2014 what warapp_my_games does two games per call. \`window\` widens how many of your newest finished games are considered (default 250, at most ${MAX_FINISHED_RECORDS}). Reports what it processed and how many remain; safe to call again until \`remaining\` is 0. It also gives map records kept before the winners' income curves were those curves, from the histories already kept (\`winnerCurves\`, no request). Writes only this server's state and never writes to war.app. ` + BRIDGE_NOTE,
|
|
165219
|
+
description: `Give the end-of-game pass to up to \`limit\` (default 10, at most 25) of your finished war.app games not yet processed, newest first: each game's history is read ONCE from GameFeed (never again, whatever comes of it) and kept name-free for the opponent profiles, map records and lessons \u2014 what warapp_my_games does two games per call. \`window\` widens how many of your newest finished games are considered (default 250, at most ${MAX_FINISHED_RECORDS}). Reports what it processed and how many remain; safe to call again until \`remaining\` is 0. \`games\` lists every game considered one by one, from this server's state (no request): recorded (captured, read-failed or history-unreadable, with the failure code, history turns, boards kept, stats version, collector version and \`outdated\` when kept under an older collector), not-processed, processed-record-pruned or record-unreadable, and what this call did to it (read, reread, waiting). \`game_ids\` limits it to those games. \`reread\` reads the history AGAIN (one more GameFeed request per game) for games already processed \u2014 \`failed\` (read-failed or history-unreadable), \`outdated\` (kept under an older collector version, so newer metrics get captured) or \`all\` \u2014 and rebuilds the record and what was processed from it (each store replaces the game's share; nothing counts twice); a re-read that fails never replaces a captured record (\`keptPrevious\`). It also gives map records kept before the winners' income curves were those curves, from the histories already kept (\`winnerCurves\`, no request). Writes only this server's state and never writes to war.app. ` + BRIDGE_NOTE,
|
|
165131
165220
|
annotations: toolAnnotations({ title: "Backfill finished war.app games", readOnly: false, destructive: false, idempotent: true, openWorld: true }),
|
|
165132
165221
|
inputSchema: external_exports.object({
|
|
165133
165222
|
limit: external_exports.number().int().min(1).max(BACKFILL_MAX).optional().describe(`Games to process this call (default ${BACKFILL_DEFAULT}, max ${BACKFILL_MAX}).`),
|
|
165134
|
-
window: external_exports.number().int().min(1).max(MAX_FINISHED_RECORDS).optional().describe(`How many of your newest finished games to consider (default ${sweepWindow()}, max ${MAX_FINISHED_RECORDS}).`)
|
|
165223
|
+
window: external_exports.number().int().min(1).max(MAX_FINISHED_RECORDS).optional().describe(`How many of your newest finished games to consider (default ${sweepWindow()}, max ${MAX_FINISHED_RECORDS}).`),
|
|
165224
|
+
game_ids: external_exports.array(external_exports.number().int().positive()).min(1).max(MAX_FINISHED_RECORDS).optional().describe("Only these games (each a finished game of yours; others are listed in `notFinishedOrNotMine`)."),
|
|
165225
|
+
reread: external_exports.enum(["failed", "outdated", "all"]).optional().describe(
|
|
165226
|
+
"Read again the history of games already processed: `failed` (read-failed or history-unreadable), `outdated` (kept under an older collector version) or `all`. One GameFeed request per game; default none."
|
|
165227
|
+
)
|
|
165135
165228
|
})
|
|
165136
165229
|
},
|
|
165137
|
-
async ({ limit, window }) => {
|
|
165230
|
+
async ({ limit, window, game_ids, reread }) => {
|
|
165138
165231
|
if (!ctx.dataDir) refuse("This server has no data directory, so no history can be kept.", "Nothing to do here.");
|
|
165139
165232
|
if (!profileEnabled(env)) refuse("The end-of-game pass is off (WARAPP_PLAYER_PROFILE=off), so nothing was read.", "Turn profiling on to backfill.");
|
|
165140
165233
|
const { me, games } = await fetchMyGames(ctx);
|
|
@@ -165144,8 +165237,13 @@ function registerBackfillTool(server, ctx, env) {
|
|
|
165144
165237
|
const size = Math.min(window ?? sweepWindow(), MAX_FINISHED_RECORDS);
|
|
165145
165238
|
const r = await sweepFinished({ client: ctx.client, dataDir: ctx.dataDir, env }, token2, ids2, {
|
|
165146
165239
|
limit: limit ?? BACKFILL_DEFAULT,
|
|
165147
|
-
window: size
|
|
165240
|
+
window: size,
|
|
165241
|
+
report: true,
|
|
165242
|
+
...game_ids ? { only: game_ids } : {},
|
|
165243
|
+
...reread ? { reread } : {}
|
|
165148
165244
|
});
|
|
165245
|
+
const finished = new Set(ids2);
|
|
165246
|
+
const notMine = game_ids ? [...new Set(game_ids)].filter((id) => !finished.has(id)) : [];
|
|
165149
165247
|
const winnerCurves = await backfillWinnerCurves(ctx.dataDir);
|
|
165150
165248
|
return respond(void 0, ["compact"], () => ({
|
|
165151
165249
|
winnerCurves,
|
|
@@ -165154,7 +165252,10 @@ function registerBackfillTool(server, ctx, env) {
|
|
|
165154
165252
|
remaining: r.pending,
|
|
165155
165253
|
finishedGames: ids2.length,
|
|
165156
165254
|
window: size,
|
|
165157
|
-
...ids2.length > size ? { outsideWindow: ids2.length - size } : {}
|
|
165255
|
+
...ids2.length > size && !game_ids ? { outsideWindow: ids2.length - size } : {},
|
|
165256
|
+
collectorVersion: COLLECTOR_VERSION,
|
|
165257
|
+
games: r.games ?? [],
|
|
165258
|
+
...notMine.length ? { notFinishedOrNotMine: notMine } : {}
|
|
165158
165259
|
}));
|
|
165159
165260
|
}
|
|
165160
165261
|
);
|
package/dist/finished-store.js
CHANGED
|
@@ -53,6 +53,13 @@ export const finishedPath = (dir, salt, me, gameId) => join(finishedDir(dir), `$
|
|
|
53
53
|
/** The processed marks: not a record (its name is no key), so the prune and the record list skip it. */
|
|
54
54
|
export const processedPath = (dir) => join(finishedDir(dir), 'processed.json');
|
|
55
55
|
const KEY = /^[0-9a-f]{32}$/;
|
|
56
|
+
/**
|
|
57
|
+
* The version of what the end-of-game pass collects and processes from a history. Bump it whenever the capture
|
|
58
|
+
* or its processing (profiles, map record, lessons, decision-log truth, stats) gains or changes a metric:
|
|
59
|
+
* warapp_backfill_history's `reread: 'outdated'` then reads again the history of every game whose record was
|
|
60
|
+
* kept under an older one (a record kept before this field reads as 0). 1: the first versioned capture.
|
|
61
|
+
*/
|
|
62
|
+
export const COLLECTOR_VERSION = 1;
|
|
56
63
|
/**
|
|
57
64
|
* #541/#542: the version of the stats computation. 2: seat lines stop and resume as the client's (a return to
|
|
58
65
|
* Playing resumes; an AI takeover runs on under the seat with `aiFrom`). 3 (#542 follow-up): a seat ordering after
|
|
@@ -90,6 +97,39 @@ export async function readFinishedState(path) {
|
|
|
90
97
|
return 'unreadable';
|
|
91
98
|
}
|
|
92
99
|
}
|
|
100
|
+
/** The record at `path` summarised: `missing`, `unreadable` (as {@link readFinishedState}), or its summary. Never throws. */
|
|
101
|
+
export async function readFinishedSummary(path) {
|
|
102
|
+
let text;
|
|
103
|
+
try {
|
|
104
|
+
text = await readFile(path, 'utf8');
|
|
105
|
+
}
|
|
106
|
+
catch (e) {
|
|
107
|
+
return e.code === 'ENOENT' ? 'missing' : 'unreadable';
|
|
108
|
+
}
|
|
109
|
+
try {
|
|
110
|
+
const v = JSON.parse(text);
|
|
111
|
+
if (!isRec(v) || v.version !== VERSION || typeof v.status !== 'string' || !STATUSES.has(v.status))
|
|
112
|
+
return 'unreadable';
|
|
113
|
+
const r = v;
|
|
114
|
+
const f = isRec(r.failure) ? r.failure : undefined;
|
|
115
|
+
const stats = isRec(r.stats) ? r.stats : undefined;
|
|
116
|
+
return {
|
|
117
|
+
status: r.status,
|
|
118
|
+
collector: typeof r.collector === 'number' && Number.isInteger(r.collector) && r.collector >= 0 ? r.collector : 0,
|
|
119
|
+
...(f && typeof f.reason === 'string'
|
|
120
|
+
? { failure: { reason: f.reason, ...('kind' in f && typeof f.kind === 'string' ? { kind: f.kind } : {}) } }
|
|
121
|
+
: {}),
|
|
122
|
+
...(Array.isArray(r.turns) ? { turns: r.turns.length } : {}),
|
|
123
|
+
...(Array.isArray(r.boards) ? { boards: r.boards.length } : {}),
|
|
124
|
+
...(stats && typeof stats.version === 'number' ? { statsVersion: stats.version } : {}),
|
|
125
|
+
...(Array.isArray(r.kinds) ? { kinds: r.kinds.filter((k) => typeof k === 'string') } : {}),
|
|
126
|
+
...(isRec(r.outcome) && typeof r.outcome.result === 'string' ? { result: r.outcome.result } : {}),
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
catch {
|
|
130
|
+
return 'unreadable';
|
|
131
|
+
}
|
|
132
|
+
}
|
|
93
133
|
/**
|
|
94
134
|
* Write a record atomically (0600), then keep the newest {@link MAX_FINISHED_RECORDS}: never a path in
|
|
95
135
|
* `protect` (the sweep's window, src/tools/end-of-game.ts), nor the one just written. Throws on a failed write.
|
|
@@ -199,6 +239,7 @@ export function finishedRecordOf(p) {
|
|
|
199
239
|
const stored = kept ? storeBoards(kept.boards, p.game?.players.map((x) => x.id) ?? [p.me], key) : undefined;
|
|
200
240
|
return {
|
|
201
241
|
version: VERSION,
|
|
242
|
+
collector: COLLECTOR_VERSION,
|
|
202
243
|
status: p.status,
|
|
203
244
|
...(p.failure ? { failure: p.failure } : {}),
|
|
204
245
|
...(p.layout ? { layout: p.layout } : {}),
|
|
@@ -28,7 +28,7 @@ import { profileFormatOf } from '../analysis/opponent-profile.js';
|
|
|
28
28
|
import { trackGame } from '../analysis/opponents.js';
|
|
29
29
|
import { recordLessons, recordLessonsExcluded, recordMapExcluded, recordMapGame } from '../lessons-store.js';
|
|
30
30
|
import { endingOf, foldGame, markHistoryFolded, profileFileState } from '../profile-store.js';
|
|
31
|
-
import { END_STATS_VERSION, MAX_FINISHED_RECORDS, finishedPath, finishedRecordOf, markProcessed, readFinishedRecord, readFinishedState, readProcessed, storedStats, touchFinished, writeFinishedRecord, } from '../finished-store.js';
|
|
31
|
+
import { COLLECTOR_VERSION, END_STATS_VERSION, MAX_FINISHED_RECORDS, finishedPath, finishedRecordOf, markProcessed, readFinishedRecord, readFinishedState, readFinishedSummary, readProcessed, storedStats, touchFinished, writeFinishedRecord, } from '../finished-store.js';
|
|
32
32
|
import { playerKey } from '../player-record-store.js';
|
|
33
33
|
import { withPathLock } from '../path-lock.js';
|
|
34
34
|
import { finalOutlookOf, readOutlookLog } from '../outlook-log.js';
|
|
@@ -145,18 +145,19 @@ export async function endOfGame(deps, gameId, me, seen, opts = {}) {
|
|
|
145
145
|
await closeOnly();
|
|
146
146
|
return { status: 'record-unreadable' };
|
|
147
147
|
}
|
|
148
|
-
|
|
148
|
+
const reread = opts.reread === true;
|
|
149
|
+
if (state !== 'missing' && state.status === 'captured' && !reread)
|
|
149
150
|
return await keptOrBackfilled(dataDir, path, salt, me, opts.history ?? seen, opts.history);
|
|
150
|
-
if (state !== 'missing' && (!opts.retry || !opts.history))
|
|
151
|
+
if (state !== 'missing' && !reread && (!opts.retry || !opts.history))
|
|
151
152
|
return { status: 'already-processed' };
|
|
152
153
|
// The one history read: the caller's, else one request, sent once (no transport retry) and never retried.
|
|
153
154
|
let game = opts.history;
|
|
154
155
|
let failure;
|
|
155
156
|
if (!game) {
|
|
156
|
-
if (state === 'missing' && (await isMarked(dataDir, salt, me, gameId)))
|
|
157
|
+
if (state === 'missing' && !reread && (await isMarked(dataDir, salt, me, gameId)))
|
|
157
158
|
return { status: 'already-processed' };
|
|
158
|
-
// The request is spent from here on, whatever follows: never again in this process.
|
|
159
|
-
const key = attemptKey(dataDir, me, gameId)
|
|
159
|
+
// The request is spent from here on, whatever follows: never again in this process (a re-read once).
|
|
160
|
+
const key = `${attemptKey(dataDir, me, gameId)}${reread ? '|reread' : ''}`;
|
|
160
161
|
if (attempted.has(key))
|
|
161
162
|
return { status: 'attempted' };
|
|
162
163
|
remember(attempted, key);
|
|
@@ -192,6 +193,9 @@ export async function endOfGame(deps, gameId, me, seen, opts = {}) {
|
|
|
192
193
|
read = game;
|
|
193
194
|
const shown = game ?? seen;
|
|
194
195
|
const { record, history } = await buildRecord(dataDir, salt, me, gameId, game, shown, failure);
|
|
196
|
+
// A re-read that failed never replaces a capture kept before it.
|
|
197
|
+
if (reread && state !== 'missing' && state.status === 'captured' && record.status !== 'captured')
|
|
198
|
+
return { status: record.status, keptPrevious: true, ...(record.failure ? { failure: record.failure } : {}) };
|
|
195
199
|
kept = excludedKind(record.kinds ?? []);
|
|
196
200
|
try {
|
|
197
201
|
const protect = opts.protectIds ? new Set(opts.protectIds.map((id) => finishedPath(dataDir, salt, me, id))) : undefined;
|
|
@@ -537,24 +541,92 @@ export const sweepWindow = (keep = MAX_FINISHED_RECORDS) => Math.max(1, Math.flo
|
|
|
537
541
|
* sweep processed is so never read again (P2). `window` widens (or narrows) it for warapp_backfill_history,
|
|
538
542
|
* at most `keep` games.
|
|
539
543
|
*/
|
|
540
|
-
export async function sweepFinished(deps, me, gameIds, { limit = END_OF_GAME_PER_CALL, keep = MAX_FINISHED_RECORDS, window: size, } = {}) {
|
|
544
|
+
export async function sweepFinished(deps, me, gameIds, { limit = END_OF_GAME_PER_CALL, keep = MAX_FINISHED_RECORDS, window: size, only, reread, report, } = {}) {
|
|
541
545
|
// warapp_backfill_history may widen the window, never past the record bound (every game in it is protected).
|
|
542
546
|
const window = gameIds.slice(0, Math.max(1, Math.min(size ?? sweepWindow(keep), keep)));
|
|
547
|
+
const scope = only ? gameIds.filter((id) => only.includes(id)) : window;
|
|
543
548
|
// #412: with profiling off no pass runs, but these games are over: their decision logs leave `active`
|
|
544
549
|
// (no request; a log already closed costs one head read).
|
|
545
550
|
if (deps.dataDir && !profileEnabled(deps.env))
|
|
546
|
-
await finishDecisionLogs(deps.dataDir,
|
|
551
|
+
await finishDecisionLogs(deps.dataDir, scope, me, { mode: decisionLogModeOf(deps.env) });
|
|
552
|
+
const before = new Map();
|
|
553
|
+
if (report || reread)
|
|
554
|
+
for (const id of scope)
|
|
555
|
+
before.set(id, await gameStanding(deps, me, id));
|
|
547
556
|
const todo = [];
|
|
548
|
-
for (const id of
|
|
557
|
+
for (const id of scope) {
|
|
549
558
|
if (await needsEndOfGame(deps.dataDir, deps.env, id, me))
|
|
550
|
-
todo.push(id);
|
|
559
|
+
todo.push({ id, reread: false });
|
|
560
|
+
else if (reread && rereadWanted(before.get(id), reread))
|
|
561
|
+
todo.push({ id, reread: true });
|
|
562
|
+
}
|
|
551
563
|
await refreshProcessed(deps, me, window).catch(() => undefined);
|
|
552
564
|
const processed = [];
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
565
|
+
const protectIds = only ? [...new Set([...window, ...scope])] : window;
|
|
566
|
+
for (const t of todo.slice(0, limit)) {
|
|
567
|
+
const r = await endOfGame(deps, t.id, me, undefined, { fold: true, keep, protectIds, ...(t.reread ? { reread: true } : {}) });
|
|
568
|
+
processed.push({
|
|
569
|
+
gameId: t.id,
|
|
570
|
+
status: r.status,
|
|
571
|
+
...(t.reread ? { reread: true } : {}),
|
|
572
|
+
...(r.turns !== undefined ? { turns: r.turns } : {}),
|
|
573
|
+
...(r.failure ? { failure: failureCode(r.failure) } : {}),
|
|
574
|
+
...(r.keptPrevious ? { keptPrevious: true } : {}),
|
|
575
|
+
});
|
|
576
|
+
}
|
|
577
|
+
const out = { processed, pending: Math.max(0, todo.length - limit) };
|
|
578
|
+
if (report) {
|
|
579
|
+
const thisCall = new Map(processed.map((p) => [p.gameId, p]));
|
|
580
|
+
const waiting = new Set(todo.slice(limit).map((t) => t.id));
|
|
581
|
+
const games = [];
|
|
582
|
+
for (const id of scope) {
|
|
583
|
+
const now = thisCall.has(id) ? await gameStanding(deps, me, id) : before.get(id);
|
|
584
|
+
const p = thisCall.get(id);
|
|
585
|
+
games.push({
|
|
586
|
+
gameId: id,
|
|
587
|
+
...now,
|
|
588
|
+
...(p ? { thisCall: p.reread ? 'reread' : 'read' } : waiting.has(id) ? { thisCall: 'waiting' } : {}),
|
|
589
|
+
});
|
|
590
|
+
}
|
|
591
|
+
out.games = games;
|
|
592
|
+
}
|
|
593
|
+
return out;
|
|
594
|
+
}
|
|
595
|
+
/** One game's standing from this server's state alone (no request). Never throws. */
|
|
596
|
+
export async function gameStanding(deps, me, gameId) {
|
|
597
|
+
const { dataDir, env } = deps;
|
|
598
|
+
if (!dataDir || !profileEnabled(env))
|
|
599
|
+
return { state: 'unknown' };
|
|
600
|
+
try {
|
|
601
|
+
const salt = await playerRecordSalt(dataDir);
|
|
602
|
+
if (!salt)
|
|
603
|
+
return { state: 'not-processed' };
|
|
604
|
+
const summary = await readFinishedSummary(finishedPath(dataDir, salt, me, gameId));
|
|
605
|
+
if (summary === 'unreadable')
|
|
606
|
+
return { state: 'record-unreadable' };
|
|
607
|
+
if (summary !== 'missing')
|
|
608
|
+
return { state: 'recorded', outdated: summary.collector < COLLECTOR_VERSION, ...summary };
|
|
609
|
+
return (await isMarked(dataDir, salt, me, gameId)) ? { state: 'processed-record-pruned' } : { state: 'not-processed' };
|
|
556
610
|
}
|
|
557
|
-
|
|
611
|
+
catch {
|
|
612
|
+
return { state: 'unknown' };
|
|
613
|
+
}
|
|
614
|
+
}
|
|
615
|
+
/** Whether `reread` names a game in this standing. */
|
|
616
|
+
function rereadWanted(s, scope) {
|
|
617
|
+
if (s.state === 'processed-record-pruned')
|
|
618
|
+
return scope === 'all';
|
|
619
|
+
if (s.state !== 'recorded')
|
|
620
|
+
return false;
|
|
621
|
+
if (scope === 'all')
|
|
622
|
+
return true;
|
|
623
|
+
if (scope === 'failed')
|
|
624
|
+
return s.status !== 'captured';
|
|
625
|
+
return s.outdated;
|
|
626
|
+
}
|
|
627
|
+
/** A failure as the sweep reports it: codes only. */
|
|
628
|
+
function failureCode(f) {
|
|
629
|
+
return { reason: f.reason, ...('kind' in f && f.kind ? { kind: f.kind } : {}) };
|
|
558
630
|
}
|
|
559
631
|
/** Mark the window's records most recently used, so a prune drops a record outside the window first. */
|
|
560
632
|
async function refreshProcessed(deps, me, window) {
|
package/dist/tools/state.js
CHANGED
|
@@ -20,7 +20,7 @@ import { backfillWinnerCurves } from './map-curves.js';
|
|
|
20
20
|
import { CONFIRM_INJECTION_RULE, McpToolError, toolAnnotations } from '@chrischall/mcp-utils';
|
|
21
21
|
import { mintUploadSlot, resolveUploadSource } from '@chrischall/mcp-utils/export';
|
|
22
22
|
import { z } from 'zod';
|
|
23
|
-
import { MAX_FINISHED_RECORDS } from '../finished-store.js';
|
|
23
|
+
import { COLLECTOR_VERSION, MAX_FINISHED_RECORDS } from '../finished-store.js';
|
|
24
24
|
import { profileEnabled } from '../profile-store.js';
|
|
25
25
|
import { applyImport, decodeBundle, MAX_BUNDLE_BYTES, planImport, StateBundleError, } from '../state-bundle.js';
|
|
26
26
|
import { respond } from './common.js';
|
|
@@ -188,7 +188,15 @@ function registerBackfillTool(server, ctx, env) {
|
|
|
188
188
|
'it) and kept name-free for the opponent profiles, map records and lessons — what warapp_my_games does two ' +
|
|
189
189
|
'games per call. `window` widens how many of your newest finished games are considered (default 250, at ' +
|
|
190
190
|
`most ${MAX_FINISHED_RECORDS}). Reports what it processed and how many remain; safe to call again until ` +
|
|
191
|
-
'`remaining` is 0.
|
|
191
|
+
'`remaining` is 0. `games` lists every game considered one by one, from this server\'s state (no request): ' +
|
|
192
|
+
'recorded (captured, read-failed or history-unreadable, with the failure code, history turns, boards kept, ' +
|
|
193
|
+
'stats version, collector version and `outdated` when kept under an older collector), not-processed, ' +
|
|
194
|
+
'processed-record-pruned or record-unreadable, and what this call did to it (read, reread, waiting). ' +
|
|
195
|
+
'`game_ids` limits it to those games. `reread` reads the history AGAIN (one more GameFeed request per game) ' +
|
|
196
|
+
'for games already processed — `failed` (read-failed or history-unreadable), `outdated` (kept under an older ' +
|
|
197
|
+
'collector version, so newer metrics get captured) or `all` — and rebuilds the record and what was processed ' +
|
|
198
|
+
'from it (each store replaces the game\'s share; nothing counts twice); a re-read that fails never replaces a ' +
|
|
199
|
+
'captured record (`keptPrevious`). It also gives map records kept before the winners\' income curves were those curves, from the ' +
|
|
192
200
|
'histories already kept (`winnerCurves`, no request). Writes only this server\'s state and never writes to war.app. ' +
|
|
193
201
|
BRIDGE_NOTE,
|
|
194
202
|
annotations: toolAnnotations({ title: 'Backfill finished war.app games', readOnly: false, destructive: false, idempotent: true, openWorld: true }),
|
|
@@ -201,8 +209,18 @@ function registerBackfillTool(server, ctx, env) {
|
|
|
201
209
|
.max(MAX_FINISHED_RECORDS)
|
|
202
210
|
.optional()
|
|
203
211
|
.describe(`How many of your newest finished games to consider (default ${sweepWindow()}, max ${MAX_FINISHED_RECORDS}).`),
|
|
212
|
+
game_ids: z
|
|
213
|
+
.array(z.number().int().positive())
|
|
214
|
+
.min(1)
|
|
215
|
+
.max(MAX_FINISHED_RECORDS)
|
|
216
|
+
.optional()
|
|
217
|
+
.describe('Only these games (each a finished game of yours; others are listed in `notFinishedOrNotMine`).'),
|
|
218
|
+
reread: z
|
|
219
|
+
.enum(['failed', 'outdated', 'all'])
|
|
220
|
+
.optional()
|
|
221
|
+
.describe("Read again the history of games already processed: `failed` (read-failed or history-unreadable), `outdated` (kept under an older collector version) or `all`. One GameFeed request per game; default none."),
|
|
204
222
|
}),
|
|
205
|
-
}, async ({ limit, window }) => {
|
|
223
|
+
}, async ({ limit, window, game_ids, reread }) => {
|
|
206
224
|
if (!ctx.dataDir)
|
|
207
225
|
refuse('This server has no data directory, so no history can be kept.', 'Nothing to do here.');
|
|
208
226
|
if (!profileEnabled(env))
|
|
@@ -216,7 +234,12 @@ function registerBackfillTool(server, ctx, env) {
|
|
|
216
234
|
const r = await sweepFinished({ client: ctx.client, dataDir: ctx.dataDir, env }, token, ids, {
|
|
217
235
|
limit: limit ?? BACKFILL_DEFAULT,
|
|
218
236
|
window: size,
|
|
237
|
+
report: true,
|
|
238
|
+
...(game_ids ? { only: game_ids } : {}),
|
|
239
|
+
...(reread ? { reread } : {}),
|
|
219
240
|
});
|
|
241
|
+
const finished = new Set(ids);
|
|
242
|
+
const notMine = game_ids ? [...new Set(game_ids)].filter((id) => !finished.has(id)) : [];
|
|
220
243
|
// #419: entries kept before the winners' curves were, given them from the kept histories (no request).
|
|
221
244
|
const winnerCurves = await backfillWinnerCurves(ctx.dataDir);
|
|
222
245
|
return respond(undefined, ['compact'], () => ({
|
|
@@ -226,7 +249,10 @@ function registerBackfillTool(server, ctx, env) {
|
|
|
226
249
|
remaining: r.pending,
|
|
227
250
|
finishedGames: ids.length,
|
|
228
251
|
window: size,
|
|
229
|
-
...(ids.length > size ? { outsideWindow: ids.length - size } : {}),
|
|
252
|
+
...(ids.length > size && !game_ids ? { outsideWindow: ids.length - size } : {}),
|
|
253
|
+
collectorVersion: COLLECTOR_VERSION,
|
|
254
|
+
games: r.games ?? [],
|
|
255
|
+
...(notMine.length ? { notFinishedOrNotMine: notMine } : {}),
|
|
230
256
|
}));
|
|
231
257
|
});
|
|
232
258
|
}
|
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.
|
|
4
|
+
export const VERSION = '0.16.0'; // x-release-please-version
|
package/manifest.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"manifest_version": "0.3",
|
|
4
4
|
"name": "warapp-mcp",
|
|
5
5
|
"display_name": "war.app (Warzone)",
|
|
6
|
-
"version": "0.
|
|
6
|
+
"version": "0.16.0",
|
|
7
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, closing out a finished 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, importing local history into a hosted server and linking a session (local only) are confirm-gated.",
|
|
8
8
|
"author": {
|
|
9
9
|
"name": "Chris Hall",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@chrischall/warapp-mcp",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.16.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>",
|
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.
|
|
9
|
+
"version": "0.16.0",
|
|
10
10
|
"packages": [
|
|
11
11
|
{
|
|
12
12
|
"registryType": "npm",
|
|
13
13
|
"identifier": "@chrischall/warapp-mcp",
|
|
14
|
-
"version": "0.
|
|
14
|
+
"version": "0.16.0",
|
|
15
15
|
"transport": {
|
|
16
16
|
"type": "stdio"
|
|
17
17
|
},
|