@chrischall/warapp-mcp 0.5.0 → 0.7.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 +3 -3
- package/.claude-plugin/plugin.json +1 -1
- package/README.md +133 -8
- package/dist/analysis/accept-surrender.js +20 -2
- package/dist/analysis/calibrate.js +1 -0
- package/dist/analysis/card-support.js +177 -17
- package/dist/analysis/card-threats.js +126 -14
- 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/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 +15 -10
- package/dist/analysis/hold-diff.js +3 -1
- package/dist/analysis/income-trend.js +38 -0
- package/dist/analysis/intel.js +75 -0
- package/dist/analysis/opens.js +64 -0
- package/dist/analysis/opponent-profile.js +121 -10
- package/dist/analysis/opponents.js +246 -20
- package/dist/analysis/outlook.js +360 -15
- package/dist/analysis/picks.js +91 -12
- package/dist/analysis/plan/after-leftover.js +4 -1
- package/dist/analysis/plan/bonus-attempts.js +105 -0
- package/dist/analysis/plan/capture-instead.js +116 -0
- package/dist/analysis/plan/captures.js +49 -7
- package/dist/analysis/plan/conceded-out.js +13 -2
- package/dist/analysis/plan/estimates.js +203 -30
- package/dist/analysis/plan/guard-off.js +2 -1
- package/dist/analysis/plan/holds.js +110 -9
- package/dist/analysis/plan/jabs.js +113 -0
- package/dist/analysis/plan/leftover.js +393 -8
- package/dist/analysis/plan/orders.js +76 -4
- package/dist/analysis/plan/relations.js +135 -2
- package/dist/analysis/plan/report.js +69 -3
- package/dist/analysis/plan/second-sizing.js +133 -0
- package/dist/analysis/plan/shared.js +279 -27
- package/dist/analysis/plan/siege.js +303 -0
- package/dist/analysis/plan/stand-still.js +9 -5
- package/dist/analysis/plan/state.js +8 -0
- package/dist/analysis/plan/stockpile.js +104 -0
- package/dist/analysis/plan/strike.js +39 -7
- package/dist/analysis/plan/targets.js +256 -110
- package/dist/analysis/plan/threats.js +148 -10
- package/dist/analysis/plan/transfers.js +57 -6
- package/dist/analysis/plan/two-move.js +70 -0
- package/dist/analysis/plan/vacated.js +124 -2
- package/dist/analysis/planner.js +527 -49
- package/dist/analysis/profile.js +13 -2
- package/dist/analysis/since-last.js +18 -5
- package/dist/analysis/stress.js +8 -2
- package/dist/board.js +36 -2
- package/dist/bonus-attempt-store.js +55 -0
- package/dist/build-id.js +106 -0
- package/dist/bundle.js +54138 -41059
- package/dist/cards.js +7 -5
- package/dist/chat-automation.js +22 -0
- package/dist/chat.js +35 -1
- package/dist/client.js +14 -0
- package/dist/commerce.js +111 -0
- package/dist/decision-log.js +1093 -0
- package/dist/finished-store.js +5 -1
- package/dist/index.js +9 -1
- package/dist/lessons-store.js +322 -21
- package/dist/live.js +43 -0
- package/dist/move-order.js +64 -3
- package/dist/normalize.js +17 -0
- package/dist/open-games.js +36 -16
- package/dist/outlook-log.js +42 -1
- package/dist/profile-store.js +12 -2
- package/dist/protocol/methods.js +62 -5
- package/dist/protocol/rpc.js +8 -0
- package/dist/relations-store.js +38 -4
- package/dist/review-export.js +198 -0
- package/dist/siege-store.js +49 -0
- package/dist/state-bundle.js +584 -0
- package/dist/state-cli.js +71 -0
- package/dist/strategy/notes.js +56 -0
- package/dist/team-cards.js +25 -0
- package/dist/tools/accept-surrender.js +23 -9
- package/dist/tools/award.js +20 -2
- package/dist/tools/card-advice.js +93 -28
- package/dist/tools/card-plays.js +2 -2
- package/dist/tools/card-support-advice.js +37 -7
- package/dist/tools/chat-advice.js +330 -0
- package/dist/tools/chat-inbox.js +19 -4
- package/dist/tools/chat.js +106 -17
- package/dist/tools/check-plan.js +68 -12
- package/dist/tools/commerce-deploy.js +33 -0
- package/dist/tools/common.js +31 -0
- package/dist/tools/decision-capture.js +459 -0
- package/dist/tools/end-of-game.js +151 -21
- package/dist/tools/game-kind.js +92 -0
- package/dist/tools/how-lost.js +7 -2
- package/dist/tools/index.js +10 -0
- package/dist/tools/join-game.js +10 -4
- package/dist/tools/live-context.js +6 -0
- package/dist/tools/live.js +10 -1
- package/dist/tools/map-curves.js +73 -0
- package/dist/tools/notifications.js +4 -3
- package/dist/tools/opponents.js +2 -0
- package/dist/tools/past-games.js +74 -8
- package/dist/tools/picks.js +61 -10
- package/dist/tools/profile-hook.js +62 -3
- package/dist/tools/profile-opponents.js +4 -0
- package/dist/tools/push.js +2 -2
- package/dist/tools/relations.js +139 -0
- package/dist/tools/scout.js +16 -2
- package/dist/tools/state.js +232 -0
- package/dist/tools/strategy.js +3 -3
- package/dist/tools/stress-opponents.js +7 -2
- package/dist/tools/surrender-pending.js +10 -1
- package/dist/tools/surrender.js +18 -3
- package/dist/tools/survival.js +11 -3
- package/dist/tools/team-brief.js +2 -2
- package/dist/tools/team.js +12 -3
- package/dist/tools/turn.js +643 -76
- package/dist/tools/where.js +3 -1
- package/dist/version.js +1 -1
- package/manifest.json +32 -3
- package/mint.yaml +37 -4
- package/package.json +4 -4
- package/server.json +20 -2
- package/skills/warapp-mcp/SKILL.md +73 -17
|
@@ -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, `
|
|
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 {
|
|
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 =
|
|
131
|
+
const files = await foldKeptProfile(dir, game, env);
|
|
131
132
|
if (files > 0)
|
|
132
133
|
out.push({ gameId, files });
|
|
133
134
|
}
|
package/dist/tools/opponents.js
CHANGED
|
@@ -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
|
}
|
package/dist/tools/past-games.js
CHANGED
|
@@ -1,8 +1,28 @@
|
|
|
1
1
|
import { PACE_TURNS, startRegion } from '../analysis/game-lessons.js';
|
|
2
|
-
import {
|
|
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 =
|
|
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).
|
|
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.
|
|
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
|
+
}
|
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,37 @@ 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'];
|
|
22
24
|
/** The only GameFeed state in which territories are picked. */
|
|
23
25
|
export const PICK_PHASE_STATE = 'DistributingTerritories';
|
|
24
26
|
/** TerritoryLimit assumed when the settings do not say (war.app's usual default; shared with the outlook). */
|
|
25
27
|
export { DEFAULT_TERRITORY_LIMIT };
|
|
28
|
+
/**
|
|
29
|
+
* The territories each player is granted, as the pick advisor plans them (#428): the settings'
|
|
30
|
+
* TerritoryLimit when set; under full distribution (DistributionMode 0 with no limit) every territory is
|
|
31
|
+
* dealt, so the client's no-cap share — floor(pickable ÷ players), at least 1 — the picks only choosing
|
|
32
|
+
* which ones; otherwise (a limited start that does not say) {@link DEFAULT_TERRITORY_LIMIT}. `warning`
|
|
33
|
+
* says which assumption it made.
|
|
34
|
+
*/
|
|
35
|
+
export function pickTerritoryLimit(settings, players, pickable) {
|
|
36
|
+
const set = settings?.territoryLimit;
|
|
37
|
+
if (set !== undefined && set > 0)
|
|
38
|
+
return { limit: set };
|
|
39
|
+
if (fullDistribution(settings)) {
|
|
40
|
+
const n = Math.max(1, players);
|
|
41
|
+
const limit = Math.max(1, Math.floor(pickable / n));
|
|
42
|
+
return {
|
|
43
|
+
limit,
|
|
44
|
+
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.`,
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
return { limit: DEFAULT_TERRITORY_LIMIT, warning: `Territory limit missing from settings; assumed ${DEFAULT_TERRITORY_LIMIT}.` };
|
|
48
|
+
}
|
|
26
49
|
/** The pick scorer's view of the game settings. */
|
|
27
50
|
export function pickSettings(s) {
|
|
28
51
|
if (!s)
|
|
@@ -96,6 +119,9 @@ export function registerPickTools(server, ctx, deps = {}) {
|
|
|
96
119
|
'`twoOrderCaptures` (neutrals its opening takes with two attacks because one cannot be paid for), ' +
|
|
97
120
|
'the award (how many sets the round-by-round award order can grant from the list, and the worst of them with the ' +
|
|
98
121
|
'other players\' starts it implies), ' +
|
|
122
|
+
'`side` (the positive bonus income on my side of the map — every member strictly nearer the primary than any start the ' +
|
|
123
|
+
'award implies for the others — against the contested rest; `known: false` with a note when no start is implied; ' +
|
|
124
|
+
'report only, never in the score), ' +
|
|
99
125
|
'warnings (assumed settings) and the reasoning. The primary group carries its `coverage`: the share of reasonable bonuses ' +
|
|
100
126
|
'(positive, with a pickable territory, no wasteland, value per army at least the median) a pick can stand next to within 2 moves, ' +
|
|
101
127
|
'and the ones it cannot, by name. In a two-player game without spread it may also return an `alternative`: a coverage-first list ' +
|
|
@@ -143,16 +169,16 @@ export function registerPickTools(server, ctx, deps = {}) {
|
|
|
143
169
|
const { game, source: teamSource } = await resolveTeams(ctx, feed);
|
|
144
170
|
const map = mapOf(game);
|
|
145
171
|
const warnings = [];
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
172
|
+
const active = game.players.filter((p) => (p.state ?? 'Playing') === 'Playing').length;
|
|
173
|
+
const players = Math.max(2, active || game.players.length);
|
|
174
|
+
// #428: the limit set, else the full-distribution share, else the default (each with a warning).
|
|
175
|
+
const limitRead = pickTerritoryLimit(game.settings, game.players.length, pickable.length);
|
|
176
|
+
const territoryLimit = limitRead.limit;
|
|
177
|
+
if (limitRead.warning)
|
|
178
|
+
warnings.push(limitRead.warning);
|
|
151
179
|
// The list is as long as war.app's client allows (players × territories per player, #129),
|
|
152
180
|
// never shorter than the primary.
|
|
153
181
|
const maxPicks = Math.max(territoryLimit, clientPickLimits({ territoryLimit, players: game.players.length, pickable: pickable.length })?.max ?? 0);
|
|
154
|
-
const active = game.players.filter((p) => (p.state ?? 'Playing') === 'Playing').length;
|
|
155
|
-
const players = Math.max(2, active || game.players.length);
|
|
156
182
|
const settings = pickSettings(game.settings);
|
|
157
183
|
// A team game (C2): only the players off my team are opponents. My seat is looked up only here.
|
|
158
184
|
const team = isTeamGame(game.players) ? await teamOf(ctx, game, warnings) : undefined;
|
|
@@ -204,6 +230,15 @@ export function registerPickTools(server, ctx, deps = {}) {
|
|
|
204
230
|
const alt = plan.alternative;
|
|
205
231
|
// #312 E3: what my finished games on this map say (reported only: the ranking above never reads it).
|
|
206
232
|
const record = await mapRecordFor(ctx.dataDir, deps.env, game.settings?.mapId);
|
|
233
|
+
// #437 task 3: the advice into the game's decision log (ids, scores and codes; a re-plan replaces it).
|
|
234
|
+
await capturePicksAdvice(ctx, game, picksAdviceLog(plan, {
|
|
235
|
+
players,
|
|
236
|
+
territoryLimit,
|
|
237
|
+
maxPicks,
|
|
238
|
+
spread: spread === true,
|
|
239
|
+
warnings,
|
|
240
|
+
...(team ? { team: { teammates: team.map((p) => p.id), listsRead: mateLists.filter((l) => l !== null).length, mirrored: !!coord?.mirrored } } : {}),
|
|
241
|
+
}));
|
|
207
242
|
return respond(view, VIEWS, (rung) => ({
|
|
208
243
|
game: { id: game.id, name: game.name ?? null, state: game.state },
|
|
209
244
|
players,
|
|
@@ -279,6 +314,15 @@ export function registerPickTools(server, ctx, deps = {}) {
|
|
|
279
314
|
reordered: plan.award.reordered,
|
|
280
315
|
}
|
|
281
316
|
: null,
|
|
317
|
+
// #305: the bonus income on my side of the map (nearer my primary than any start the award implies
|
|
318
|
+
// for the others) against the rest; report only, never scored.
|
|
319
|
+
side: {
|
|
320
|
+
known: plan.side.known,
|
|
321
|
+
opponentStarts: plan.side.opponentStarts.map(name),
|
|
322
|
+
...(plan.side.mine ? { mine: plan.side.mine } : {}),
|
|
323
|
+
...(plan.side.contested ? { contested: plan.side.contested } : {}),
|
|
324
|
+
...(plan.side.note ? { note: plan.side.note } : {}),
|
|
325
|
+
},
|
|
282
326
|
warnings: [...warnings, ...plan.warnings],
|
|
283
327
|
rationale: plan.rationale,
|
|
284
328
|
submitPicks: { game_id: game.id, territories: plan.picks.map((p) => p.territoryId) },
|
|
@@ -296,7 +340,14 @@ export function registerPickTools(server, ctx, deps = {}) {
|
|
|
296
340
|
? {
|
|
297
341
|
mapRecord: record === 'unreadable'
|
|
298
342
|
? record
|
|
299
|
-
: mapRecordView(record, {
|
|
343
|
+
: mapRecordView(record, {
|
|
344
|
+
bonusName,
|
|
345
|
+
full: rung === 'full',
|
|
346
|
+
graph: graphOf(map),
|
|
347
|
+
picks: plan.groups.primary.territoryIds,
|
|
348
|
+
// #437: only the games of this game's format and settings.
|
|
349
|
+
match: mapMatchOf(profileFormatOf(game.players), game.settings),
|
|
350
|
+
}),
|
|
300
351
|
}
|
|
301
352
|
: {}),
|
|
302
353
|
...(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
|
}
|
|
@@ -108,6 +110,8 @@ export function registerProfileOpponentsTool(server, ctx, deps = {}) {
|
|
|
108
110
|
stacking: { n: h.stacking.n, sum: Math.round(h.stacking.sum * 1000) / 1000 },
|
|
109
111
|
retaliate: h.retaliate,
|
|
110
112
|
retake: h.retake,
|
|
113
|
+
jab: h.jab,
|
|
114
|
+
capacityTopUp: h.capacityTopUp,
|
|
111
115
|
},
|
|
112
116
|
defaults: HABIT_DEFAULTS,
|
|
113
117
|
turns: turns.map((t) => ({ turn: t.turn, ...t.primitives })),
|
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);
|