@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.
Files changed (111) hide show
  1. package/.claude-plugin/marketplace.json +2 -2
  2. package/.claude-plugin/plugin.json +1 -1
  3. package/README.md +100 -7
  4. package/dist/analysis/accept-surrender.js +20 -2
  5. package/dist/analysis/calibrate.js +1 -0
  6. package/dist/analysis/card-support.js +187 -20
  7. package/dist/analysis/card-threats.js +68 -3
  8. package/dist/analysis/chat-advice.js +182 -0
  9. package/dist/analysis/chat-blocks.js +106 -0
  10. package/dist/analysis/chat-intent.js +559 -0
  11. package/dist/analysis/chat-read.js +159 -0
  12. package/dist/analysis/coalition.js +55 -0
  13. package/dist/analysis/decision-replay.js +279 -0
  14. package/dist/analysis/decision-truth.js +146 -0
  15. package/dist/analysis/finished-game.js +62 -3
  16. package/dist/analysis/game-lessons.js +12 -6
  17. package/dist/analysis/local-deploy.js +14 -0
  18. package/dist/analysis/opponent-profile.js +46 -3
  19. package/dist/analysis/opponents.js +246 -19
  20. package/dist/analysis/outlook.js +323 -17
  21. package/dist/analysis/picks.js +270 -37
  22. package/dist/analysis/plan/after-leftover.js +28 -3
  23. package/dist/analysis/plan/captures.js +80 -16
  24. package/dist/analysis/plan/completed.js +8 -1
  25. package/dist/analysis/plan/conceded-out.js +16 -11
  26. package/dist/analysis/plan/deploy-estimates.js +513 -0
  27. package/dist/analysis/plan/doomed-out.js +135 -0
  28. package/dist/analysis/plan/estimates.js +73 -7
  29. package/dist/analysis/plan/free-capture.js +34 -0
  30. package/dist/analysis/plan/guard-off.js +2 -1
  31. package/dist/analysis/plan/holds.js +85 -313
  32. package/dist/analysis/plan/horizon.js +42 -0
  33. package/dist/analysis/plan/leftover.js +188 -10
  34. package/dist/analysis/plan/observe.js +896 -0
  35. package/dist/analysis/plan/orders.js +35 -1
  36. package/dist/analysis/plan/relations.js +115 -2
  37. package/dist/analysis/plan/report.js +10 -4
  38. package/dist/analysis/plan/shared.js +7 -1189
  39. package/dist/analysis/plan/stand-still.js +7 -5
  40. package/dist/analysis/plan/state.js +12 -0
  41. package/dist/analysis/plan/stockpile.js +104 -0
  42. package/dist/analysis/plan/strike-stack.js +467 -0
  43. package/dist/analysis/plan/strike.js +8 -441
  44. package/dist/analysis/plan/targets.js +374 -72
  45. package/dist/analysis/plan/threats.js +120 -9
  46. package/dist/analysis/plan/transfers.js +35 -1
  47. package/dist/analysis/plan/two-move.js +70 -0
  48. package/dist/analysis/plan/vacated.js +124 -2
  49. package/dist/analysis/plan/withdraw.js +316 -0
  50. package/dist/analysis/planner.js +356 -53
  51. package/dist/analysis/player.js +4 -0
  52. package/dist/analysis/relations.js +8 -2
  53. package/dist/analysis/since-last.js +18 -5
  54. package/dist/analysis/stress.js +1 -1
  55. package/dist/board.js +36 -2
  56. package/dist/build-id.js +106 -0
  57. package/dist/bundle.js +15863 -10242
  58. package/dist/chat-automation.js +22 -0
  59. package/dist/client.js +14 -0
  60. package/dist/decision-log.js +1093 -0
  61. package/dist/finished-store.js +5 -1
  62. package/dist/lessons-store.js +322 -21
  63. package/dist/my-games.js +2 -0
  64. package/dist/open-games.js +122 -18
  65. package/dist/outlook-log.js +42 -1
  66. package/dist/protocol/methods.js +4 -2
  67. package/dist/review-export.js +198 -0
  68. package/dist/state-bundle.js +62 -3
  69. package/dist/state-cli.js +5 -3
  70. package/dist/strategy/notes.js +56 -0
  71. package/dist/tools/accept-surrender.js +23 -9
  72. package/dist/tools/award.js +5 -1
  73. package/dist/tools/card-advice.js +102 -33
  74. package/dist/tools/card-support-advice.js +53 -8
  75. package/dist/tools/chat-advice.js +330 -0
  76. package/dist/tools/chat-inbox.js +15 -4
  77. package/dist/tools/chat.js +41 -11
  78. package/dist/tools/check-plan.js +16 -3
  79. package/dist/tools/commander-check.js +2 -1
  80. package/dist/tools/decision-capture.js +461 -0
  81. package/dist/tools/end-of-game.js +146 -18
  82. package/dist/tools/game-kind.js +92 -0
  83. package/dist/tools/how-lost.js +7 -2
  84. package/dist/tools/index.js +3 -0
  85. package/dist/tools/join-game.js +51 -9
  86. package/dist/tools/live-context.js +6 -0
  87. package/dist/tools/live.js +43 -6
  88. package/dist/tools/map-curves.js +73 -0
  89. package/dist/tools/notifications.js +4 -3
  90. package/dist/tools/open-games.js +2 -2
  91. package/dist/tools/opponents.js +2 -0
  92. package/dist/tools/past-games.js +74 -8
  93. package/dist/tools/picks.js +169 -57
  94. package/dist/tools/profile-hook.js +62 -3
  95. package/dist/tools/profile-opponents.js +2 -0
  96. package/dist/tools/push.js +2 -2
  97. package/dist/tools/relations.js +2 -0
  98. package/dist/tools/scout.js +16 -2
  99. package/dist/tools/state.js +6 -1
  100. package/dist/tools/strategy.js +3 -3
  101. package/dist/tools/stress-opponents.js +2 -0
  102. package/dist/tools/surrender-pending.js +10 -1
  103. package/dist/tools/surrender.js +18 -3
  104. package/dist/tools/turn.js +353 -19
  105. package/dist/tools/where.js +3 -1
  106. package/dist/version.js +1 -1
  107. package/manifest.json +23 -2
  108. package/mint.yaml +23 -0
  109. package/package.json +1 -1
  110. package/server.json +20 -2
  111. package/skills/warapp-mcp/SKILL.md +42 -8
@@ -4,18 +4,21 @@
4
4
  import { CONFIRM_INJECTION_RULE, McpToolError, toolAnnotations } from '@chrischall/mcp-utils';
5
5
  import { z } from 'zod';
6
6
  import { clientPickLimits } from '../analysis/picks.js';
7
- import { isTeamGame } from '../teams.js';
7
+ import { isTeamGame, teammatesOf } from '../teams.js';
8
+ import { teammateOrdersOf } from '../team-orders.js';
8
9
  import { parseGameId } from '../client.js';
9
10
  import { FOG_LEVEL_NAMES, inGameId, OWNER_NEUTRAL, OWNER_PICKABLE, playersByInGameId, } from '../live.js';
10
11
  import { pickingNeutrals, writePickable, writePickList } from '../pick-list.js';
11
12
  import { Method, writeSendTerritoryPicksParams } from '../protocol/methods.js';
12
13
  import { currentTurn, gameIdArg, namer, readAnnotations, respond, shownAccount, turnsCompleted, UNTRUSTED_PREVIEW_NOTE, untrustedDescription, UNTRUSTED_LIST_MAX, untrustedList, untrustedText, viewArg, } from './common.js';
13
14
  import { lookupMeta, mintMeta } from './hints.js';
14
- import { loadLiveTerritories, loadPicks, requireApprovedAccount, writeAccount } from './live-context.js';
15
+ import { loadLiveGame, loadLiveTerritories, loadPicks, requireApprovedAccount, writeAccount } from './live-context.js';
16
+ import { readTeammatePicks } from './team.js';
15
17
  import { mapOf } from './map.js';
16
18
  import { resolvePlayer, resolveTerritory } from './resolve.js';
17
19
  import { defineGatedWrite, requireMySeat, sendAndVerify } from './write-kit.js';
18
20
  import { resolveTeamsFor } from './team-source.js';
21
+ import { capturePicksSent } from './decision-capture.js';
19
22
  const VIEWS = ['compact', 'full'];
20
23
  const MAX_PICK_ARGS = 200;
21
24
  export const BRIDGE_NOTE = 'Reads through your signed-in war.app tab (ContextMint Bridge), so it sees exactly what you see — fog included.';
@@ -252,6 +255,12 @@ export function registerLiveTools(server, ctx) {
252
255
  .min(1)
253
256
  .max(MAX_PICK_ARGS)
254
257
  .describe('Your picks in priority order (first = most wanted): territory ids or names. Replaces any picks already submitted.'),
258
+ without_teammate_list: z
259
+ .boolean()
260
+ .optional()
261
+ .describe("Team games only (#435): submit even though a teammate's list could not be read (unknown, not empty). " +
262
+ 'Default false: the submit is refused until it can be read, since a pick you both list goes to one of you. ' +
263
+ 'Set it only when waiting is worse, e.g. the pick deadline is close.'),
255
264
  });
256
265
  defineGatedWrite(server, {
257
266
  title: 'Submit territory picks in a war.app game',
@@ -261,7 +270,8 @@ export function registerLiveTools(server, ctx) {
261
270
  description: 'Submit your territory picks for a war.app (Warzone) game in manual distribution, in priority order — ' +
262
271
  'they replace any picks you submitted before. Every territory must be pickable on the live board; a list ' +
263
272
  "longer than war.app's client allows (players × territories per player) or shorter than the territories " +
264
- 'each player is granted is warned about in the preview. After sending, the picks are read back and ' +
273
+ 'each player is granted is warned about in the preview. In a team game it is refused while a teammate\'s pick ' +
274
+ 'list cannot be read (unknown, not empty) unless `without_teammate_list: true` is passed (#435). After sending, the picks are read back and ' +
265
275
  `reported verified only if they match exactly. ${BRIDGE_NOTE} ${CONFIRM_INJECTION_RULE}`,
266
276
  annotations: toolAnnotations({
267
277
  title: 'Submit war.app picks',
@@ -271,7 +281,7 @@ export function registerLiveTools(server, ctx) {
271
281
  openWorld: true,
272
282
  }),
273
283
  inputSchema: submitSchema,
274
- async plan({ game_id, player, territories }) {
284
+ async plan({ game_id, player, territories, without_teammate_list }) {
275
285
  const feed = await ctx.client.getGame(parseGameId(game_id), { settings: true });
276
286
  const map = mapOf(feed);
277
287
  // A write through the bridge always acts as the signed-in account, whatever `player` says
@@ -287,7 +297,7 @@ export function registerLiveTools(server, ctx) {
287
297
  }
288
298
  seen.add(t.id);
289
299
  }
290
- const board = await loadLiveTerritories(ctx, game);
300
+ const { territories: board, info } = await loadLiveGame(ctx, game);
291
301
  const owner = new Map(board.map((t) => [t.territoryId, t]));
292
302
  const unpickable = picks.filter((t) => {
293
303
  const s = owner.get(t.id);
@@ -325,6 +335,25 @@ export function registerLiveTools(server, ctx) {
325
335
  "A shorter list is safe only when no teammate lists any of its picks (warapp_plan_picks shortens it only then).");
326
336
  if (bounds && picks.length < bounds.min)
327
337
  lengthWarnings.push(`war.app expects at least ${bounds.min} picks here (the territories each player is granted); got ${picks.length}, which it may reject.`);
338
+ // #435 (bug): a team game's picks went in while a teammate's list was unread (null), so an
339
+ // overlap could not be seen (45731288: my second pick went to my teammate). Each teammate still
340
+ // playing has its list read as warapp_plan_picks reads it (V5 teammate orders, else V6
341
+ // GetTerritoryPicks); an unread one refuses the submit unless the caller says to go without it.
342
+ // An empty list read is no refusal: the teammate has not picked yet, and picks around mine.
343
+ const unread = [];
344
+ if (isTeamGame(game.players)) {
345
+ const entries = teammateOrdersOf(info, game.players);
346
+ for (const mate of teammatesOf(game.players, me).filter((p) => (p.state ?? 'Playing') === 'Playing'))
347
+ if ((await readTeammatePicks(ctx, game.id, mate, entries?.find((e) => e.playerId === mate.id))) === null)
348
+ unread.push(mate.id);
349
+ }
350
+ if (unread.length && without_teammate_list !== true)
351
+ throw new McpToolError(`Your teammate's list (player ${unread.join(', ')}) could not be read, so an overlap with yours cannot be seen: a pick you both list goes to one of you.`, {
352
+ hint: "Nothing was sent. Wait until it can be read (warapp_get_team, warapp_plan_picks show it), agree a list in team chat, " +
353
+ 'or pass without_teammate_list: true to submit anyway when the pick deadline is close.',
354
+ });
355
+ if (unread.length)
356
+ lengthWarnings.push(`Your teammate's list (player ${unread.join(', ')}) was not read: submitted without it (without_teammate_list), so an overlap cannot be seen.`);
328
357
  const playerId = inGameId(me);
329
358
  const territoryIds = picks.map((t) => t.id);
330
359
  const named = picks.map((t) => ({ id: t.id, name: t.name }));
@@ -356,7 +385,7 @@ export function registerLiveTools(server, ctx) {
356
385
  await requireApprovedAccount(ctx, writeAccount(me));
357
386
  const ids = picks.map((p) => p.id);
358
387
  const base = { game: gameId, picks };
359
- return sendAndVerify({
388
+ const result = await sendAndVerify({
360
389
  send: async () => {
361
390
  await ctx.rpc.call('SendTerritoryPicks', Method.SendTerritoryPicks, (w) => writeSendTerritoryPicksParams(w, gameId, ids));
362
391
  },
@@ -399,6 +428,14 @@ export function registerLiveTools(server, ctx) {
399
428
  };
400
429
  },
401
430
  });
431
+ // #437 task 3: what was sent and read back into the game's decision log (ids only; the latest send wins).
432
+ await capturePicksSent(ctx, gameId, me, {
433
+ sent: ids,
434
+ readBack: result.readBack ?? null,
435
+ verified: result.verified,
436
+ outcome: result.outcome,
437
+ });
438
+ return result;
402
439
  },
403
440
  });
404
441
  }
@@ -0,0 +1,73 @@
1
+ // #419: map-record entries kept before #419 hold no winner income curve, so they count for no fog pace. The end-of-game
2
+ // records (src/finished-store.ts) keep each captured game's history boards (the first and last 30), from which the
3
+ // winners' curves are read again here: no request, this server's state only. Run by warapp_backfill_history. Name-free
4
+ // like the stores: a record's players are labelled by position (`anonymousHistoryOfRecord`), winners matched to the
5
+ // map entry by their start territories. Never throws.
6
+ import { basename } from 'node:path';
7
+ import { curvePoints } from '../analysis/game-lessons.js';
8
+ import { turnIncomes } from '../analysis/finished-game.js';
9
+ import { applyBonusOverrides } from '../analysis/overrides.js';
10
+ import { anonymousHistoryOfRecord, listFinishedRecords, readFinishedRecord } from '../finished-store.js';
11
+ import { fillWinnerCurves, readMapRecord } from '../lessons-store.js';
12
+ import { readStoredMap } from '../map-store.js';
13
+ import { normalizeSettings } from '../normalize.js';
14
+ import { graphOf } from './common.js';
15
+ /** Fill the winners' curves of every map-record entry kept without them, from the end-of-game records. Never throws. */
16
+ export async function backfillWinnerCurves(dataDir) {
17
+ const out = { filled: 0, unfilled: 0 };
18
+ let paths;
19
+ try {
20
+ paths = await listFinishedRecords(dataDir);
21
+ }
22
+ catch {
23
+ return out;
24
+ }
25
+ for (const path of paths) {
26
+ try {
27
+ const rec = await readFinishedRecord(path);
28
+ if (typeof rec === 'string' || rec.status !== 'captured')
29
+ continue;
30
+ const settings = rec.settings ? normalizeSettings(rec.settings) : undefined;
31
+ const mapId = rec.mapId ?? settings?.mapId;
32
+ if (mapId === undefined)
33
+ continue;
34
+ const key = basename(path, '.json');
35
+ const mr = await readMapRecord(dataDir, mapId);
36
+ const entry = mr === 'unreadable' ? undefined : mr.entries.find((e) => e.key === key);
37
+ if (!entry || entry.winners.every((w) => w.income))
38
+ continue;
39
+ const h = anonymousHistoryOfRecord(rec);
40
+ const map = await readStoredMap(dataDir, mapId, { maxAgeMs: Number.POSITIVE_INFINITY });
41
+ if (typeof h === 'string' || !map || !settings) {
42
+ out.unfilled++;
43
+ continue;
44
+ }
45
+ const graph = graphOf(applyBonusOverrides(map, settings));
46
+ const winners = h.players.filter((p) => p.state === 'Won').map((p) => p.id);
47
+ const boards = [...h.boards].sort((a, b) => a.turn - b.turn);
48
+ const ids = h.players.map((p) => p.id);
49
+ const curves = new Map(winners.map((w) => [w, []]));
50
+ for (const b of boards) {
51
+ const inc = turnIncomes(graph, b.board, ids, settings);
52
+ for (const w of winners) {
53
+ const x = inc.get(w);
54
+ if (x)
55
+ curves.get(w).push({ afterTurn: b.turn, income: x.income });
56
+ }
57
+ }
58
+ const start = boards[0];
59
+ const startOf = (w) => start && start.turn === 0
60
+ ? start.board.territories.flatMap((t) => (t.owner.kind === 'player' && t.owner.playerId === w ? [t.territoryId] : []))
61
+ : [];
62
+ const r = await fillWinnerCurves(dataDir, mapId, key, winners.map((w) => ({ territories: startOf(w), income: curvePoints(curves.get(w)) })));
63
+ if (r === 'filled')
64
+ out.filled++;
65
+ else if (r !== 'missing')
66
+ out.unfilled++;
67
+ }
68
+ catch {
69
+ out.unfilled++;
70
+ }
71
+ }
72
+ return out;
73
+ }
@@ -8,7 +8,7 @@
8
8
  // players' names in it, read only to classify the notification and find the game its link names.
9
9
  // A game-ended notification runs the end-of-game pass on that game (#312, src/tools/end-of-game.ts:
10
10
  // idempotent, one history read per game, at most END_OF_GAME_PER_CALL per call), which folds its live
11
- // profile too; then any kept opponent profile still unfolded is folded (B2, `foldFinishedGame`) — one
11
+ // profile too; then any kept opponent profile still unfolded is folded (B2, `foldKeptProfile`: never a lottery or no-show game, #437) — one
12
12
  // GameFeed read (no map) only when one is kept unfolded, none otherwise.
13
13
  //
14
14
  // Dismissing marks read and never deletes; deleting is its own tool, one 318 per id, error 699 read as
@@ -16,8 +16,9 @@
16
16
  import { CONFIRM_INJECTION_RULE, toolAnnotations } from '@chrischall/mcp-utils';
17
17
  import { z } from 'zod';
18
18
  import { classifyNotification, readInAppNotifications } from '../notifications.js';
19
- import { foldFinishedGame, hasUnfoldedProfile, profileEnabled } from '../profile-store.js';
19
+ import { hasUnfoldedProfile, profileEnabled } from '../profile-store.js';
20
20
  import { END_OF_GAME_PER_CALL, endOfGame, finishedAccount, needsEndOfGame } from './end-of-game.js';
21
+ import { foldKeptProfile } from './profile-hook.js';
21
22
  import { Method, NOTIFICATION_ID, NOTIFICATION_NOT_FOUND, NOTIFICATIONS_PAGE_SIZE, writeAcknowledgeInAppNotificationsParams, writeDeleteInAppNotificationParams, writeGetInAppNotificationsParams, } from '../protocol/methods.js';
22
23
  import { notSent, WarappServerError } from '../protocol/rpc.js';
23
24
  import { readAnnotations, respond, untrustedDescription } from './common.js';
@@ -127,7 +128,7 @@ async function foldEndedGames(ctx, env, games) {
127
128
  lookups++;
128
129
  try {
129
130
  const game = await ctx.client.getGame(gameId, { map: false });
130
- const files = game.state === 'Finished' ? await foldFinishedGame(dir, game, env) : 0;
131
+ const files = await foldKeptProfile(dir, game, env);
131
132
  if (files > 0)
132
133
  out.push({ gameId, files });
133
134
  }
@@ -93,8 +93,8 @@ export function registerOpenGamesTool(server, ctx) {
93
93
  });
94
94
  // #134: advisory — the neutral-cost part needs each lobby's GameFeed settings, so only the join preview has it.
95
95
  const games = (await markLotteries(ctx, filtered)).map((g) => {
96
- const { breaks } = joiningPolicy(g, null);
97
- return breaks.length ? { ...g, policyBreaks: breaks } : g;
96
+ const { breaks, warnings } = joiningPolicy(g, null);
97
+ return { ...g, ...(breaks.length ? { policyBreaks: breaks } : {}), ...(warnings ? { policyWarnings: warnings } : {}) };
98
98
  });
99
99
  return respond(undefined, ['compact'], () => ({
100
100
  games,
@@ -12,6 +12,7 @@ import { pastGamesFor } from './past-games.js';
12
12
  import { profileFormatOf } from '../analysis/opponent-profile.js';
13
13
  import { recordProfile } from './profile-hook.js';
14
14
  import { boardHistory, currentTurn, plannerSettings, requireTurnPhase } from './turn.js';
15
+ import { captureObservation } from './decision-capture.js';
15
16
  import { resolveTeamsFor } from './team-source.js';
16
17
  const VIEWS = ['compact', 'full'];
17
18
  export function registerOpponentsTool(server, ctx, deps = {}) {
@@ -65,6 +66,7 @@ export function registerOpponentsTool(server, ctx, deps = {}) {
65
66
  const tracks = trackOpponents(graph, boards, me.id, settings, trackGame(game.players, game.settings, map, game.endRules));
66
67
  if (ctx.dataDir && turn !== null) {
67
68
  await writeBoardCache(ctx.dataDir, game.id, me.id, turn, board);
69
+ await captureObservation(ctx, game.id, me.id, [{ turn, board, source: 'live' }]);
68
70
  await writeGameRecord(ctx.dataDir, game);
69
71
  await recordProfile(ctx.dataDir, deps.env, game, me, boards, teamsKnown);
70
72
  }
@@ -1,8 +1,28 @@
1
1
  import { PACE_TURNS, startRegion } from '../analysis/game-lessons.js';
2
- import { lessonsSummary, mapRecordStarts, mapRecordSummary, readLessons, readMapRecord } from '../lessons-store.js';
2
+ import { MIN_CALIBRATION_SAMPLES } from '../analysis/outlook.js';
3
+ import { formatPaceAt, lessonsSummary, outlookCalibration, mapPaceAt, mapRecordStarts, mapRecordSummary, readLessons, readMapRecord, readMapRecords, } from '../lessons-store.js';
3
4
  import { profileEnabled } from '../profile-store.js';
4
5
  /** The note every view carries: where it comes from, and that no plan reads it. */
5
- export const PAST_GAMES_NOTE = 'From your own finished games (their histories, read once at the end of each game): reported only — no plan, ranking or estimate reads it.';
6
+ export const PAST_GAMES_NOTE = "From your own finished games (their histories, read once at the end of each game): reported only — no plan or ranking reads it; only the past winners' income per turn tops a thinly read opponent's estimate (#419).";
7
+ /** #437: the note beside games counted apart. */
8
+ export const EXCLUDED_NOTE = 'Lottery and no-show games are counted apart: they are in no figure here.';
9
+ /** #437: the note beside a record read for the current game's format and settings. */
10
+ export const MATCHED_NOTE = "Only the games of this game's format (and Local Deployment / Commanders setting) are read: `entries` of the `of` kept matched; `settingsUnknown` of them were kept before the setting was.";
11
+ /** The `matched` and `excluded` parts a view carries (#437). */
12
+ function matchParts(s) {
13
+ return {
14
+ ...(s.matched ? { matched: { ...s.matched, note: MATCHED_NOTE } } : {}),
15
+ ...(s.excluded ? { excluded: { ...s.excluded, note: EXCLUDED_NOTE } } : {}),
16
+ };
17
+ }
18
+ /** #437: the map-record match of a game: its format, Local Deployment and Commanders. */
19
+ export function mapMatchOf(format, settings) {
20
+ return {
21
+ format,
22
+ ...(settings?.localDeployments !== undefined ? { localDeployments: settings.localDeployments } : {}),
23
+ ...(settings?.commanders !== undefined ? { commanders: settings.commanders } : {}),
24
+ };
25
+ }
6
26
  /** Start bonuses listed on the compact views. */
7
27
  export const MAP_RECORD_COMPACT = 8;
8
28
  /** The record of `mapId` when it holds a game; `unreadable` when it cannot be parsed; `undefined` otherwise (off, no data dir, no map, none kept). Never throws. */
@@ -20,11 +40,13 @@ export async function mapRecordFor(dataDir, env, mapId) {
20
40
  /**
21
41
  * The map record as warapp_plan_picks and warapp_map_stats show it: games, my results, my results per
22
42
  * bonus my start touched (`inPrimary` when the given picks touch it too), the bonuses winners started
23
- * in, and the pace (medians of the winners' and my income after turns 4 and 8). Pure.
43
+ * in, and the pace (medians of the winners' and my income after turns 4 and 8). With `match` (#437: the
44
+ * current game's format and settings) only the games that match, and `matched` says how many; `excluded`
45
+ * counts the lottery and no-show games kept apart. Pure.
24
46
  */
25
47
  export function mapRecordView(rec, o) {
26
- const { mine, winners } = mapRecordStarts(rec);
27
- const summary = mapRecordSummary(rec);
48
+ const { mine, winners } = mapRecordStarts(rec, o.match);
49
+ const summary = mapRecordSummary(rec, o.match);
28
50
  const primary = o.graph && o.picks ? new Set(startRegion(o.graph, o.picks).bonuses) : undefined;
29
51
  const cap = (xs) => (o.full ? xs : xs.slice(0, MAP_RECORD_COMPACT));
30
52
  return {
@@ -37,18 +59,20 @@ export function mapRecordView(rec, o) {
37
59
  { winners: t === 4 ? summary.pace.winners.income4 : summary.pace.winners.income8, mine: t === 4 ? summary.pace.mine.income4 : summary.pace.mine.income8 },
38
60
  ])),
39
61
  ...(!o.full && (mine.length > MAP_RECORD_COMPACT || winners.length > MAP_RECORD_COMPACT) ? { more: 'view "full" lists every start bonus' } : {}),
62
+ ...matchParts(summary),
40
63
  note: PAST_GAMES_NOTE,
41
64
  };
42
65
  }
43
66
  /**
44
67
  * The pace beside my income on the boards after turns 4 and 8 (warapp_plan_turn): with `turnsCompleted`
45
68
  * one of {@link PACE_TURNS} and a record with a figure for it, my income now beside the median winner's
46
- * and my own past median there; `undefined` otherwise. Pure.
69
+ * and my own past median there; `undefined` otherwise. With `match` (#437) only the games of the current
70
+ * game's format and settings. Pure.
47
71
  */
48
- export function paceView(rec, turnsCompleted, myIncome) {
72
+ export function paceView(rec, turnsCompleted, myIncome, match) {
49
73
  if (turnsCompleted === null || !PACE_TURNS.includes(turnsCompleted))
50
74
  return undefined;
51
- const s = mapRecordSummary(rec);
75
+ const s = mapRecordSummary(rec, match);
52
76
  const four = turnsCompleted === 4;
53
77
  const winners = four ? s.pace.winners.income4 : s.pace.winners.income8;
54
78
  const myPast = four ? s.pace.mine.income4 : s.pace.mine.income8;
@@ -61,6 +85,7 @@ export function paceView(rec, turnsCompleted, myIncome) {
61
85
  myPast,
62
86
  games: s.games,
63
87
  ...(winners !== null ? { behindWinners: myIncome < winners } : {}),
88
+ ...matchParts(s),
64
89
  note: PAST_GAMES_NOTE,
65
90
  };
66
91
  }
@@ -83,6 +108,7 @@ export async function pastGamesFor(dataDir, env, format) {
83
108
  return {
84
109
  thisFormat: format,
85
110
  ...s,
111
+ ...(s.excluded ? { excluded: { ...s.excluded, note: EXCLUDED_NOTE } } : {}),
86
112
  readAs: 'calibration: per coverage band (the share of its frontier the track read, #294), n turns × opponents scored, the mean and geometric mean of ' +
87
113
  'the tracked income ÷ the true income from the history, and the shares read under half (low) and over 1.5× (high).',
88
114
  note: PAST_GAMES_NOTE,
@@ -92,3 +118,43 @@ export async function pastGamesFor(dataDir, env, format) {
92
118
  return undefined;
93
119
  }
94
120
  }
121
+ /**
122
+ * #419 (owner decision of 2026-11-20): the pace past winners set after `afterTurn` completed turns (the turn
123
+ * planned − 1), the fog prior's upper bound under thin evidence: this map's median winner over its games `match`
124
+ * reads when there are `MIN_PACE_GAMES` (3) or more (`map`), else the median winner ÷ mine over every map's
125
+ * games of the format (`format`), else `undefined` — as with profiling off, no data dir, map or turn. Never throws.
126
+ */
127
+ export async function fogPaceFor(dataDir, env, mapId, match, afterTurn) {
128
+ if (!dataDir || mapId === undefined || afterTurn === null || afterTurn < 0 || !profileEnabled(env ?? process.env))
129
+ return undefined;
130
+ try {
131
+ const rec = await readMapRecord(dataDir, mapId);
132
+ const own = rec === 'unreadable' ? null : mapPaceAt(rec, afterTurn, match);
133
+ if (own)
134
+ return { basis: 'map', afterTurn, games: own.games, income: own.income };
135
+ const fmt = formatPaceAt(await readMapRecords(dataDir), afterTurn, match);
136
+ return fmt ? { basis: 'format', afterTurn, games: fmt.games, ratio: fmt.ratio } : undefined;
137
+ }
138
+ catch {
139
+ return undefined;
140
+ }
141
+ }
142
+ /**
143
+ * #436 (owner decision of 2026-11-20): the outlook's calibration — past games' tracked income ÷ true income per
144
+ * coverage band, this format's band with `MIN_CALIBRATION_SAMPLES` or more, else every format's
145
+ * (`outlookCalibration`); `undefined` when off, without a data dir, unreadable or with no band. Never throws.
146
+ */
147
+ export async function outlookCalibrationFor(dataDir, env, format) {
148
+ if (!dataDir || !profileEnabled(env ?? process.env))
149
+ return undefined;
150
+ try {
151
+ const file = await readLessons(dataDir);
152
+ if (file === 'unreadable')
153
+ return undefined;
154
+ const c = outlookCalibration(file, format, MIN_CALIBRATION_SAMPLES);
155
+ return Object.keys(c).length ? c : undefined;
156
+ }
157
+ catch {
158
+ return undefined;
159
+ }
160
+ }