@chrischall/warapp-mcp 0.14.0 → 0.15.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 +2 -0
- package/dist/analysis/income-calibration.js +280 -0
- package/dist/analysis/intel.js +1 -1
- package/dist/analysis/opponents.js +52 -3
- package/dist/analysis/plan/deploy-estimates.js +1 -1
- package/dist/analysis/plan/estimates.js +40 -6
- package/dist/analysis/plan/threats.js +1 -1
- package/dist/bundle.js +1599 -481
- package/dist/decision-log.js +44 -5
- package/dist/tools/calibration-harness.js +102 -0
- package/dist/tools/calibration.js +110 -0
- package/dist/tools/check-plan.js +23 -1
- package/dist/tools/common.js +14 -0
- package/dist/tools/decision-capture.js +14 -1
- package/dist/tools/index.js +6 -0
- package/dist/tools/opponents.js +2 -0
- package/dist/tools/stress-opponents.js +8 -4
- package/dist/tools/turn-history.js +214 -0
- package/dist/tools/turn.js +25 -7
- package/dist/turn-orders.js +64 -0
- package/dist/version.js +1 -1
- package/manifest.json +9 -1
- package/package.json +1 -1
- package/server.json +2 -2
- package/skills/warapp-mcp/SKILL.md +9 -1
package/dist/decision-log.js
CHANGED
|
@@ -83,6 +83,20 @@ export function decisionLogMode(env = process.env) {
|
|
|
83
83
|
}
|
|
84
84
|
/** The keys of `PlanInput` that are not kept in {@link LoggedInput}. */
|
|
85
85
|
const INPUT_DROPPED = new Set(['graph', 'board', 'vacated', 'bonusPush', 'previousBoard']);
|
|
86
|
+
/** #568: the stages of an estimate as the decision log keeps them. */
|
|
87
|
+
export function estimateStages(e) {
|
|
88
|
+
return {
|
|
89
|
+
visible: e.base + e.bonusIncome,
|
|
90
|
+
observed: e.observed,
|
|
91
|
+
tracked: e.tracked,
|
|
92
|
+
prior: e.stated ? e.stated.full : e.prior,
|
|
93
|
+
stated: e.stated ? e.stated.scaled : null,
|
|
94
|
+
blend: e.priorBlend ? e.priorBlend.figure : null,
|
|
95
|
+
thin: e.thinEvidence ? e.thinEvidence.figure : null,
|
|
96
|
+
known: e.known ? e.known.income : null,
|
|
97
|
+
card: e.card ? e.card.armies : 0,
|
|
98
|
+
};
|
|
99
|
+
}
|
|
86
100
|
/** Chat messages kept per turn at most. */
|
|
87
101
|
export const MAX_LOGGED_CHAT = 50;
|
|
88
102
|
/** Game events kept at most per log (the newest). */
|
|
@@ -225,10 +239,19 @@ export function decodeInput(logged, board, graph) {
|
|
|
225
239
|
};
|
|
226
240
|
}
|
|
227
241
|
/** The estimates as logged: ids, figures and flags only. */
|
|
228
|
-
export function loggedEstimates(estimates) {
|
|
242
|
+
export function loggedEstimates(estimates, tracks) {
|
|
243
|
+
const methods = new Map((tracks ?? []).flatMap((t) => (t.incomeMethod ? [[t.playerId, t.incomeMethod]] : [])));
|
|
229
244
|
return [...estimates]
|
|
230
245
|
.sort((a, b) => a.playerId - b.playerId)
|
|
231
|
-
.map((e) => ({
|
|
246
|
+
.map((e) => ({
|
|
247
|
+
player: e.playerId,
|
|
248
|
+
estimate: e.estimate,
|
|
249
|
+
source: e.source,
|
|
250
|
+
coverage: e.coverage?.share ?? null,
|
|
251
|
+
thin: !!e.thinEvidence,
|
|
252
|
+
...(methods.has(e.playerId) ? { method: methods.get(e.playerId) } : {}),
|
|
253
|
+
stages: estimateStages(e),
|
|
254
|
+
}));
|
|
232
255
|
}
|
|
233
256
|
/** My income as `input` gives it, card armies out; `undefined` when it holds none. */
|
|
234
257
|
function earnedIncome(input) {
|
|
@@ -237,7 +260,7 @@ function earnedIncome(input) {
|
|
|
237
260
|
return undefined;
|
|
238
261
|
return income - (typeof cardArmies === 'number' ? cardArmies : 0);
|
|
239
262
|
}
|
|
240
|
-
function decisionOf(plan, outlook, outlookLean, estimates, income) {
|
|
263
|
+
function decisionOf(plan, outlook, outlookLean, estimates, income, tracks) {
|
|
241
264
|
return encodeValue({
|
|
242
265
|
goal: plan.goal,
|
|
243
266
|
profile: plan.profile,
|
|
@@ -252,7 +275,7 @@ function decisionOf(plan, outlook, outlookLean, estimates, income) {
|
|
|
252
275
|
warnings: plan.warnings,
|
|
253
276
|
outlook: outlook ?? null,
|
|
254
277
|
...(outlookLean ? { outlookLean } : {}),
|
|
255
|
-
...(estimates ? { estimates: loggedEstimates(estimates) } : {}),
|
|
278
|
+
...(estimates ? { estimates: loggedEstimates(estimates, tracks) } : {}),
|
|
256
279
|
...(income !== undefined ? { income } : {}),
|
|
257
280
|
});
|
|
258
281
|
}
|
|
@@ -402,7 +425,7 @@ export async function recordDecision(dir, gameId, playerId, rec, opts = {}) {
|
|
|
402
425
|
kind: 'planned',
|
|
403
426
|
input,
|
|
404
427
|
planner: { version: VERSION, ...(build ? { build } : {}) },
|
|
405
|
-
decision: decisionOf(rec.plan, rec.outlookState, rec.outlookLean, rec.estimates, earnedIncome(rec.input)),
|
|
428
|
+
decision: decisionOf(rec.plan, rec.outlookState, rec.outlookLean, rec.estimates, earnedIncome(rec.input), rec.input.tracks),
|
|
406
429
|
times: encodeValue({ plannedAt: iso(rec.now), ...rec.times }),
|
|
407
430
|
...(rec.firstMover !== undefined ? { firstMover: rec.firstMover ? { ...rec.firstMover } : null } : {}),
|
|
408
431
|
...(rec.cards ? { cards: encodeValue(rec.cards) } : {}),
|
|
@@ -653,6 +676,22 @@ export async function recordCheck(dir, gameId, playerId, turn, summary, opts = {
|
|
|
653
676
|
return false;
|
|
654
677
|
}
|
|
655
678
|
}
|
|
679
|
+
/**
|
|
680
|
+
* #570: keep the resolved turn's visible orders on that turn's entry (an entry is started when none exists).
|
|
681
|
+
* Read again, the newest read wins. `true` when written. Never throws.
|
|
682
|
+
*/
|
|
683
|
+
export async function recordSeenTurn(dir, gameId, playerId, seen, opts = {}) {
|
|
684
|
+
try {
|
|
685
|
+
const kept = { orders: seen.orders, ...(seen.omitted ? { omitted: seen.omitted } : {}) };
|
|
686
|
+
return await updateDecisionLog(dir, gameId, playerId, (log) => {
|
|
687
|
+
const was = log.turns[String(seen.turn)] ?? {};
|
|
688
|
+
return { ...log, turns: { ...log.turns, [String(seen.turn)]: { ...was, seen: kept } } };
|
|
689
|
+
}, opts);
|
|
690
|
+
}
|
|
691
|
+
catch {
|
|
692
|
+
return false;
|
|
693
|
+
}
|
|
694
|
+
}
|
|
656
695
|
// ---------------------------------------------------------------------------------------------
|
|
657
696
|
// #437 task 2: per-game events and context
|
|
658
697
|
/** States in which a seat's change is no event (still in, or not yet in). */
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
// The #318 calibration and opening-benchmark harness over the data directory: the body of
|
|
2
|
+
// `scripts/calibrate.mjs`, moved here (#569) so the script and warapp_calibration's `harness: true` share it.
|
|
3
|
+
// It reads the end-of-game records, settings records, stored maps and cached boards (src/calibration-source.ts)
|
|
4
|
+
// and returns aggregates only — no game id, player id or name. No request, nothing written. The pure parts are
|
|
5
|
+
// src/analysis/calibrate.ts; docs/PLAN-PROFILES.md "Calibration" says what it approximates.
|
|
6
|
+
import { profileFormatOf } from '../analysis/opponent-profile.js';
|
|
7
|
+
import { trackGame } from '../analysis/opponents.js';
|
|
8
|
+
import { applyBonusOverrides } from '../analysis/overrides.js';
|
|
9
|
+
import { aggregateBenchmarks, aggregateEstimates, benchmarkByEra, estimateSamples, openingBenchmark, openingEra, openingFlags, ratioSummary, } from '../analysis/calibrate.js';
|
|
10
|
+
import { addCalibration } from '../analysis/game-lessons.js';
|
|
11
|
+
import { calibrationSources } from '../calibration-source.js';
|
|
12
|
+
import { holdsSeat } from '../player-states.js';
|
|
13
|
+
import { graphOf } from './common.js';
|
|
14
|
+
import { plannerSettings } from './turn.js';
|
|
15
|
+
/** What the opening benchmark approximates: printed by the script and reported by the tool. */
|
|
16
|
+
export const HARNESS_APPROXIMATIONS = [
|
|
17
|
+
'Opening benchmark approximations: the planner sees the whole board (no fog); opponents never attack me —',
|
|
18
|
+
'they hold the land and armies the history shows, except land I hold in the replay; card plays are left out;',
|
|
19
|
+
'with luck or weighted rounding a battle is resolved at its expectation (counted as inexact).',
|
|
20
|
+
'Eras (#503): pre-tool = never planned by this server, or no local cache names the game; pre-rule-4f = turn 1',
|
|
21
|
+
'before 2026-11-13 08:24Z by its turn-1 time where known, else game id below 45690000 (ids are assigned at creation,',
|
|
22
|
+
'so the id boundary approximates the time); current = the rest. A game with a turn with no orders of mine (read off',
|
|
23
|
+
'the history boards: no capture, no failed attack, no orders cached; army growth alone is not orders) or a boot of my seat in turns',
|
|
24
|
+
'1-4 is reported apart, never averaged in.',
|
|
25
|
+
];
|
|
26
|
+
/** Run the harness over `dir`. `turns`: the opening benchmark's length (default the module's). Never requests. */
|
|
27
|
+
export async function calibrationHarness(dir, opts = {}) {
|
|
28
|
+
const src = await calibrationSources(dir);
|
|
29
|
+
const counts = { histories: src.statuses, skipped: src.skipped, scored: 0, recordOnly: 0, benchmarked: 0, samples: 0 };
|
|
30
|
+
const byFormat = {};
|
|
31
|
+
const benchByFormat = {};
|
|
32
|
+
const eraEntries = [];
|
|
33
|
+
for (const input of src.inputs) {
|
|
34
|
+
const { history: h, settings, map, cached } = input;
|
|
35
|
+
if (input.source === 'record-only')
|
|
36
|
+
counts.recordOnly++;
|
|
37
|
+
const me = h.me;
|
|
38
|
+
const graph = graphOf(applyBonusOverrides(map, settings));
|
|
39
|
+
const seated = h.players.filter((p) => holdsSeat(p.state));
|
|
40
|
+
const format = profileFormatOf(seated);
|
|
41
|
+
const mine = seated.find((p) => p.id === me);
|
|
42
|
+
const myTeam = typeof mine?.team === 'number' && mine.team >= 0 ? mine.team : undefined;
|
|
43
|
+
const opponents = seated.filter((p) => p.id !== me && (myTeam === undefined || p.team !== myTeam)).map((p) => p.id);
|
|
44
|
+
const asPlaying = seated.map(({ state: _s, ...p }) => p);
|
|
45
|
+
const ps = plannerSettings(settings);
|
|
46
|
+
const samples = estimateSamples({
|
|
47
|
+
graph,
|
|
48
|
+
me,
|
|
49
|
+
cached,
|
|
50
|
+
history: h.boards,
|
|
51
|
+
plannerSettings: ps,
|
|
52
|
+
incomeSettings: settings,
|
|
53
|
+
settings,
|
|
54
|
+
game: trackGame(asPlaying, settings, map),
|
|
55
|
+
players: asPlaying,
|
|
56
|
+
opponents,
|
|
57
|
+
});
|
|
58
|
+
counts.samples += samples.length;
|
|
59
|
+
if (samples.length)
|
|
60
|
+
counts.scored++;
|
|
61
|
+
const agg = aggregateEstimates(samples);
|
|
62
|
+
const f = (byFormat[format] ??= {});
|
|
63
|
+
for (const [k, c] of Object.entries(agg))
|
|
64
|
+
f[k] = addCalibration(f[k] ?? {}, c);
|
|
65
|
+
const bench = openingBenchmark({
|
|
66
|
+
graph,
|
|
67
|
+
me,
|
|
68
|
+
history: h.boards,
|
|
69
|
+
plannerSettings: ps,
|
|
70
|
+
incomeSettings: settings,
|
|
71
|
+
players: asPlaying,
|
|
72
|
+
winners: seated.filter((p) => p.state === 'Won').map((p) => p.id),
|
|
73
|
+
...(opts.turns ? { turns: opts.turns } : {}),
|
|
74
|
+
});
|
|
75
|
+
if (bench.turns.length) {
|
|
76
|
+
counts.benchmarked++;
|
|
77
|
+
(benchByFormat[format] ??= []).push(bench);
|
|
78
|
+
// #503: the era (turn-1 time where known — no record keeps one yet — else the game id) and the
|
|
79
|
+
// opening window's flags (turns with no orders of mine, a boot of my seat).
|
|
80
|
+
const o = input.opening;
|
|
81
|
+
const { era, basis } = openingEra({ planned: o.planned, ...(o.gameId !== undefined ? { gameId: o.gameId } : {}) });
|
|
82
|
+
const flags = openingFlags({
|
|
83
|
+
me,
|
|
84
|
+
history: h.boards,
|
|
85
|
+
sentTurns: o.sentTurns,
|
|
86
|
+
failedAttackTurns: o.failedAttackTurns,
|
|
87
|
+
booted: { turn: o.bootedTurn },
|
|
88
|
+
});
|
|
89
|
+
eraEntries.push({ era, basis, format, territories: graph.territoryById.size, flags, bench });
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
const calibration = {};
|
|
93
|
+
for (const [format, ests] of Object.entries(byFormat))
|
|
94
|
+
for (const [k, c] of Object.entries(ests))
|
|
95
|
+
for (const [band, stats] of Object.entries(c))
|
|
96
|
+
((calibration[format] ??= {})[k] ??= {})[band] = ratioSummary(stats);
|
|
97
|
+
const benchmark = {};
|
|
98
|
+
for (const [format, list] of Object.entries(benchByFormat))
|
|
99
|
+
benchmark[format] = aggregateBenchmarks(list);
|
|
100
|
+
benchmark.all = aggregateBenchmarks(Object.values(benchByFormat).flat());
|
|
101
|
+
return { counts, calibration, benchmark, byEra: benchmarkByEra(eraEntries) };
|
|
102
|
+
}
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
// warapp_calibration (#569, for #568): the income estimates this server planned with, scored against the
|
|
2
|
+
// truth its finished games kept — read-only, from this server's state alone (no war.app request), so an agent
|
|
3
|
+
// can run the calibration on a hosted server whose data directory no local script can reach. The pure part is
|
|
4
|
+
// src/analysis/income-calibration.ts; `harness: true` adds the #318 harness (src/tools/calibration-harness.ts).
|
|
5
|
+
// Name-free: games are numbered by their place in the report, never by id; no player is named or numbered.
|
|
6
|
+
import { toolAnnotations } from '@chrischall/mcp-utils';
|
|
7
|
+
import { z } from 'zod';
|
|
8
|
+
import { incomeCalibration, incomeSamples } from '../analysis/income-calibration.js';
|
|
9
|
+
import { profileFormatOf } from '../analysis/opponent-profile.js';
|
|
10
|
+
import { listDecisionLogs, readDecisionLog } from '../decision-log.js';
|
|
11
|
+
import { holdsSeat } from '../player-states.js';
|
|
12
|
+
import { readGameRecord } from '../replay.js';
|
|
13
|
+
import { calibrationHarness, HARNESS_APPROXIMATIONS } from './calibration-harness.js';
|
|
14
|
+
import { respond } from './common.js';
|
|
15
|
+
import { mintMeta } from './hints.js';
|
|
16
|
+
import { refuse } from './write-kit.js';
|
|
17
|
+
/** Scored rows returned at most with `samples: true`. */
|
|
18
|
+
export const MAX_SAMPLES = 2000;
|
|
19
|
+
export const CALIBRATION_NOTE = 'Each sample is one income estimate a planned turn worked from, against that opponent\'s true income (base plus ' +
|
|
20
|
+
'full bonuses, cards and the army cap aside) on the board the turn was played on, read from the finished game\'s ' +
|
|
21
|
+
'history. ratio = estimate ÷ truth; meanError = estimate − truth in armies. Reported only: nothing plans on it. ' +
|
|
22
|
+
'Only games whose decision log was given the end-of-game truth count (games played on builds with the decision log, ' +
|
|
23
|
+
'finished, their history read); `method` (the tracker\'s, incl. rise-capped) is logged only since #569. The ' +
|
|
24
|
+
'consequences block is a proxy: a lost territory has many causes.';
|
|
25
|
+
/** Every finished decision log in `dir` as the scoring reads it, in game-id order; lotteries counted apart. Never throws. */
|
|
26
|
+
export async function calibrationGames(dir) {
|
|
27
|
+
const listed = (await listDecisionLogs(dir)).filter((l) => l.status !== 'active');
|
|
28
|
+
const games = [];
|
|
29
|
+
let lotteries = 0;
|
|
30
|
+
let withoutTruth = 0;
|
|
31
|
+
for (const l of listed) {
|
|
32
|
+
const log = await readDecisionLog(dir, l.gameId, l.playerId);
|
|
33
|
+
if (!log)
|
|
34
|
+
continue;
|
|
35
|
+
if (log.join?.lottery !== undefined) {
|
|
36
|
+
lotteries++;
|
|
37
|
+
continue;
|
|
38
|
+
}
|
|
39
|
+
if (!Object.values(log.turns).some((e) => e.accuracy?.estimates.length)) {
|
|
40
|
+
withoutTruth++;
|
|
41
|
+
continue;
|
|
42
|
+
}
|
|
43
|
+
games.push({ ...(await formatOf(dir, log)), turns: log.turns });
|
|
44
|
+
}
|
|
45
|
+
return { games, logs: listed.length, lotteries, withoutTruth };
|
|
46
|
+
}
|
|
47
|
+
async function formatOf(dir, log) {
|
|
48
|
+
const game = await readGameRecord(dir, log.gameId);
|
|
49
|
+
if (game?.players.length) {
|
|
50
|
+
const seated = game.players.filter((p) => holdsSeat(p.state));
|
|
51
|
+
return { format: profileFormatOf(seated), seats: seated.length };
|
|
52
|
+
}
|
|
53
|
+
if (log.join)
|
|
54
|
+
return { format: log.join.flags.format, seats: log.join.flags.seats };
|
|
55
|
+
const seats = log.seats ? Object.keys(log.seats).length : null;
|
|
56
|
+
return { format: seats === 2 ? '1v1' : 'unknown', seats };
|
|
57
|
+
}
|
|
58
|
+
export function registerCalibrationTool(server, dataDir) {
|
|
59
|
+
server.registerTool('warapp_calibration', {
|
|
60
|
+
title: 'Score the income estimates against finished games',
|
|
61
|
+
_meta: mintMeta('lookup', ['how accurate are the income estimates', 'calibrate opponent income', 'estimate accuracy']),
|
|
62
|
+
description: 'Score the opponent income estimates this server planned with against the truth its finished games kept ' +
|
|
63
|
+
'(the decision log\'s end-of-game truth): each estimate ÷ the true income, and its signed error in armies, ' +
|
|
64
|
+
'overall and by format, seats, phase (turns 1–4, 5–10, 11+), frontier coverage band, estimate source, thin ' +
|
|
65
|
+
'evidence, the tracker\'s income method (rise-capped or not; logged since #569), leader vs trailer, and phase ' +
|
|
66
|
+
'by coverage; the catch-up lag after a true income jump of 1.5× or more (turns until the estimate reaches two ' +
|
|
67
|
+
'thirds of the truth); a consequences proxy (turns that lost a territory the plan did not concede, with an ' +
|
|
68
|
+
'estimate under half the truth vs without); the largest misses; each pipeline stage\'s figure ÷ the truth ' +
|
|
69
|
+
'(visible, observed, tracked, prior, stated, blend, thin, known; logged since #568); and what correcting the ' +
|
|
70
|
+
'tracked figure by its coverage band would have read at dampings 0 to 1 (leave one game out). `samples: true` adds the scored rows ' +
|
|
71
|
+
`(at most ${MAX_SAMPLES}), name-free, as a fixture set; \`harness: true\` also runs the #318 harness over the ` +
|
|
72
|
+
'cached boards (tracker, fog prior and plan estimate by coverage band, and the opening benchmark), which can ' +
|
|
73
|
+
'take a while on many games. Games are numbered by their place in the report, never by id, and no player is ' +
|
|
74
|
+
'named. Makes no war.app request and writes nothing. Read-only.',
|
|
75
|
+
annotations: toolAnnotations({ title: 'Income estimate calibration', readOnly: true, destructive: false, idempotent: true, openWorld: false }),
|
|
76
|
+
inputSchema: z.object({
|
|
77
|
+
samples: z.boolean().optional().describe(`Also return the scored rows, name-free (default false; at most ${MAX_SAMPLES}).`),
|
|
78
|
+
harness: z.boolean().optional().describe('Also run the #318 harness over the cached boards and the opening benchmark (default false).'),
|
|
79
|
+
format: z.enum(['1v1', 'ffa', 'team']).optional().describe('Only games of this format.'),
|
|
80
|
+
}),
|
|
81
|
+
}, async ({ samples, harness, format }) => {
|
|
82
|
+
const dir = dataDir();
|
|
83
|
+
if (!dir)
|
|
84
|
+
refuse('This server has no data directory, so there is nothing to score.', 'Nothing to do here.');
|
|
85
|
+
const src = await calibrationGames(dir);
|
|
86
|
+
const games = format ? src.games.filter((g) => g.format === format) : src.games;
|
|
87
|
+
const report = incomeCalibration(games);
|
|
88
|
+
const rows = samples ? incomeSamples(games) : [];
|
|
89
|
+
const extra = harness ? await calibrationHarness(dir) : undefined;
|
|
90
|
+
return respond(undefined, ['compact'], () => ({
|
|
91
|
+
readAs: CALIBRATION_NOTE,
|
|
92
|
+
sources: {
|
|
93
|
+
finishedLogs: src.logs,
|
|
94
|
+
scoredGames: report.games,
|
|
95
|
+
lotteriesLeftOut: src.lotteries,
|
|
96
|
+
withoutTruth: src.withoutTruth,
|
|
97
|
+
...(format ? { format, otherFormats: src.games.length - games.length } : {}),
|
|
98
|
+
},
|
|
99
|
+
...(report.samples
|
|
100
|
+
? { report }
|
|
101
|
+
: {
|
|
102
|
+
report: null,
|
|
103
|
+
empty: 'No finished game with the end-of-game truth in its decision log yet: the truth is written when a finished ' +
|
|
104
|
+
"game's history is read (warapp_backfill_history, warapp_my_games' sweep, warapp_get_game on it).",
|
|
105
|
+
}),
|
|
106
|
+
...(samples ? { samples: rows.slice(0, MAX_SAMPLES), ...(rows.length > MAX_SAMPLES ? { samplesLeftOut: rows.length - MAX_SAMPLES } : {}) } : {}),
|
|
107
|
+
...(extra ? { harness: { ...extra, approximations: HARNESS_APPROXIMATIONS } } : {}),
|
|
108
|
+
}));
|
|
109
|
+
});
|
|
110
|
+
}
|
package/dist/tools/check-plan.js
CHANGED
|
@@ -21,7 +21,7 @@ import { assumedWarning, awardView, loadAward, openingThreat } from './award.js'
|
|
|
21
21
|
import { readLedger } from '../relations-store.js';
|
|
22
22
|
import { resolveIntel } from '../analysis/intel.js';
|
|
23
23
|
import { allyAttackLine, attacksOnAllies, modAllianceWarnings } from './mod-alliances.js';
|
|
24
|
-
import { avoidPlayersArg, avoidTerritoriesArg, gameIdArg, graphOf, knownIncomeArg, namer, readAnnotations, respond, untrustedDescription, untrustedText, viewArg } from './common.js';
|
|
24
|
+
import { avoidPlayersArg, avoidTerritoriesArg, gameIdArg, graphOf, knownIncomeArg, namer, playerNamer, readAnnotations, respond, untrustedDescription, untrustedText, viewArg } from './common.js';
|
|
25
25
|
import { lookupMeta } from './hints.js';
|
|
26
26
|
import { HEADROOM_COMPACT, headroomView, readTripwires, safeHeadroom, teamsOf, tripwireWarnings, untrustedDeploy } from './survival.js';
|
|
27
27
|
import { loadLiveGame, standInLine, standInOf } from './live-context.js';
|
|
@@ -31,6 +31,8 @@ import { resolvePlayer, resolveTerritory } from './resolve.js';
|
|
|
31
31
|
import { BELOW_PLAN_BASIS, boardHistory, bordersBelowPlan, currentTurn, truceRelations, friendsOf, guardOffWarnings, modsWarning, plannerSettings, requirePlayingSeat, requireTurnPhase, turnOrdersArg, } from './turn.js';
|
|
32
32
|
import { resolveTeamsFor } from './team-source.js';
|
|
33
33
|
import { stressOpponents } from './stress-opponents.js';
|
|
34
|
+
import { observedLowWarning } from '../analysis/opponents.js';
|
|
35
|
+
import { statedShiftWarning } from '../analysis/plan/estimates.js';
|
|
34
36
|
import { sanctionPercentage } from '../analysis/cards-in-effect.js';
|
|
35
37
|
import { CARD_SANCTIONS, sanctionsPlayed } from './sanctions-played.js';
|
|
36
38
|
import { COMMANDER_SIZING, commanderCheckOn, defaultFoggedCount, foggedAttackersArg, foggedCommanderOn, foggedCommanderText, myLargestStack } from './commander-check.js';
|
|
@@ -488,6 +490,8 @@ export function registerCheckPlanTool(server, ctx) {
|
|
|
488
490
|
await captureCheck(ctx, game.id, me.id, turn, checkPlanLog(report, { whatIf: enemy_deploy !== undefined || known_income !== undefined }));
|
|
489
491
|
const name = namer(map);
|
|
490
492
|
const playerName = new Map(game.players.map((p) => [p.id, p.name]));
|
|
493
|
+
/** #573: a player in a warning sentence, by name (delimited) and id, as warapp_track_opponents names it. */
|
|
494
|
+
const playerNamed = playerNamer(game.players);
|
|
491
495
|
const who = (id) => ({ id, name: playerName.get(id) ?? String(id) });
|
|
492
496
|
const bonusOf = (id) => {
|
|
493
497
|
const b = map.bonuses.find((x) => x.id === id);
|
|
@@ -730,6 +734,14 @@ export function registerCheckPlanTool(server, ctx) {
|
|
|
730
734
|
...(modRead ? modAllianceWarnings(modRead) : []),
|
|
731
735
|
// #275 (b): an untrusted estimate is the first thing said (not under an explicit enemy_deploy).
|
|
732
736
|
...(enemy_deploy === undefined ? tripwireWarnings(trip.tripwires, (w) => untrustedOf.get(w.player) ?? untrustedDeploy(w, income), (p) => estimates.find((x) => x.playerId === p)?.estimate) : []),
|
|
737
|
+
// #567: a known income that moved another opponent's estimate through #444's scale, by how much.
|
|
738
|
+
...[statedShiftWarning(so.statedShifts, playerNamed)].filter((w) => w !== null),
|
|
739
|
+
// #567: an opponent tried at an income its tracker holds below what a turn surely read (not one given known_income).
|
|
740
|
+
...(enemy_deploy === undefined
|
|
741
|
+
? (tracks ?? [])
|
|
742
|
+
.filter((t) => t.observedLow && t.income !== null && !knownOf.has(t.playerId) && inView.has(t.playerId))
|
|
743
|
+
.map((t) => observedLowWarning(playerNamed(t.playerId), t.income, t.observedLow, t.incomeMethod))
|
|
744
|
+
: []),
|
|
733
745
|
...(award ? assumedWarning(award) : []),
|
|
734
746
|
// #270: the static seats whose territories the test read as neutrals.
|
|
735
747
|
...[...seatTerritories(award?.board ?? seen, seats)]
|
|
@@ -834,6 +846,16 @@ export function registerCheckPlanTool(server, ctx) {
|
|
|
834
846
|
...(o.sanctioned?.applied && o.sanctioned.after !== undefined
|
|
835
847
|
? { sanctionApplied: { player: o.id, percentage: sanctionPercentage(o.sanctioned.percentages), before: o.sanctioned.before, after: o.sanctioned.after } }
|
|
836
848
|
: {}),
|
|
849
|
+
// #567: the uncapped low end its tracker read above the income it holds (reported only).
|
|
850
|
+
...(() => {
|
|
851
|
+
const t = tracks?.find((x) => x.playerId === o.id);
|
|
852
|
+
return t?.observedLow && enemy_deploy === undefined && !knownOf.has(o.id) ? { observedLow: t.observedLow } : {};
|
|
853
|
+
})(),
|
|
854
|
+
// #567: its estimate without the known incomes that scaled its fog prior (#444).
|
|
855
|
+
...(() => {
|
|
856
|
+
const sh = so.statedShifts.find((x) => x.player === o.id);
|
|
857
|
+
return sh ? { statedScaled: { was: sh.was, by: sh.by.map((b) => b.id) } } : {};
|
|
858
|
+
})(),
|
|
837
859
|
})),
|
|
838
860
|
// Whether the replies carry the card the clock adds (default "clock").
|
|
839
861
|
assumeEnemyCards: assumeCards,
|
package/dist/tools/common.js
CHANGED
|
@@ -15,6 +15,12 @@ export const knownIncomeArg = z
|
|
|
15
15
|
.array(z.object({
|
|
16
16
|
player: z.coerce.number().int().describe('The player\'s GameFeed id (as warapp_get_game lists it).'),
|
|
17
17
|
income: z.coerce.number().int().min(0).max(10_000).describe('The income it earns per turn, card armies aside.'),
|
|
18
|
+
source: z
|
|
19
|
+
.enum(['chat', 'board'])
|
|
20
|
+
.optional()
|
|
21
|
+
.describe('Where the figure came from (#567): "board" (the default) — your own what-if or board evidence — replaces only this ' +
|
|
22
|
+
"player's estimate; \"chat\" — the player stated it — also scales the fog prior of the opponents who stated none, once " +
|
|
23
|
+
'two or more players in view have stated one (#444). Incomes warapp_record_intel kept count as "chat".'),
|
|
18
24
|
}))
|
|
19
25
|
.max(50)
|
|
20
26
|
.optional()
|
|
@@ -121,6 +127,14 @@ export const UNTRUSTED_PREVIEW_NOTE = `Names and chat text in this preview (in $
|
|
|
121
127
|
* words, so delimited) and the account id the approval is bound to.
|
|
122
128
|
*/
|
|
123
129
|
export const shownAccount = (name, id) => `${name === undefined ? 'you' : untrustedText(name)} (${id})`;
|
|
130
|
+
/**
|
|
131
|
+
* A player as a warning sentence names it (#573): its name, delimited (their own words), and its GameFeed id;
|
|
132
|
+
* the bare id when the game does not list the player or names it not.
|
|
133
|
+
*/
|
|
134
|
+
export const playerNamer = (players) => (id) => {
|
|
135
|
+
const name = players.find((p) => p.id === id)?.name;
|
|
136
|
+
return name ? `${untrustedText(name)} (${id})` : String(id);
|
|
137
|
+
};
|
|
124
138
|
export const untrustedDescription = (description) => `${description} ${UNTRUSTED_DESCRIPTION_SUFFIX}`;
|
|
125
139
|
/** The `view` parameter over `views`, with a note naming what compact keeps. */
|
|
126
140
|
export const viewArg = (views, note) => viewParam(views, { note });
|
|
@@ -23,7 +23,8 @@ import { parseFeedTime } from '../normalize.js';
|
|
|
23
23
|
import { bonusTerritories } from '../analysis/bonuses.js';
|
|
24
24
|
import { policyChecks } from '../open-games.js';
|
|
25
25
|
import { nameFreeSettings } from '../replay.js';
|
|
26
|
-
import {
|
|
26
|
+
import { readSeenTurn } from '../turn-orders.js';
|
|
27
|
+
import { recordPicksAdvice, recordPicksAward, recordPicksSent, decisionLogMode, decisionLogOwner, decisionLogPath, decisionOutcome, recordGameEvent, recordJoin, recordOpponentRead, recordSeats, fillOutcome, recordChat, recordCheck, recordDecision, recordObservations, recordSeenTurn, recordSubmission, } from '../decision-log.js';
|
|
27
28
|
const modeOf = (ctx) => (ctx.decisionLog ? { mode: ctx.decisionLog } : {});
|
|
28
29
|
/** Every bonus of the map with its member territories (superbonuses flattened). */
|
|
29
30
|
const bonusesOf = (graph) => new Map([...graph.bonusById.keys()].map((id) => [id, bonusTerritories(graph, id)]));
|
|
@@ -76,6 +77,18 @@ export async function captureChat(ctx, gameId, me, turn, chat, opts = {}) {
|
|
|
76
77
|
return;
|
|
77
78
|
await recordChat(ctx.dataDir, gameId, me, turn, chat, { ...modeOf(ctx), ...opts });
|
|
78
79
|
}
|
|
80
|
+
/**
|
|
81
|
+
* #570: keep the resolved turn's visible orders (every player's, from the LatestGameInfo's GameTurn) on that
|
|
82
|
+
* turn's entry — only when the GameTurn is the turn just before `turn`, the one being played. Never throws.
|
|
83
|
+
*/
|
|
84
|
+
export async function captureSeenTurn(ctx, game, me, info, turn) {
|
|
85
|
+
if (!ctx.dataDir || turn === null)
|
|
86
|
+
return false;
|
|
87
|
+
const seen = readSeenTurn(info, game.players);
|
|
88
|
+
if (!seen || seen.turn !== turn - 1)
|
|
89
|
+
return false;
|
|
90
|
+
return recordSeenTurn(ctx.dataDir, game.id, me, seen, modeOf(ctx));
|
|
91
|
+
}
|
|
79
92
|
/** Log warapp_check_plan's summary of the turn (the latest run wins). Never throws. */
|
|
80
93
|
export async function captureCheck(ctx, gameId, me, turn, summary) {
|
|
81
94
|
if (!ctx.dataDir)
|
package/dist/tools/index.js
CHANGED
|
@@ -41,6 +41,8 @@ import { registerLeaveGameTool } from './leave-game.js';
|
|
|
41
41
|
import { registerCloseFinishedGameTool } from './close-finished-game.js';
|
|
42
42
|
import { registerWhereTool } from './where.js';
|
|
43
43
|
import { registerStateTools } from './state.js';
|
|
44
|
+
import { registerCalibrationTool } from './calibration.js';
|
|
45
|
+
import { registerTurnHistoryTool } from './turn-history.js';
|
|
44
46
|
import { blobStoreFromEnv } from '@chrischall/mcp-utils/export';
|
|
45
47
|
import { registerProfileOpponentsTool } from './profile-opponents.js';
|
|
46
48
|
import { pushListenerFor } from '../push/listener.js';
|
|
@@ -191,6 +193,10 @@ function registerEveryTool(server, deps) {
|
|
|
191
193
|
...(deps.env ? { env: deps.env } : {}),
|
|
192
194
|
store: deps.blobStore === undefined ? blobStoreFromEnv(deps.env ?? process.env) : deps.blobStore,
|
|
193
195
|
});
|
|
196
|
+
// #569: the income estimates scored against finished games' truth — this server's state only, read-only.
|
|
197
|
+
registerCalibrationTool(server, () => dataDir(deps.env));
|
|
198
|
+
// #570: a game turn by turn as I saw it, beside the plan and the orders sent (the decision log), read-only.
|
|
199
|
+
registerTurnHistoryTool(server, live);
|
|
194
200
|
// Hosted only: the war.app sign-in mcp-host's authFlow captures the AuthToken from (#333 part B).
|
|
195
201
|
// Locally warapp_link_session stays the way to the direct transport.
|
|
196
202
|
if (hosted)
|
package/dist/tools/opponents.js
CHANGED
|
@@ -144,6 +144,8 @@ export function registerOpponentsTool(server, ctx, deps = {}) {
|
|
|
144
144
|
usedByPlanner: t.income !== null && t.turns.length >= TRACKED_MIN_TURNS,
|
|
145
145
|
// #250: set by one turn far above the turns before it, with what the boards say of it.
|
|
146
146
|
...(t.incomeJump ? { jump: t.incomeJump } : {}),
|
|
147
|
+
// #567: a turn of the window surely read more than the income held (reported only).
|
|
148
|
+
...(t.observedLow ? { observedLow: t.observedLow } : {}),
|
|
147
149
|
},
|
|
148
150
|
unexplainedArmies: t.unexplained,
|
|
149
151
|
// #164: large stacks last seen on a territory hidden since (the planner counts each where it can reach).
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
// warapp_plan_turn works from. Shared by warapp_check_plan and warapp_submit_turn's commander
|
|
3
3
|
// check (#274), so both size a reply alike.
|
|
4
4
|
import { incomeDetail, planEnemyEstimates, symmetricStart, trackGame, trackOpponents, unevenStart } from '../analysis/index.js';
|
|
5
|
+
import { statedShifts } from '../analysis/plan/estimates.js';
|
|
5
6
|
import { neutralizeSeats, seatEndRules, staticSeats } from '../analysis/static-seats.js';
|
|
6
7
|
import { carriesTeam } from '../teams.js';
|
|
7
8
|
import { opponentReinforcement } from './card-advice.js';
|
|
@@ -37,7 +38,7 @@ export function stressOpponents(input) {
|
|
|
37
38
|
// PLAN-TEAMS D3: the cards in effect the decoder is sure of.
|
|
38
39
|
const effect = boardCardsInEffect(game, me, turn, info);
|
|
39
40
|
const previousOrders = previous && turn !== null ? input.boards.find((b) => b.turn === turn - 1)?.orders : undefined;
|
|
40
|
-
const
|
|
41
|
+
const estimateArgs = {
|
|
41
42
|
graph,
|
|
42
43
|
board,
|
|
43
44
|
me: me.id,
|
|
@@ -67,8 +68,11 @@ export function stressOpponents(input) {
|
|
|
67
68
|
},
|
|
68
69
|
turn,
|
|
69
70
|
...(effect.sanctionsOnOthers.length ? { sanctions: effect.sanctionsOnOthers } : {}),
|
|
70
|
-
|
|
71
|
-
|
|
71
|
+
};
|
|
72
|
+
const known = input.known?.length && input.enemyDeploy === undefined ? input.known : undefined;
|
|
73
|
+
const { estimates, prior } = planEnemyEstimates({ ...estimateArgs, ...(known ? { known } : {}) });
|
|
74
|
+
// #567: the opponents a known income moved through #444's scale, against the estimates made without it.
|
|
75
|
+
const shifts = known ? statedShifts(planEnemyEstimates(estimateArgs).estimates, estimates, prior) : [];
|
|
72
76
|
const myTeam = carriesTeam(me.team) ? me.team : undefined;
|
|
73
77
|
const teamOf = new Map(game.players.map((p) => [p.id, p.team]));
|
|
74
78
|
const friend = (id) => id === me.id || (myTeam !== undefined && teamOf.get(id) === myTeam);
|
|
@@ -107,5 +111,5 @@ export function stressOpponents(input) {
|
|
|
107
111
|
// (two at least; enemy_deploy is a what-if, not the game's standing).
|
|
108
112
|
const rivals = opponents.filter((o) => inView.has(o.id));
|
|
109
113
|
const leader = teams.size === 0 && rivals.length >= 2 && rivals.every((o) => earnedIncome > estimateOf(o.id));
|
|
110
|
-
return { board, seats, tracks, incomeOnBoard, income, earnedIncome, effect, estimates, estimateOf, friend, opponents, teams, inView, leader, commerce };
|
|
114
|
+
return { board, seats, tracks, incomeOnBoard, income, earnedIncome, effect, estimates, estimateOf, friend, opponents, teams, inView, leader, commerce, statedShifts: shifts };
|
|
111
115
|
}
|