@chrischall/warapp-mcp 0.6.0 → 0.8.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 +100 -7
- package/dist/analysis/accept-surrender.js +20 -2
- package/dist/analysis/calibrate.js +1 -0
- package/dist/analysis/card-support.js +187 -20
- package/dist/analysis/card-threats.js +68 -3
- package/dist/analysis/chat-advice.js +182 -0
- package/dist/analysis/chat-blocks.js +106 -0
- package/dist/analysis/chat-intent.js +559 -0
- package/dist/analysis/chat-read.js +159 -0
- package/dist/analysis/coalition.js +55 -0
- package/dist/analysis/decision-replay.js +279 -0
- package/dist/analysis/decision-truth.js +146 -0
- package/dist/analysis/finished-game.js +62 -3
- package/dist/analysis/game-lessons.js +12 -6
- package/dist/analysis/local-deploy.js +14 -0
- package/dist/analysis/opponent-profile.js +46 -3
- package/dist/analysis/opponents.js +246 -19
- package/dist/analysis/outlook.js +323 -17
- package/dist/analysis/picks.js +270 -37
- package/dist/analysis/plan/after-leftover.js +28 -3
- package/dist/analysis/plan/captures.js +80 -16
- package/dist/analysis/plan/completed.js +8 -1
- package/dist/analysis/plan/conceded-out.js +16 -11
- package/dist/analysis/plan/deploy-estimates.js +513 -0
- package/dist/analysis/plan/doomed-out.js +135 -0
- package/dist/analysis/plan/estimates.js +73 -7
- package/dist/analysis/plan/free-capture.js +34 -0
- package/dist/analysis/plan/guard-off.js +2 -1
- package/dist/analysis/plan/holds.js +85 -313
- package/dist/analysis/plan/horizon.js +42 -0
- package/dist/analysis/plan/leftover.js +188 -10
- package/dist/analysis/plan/observe.js +896 -0
- package/dist/analysis/plan/orders.js +35 -1
- package/dist/analysis/plan/relations.js +115 -2
- package/dist/analysis/plan/report.js +10 -4
- package/dist/analysis/plan/shared.js +7 -1189
- package/dist/analysis/plan/stand-still.js +7 -5
- package/dist/analysis/plan/state.js +12 -0
- package/dist/analysis/plan/stockpile.js +104 -0
- package/dist/analysis/plan/strike-stack.js +467 -0
- package/dist/analysis/plan/strike.js +8 -441
- package/dist/analysis/plan/targets.js +374 -72
- package/dist/analysis/plan/threats.js +120 -9
- package/dist/analysis/plan/transfers.js +35 -1
- package/dist/analysis/plan/two-move.js +70 -0
- package/dist/analysis/plan/vacated.js +124 -2
- package/dist/analysis/plan/withdraw.js +316 -0
- package/dist/analysis/planner.js +356 -53
- package/dist/analysis/player.js +4 -0
- package/dist/analysis/relations.js +8 -2
- package/dist/analysis/since-last.js +18 -5
- package/dist/analysis/stress.js +1 -1
- package/dist/board.js +36 -2
- package/dist/build-id.js +106 -0
- package/dist/bundle.js +15863 -10242
- package/dist/chat-automation.js +22 -0
- package/dist/client.js +14 -0
- package/dist/decision-log.js +1093 -0
- package/dist/finished-store.js +5 -1
- package/dist/lessons-store.js +322 -21
- package/dist/my-games.js +2 -0
- package/dist/open-games.js +122 -18
- package/dist/outlook-log.js +42 -1
- package/dist/protocol/methods.js +4 -2
- package/dist/review-export.js +198 -0
- package/dist/state-bundle.js +62 -3
- package/dist/state-cli.js +5 -3
- package/dist/strategy/notes.js +56 -0
- package/dist/tools/accept-surrender.js +23 -9
- package/dist/tools/award.js +5 -1
- package/dist/tools/card-advice.js +102 -33
- package/dist/tools/card-support-advice.js +53 -8
- package/dist/tools/chat-advice.js +330 -0
- package/dist/tools/chat-inbox.js +15 -4
- package/dist/tools/chat.js +41 -11
- package/dist/tools/check-plan.js +16 -3
- package/dist/tools/commander-check.js +2 -1
- package/dist/tools/decision-capture.js +461 -0
- package/dist/tools/end-of-game.js +146 -18
- package/dist/tools/game-kind.js +92 -0
- package/dist/tools/how-lost.js +7 -2
- package/dist/tools/index.js +3 -0
- package/dist/tools/join-game.js +51 -9
- package/dist/tools/live-context.js +6 -0
- package/dist/tools/live.js +43 -6
- package/dist/tools/map-curves.js +73 -0
- package/dist/tools/notifications.js +4 -3
- package/dist/tools/open-games.js +2 -2
- package/dist/tools/opponents.js +2 -0
- package/dist/tools/past-games.js +74 -8
- package/dist/tools/picks.js +169 -57
- package/dist/tools/profile-hook.js +62 -3
- package/dist/tools/profile-opponents.js +2 -0
- package/dist/tools/push.js +2 -2
- package/dist/tools/relations.js +2 -0
- package/dist/tools/scout.js +16 -2
- package/dist/tools/state.js +6 -1
- package/dist/tools/strategy.js +3 -3
- package/dist/tools/stress-opponents.js +2 -0
- package/dist/tools/surrender-pending.js +10 -1
- package/dist/tools/surrender.js +18 -3
- package/dist/tools/turn.js +353 -19
- package/dist/tools/where.js +3 -1
- package/dist/version.js +1 -1
- package/manifest.json +23 -2
- package/mint.yaml +23 -0
- package/package.json +1 -1
- package/server.json +20 -2
- package/skills/warapp-mcp/SKILL.md +42 -8
package/dist/tools/picks.js
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
import { McpToolError } from '@chrischall/mcp-utils';
|
|
5
5
|
import { z } from 'zod';
|
|
6
6
|
import { clientPickLimits, planPicks } from '../analysis/picks.js';
|
|
7
|
-
import { DEFAULT_TERRITORY_LIMIT } from '../analysis/opponents.js';
|
|
7
|
+
import { DEFAULT_TERRITORY_LIMIT, fullDistribution } from '../analysis/opponents.js';
|
|
8
8
|
import { OWNER_PICKABLE } from '../live.js';
|
|
9
9
|
import { bonusNamer, gameIdArg, graphOf, namer, readAnnotations, respond, untrustedDescription, untrustedText, viewArg } from './common.js';
|
|
10
10
|
import { lookupMeta } from './hints.js';
|
|
@@ -15,14 +15,68 @@ import { teammateOrdersOf } from '../team-orders.js';
|
|
|
15
15
|
import { readTeammatePicks } from './team.js';
|
|
16
16
|
import { pickingNeutrals } from '../pick-list.js';
|
|
17
17
|
import { mapOf } from './map.js';
|
|
18
|
-
import {
|
|
18
|
+
import { profileFormatOf } from '../analysis/opponent-profile.js';
|
|
19
|
+
import { mapMatchOf, mapRecordFor, mapRecordView } from './past-games.js';
|
|
19
20
|
import { keepPickable } from './where.js';
|
|
20
21
|
import { resolveTeams } from './team-source.js';
|
|
22
|
+
import { capturePicksAdvice, picksAdviceLog } from './decision-capture.js';
|
|
21
23
|
const VIEWS = ['compact', 'full'];
|
|
24
|
+
/** #(large maps) The time budget of one plan, milliseconds; `WARAPP_PICKS_BUDGET_MS` sets it (0 or less: none). */
|
|
25
|
+
export const DEFAULT_PICKS_BUDGET_MS = 20_000;
|
|
26
|
+
/** The compact view's caps, so its size does not grow with the map: lists beyond them become counts. `submitPicks` is never cut. */
|
|
27
|
+
export const COMPACT_REASONS = 8;
|
|
28
|
+
export const COMPACT_DETAILED_PICKS = 30;
|
|
29
|
+
export const COMPACT_THREATS = 6;
|
|
30
|
+
export const COMPACT_BONUSES = 15;
|
|
31
|
+
export const COMPACT_UNCOVERED = 15;
|
|
32
|
+
export const COMPACT_LINES = 15;
|
|
33
|
+
/** The compact view is capped only for a very large map or a list longer than this. */
|
|
34
|
+
export const COMPACT_LONG_LIST = 100;
|
|
35
|
+
const capped = (xs, n, full) => ({
|
|
36
|
+
items: full ? [...xs] : xs.slice(0, n),
|
|
37
|
+
omitted: full ? 0 : Math.max(0, xs.length - n),
|
|
38
|
+
});
|
|
39
|
+
/** `{ [key]: lines }` capped in the compact view, with `<key>Omitted` counting what was cut. */
|
|
40
|
+
function cappedLines(key, lines, full) {
|
|
41
|
+
const l = capped(lines, COMPACT_LINES, full);
|
|
42
|
+
return { [key]: l.items, ...(l.omitted ? { [`${key}Omitted`]: l.omitted } : {}) };
|
|
43
|
+
}
|
|
44
|
+
/** The plan's time budget in milliseconds from the environment (undefined: no budget). */
|
|
45
|
+
export function picksBudgetMs(env) {
|
|
46
|
+
const raw = (env ?? process.env).WARAPP_PICKS_BUDGET_MS;
|
|
47
|
+
if (raw === undefined || raw.trim() === '')
|
|
48
|
+
return DEFAULT_PICKS_BUDGET_MS;
|
|
49
|
+
const n = Number(raw);
|
|
50
|
+
if (!Number.isFinite(n))
|
|
51
|
+
return DEFAULT_PICKS_BUDGET_MS;
|
|
52
|
+
return n > 0 ? Math.floor(n) : undefined;
|
|
53
|
+
}
|
|
22
54
|
/** The only GameFeed state in which territories are picked. */
|
|
23
55
|
export const PICK_PHASE_STATE = 'DistributingTerritories';
|
|
24
56
|
/** TerritoryLimit assumed when the settings do not say (war.app's usual default; shared with the outlook). */
|
|
25
57
|
export { DEFAULT_TERRITORY_LIMIT };
|
|
58
|
+
/**
|
|
59
|
+
* The territories each player is granted, as the pick advisor plans them (#428): the settings'
|
|
60
|
+
* TerritoryLimit when set; under full distribution (DistributionMode 0 with no limit) every territory is
|
|
61
|
+
* dealt, so the client's no-cap share — floor(pickable ÷ players), at least 1 — the picks only choosing
|
|
62
|
+
* which ones; otherwise (a limited start that does not say) {@link DEFAULT_TERRITORY_LIMIT}. `warning`
|
|
63
|
+
* says which assumption it made.
|
|
64
|
+
*/
|
|
65
|
+
export function pickTerritoryLimit(settings, players, pickable) {
|
|
66
|
+
const set = settings?.territoryLimit;
|
|
67
|
+
if (set !== undefined && set > 0)
|
|
68
|
+
return { limit: set };
|
|
69
|
+
if (fullDistribution(settings)) {
|
|
70
|
+
const n = Math.max(1, players);
|
|
71
|
+
const limit = Math.max(1, Math.floor(pickable / n));
|
|
72
|
+
return {
|
|
73
|
+
limit,
|
|
74
|
+
fullDeal: true,
|
|
75
|
+
warning: `Full distribution (DistributionMode 0, no territory limit): every territory is dealt, so each of the ${n} players gets about ${limit} of the ${pickable} pickable; the list only says which you would rather hold.`,
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
return { limit: DEFAULT_TERRITORY_LIMIT, warning: `Territory limit missing from settings; assumed ${DEFAULT_TERRITORY_LIMIT}.` };
|
|
79
|
+
}
|
|
26
80
|
/** The pick scorer's view of the game settings. */
|
|
27
81
|
export function pickSettings(s) {
|
|
28
82
|
if (!s)
|
|
@@ -107,6 +161,9 @@ export function registerPickTools(server, ctx, deps = {}) {
|
|
|
107
161
|
'way into every region matter more than the fastest start — the user chooses per game. ' +
|
|
108
162
|
'Its `submitPicks` is exactly what warapp_submit_picks ' +
|
|
109
163
|
'takes — review it with the user first. Refuses outside the picking stage or when nothing is pickable. ' +
|
|
164
|
+
'On a very large map (over 400 pickable territories) only the territories that score best alone are ranked, 400 at the default budget and more with a larger one (`candidates` says how many); ' +
|
|
165
|
+
'the plan has a time budget (20 s; `WARAPP_PICKS_BUDGET_MS` sets it, 0 for none) and, when it runs out, answers `partial: true` with a valid list; ' +
|
|
166
|
+
'the compact view caps its reasons, threats, coverage and warning lists (counts say what was cut; `submitPicks` is never cut). ' +
|
|
110
167
|
'In a team game only the players off your team are threats, `team` names your teammates, and the list is judged by both award ' +
|
|
111
168
|
"orders that fit (`award.orders`; a team game's is unverified). When a teammate's pick list can be read (unverified), each " +
|
|
112
169
|
"teammate carries `picks`, and `team.coordination` reports the overlap with your list, the bonuses their top picks into " +
|
|
@@ -146,16 +203,16 @@ export function registerPickTools(server, ctx, deps = {}) {
|
|
|
146
203
|
const { game, source: teamSource } = await resolveTeams(ctx, feed);
|
|
147
204
|
const map = mapOf(game);
|
|
148
205
|
const warnings = [];
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
206
|
+
const active = game.players.filter((p) => (p.state ?? 'Playing') === 'Playing').length;
|
|
207
|
+
const players = Math.max(2, active || game.players.length);
|
|
208
|
+
// #428: the limit set, else the full-distribution share, else the default (each with a warning).
|
|
209
|
+
const limitRead = pickTerritoryLimit(game.settings, game.players.length, pickable.length);
|
|
210
|
+
const territoryLimit = limitRead.limit;
|
|
211
|
+
if (limitRead.warning)
|
|
212
|
+
warnings.push(limitRead.warning);
|
|
154
213
|
// The list is as long as war.app's client allows (players × territories per player, #129),
|
|
155
214
|
// never shorter than the primary.
|
|
156
215
|
const maxPicks = Math.max(territoryLimit, clientPickLimits({ territoryLimit, players: game.players.length, pickable: pickable.length })?.max ?? 0);
|
|
157
|
-
const active = game.players.filter((p) => (p.state ?? 'Playing') === 'Playing').length;
|
|
158
|
-
const players = Math.max(2, active || game.players.length);
|
|
159
216
|
const settings = pickSettings(game.settings);
|
|
160
217
|
// A team game (C2): only the players off my team are opponents. My seat is looked up only here.
|
|
161
218
|
const team = isTeamGame(game.players) ? await teamOf(ctx, game, warnings) : undefined;
|
|
@@ -166,47 +223,88 @@ export function registerPickTools(server, ctx, deps = {}) {
|
|
|
166
223
|
for (const mate of team)
|
|
167
224
|
mateLists.push(await readTeammatePicks(ctx, game.id, mate, entries?.find((e) => e.playerId === mate.id)));
|
|
168
225
|
}
|
|
226
|
+
// #435: an unread list is unknown, not empty: say to hold the submit (warapp_submit_picks refuses meanwhile).
|
|
227
|
+
const unreadMates = (team ?? []).filter((_, i) => mateLists[i] === null).map((p) => p.id);
|
|
228
|
+
if (unreadMates.length)
|
|
229
|
+
warnings.push(`Your teammate's list (player ${unreadMates.join(', ')}) could not be read, so this plan cannot avoid their picks: ` +
|
|
230
|
+
'hold the submit until it can be read or a list is agreed in team chat (warapp_submit_picks refuses meanwhile unless without_teammate_list: true).');
|
|
169
231
|
const lists = mateLists.map((l) => l?.territories ?? []);
|
|
170
|
-
const
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
232
|
+
const budgetMs = picksBudgetMs(deps.env);
|
|
233
|
+
let plan;
|
|
234
|
+
try {
|
|
235
|
+
plan = planPicks({
|
|
236
|
+
graph: graphOf(map),
|
|
237
|
+
pickable,
|
|
238
|
+
settings,
|
|
239
|
+
players,
|
|
240
|
+
territoryLimit,
|
|
241
|
+
maxPicks,
|
|
242
|
+
neutralArmies,
|
|
243
|
+
spread: spread === true,
|
|
244
|
+
...(team ? { team: { teammates: team.length, ...(lists.some((l) => l.length) ? { lists } : {}) } } : {}),
|
|
245
|
+
...(budgetMs !== undefined ? { budgetMs } : {}),
|
|
246
|
+
...(limitRead.fullDeal ? { fullDeal: true } : {}),
|
|
247
|
+
});
|
|
248
|
+
}
|
|
249
|
+
catch (e) {
|
|
250
|
+
// A failure inside the advisor is a tool error with a reason, never a silent host failure.
|
|
251
|
+
throw new McpToolError(`The pick advisor failed on game ${game.id} (${map.territories.length} territories, ${players} players): ${e instanceof Error ? e.message : String(e)}`, {
|
|
252
|
+
hint: 'Nothing was submitted. Try again, or set WARAPP_PICKS_BUDGET_MS lower; report this if it repeats.',
|
|
253
|
+
});
|
|
254
|
+
}
|
|
181
255
|
const name = namer(map);
|
|
182
256
|
const bonusName = bonusNamer(map);
|
|
183
257
|
const coord = plan.team;
|
|
184
|
-
const groupView = (g) =>
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
258
|
+
const groupView = (g, full) => {
|
|
259
|
+
const bs = capped(g.bonuses, COMPACT_BONUSES, full);
|
|
260
|
+
return {
|
|
261
|
+
territories: g.territoryIds.map(name),
|
|
262
|
+
score: g.score,
|
|
263
|
+
maxHops: g.maxHops,
|
|
264
|
+
bonuses: bs.items.map((b) => {
|
|
265
|
+
const th = capped(b.threats, COMPACT_THREATS, full);
|
|
266
|
+
return {
|
|
267
|
+
id: b.bonusId,
|
|
268
|
+
name: b.name,
|
|
269
|
+
value: b.value,
|
|
270
|
+
turn: b.turn,
|
|
271
|
+
threats: th.items.map(name),
|
|
272
|
+
...(th.omitted ? { threatsOmitted: th.omitted } : {}),
|
|
273
|
+
};
|
|
274
|
+
}),
|
|
275
|
+
...(bs.omitted ? { bonusesOmitted: bs.omitted } : {}),
|
|
276
|
+
twoOrderCaptures: g.twoOrderCaptures.map((c) => ({
|
|
277
|
+
turn: c.turn,
|
|
278
|
+
territory: name(c.territoryId),
|
|
279
|
+
orders: c.orders.map((o) => ({ from: name(o.from), armies: o.armies })),
|
|
280
|
+
})),
|
|
281
|
+
};
|
|
282
|
+
};
|
|
283
|
+
const coverageView = (c, full) => {
|
|
284
|
+
const u = capped(c.uncovered, COMPACT_UNCOVERED, full);
|
|
285
|
+
return {
|
|
286
|
+
share: c.share,
|
|
287
|
+
covered: c.covered,
|
|
288
|
+
reasonable: c.reasonable,
|
|
289
|
+
uncovered: u.items.map((b) => ({ id: b.bonusId, name: b.name })),
|
|
290
|
+
...(u.omitted ? { uncoveredOmitted: u.omitted } : {}),
|
|
291
|
+
};
|
|
292
|
+
};
|
|
207
293
|
const alt = plan.alternative;
|
|
208
294
|
// #312 E3: what my finished games on this map say (reported only: the ranking above never reads it).
|
|
209
295
|
const record = await mapRecordFor(ctx.dataDir, deps.env, game.settings?.mapId);
|
|
296
|
+
// #437 task 3: the advice into the game's decision log (ids, scores and codes; a re-plan replaces it).
|
|
297
|
+
await capturePicksAdvice(ctx, game, picksAdviceLog(plan, {
|
|
298
|
+
players,
|
|
299
|
+
territoryLimit,
|
|
300
|
+
maxPicks,
|
|
301
|
+
spread: spread === true,
|
|
302
|
+
warnings,
|
|
303
|
+
...(team ? { team: { teammates: team.map((p) => p.id), listsRead: mateLists.filter((l) => l !== null).length, mirrored: !!coord?.mirrored } } : {}),
|
|
304
|
+
}));
|
|
305
|
+
// The caps apply to the compact view of a game big enough to need them (a very large map, or a very long list);
|
|
306
|
+
// a small game's compact view is the whole answer, as before.
|
|
307
|
+
const lean = (rung) => rung !== 'full' && (plan.candidates !== undefined || plan.picks.length > COMPACT_LONG_LIST);
|
|
210
308
|
return respond(view, VIEWS, (rung) => ({
|
|
211
309
|
game: { id: game.id, name: game.name ?? null, state: game.state },
|
|
212
310
|
players,
|
|
@@ -259,16 +357,21 @@ export function registerPickTools(server, ctx, deps = {}) {
|
|
|
259
357
|
},
|
|
260
358
|
}
|
|
261
359
|
: {}),
|
|
262
|
-
picks: plan.picks.map((p, i) =>
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
360
|
+
picks: plan.picks.map((p, i) => {
|
|
361
|
+
// The compact view keeps the first picks' reasons (capped) and counts the rest, so it stays small on any map.
|
|
362
|
+
const r = capped(p.reasons, i < COMPACT_DETAILED_PICKS ? COMPACT_REASONS : 0, !lean(rung));
|
|
363
|
+
return {
|
|
364
|
+
priority: i + 1,
|
|
365
|
+
territory: name(p.territoryId),
|
|
366
|
+
group: p.group,
|
|
367
|
+
score: p.score,
|
|
368
|
+
reasons: r.items,
|
|
369
|
+
...(r.omitted ? { reasonsOmitted: r.omitted } : {}),
|
|
370
|
+
};
|
|
371
|
+
}),
|
|
269
372
|
groups: {
|
|
270
|
-
primary: { ...groupView(plan.groups.primary), coverage: coverageView(plan.coverage) },
|
|
271
|
-
fallback: groupView(plan.groups.fallback),
|
|
373
|
+
primary: { ...groupView(plan.groups.primary, !lean(rung)), coverage: coverageView(plan.coverage, !lean(rung)) },
|
|
374
|
+
fallback: groupView(plan.groups.fallback, !lean(rung)),
|
|
272
375
|
},
|
|
273
376
|
award: plan.award
|
|
274
377
|
? {
|
|
@@ -291,14 +394,16 @@ export function registerPickTools(server, ctx, deps = {}) {
|
|
|
291
394
|
...(plan.side.contested ? { contested: plan.side.contested } : {}),
|
|
292
395
|
...(plan.side.note ? { note: plan.side.note } : {}),
|
|
293
396
|
},
|
|
294
|
-
|
|
295
|
-
|
|
397
|
+
...(plan.partial ? { partial: true } : {}),
|
|
398
|
+
...(plan.candidates ? { candidates: plan.candidates } : {}),
|
|
399
|
+
...cappedLines('warnings', [...warnings, ...plan.warnings], !lean(rung)),
|
|
400
|
+
...cappedLines('rationale', plan.rationale, !lean(rung)),
|
|
296
401
|
submitPicks: { game_id: game.id, territories: plan.picks.map((p) => p.territoryId) },
|
|
297
402
|
...(alt
|
|
298
403
|
? {
|
|
299
404
|
alternative: {
|
|
300
|
-
...groupView(alt.group),
|
|
301
|
-
coverage: coverageView(alt.coverage),
|
|
405
|
+
...groupView(alt.group, !lean(rung)),
|
|
406
|
+
coverage: coverageView(alt.coverage, !lean(rung)),
|
|
302
407
|
fallback: alt.fallback.map(name),
|
|
303
408
|
submitPicks: { game_id: game.id, territories: alt.submitPicks },
|
|
304
409
|
},
|
|
@@ -308,7 +413,14 @@ export function registerPickTools(server, ctx, deps = {}) {
|
|
|
308
413
|
? {
|
|
309
414
|
mapRecord: record === 'unreadable'
|
|
310
415
|
? record
|
|
311
|
-
: mapRecordView(record, {
|
|
416
|
+
: mapRecordView(record, {
|
|
417
|
+
bonusName,
|
|
418
|
+
full: rung === 'full',
|
|
419
|
+
graph: graphOf(map),
|
|
420
|
+
picks: plan.groups.primary.territoryIds,
|
|
421
|
+
// #437: only the games of this game's format and settings.
|
|
422
|
+
match: mapMatchOf(profileFormatOf(game.players), game.settings),
|
|
423
|
+
}),
|
|
312
424
|
}
|
|
313
425
|
: {}),
|
|
314
426
|
...(rung === 'full' ? { settings } : {}),
|
|
@@ -3,10 +3,12 @@
|
|
|
3
3
|
// turns its boards show are observed and kept (src/profile-store.ts). Best effort, never throws.
|
|
4
4
|
// Its own module so src/tools/turn.ts can call it without importing the tool that imports turn.ts.
|
|
5
5
|
import { stat, utimes } from 'node:fs/promises';
|
|
6
|
-
import {
|
|
6
|
+
import { quietNeighbour } from '../analysis/opponent-profile.js';
|
|
7
|
+
import { foldFinishedGame, observeBoards, profileEnabled, profileFileState, profileGameFolded, profileGamePath, profileSeatsOf, readProfileTurns, recordBehaviour, } from '../profile-store.js';
|
|
7
8
|
import { teammatesOf } from '../teams.js';
|
|
8
9
|
import { boardCachePath, readBoardHistory, readCachedOrders, readCachedPlayer } from '../trend.js';
|
|
9
10
|
import { graphOf } from './common.js';
|
|
11
|
+
import { foldExclusion } from './game-kind.js';
|
|
10
12
|
import { mapOf } from './map.js';
|
|
11
13
|
import { keptTeams } from './team-source.js';
|
|
12
14
|
/** The combat settings an observation reads, from the game's settings. */
|
|
@@ -62,13 +64,65 @@ export async function recordProfile(dataDir, env, game, me, boards, teamsKnown)
|
|
|
62
64
|
// Best effort: profiling never blocks a tool.
|
|
63
65
|
}
|
|
64
66
|
}
|
|
67
|
+
/**
|
|
68
|
+
* #420 (P1 amended, owner decision of 2026-11-20): the quiet neighbours the planner may size at their
|
|
69
|
+
* stack plus their largest top-up (`PlanInput.quiet`). This game's kept turns (`readProfileTurns`) with
|
|
70
|
+
* the turns `boards` show observed afresh over them (`observeBoards`: the board just read included, so an
|
|
71
|
+
* attack on me last turn restores full sizing at once, before the hook keeps it), each opponent read by
|
|
72
|
+
* `quietNeighbour`. Nothing without a data directory, with `WARAPP_PLAYER_PROFILE=off`, or while the
|
|
73
|
+
* teams are unknown (any player may be my teammate). Never throws.
|
|
74
|
+
*/
|
|
75
|
+
export async function quietNeighbours(a) {
|
|
76
|
+
if (!a.dataDir || !a.teamsKnown || !profileEnabled(a.env))
|
|
77
|
+
return [];
|
|
78
|
+
try {
|
|
79
|
+
const kept = await readProfileTurns(a.dataDir, a.gameId, a.me, a.env);
|
|
80
|
+
const fresh = observeBoards({
|
|
81
|
+
gameId: a.gameId,
|
|
82
|
+
me: a.me,
|
|
83
|
+
graph: a.graph,
|
|
84
|
+
settings: a.settings,
|
|
85
|
+
...(a.cards !== undefined ? { cards: a.cards } : {}),
|
|
86
|
+
opponents: a.opponents,
|
|
87
|
+
boards: a.boards,
|
|
88
|
+
});
|
|
89
|
+
const out = [];
|
|
90
|
+
for (const player of [...a.opponents].sort((x, y) => x - y)) {
|
|
91
|
+
const byTurn = new Map((kept.get(player) ?? []).map((t) => [t.turn, t]));
|
|
92
|
+
for (const [turn, m] of fresh) {
|
|
93
|
+
const p = m.get(player);
|
|
94
|
+
if (p)
|
|
95
|
+
byTurn.set(turn, { turn, primitives: p });
|
|
96
|
+
}
|
|
97
|
+
const q = quietNeighbour([...byTurn.values()]);
|
|
98
|
+
if (q.quiet)
|
|
99
|
+
out.push({ player, contactTurns: q.contactTurns, attacks: q.attacks });
|
|
100
|
+
}
|
|
101
|
+
return out;
|
|
102
|
+
}
|
|
103
|
+
catch {
|
|
104
|
+
return [];
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* {@link foldFinishedGame} for a read that shows a game finished with no fold report (warapp_wait_for_turn's
|
|
109
|
+
* read, a game-ended notification): nothing for a lottery or no-show game (#437, {@link foldExclusion}).
|
|
110
|
+
* The files folded, as `foldFinishedGame` counts them.
|
|
111
|
+
*/
|
|
112
|
+
export async function foldKeptProfile(dataDir, game, env) {
|
|
113
|
+
if (game.state !== 'Finished' || (await foldExclusion(dataDir, game)))
|
|
114
|
+
return 0;
|
|
115
|
+
return foldFinishedGame(dataDir, game, env);
|
|
116
|
+
}
|
|
65
117
|
/** The note on a finished game with nothing to fold (#264). */
|
|
66
118
|
export const NOTHING_TO_FOLD = 'Nothing of this game could be counted: counts start with games played on this build.';
|
|
67
119
|
/** The note on a fold that failed (`failed`): the turns may well be kept, and the next read tries again. */
|
|
68
120
|
export const FOLD_FAILED = "This game's turns could not be counted now (a profile store could not be read or written); the next read of the finished game tries again.";
|
|
69
121
|
/** The note when there is no data directory (`no-data-dir`): nothing is kept, so nothing is counted. */
|
|
70
122
|
export const NO_DATA_DIR = 'Nothing is kept without a data directory, so no game is counted.';
|
|
71
|
-
|
|
123
|
+
/** #437: the note on a lottery or no-show game (`excluded`). */
|
|
124
|
+
export const EXCLUDED_FOLD_NOTE = 'A lottery or no-show game teaches nothing of its players: it is counted apart, never folded.';
|
|
125
|
+
const GAP_NOTES = { failed: FOLD_FAILED, 'no-data-dir': NO_DATA_DIR, excluded: EXCLUDED_FOLD_NOTE };
|
|
72
126
|
/** The opponents and turns the per-game file of `game` holds as `me` saw it. */
|
|
73
127
|
async function foldedOpponents(dataDir, env, game, me) {
|
|
74
128
|
const turns = await readProfileTurns(dataDir, game.id, me, env);
|
|
@@ -86,7 +140,9 @@ async function foldedOpponents(dataDir, env, game, me) {
|
|
|
86
140
|
* `already-folded`). The backfilled file takes the board cache's age, so it is deleted when the board
|
|
87
141
|
* cache would be (no id-bearing file outlives it). Nothing with profiling off. A fold that fails
|
|
88
142
|
* (`failed`: an unreadable store, an error) and a missing data directory (`no-data-dir`) carry their
|
|
89
|
-
* own notes
|
|
143
|
+
* own notes, as does a lottery or no-show game (`excluded`, #437: {@link foldExclusion}, checked before
|
|
144
|
+
* any fold, so such a game is never folded whichever tool reads it first); every other gap says counts
|
|
145
|
+
* start with games played on this build. Never throws.
|
|
90
146
|
*/
|
|
91
147
|
export async function foldFinished(dataDir, env, game) {
|
|
92
148
|
if (!profileEnabled(env))
|
|
@@ -97,6 +153,9 @@ export async function foldFinished(dataDir, env, game) {
|
|
|
97
153
|
try {
|
|
98
154
|
if (game.state !== 'Finished')
|
|
99
155
|
return nothing('not-finished');
|
|
156
|
+
// #437: a lottery or no-show game is counted apart by every fold, whichever tool reads it first.
|
|
157
|
+
if (await foldExclusion(dataDir, game))
|
|
158
|
+
return nothing('excluded');
|
|
100
159
|
const me = await readCachedPlayer(dataDir, game.id);
|
|
101
160
|
// A per-game file kept while it was played (any account of mine): the live fold.
|
|
102
161
|
const live = await foldFinishedGame(dataDir, game, env);
|
|
@@ -12,6 +12,7 @@ import { foldFinished, recordProfile } from './profile-hook.js';
|
|
|
12
12
|
import { counterOf, readOpponents } from './profile-reads.js';
|
|
13
13
|
import { resolveTeamsFor } from './team-source.js';
|
|
14
14
|
import { boardHistory, currentTurn, requireTurnPhase } from './turn.js';
|
|
15
|
+
import { captureObservation } from './decision-capture.js';
|
|
15
16
|
const VIEWS = ['compact', 'full'];
|
|
16
17
|
export function registerProfileOpponentsTool(server, ctx, deps = {}) {
|
|
17
18
|
const env = deps.env ?? process.env;
|
|
@@ -70,6 +71,7 @@ export function registerProfileOpponentsTool(server, ctx, deps = {}) {
|
|
|
70
71
|
const boards = turn !== null ? [...history.boards, { turn, board }] : [];
|
|
71
72
|
if (ctx.dataDir && turn !== null) {
|
|
72
73
|
await writeBoardCache(ctx.dataDir, game.id, me.id, turn, board);
|
|
74
|
+
await captureObservation(ctx, game.id, me.id, [{ turn, board, source: 'live' }]);
|
|
73
75
|
await writeGameRecord(ctx.dataDir, game);
|
|
74
76
|
await recordProfile(ctx.dataDir, env, game, me, boards, teamsKnown);
|
|
75
77
|
}
|
package/dist/tools/push.js
CHANGED
|
@@ -5,7 +5,7 @@ import { callerWantsProgress, currentCallSignal, McpToolError, reportProgress }
|
|
|
5
5
|
import { z } from 'zod';
|
|
6
6
|
import { parseGameId } from '../client.js';
|
|
7
7
|
import { activeGameIds } from '../my-games.js';
|
|
8
|
-
import {
|
|
8
|
+
import { foldKeptProfile } from './profile-hook.js';
|
|
9
9
|
import { endOfGame } from './end-of-game.js';
|
|
10
10
|
import { currentTurn, gameIdArg, readAnnotations, respond, untrustedDescription } from './common.js';
|
|
11
11
|
import { lookupMeta, mintMeta } from './hints.js';
|
|
@@ -345,7 +345,7 @@ export function registerPushTools(server, ctx, push, deps = {}) {
|
|
|
345
345
|
}
|
|
346
346
|
// The first read that shows a game of mine finished folds its opponent profile (B2; best effort, no request).
|
|
347
347
|
if (game.state === 'Finished' && ctx.dataDir)
|
|
348
|
-
await
|
|
348
|
+
await foldKeptProfile(ctx.dataDir, game, env);
|
|
349
349
|
// #312: its end-of-game pass, once (one history read; best effort, never throws).
|
|
350
350
|
if (game.state === 'Finished')
|
|
351
351
|
await endOfGame({ client: ctx.client, dataDir: ctx.dataDir, env }, id, token, game);
|
package/dist/tools/relations.js
CHANGED
|
@@ -26,6 +26,7 @@ import { mapOf } from './map.js';
|
|
|
26
26
|
import { recordProfile } from './profile-hook.js';
|
|
27
27
|
import { resolveBonus, resolvePlayer, resolveTerritory } from './resolve.js';
|
|
28
28
|
import { boardHistory, plannerSettings } from './turn.js';
|
|
29
|
+
import { captureObservation } from './decision-capture.js';
|
|
29
30
|
import { resolveTeamsFor } from './team-source.js';
|
|
30
31
|
const VIEWS = ['compact', 'full'];
|
|
31
32
|
const MAX_SCOPE_ITEMS = 200;
|
|
@@ -373,6 +374,7 @@ export function registerRelationsTools(server, ctx, opts = {}) {
|
|
|
373
374
|
live = true;
|
|
374
375
|
if (ctx.dataDir) {
|
|
375
376
|
await writeBoardCache(ctx.dataDir, game.id, me.id, turn, board);
|
|
377
|
+
await captureObservation(ctx, game.id, me.id, [{ turn, board, source: 'live' }]);
|
|
376
378
|
await writeGameRecord(ctx.dataDir, game);
|
|
377
379
|
await recordProfile(ctx.dataDir, env, game, me, boards, teamsKnown);
|
|
378
380
|
}
|
package/dist/tools/scout.js
CHANGED
|
@@ -9,6 +9,8 @@ import { gameIdArg, readAnnotations, respond, untrustedDescription } from './com
|
|
|
9
9
|
import { lookupMeta } from './hints.js';
|
|
10
10
|
import { metRead } from './profile-reads.js';
|
|
11
11
|
import { resolvePlayer } from './resolve.js';
|
|
12
|
+
import { captureOpponentRead, turnOfGame } from './decision-capture.js';
|
|
13
|
+
import { decisionLogOwner, decisionLogPath } from '../decision-log.js';
|
|
12
14
|
/**
|
|
13
15
|
* The player's invite token (= GameFeed player id), looked up in a game or given raw, and the numeric
|
|
14
16
|
* id the profile store keys it by (a raw token read as GameFeed ids are).
|
|
@@ -24,7 +26,7 @@ async function tokenOf(ctx, gameId, player) {
|
|
|
24
26
|
}
|
|
25
27
|
const game = await ctx.client.getGame(gameId, { map: false });
|
|
26
28
|
const p = resolvePlayer(game.players, raw);
|
|
27
|
-
return { token: p.feedId ?? String(p.id), id: p.id };
|
|
29
|
+
return { token: p.feedId ?? String(p.id), id: p.id, game };
|
|
28
30
|
}
|
|
29
31
|
async function page(ctx, url, what) {
|
|
30
32
|
try {
|
|
@@ -60,7 +62,7 @@ export function registerScoutTool(server, ctx, opts = {}) {
|
|
|
60
62
|
.describe('The player: a name (or part of one) in game_id, or their player id (GameFeed id / invite token).'),
|
|
61
63
|
}),
|
|
62
64
|
}, async ({ game_id, player }) => {
|
|
63
|
-
const { token, id } = await tokenOf(ctx, game_id, player);
|
|
65
|
+
const { token, id, game } = await tokenOf(ctx, game_id, player);
|
|
64
66
|
const [profileHtml, commonHtml] = await Promise.all([
|
|
65
67
|
page(ctx, profileUrl(token), 'profile'),
|
|
66
68
|
page(ctx, commonGamesUrl(token), 'common games'),
|
|
@@ -77,6 +79,18 @@ export function registerScoutTool(server, ctx, opts = {}) {
|
|
|
77
79
|
const { name, ...stats } = profile;
|
|
78
80
|
// Part D (docs/PLAN-PROFILES.md section 11): the cross-game read, when the record has the player.
|
|
79
81
|
const met = await metRead(ctx.dataDir, env, id).catch(() => undefined);
|
|
82
|
+
// #437: with a game, what was read goes into its decision log (the log's own account; none: nothing kept).
|
|
83
|
+
if (game && ctx.dataDir) {
|
|
84
|
+
const owner = await decisionLogOwner(decisionLogPath(ctx.dataDir, game.id), game.id);
|
|
85
|
+
if (owner !== undefined && owner !== id && game.players.some((p) => p.id === owner)) {
|
|
86
|
+
await captureOpponentRead(ctx, game.id, owner, id, {
|
|
87
|
+
turn: turnOfGame(game),
|
|
88
|
+
level: stats.level,
|
|
89
|
+
ranked: stats.ranked,
|
|
90
|
+
bootRatePct: stats.bootRatePct,
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
}
|
|
80
94
|
return respond(undefined, ['compact'], () => ({
|
|
81
95
|
player: { id: token, name },
|
|
82
96
|
profile: stats,
|
package/dist/tools/state.js
CHANGED
|
@@ -16,6 +16,7 @@
|
|
|
16
16
|
// warapp_backfill_history: the warapp_my_games sweep (src/tools/end-of-game.ts) at a bigger batch —
|
|
17
17
|
// up to 25 finished games not yet processed per call, each history read once, as the sweep reads it —
|
|
18
18
|
// with an optional wider window. Writes only this server's state; nothing goes to war.app.
|
|
19
|
+
import { backfillWinnerCurves } from './map-curves.js';
|
|
19
20
|
import { CONFIRM_INJECTION_RULE, McpToolError, toolAnnotations } from '@chrischall/mcp-utils';
|
|
20
21
|
import { mintUploadSlot, resolveUploadSource } from '@chrischall/mcp-utils/export';
|
|
21
22
|
import { z } from 'zod';
|
|
@@ -187,7 +188,8 @@ function registerBackfillTool(server, ctx, env) {
|
|
|
187
188
|
'it) and kept name-free for the opponent profiles, map records and lessons — what warapp_my_games does two ' +
|
|
188
189
|
'games per call. `window` widens how many of your newest finished games are considered (default 250, at ' +
|
|
189
190
|
`most ${MAX_FINISHED_RECORDS}). Reports what it processed and how many remain; safe to call again until ` +
|
|
190
|
-
'`remaining` is 0.
|
|
191
|
+
'`remaining` is 0. It also gives map records kept before the winners\' income curves were those curves, from the ' +
|
|
192
|
+
'histories already kept (`winnerCurves`, no request). Writes only this server\'s state and never writes to war.app. ' +
|
|
191
193
|
BRIDGE_NOTE,
|
|
192
194
|
annotations: toolAnnotations({ title: 'Backfill finished war.app games', readOnly: false, destructive: false, idempotent: true, openWorld: true }),
|
|
193
195
|
inputSchema: z.object({
|
|
@@ -215,7 +217,10 @@ function registerBackfillTool(server, ctx, env) {
|
|
|
215
217
|
limit: limit ?? BACKFILL_DEFAULT,
|
|
216
218
|
window: size,
|
|
217
219
|
});
|
|
220
|
+
// #419: entries kept before the winners' curves were, given them from the kept histories (no request).
|
|
221
|
+
const winnerCurves = await backfillWinnerCurves(ctx.dataDir);
|
|
218
222
|
return respond(undefined, ['compact'], () => ({
|
|
223
|
+
winnerCurves,
|
|
219
224
|
processed: r.processed,
|
|
220
225
|
processedCount: r.processed.length,
|
|
221
226
|
remaining: r.pending,
|
package/dist/tools/strategy.js
CHANGED
|
@@ -12,7 +12,7 @@ import { cardClock } from '../strategy/card-clock.js';
|
|
|
12
12
|
import { cardRules } from '../cards.js';
|
|
13
13
|
import { gameIdArg, graphOf, readAnnotations, respond, untrustedDescription, viewArg, WARAPP_UNTRUSTED_NOTE } from './common.js';
|
|
14
14
|
import { lookupMeta } from './hints.js';
|
|
15
|
-
import {
|
|
15
|
+
import { PICK_PHASE_STATE, pickSettings, pickTerritoryLimit } from './picks.js';
|
|
16
16
|
import { mapOf } from './map.js';
|
|
17
17
|
import { currentTurn } from './turn.js';
|
|
18
18
|
import { FROZEN_TAB_HINT, loadLiveGame } from './live-context.js';
|
|
@@ -57,7 +57,6 @@ const mapView = (map, n, full) => ({
|
|
|
57
57
|
function gameMapNotes(game, map) {
|
|
58
58
|
const picking = game.state === PICK_PHASE_STATE;
|
|
59
59
|
const playing = game.players.filter((p) => (p.state ?? 'Playing') === 'Playing').length;
|
|
60
|
-
const limit = game.settings?.territoryLimit;
|
|
61
60
|
const board = game.standing?.territories ?? [];
|
|
62
61
|
const pickable = board.filter((t) => t.owner.kind === 'available').map((t) => t.territoryId);
|
|
63
62
|
const neutralArmies = new Map(board.flatMap((t) => (t.owner.kind === 'neutral' && t.armies !== null ? [[t.territoryId, t.armies]] : [])));
|
|
@@ -69,7 +68,8 @@ function gameMapNotes(game, map) {
|
|
|
69
68
|
? {
|
|
70
69
|
opening: {
|
|
71
70
|
players: Math.max(2, playing || game.players.length),
|
|
72
|
-
|
|
71
|
+
// #428: the limit set, else the full-distribution share, else the default.
|
|
72
|
+
territoryLimit: pickTerritoryLimit(game.settings, game.players.length, pickable.length).limit,
|
|
73
73
|
pickable,
|
|
74
74
|
...(neutralArmies.size ? { neutralArmies } : {}),
|
|
75
75
|
},
|
|
@@ -50,11 +50,13 @@ export function stressOpponents(input) {
|
|
|
50
50
|
symmetricStart: symmetricStart(game.settings),
|
|
51
51
|
...(unevenStart(game.settings) ? { unevenStart: unevenStart(game.settings) } : {}),
|
|
52
52
|
...(input.opening ? { opening: input.opening } : {}),
|
|
53
|
+
...(input.mapPace ? { mapPace: input.mapPace } : {}),
|
|
53
54
|
...(game.settings?.fog !== undefined ? { fog: game.settings.fog } : {}),
|
|
54
55
|
...(opponentReinforcement(game.settings, hand) ? { reinforcement: opponentReinforcement(game.settings, hand) } : {}),
|
|
55
56
|
},
|
|
56
57
|
turn,
|
|
57
58
|
...(effect.sanctionsOnOthers.length ? { sanctions: effect.sanctionsOnOthers } : {}),
|
|
59
|
+
...(input.known?.length && input.enemyDeploy === undefined ? { known: input.known } : {}),
|
|
58
60
|
});
|
|
59
61
|
const myTeam = carriesTeam(me.team) ? me.team : undefined;
|
|
60
62
|
const teamOf = new Map(game.players.map((p) => [p.id, p.team]));
|
|
@@ -8,6 +8,7 @@ import { inGameOf } from '../live.js';
|
|
|
8
8
|
import { Method, writeGameRefreshParams } from '../protocol/methods.js';
|
|
9
9
|
import { pendingSurrenders, readGameDetailsSeats } from '../surrender-pending.js';
|
|
10
10
|
import { untrustedText } from './common.js';
|
|
11
|
+
import { captureGameEvent, turnOfGame } from './decision-capture.js';
|
|
11
12
|
/** Where the read comes from, for a result's note. */
|
|
12
13
|
export const SURRENDER_PENDING_NOTE = "Read from the game details (the web client's GameRefresh), UNVERIFIED live: a list is what the details showed " +
|
|
13
14
|
'(empty: no surrender pending); null means they could not be read, not that none is pending. A lobby, a finished ' +
|
|
@@ -62,7 +63,15 @@ export async function readPendingSurrenders(ctx, game, me, read = (id) => readDe
|
|
|
62
63
|
if (id !== undefined)
|
|
63
64
|
byInGame.set(id, p);
|
|
64
65
|
}
|
|
65
|
-
|
|
66
|
+
const pending = pendingSurrenders(seats, inGameOf(me), (id) => byInGame.get(id)?.id ?? null);
|
|
67
|
+
// #437: each pending surrender seen goes into the decision log once (by GameFeed id; one without is not kept).
|
|
68
|
+
for (const p of pending) {
|
|
69
|
+
if (p.player === null)
|
|
70
|
+
continue;
|
|
71
|
+
const detail = p.owedByMe === true ? 'owed' : p.owedByMe === false ? 'not-owed' : 'unknown';
|
|
72
|
+
await captureGameEvent(ctx, game.id, me.id, { turn: turnOfGame(game), kind: 'surrender-pending', player: p.player, detail }, { create: true });
|
|
73
|
+
}
|
|
74
|
+
return pending.map((p) => {
|
|
66
75
|
const player = byInGame.get(p.inGameId);
|
|
67
76
|
return { ...p, name: player ? untrustedText(player.name) : null };
|
|
68
77
|
});
|