@chrischall/warapp-mcp 0.5.0 → 0.6.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 +37 -5
- package/dist/analysis/card-support.js +2 -1
- package/dist/analysis/card-threats.js +59 -12
- package/dist/analysis/game-lessons.js +3 -4
- 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 +75 -7
- package/dist/analysis/opponents.js +2 -2
- package/dist/analysis/outlook.js +39 -0
- package/dist/analysis/picks.js +91 -12
- package/dist/analysis/plan/bonus-attempts.js +105 -0
- package/dist/analysis/plan/capture-instead.js +116 -0
- package/dist/analysis/plan/captures.js +45 -4
- package/dist/analysis/plan/conceded-out.js +13 -2
- package/dist/analysis/plan/estimates.js +135 -26
- package/dist/analysis/plan/holds.js +31 -3
- package/dist/analysis/plan/jabs.js +113 -0
- package/dist/analysis/plan/leftover.js +249 -4
- package/dist/analysis/plan/orders.js +76 -4
- package/dist/analysis/plan/relations.js +21 -1
- package/dist/analysis/plan/report.js +69 -3
- package/dist/analysis/plan/second-sizing.js +133 -0
- package/dist/analysis/plan/shared.js +82 -20
- package/dist/analysis/plan/siege.js +303 -0
- package/dist/analysis/plan/stand-still.js +7 -3
- package/dist/analysis/plan/state.js +8 -0
- package/dist/analysis/plan/strike.js +10 -5
- package/dist/analysis/plan/targets.js +91 -60
- package/dist/analysis/plan/threats.js +41 -6
- package/dist/analysis/plan/transfers.js +46 -6
- package/dist/analysis/planner.js +234 -16
- package/dist/analysis/profile.js +13 -2
- package/dist/analysis/stress.js +8 -2
- package/dist/bonus-attempt-store.js +55 -0
- package/dist/bundle.js +47965 -39683
- package/dist/cards.js +7 -5
- package/dist/chat.js +35 -1
- package/dist/commerce.js +111 -0
- package/dist/index.js +9 -1
- package/dist/live.js +43 -0
- package/dist/move-order.js +64 -3
- package/dist/normalize.js +17 -0
- package/dist/profile-store.js +12 -2
- package/dist/protocol/methods.js +60 -5
- package/dist/protocol/rpc.js +8 -0
- package/dist/relations-store.js +38 -4
- package/dist/siege-store.js +49 -0
- package/dist/state-bundle.js +525 -0
- package/dist/state-cli.js +69 -0
- package/dist/team-cards.js +25 -0
- package/dist/tools/award.js +15 -1
- package/dist/tools/card-advice.js +16 -5
- package/dist/tools/card-plays.js +2 -2
- package/dist/tools/card-support-advice.js +2 -1
- package/dist/tools/chat-inbox.js +4 -0
- package/dist/tools/chat.js +65 -6
- package/dist/tools/check-plan.js +54 -10
- package/dist/tools/commerce-deploy.js +33 -0
- package/dist/tools/common.js +31 -0
- package/dist/tools/end-of-game.js +5 -3
- package/dist/tools/index.js +7 -0
- package/dist/tools/picks.js +12 -0
- package/dist/tools/profile-opponents.js +2 -0
- package/dist/tools/relations.js +137 -0
- package/dist/tools/state.js +227 -0
- package/dist/tools/stress-opponents.js +5 -2
- 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 +332 -60
- package/dist/version.js +1 -1
- package/manifest.json +10 -2
- package/mint.yaml +14 -4
- package/package.json +4 -4
- package/server.json +2 -2
- package/skills/warapp-mcp/SKILL.md +31 -9
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
// `warapp-mcp export-state --out <file>`: write this install's history as a state bundle
|
|
2
|
+
// (src/state-bundle.ts) for `warapp_import_state` on another server, the hosted one included.
|
|
3
|
+
// Local only: it reads the data dir (`--data-dir`, else `MCP_DATA_DIR`, else ~/.config/warapp-mcp)
|
|
4
|
+
// and nothing else — never the env file or a credential, never a request. It prints counts and sizes
|
|
5
|
+
// only: never the salt, a file's contents, or an id.
|
|
6
|
+
import { dataDir } from './config.js';
|
|
7
|
+
import { collectExport, encodeBundle, humanSize, StateBundleError, STORES, writeBundleFile } from './state-bundle.js';
|
|
8
|
+
const USAGE = 'Usage: warapp-mcp export-state --out <file> [--data-dir <dir>] [--account <war.app player id>] [--force]\n' +
|
|
9
|
+
'Writes this install\'s warapp-mcp history (file mode 0600) for warapp_import_state. The file holds the\n' +
|
|
10
|
+
'salt behind your hashed history: keep it private and delete it once imported.';
|
|
11
|
+
const defaultIo = { out: (s) => process.stdout.write(`${s}\n`), err: (s) => process.stderr.write(`${s}\n`) };
|
|
12
|
+
/** Run the CLI; resolves to the exit code (0 ok, 1 refused, 2 usage). */
|
|
13
|
+
export async function runExportCli(argv, io = defaultIo) {
|
|
14
|
+
let out;
|
|
15
|
+
let dir;
|
|
16
|
+
let account;
|
|
17
|
+
let force = false;
|
|
18
|
+
for (let i = 0; i < argv.length; i++) {
|
|
19
|
+
const a = argv[i];
|
|
20
|
+
const value = () => argv[++i];
|
|
21
|
+
if (a === '--out')
|
|
22
|
+
out = value();
|
|
23
|
+
else if (a === '--data-dir')
|
|
24
|
+
dir = value();
|
|
25
|
+
else if (a === '--account') {
|
|
26
|
+
const v = Number(value());
|
|
27
|
+
if (!Number.isSafeInteger(v) || v <= 0) {
|
|
28
|
+
io.err('--account must be a positive integer.');
|
|
29
|
+
return 2;
|
|
30
|
+
}
|
|
31
|
+
account = v;
|
|
32
|
+
}
|
|
33
|
+
else if (a === '--force')
|
|
34
|
+
force = true;
|
|
35
|
+
else if (a === '--help' || a === '-h') {
|
|
36
|
+
io.out(USAGE);
|
|
37
|
+
return 0;
|
|
38
|
+
}
|
|
39
|
+
else {
|
|
40
|
+
io.err(`Unknown argument.\n${USAGE}`);
|
|
41
|
+
return 2;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
if (!out) {
|
|
45
|
+
io.err(`--out is required.\n${USAGE}`);
|
|
46
|
+
return 2;
|
|
47
|
+
}
|
|
48
|
+
try {
|
|
49
|
+
const r = await collectExport(dir ?? dataDir(), account !== undefined ? { account } : {});
|
|
50
|
+
const bytes = encodeBundle(r);
|
|
51
|
+
await writeBundleFile(out, bytes, { force });
|
|
52
|
+
const raw = r.files.reduce((n, f) => n + f.bytes.length, 0);
|
|
53
|
+
io.out(`Wrote ${out}: ${r.files.length} files, ${humanSize(raw)} (${humanSize(bytes.length)} compressed), file mode 0600.`);
|
|
54
|
+
for (const store of STORES) {
|
|
55
|
+
const fs = r.files.filter((f) => f.store === store);
|
|
56
|
+
if (fs.length)
|
|
57
|
+
io.out(` ${store}: ${fs.length} file${fs.length === 1 ? '' : 's'}, ${humanSize(fs.reduce((n, f) => n + f.bytes.length, 0))}`);
|
|
58
|
+
}
|
|
59
|
+
const { finishedGames, unknownGames, otherAccountFiles } = r.leftOut;
|
|
60
|
+
io.out(`Left out: per-game files of ${finishedGames} finished game(s) and ${unknownGames} game(s) of unknown state, ` +
|
|
61
|
+
`${otherAccountFiles} file(s) of another account; credentials, chat, maps, stats and the bundle cache are never included.`);
|
|
62
|
+
io.out('It holds the salt behind your hashed history: keep it private, and delete it once imported.');
|
|
63
|
+
return 0;
|
|
64
|
+
}
|
|
65
|
+
catch (e) {
|
|
66
|
+
io.err(e instanceof StateBundleError ? e.message : `Export failed: ${e.code ?? 'error'}.`);
|
|
67
|
+
return 1;
|
|
68
|
+
}
|
|
69
|
+
}
|
package/dist/team-cards.js
CHANGED
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
// PLAN-TEAMS C3.7: the team hand and my teammates' entered card plays (#163). A team shares one hand, so a
|
|
2
|
+
// card my teammate has already entered a play or a discard of is theirs this turn: the plan never plays it
|
|
3
|
+
// too, and the card advice says who plays each card.
|
|
4
|
+
//
|
|
5
|
+
// UNVERIFIED live: whether war.app sends a teammate's orders before they commit (V5). VERIFIED (V8, #310): how a
|
|
6
|
+
// team's hand and its limit are keyed (teamCardLimit). Tolerant: no teammate orders read means no claim.
|
|
7
|
+
import { cardsToShed } from './cards.js';
|
|
1
8
|
/** Every card play and discard in my teammates' entered orders (`teammates`: their player ids), in entry order. */
|
|
2
9
|
export function teamCardClaims(entries, teammates) {
|
|
3
10
|
const out = [];
|
|
@@ -82,3 +89,21 @@ export function unclaimedFirst(hand, claimed) {
|
|
|
82
89
|
const ids = new Set(claimed.map((c) => c.card.id));
|
|
83
90
|
return [...hand.filter((c) => !ids.has(c.id)), ...hand.filter((c) => ids.has(c.id))];
|
|
84
91
|
}
|
|
92
|
+
/**
|
|
93
|
+
* The team's card limit as war.app applies it (V8, #310; the client bundle's GameValidateOrders, the hand seen
|
|
94
|
+
* live): the standing keeps each player's cards under that player's id, and a team's hand is every card under
|
|
95
|
+
* any of its players, counted against `MaxCardsHold` (the settings call it the most "a player or team" may hold).
|
|
96
|
+
* The cards my committed teammates' orders play or discard leave it first; then mine. Over the limit, war.app
|
|
97
|
+
* refuses (error 51) only the orders of the last of the team still playing to commit: while a teammate has yet
|
|
98
|
+
* to commit, they may still shed, and the orders are taken. `binding` holds only when every committed
|
|
99
|
+
* teammate's orders were read, so an unread teammate never makes a refusal.
|
|
100
|
+
*/
|
|
101
|
+
export function teamCardLimit(hand, rules, mates, entries) {
|
|
102
|
+
const playing = mates.filter((m) => (m.state ?? 'Playing') === 'Playing');
|
|
103
|
+
const committed = playing.filter((m) => m.hasCommittedOrders);
|
|
104
|
+
const lastToCommit = playing.every((m) => m.hasCommittedOrders);
|
|
105
|
+
const ordersRead = committed.every((m) => entries?.some((e) => e.playerId === m.id && e.orders !== null) === true);
|
|
106
|
+
const { left } = teamHandLeft(hand, teamCardClaims(entries, new Set(committed.map((m) => m.id))));
|
|
107
|
+
const shed = cardsToShed(left, rules);
|
|
108
|
+
return { left, shed, lastToCommit, ordersRead, binding: lastToCommit && ordersRead };
|
|
109
|
+
}
|
package/dist/tools/award.js
CHANGED
|
@@ -177,6 +177,11 @@ export function awardView(a, game, turn, name) {
|
|
|
177
177
|
notes,
|
|
178
178
|
};
|
|
179
179
|
}
|
|
180
|
+
const FROM_SAID = {
|
|
181
|
+
explicit: 'first_mover given',
|
|
182
|
+
award: 'the award of picks',
|
|
183
|
+
inferred: 'inferred from my first order there, not verified',
|
|
184
|
+
};
|
|
180
185
|
/**
|
|
181
186
|
* Who moves first on `turn` (#127): `first_mover` when given, else what this server knows — a
|
|
182
187
|
* turn kept at `<dataDir>/move-order/` alternated, or the award of picks — in a two-player game
|
|
@@ -190,6 +195,7 @@ export async function firstMoverFor(dataDir, game, me, turn, explicit, award, o
|
|
|
190
195
|
cyclicDuel,
|
|
191
196
|
...(explicit ? { explicit } : {}),
|
|
192
197
|
award: award?.firstMover ?? null,
|
|
198
|
+
...(o.inferred ? { inferred: o.inferred } : {}),
|
|
193
199
|
...(remembered ? { remembered } : {}),
|
|
194
200
|
});
|
|
195
201
|
if (dataDir && record && o.write !== false)
|
|
@@ -200,7 +206,15 @@ export async function firstMoverFor(dataDir, game, me, turn, explicit, award, o
|
|
|
200
206
|
firstMover: resolved.firstMover,
|
|
201
207
|
// #215 review: only a first mover the user gave is verified; the award's is the wiki's rule.
|
|
202
208
|
verified: verifiedFirstMover(resolved),
|
|
203
|
-
view: {
|
|
209
|
+
view: {
|
|
210
|
+
who: resolved.firstMover === 'me' ? 'you' : 'opponent',
|
|
211
|
+
source: resolved.source,
|
|
212
|
+
...(resolved.from ? { from: resolved.from } : {}),
|
|
213
|
+
line: `${resolved.firstMover === 'me' ? 'You move' : 'The opponent moves'} first` +
|
|
214
|
+
`${turn === null ? ' this turn' : ` on turn ${turn}`} (` +
|
|
215
|
+
(resolved.from ? `alternated from turn ${resolved.from.turn}: ${FROM_SAID[resolved.from.source]}` : FROM_SAID[resolved.source]) +
|
|
216
|
+
').',
|
|
217
|
+
},
|
|
204
218
|
warnings,
|
|
205
219
|
};
|
|
206
220
|
}
|
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
// orders; my Bomb and Emergency Blockade and the D2 cards carry an `order` to pass to warapp_submit_turn.
|
|
7
7
|
import { adviseOrderDelay, CARD_ORDER_DELAY, CARD_REINFORCEMENT, isMyCard, readActiveCards } from '../cards.js';
|
|
8
8
|
import { bombAdvice, bombExposure, wallOffer, wallThreats } from '../analysis/card-threats.js';
|
|
9
|
+
import { bonusTerritories } from '../analysis/bonuses.js';
|
|
9
10
|
import { supportAdvice } from './card-support-advice.js';
|
|
10
11
|
import { inGameId } from '../live.js';
|
|
11
12
|
import { capturePieceValue, cardClock } from '../strategy/card-clock.js';
|
|
@@ -50,8 +51,8 @@ export const handOwners = (game, me) => [
|
|
|
50
51
|
];
|
|
51
52
|
/** In a team game: the hand and the limit are the team's (said once in the plan's warnings). */
|
|
52
53
|
export const TEAM_HAND = "This is a team game: the hand and the card limit are the team's, shared with your teammates. The hand shown " +
|
|
53
|
-
"
|
|
54
|
-
'
|
|
54
|
+
"is every card under you and your teammates (war.app keeps each player's cards under that player's id), and war.app " +
|
|
55
|
+
'refuses only the last of the team to commit while the team is over the limit: agree in team chat who sheds.';
|
|
55
56
|
/** A card setting's `MultiplyAmount` (Blockade, Emergency Blockade), when the game sets one. */
|
|
56
57
|
function multiplier(settings, key) {
|
|
57
58
|
const r = settings?.raw[key];
|
|
@@ -79,7 +80,7 @@ export function adviseCards(input) {
|
|
|
79
80
|
const { game, me, turn, hand, choice, plan, label } = input;
|
|
80
81
|
const view = {};
|
|
81
82
|
const warnings = [];
|
|
82
|
-
// V8: in a team game a card read under a teammate's id is
|
|
83
|
+
// V8 (#310): in a team game a card read under a teammate's id is left to them, never advised to me.
|
|
83
84
|
const own = hand.filter((c) => isMyCard(c, cardGame(game, me).me));
|
|
84
85
|
const gone = new Set([...choice.plays, ...choice.discards].map((c) => c.id));
|
|
85
86
|
const held = (type) => own.find((c) => c.type === type && !gone.has(c.id));
|
|
@@ -160,9 +161,19 @@ export function adviseCards(input) {
|
|
|
160
161
|
const offer = ebMultiplier !== undefined ? wallOffer(cb, ebMultiplier, plan.conceded) : undefined;
|
|
161
162
|
if (offer) {
|
|
162
163
|
view.emergencyBlockade = { ...offer, order: { kind: 'card', card: wallCard.id, target: offer.territory } };
|
|
164
|
+
const bonusName = (id) => input.graph.map.bonuses.find((b) => b.id === id)?.name ?? `${id}`;
|
|
165
|
+
const p = offer.protects;
|
|
166
|
+
const shields = p.territories.length
|
|
167
|
+
? ` It shields ${p.territories
|
|
168
|
+
.map((t) => {
|
|
169
|
+
const of = p.bonuses.filter((b) => bonusTerritories(input.graph, b.bonus).includes(t));
|
|
170
|
+
return `${label(t)}${of.length ? ` (${of.map((b) => `bonus ${bonusName(b.bonus)}, +${b.value} a turn`).join('; ')})` : ''}`;
|
|
171
|
+
})
|
|
172
|
+
.join(', ')}${p.commander ? ', where your commander stands,' : ''} from player ${offer.player}'s ~${offer.reach}, which can reach ${p.territories.length === 1 ? 'it' : 'them'} next turn only through the wall.`
|
|
173
|
+
: '';
|
|
163
174
|
warnings.push(`Consider an Emergency Blockade on ${label(offer.territory)}: the plan concedes it, and its ${offer.givesUp} armies × ${ebMultiplier} make a ` +
|
|
164
|
-
`wall of ${offer.wall} that player ${offer.player}'s ~${offer.reach} would lose ~${offer.kills} attacking — if it attacks
|
|
165
|
-
|
|
175
|
+
`wall of ${offer.wall} that player ${offer.player}'s ~${offer.reach} would lose ~${offer.kills} attacking — if it attacks.${shields} ` +
|
|
176
|
+
`It gives up ${label(offer.territory)} and its ${offer.givesUp} armies for good (it turns neutral). Advice only, not in the orders: pass \`cards.advice.emergencyBlockade.order\` ` +
|
|
166
177
|
'to warapp_submit_turn to play it (the encoding is read from the client, not yet verified live).');
|
|
167
178
|
}
|
|
168
179
|
else if (ebMultiplier === undefined) {
|
package/dist/tools/card-plays.js
CHANGED
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
// Surveillance, Airlift, Gift, Diplomacy and Sanctions, and the combat cards Bomb and Emergency Blockade. Each card's fields come from the client
|
|
3
3
|
// bundle's `GameOrderPlayCard<X>` writer and its refusals mirror the bundle's `GameValidateOrders`
|
|
4
4
|
// (the error code each check stands in for is named), so a target war.app would refuse is refused
|
|
5
|
-
// here before anything is sent. The encodings are golden-pinned
|
|
6
|
-
// docs/WEB-PROTOCOL.md "Targeted card plays"). Third-party names reach errors only through
|
|
5
|
+
// here before anything is sent. The encodings are golden-pinned; Airlift's (#296) and Diplomacy's (#369) are
|
|
6
|
+
// verified live, the rest UNVERIFIED live (V9, docs/WEB-PROTOCOL.md "Targeted card plays"). Third-party names reach errors only through
|
|
7
7
|
// `untrustedText`.
|
|
8
8
|
import { McpToolError } from '@chrischall/mcp-utils';
|
|
9
9
|
import { inGameId } from '../live.js';
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
// PLAN-TEAMS D2: where to play my Diplomacy, Sanctions, Airlift and Gift cards this turn, read against the
|
|
2
2
|
// plan (src/analysis/card-support.ts). Advice only, never auto-played: each carries the `order` to pass to
|
|
3
|
-
// warapp_submit_turn as is, whose encodings are UNVERIFIED live (V9)
|
|
3
|
+
// warapp_submit_turn as is, whose encodings are UNVERIFIED live (V9) save Airlift's and Diplomacy's (verified
|
|
4
|
+
// live, #296 and #369). Players and territories by id only.
|
|
4
5
|
import { airliftAdvice, diplomacyAdvice, giftAdvice, intelAdvice, sanctionsAdvice } from '../analysis/card-support.js';
|
|
5
6
|
import { visibleIncomeFor } from '../analysis/plan/shared.js';
|
|
6
7
|
import { STRENGTH_INCOME_TURNS } from '../analysis/profile.js';
|
package/dist/tools/chat-inbox.js
CHANGED
|
@@ -126,6 +126,8 @@ export function registerChatInboxTool(server, ctx) {
|
|
|
126
126
|
sources.add(read.source);
|
|
127
127
|
const messages = fresh_.slice(-n).map((l) => shown(l, true, game.players, byInGame, me));
|
|
128
128
|
const name = game.name === undefined ? null : untrustedText(game.name);
|
|
129
|
+
// #387: new private messages addressed to me (diplomacy), counted for the watcher.
|
|
130
|
+
const toMe = me ? fresh_.filter((l) => l.channel === 'private' && l.to === me.inGameId).length : 0;
|
|
129
131
|
withNew.push({
|
|
130
132
|
// #322/#323: the game as warapp_get_chat nests it; the top-level keys stay for existing callers.
|
|
131
133
|
game: { id: game.id, name, state: game.state },
|
|
@@ -134,8 +136,10 @@ export function registerChatInboxTool(server, ctx) {
|
|
|
134
136
|
state: game.state,
|
|
135
137
|
source: read.source,
|
|
136
138
|
...feedFillFields(read),
|
|
139
|
+
...(read.olderUnread ? { olderUnread: read.olderUnread } : {}),
|
|
137
140
|
unread,
|
|
138
141
|
newCount: fresh_.length,
|
|
142
|
+
...(toMe ? { toMe } : {}),
|
|
139
143
|
messages,
|
|
140
144
|
...(mark_seen ? { markedSeen: marked ?? [] } : {}),
|
|
141
145
|
...(marked && fresh_.length > messages.length ? { markedUnshown: fresh_.length - messages.length } : {}),
|
package/dist/tools/chat.js
CHANGED
|
@@ -4,11 +4,11 @@
|
|
|
4
4
|
// confirmation — a message reaches other players and cannot be unsent.
|
|
5
5
|
import { CONFIRM_INJECTION_RULE, McpToolError, toolAnnotations } from '@chrischall/mcp-utils';
|
|
6
6
|
import { z } from 'zod';
|
|
7
|
-
import { CHAT_CHANNELS, feedChatLines, fillFromFeed, readGameRefreshChat, readSendChatReply } from '../chat.js';
|
|
7
|
+
import { CHAT_CHANNELS, feedChatLines, fillFromFeed, mergeChatLines, oldestId, readGameRefreshChat, readMessageHistoryReply, readSendChatReply, } from '../chat.js';
|
|
8
8
|
import { advanceCursor, markedChannels, markNew, readChatCursor, unreadCounts, writeChatCursor, } from '../chat-cursor.js';
|
|
9
9
|
import { parseGameId } from '../client.js';
|
|
10
|
-
import { inGameId, playersByInGameId } from '../live.js';
|
|
11
|
-
import { CHAT_CHANNEL_PUBLIC, Method, writeGameRefreshParams, writeSendChatParams } from '../protocol/methods.js';
|
|
10
|
+
import { inGameId, inGameOf, playersByInGameId } from '../live.js';
|
|
11
|
+
import { CHAT_CHANNEL_PUBLIC, Method, writeGameRefreshParams, writeRetrieveChatParams, writeRetrievePrivateMessageHistoryParams, writeSendChatParams, } from '../protocol/methods.js';
|
|
12
12
|
import { carriesTeam } from '../teams.js';
|
|
13
13
|
import { gameIdArg, readAnnotations, respond, UNTRUSTED_PREVIEW_NOTE, untrustedBody, untrustedDescription, untrustedText, } from './common.js';
|
|
14
14
|
import { checkMessageCommitments, commitmentsArg, COMMITMENTS_NOTE, DEFAULT_PLAN_CHECKED } from './commitments.js';
|
|
@@ -54,9 +54,12 @@ export async function readChat(ctx, game, me) {
|
|
|
54
54
|
if (me) {
|
|
55
55
|
try {
|
|
56
56
|
const env = await ctx.rpc.call('GameRefresh', Method.GameRefresh, (w) => writeGameRefreshParams(w, { gameId: game.id, chat: true, nonChat: false, lobby: game.state === 'WaitingForPlayers' }));
|
|
57
|
-
const
|
|
58
|
-
if (
|
|
59
|
-
|
|
57
|
+
const refreshed = readGameRefreshChat(await ctx.bundle(), env.body);
|
|
58
|
+
if (refreshed) {
|
|
59
|
+
const { lines, olderUnread } = await withOlder(ctx, game, me, refreshed);
|
|
60
|
+
const read = lines.length < (feed?.length ?? 0) ? withFeed(lines, feed) : { source: 'web', lines };
|
|
61
|
+
return olderUnread.length ? { ...read, olderUnread } : read;
|
|
62
|
+
}
|
|
60
63
|
}
|
|
61
64
|
catch {
|
|
62
65
|
// Fall back to GameFeed.
|
|
@@ -64,6 +67,59 @@ export async function readChat(ctx, game, me) {
|
|
|
64
67
|
}
|
|
65
68
|
return feed ? { source: 'gamefeed', lines: feed } : undefined;
|
|
66
69
|
}
|
|
70
|
+
/** The most private conversations whose history one chat read asks for (one request each). */
|
|
71
|
+
export const MAX_PRIVATE_HISTORY = 8;
|
|
72
|
+
/**
|
|
73
|
+
* GameRefresh's chat with the messages it leaves out added (#363, #387). Sent `-1` markers (as the client
|
|
74
|
+
* sends on a first load), GameRefresh leaves out messages war.app counts as seen — live, an own team message
|
|
75
|
+
* showed in the official app only after "Show older messages". The client's button sends RetrieveChat (45)
|
|
76
|
+
* with, per channel, the oldest message id received (9999E14 when none), and a private conversation's history
|
|
77
|
+
* button RetrievePrivateMessageHistory (46) the same per counterpart: both are asked here, once each, the
|
|
78
|
+
* private one per other human seat with an in-game id (at most {@link MAX_PRIVATE_HISTORY}) unless the game
|
|
79
|
+
* turns private messaging off. A read that fails or does not decode adds nothing and names its channels.
|
|
80
|
+
*/
|
|
81
|
+
async function withOlder(ctx, game, me, refreshed) {
|
|
82
|
+
let lines = refreshed;
|
|
83
|
+
const olderUnread = [];
|
|
84
|
+
const history = async (name, method, write) => {
|
|
85
|
+
try {
|
|
86
|
+
const env = await ctx.rpc.call(name, method, write);
|
|
87
|
+
return readMessageHistoryReply(await ctx.bundle(), env.body);
|
|
88
|
+
}
|
|
89
|
+
catch {
|
|
90
|
+
return undefined;
|
|
91
|
+
}
|
|
92
|
+
};
|
|
93
|
+
const older = await history('RetrieveChat', Method.RetrieveChat, (w) => writeRetrieveChatParams(w, {
|
|
94
|
+
gameId: game.id,
|
|
95
|
+
publicBefore: oldestId(refreshed, (l) => l.channel === 'public'),
|
|
96
|
+
teamBefore: oldestId(refreshed, (l) => l.channel === 'team'),
|
|
97
|
+
}));
|
|
98
|
+
if (older)
|
|
99
|
+
lines = mergeChatLines(lines, older);
|
|
100
|
+
else
|
|
101
|
+
olderUnread.push('public', 'team');
|
|
102
|
+
if (game.settings?.privateMessaging !== false) {
|
|
103
|
+
const counterparts = game.players
|
|
104
|
+
.filter((p) => !p.isAI)
|
|
105
|
+
.map((p) => inGameOf(p))
|
|
106
|
+
.filter((id) => id !== undefined && id !== me.inGameId)
|
|
107
|
+
.sort((a, b) => a - b)
|
|
108
|
+
.slice(0, MAX_PRIVATE_HISTORY);
|
|
109
|
+
let failed = false;
|
|
110
|
+
for (const counterpart of counterparts) {
|
|
111
|
+
const withThem = (l) => l.channel === 'private' && (l.to === counterpart || (l.sender === counterpart && l.to === me.inGameId));
|
|
112
|
+
const got = await history('RetrievePrivateMessageHistory', Method.RetrievePrivateMessageHistory, (w) => writeRetrievePrivateMessageHistoryParams(w, { gameId: game.id, before: oldestId(refreshed, withThem), counterpart }));
|
|
113
|
+
if (got)
|
|
114
|
+
lines = mergeChatLines(lines, got);
|
|
115
|
+
else
|
|
116
|
+
failed = true;
|
|
117
|
+
}
|
|
118
|
+
if (failed)
|
|
119
|
+
olderUnread.push('private');
|
|
120
|
+
}
|
|
121
|
+
return { lines, olderUnread };
|
|
122
|
+
}
|
|
67
123
|
/** A web read shorter than GameFeed's list, filled from it (#313). */
|
|
68
124
|
function withFeed(web, feed) {
|
|
69
125
|
const counts = `The web client's read returned fewer messages (${web.length}) than GameFeed's chat (${feed.length})`;
|
|
@@ -184,6 +240,8 @@ export function shown(line, isNew, players, byInGame, me) {
|
|
|
184
240
|
channel: line.channel,
|
|
185
241
|
...(line.team !== undefined ? { team: line.team } : {}),
|
|
186
242
|
...(to ? { to } : {}),
|
|
243
|
+
// #387: a private message addressed to me, so a watcher can flag diplomacy the moment it arrives.
|
|
244
|
+
...(line.channel === 'private' && me !== undefined && line.to === me.inGameId ? { toMe: true } : {}),
|
|
187
245
|
mine: isMine(line, me),
|
|
188
246
|
new: isNew,
|
|
189
247
|
};
|
|
@@ -249,6 +307,7 @@ export function registerChatTools(server, ctx, opts = {}) {
|
|
|
249
307
|
...header,
|
|
250
308
|
source: read.source,
|
|
251
309
|
...feedFillFields(read),
|
|
310
|
+
...(read.olderUnread ? { olderUnread: read.olderUnread } : {}),
|
|
252
311
|
messages,
|
|
253
312
|
count: picked.length,
|
|
254
313
|
shown: messages.length,
|
package/dist/tools/check-plan.js
CHANGED
|
@@ -14,7 +14,9 @@ import { claimedCardUses, claimedCardWarning, teamCardClaims, teamHandLeft, uncl
|
|
|
14
14
|
import { boardStateFromLive } from '../live.js';
|
|
15
15
|
import { withTeammateOrders } from '../team-orders.js';
|
|
16
16
|
import { assumedWarning, awardView, loadAward, openingThreat } from './award.js';
|
|
17
|
-
import {
|
|
17
|
+
import { readLedger } from '../relations-store.js';
|
|
18
|
+
import { resolveIntel } from '../analysis/intel.js';
|
|
19
|
+
import { avoidPlayersArg, avoidTerritoriesArg, gameIdArg, graphOf, knownIncomeArg, namer, readAnnotations, respond, untrustedDescription, untrustedText, viewArg } from './common.js';
|
|
18
20
|
import { lookupMeta } from './hints.js';
|
|
19
21
|
import { HEADROOM_COMPACT, headroomView, readTripwires, safeHeadroom, teamsOf, tripwireWarnings, untrustedDeploy } from './survival.js';
|
|
20
22
|
import { loadLiveGame, standInLine, standInOf } from './live-context.js';
|
|
@@ -125,6 +127,9 @@ export function registerCheckPlanTool(server, ctx) {
|
|
|
125
127
|
'income when larger; in a 1v1 that started even, an opponent bordering the fog at least your own income; while an ' +
|
|
126
128
|
'observation has made its estimate untrusted, the larger of what it implied and your own income). ' +
|
|
127
129
|
'Income in the fog is unseen, so raise it to test a stronger opponent.'),
|
|
130
|
+
known_income: knownIncomeArg,
|
|
131
|
+
avoid_territories: avoidTerritoriesArg,
|
|
132
|
+
avoid_players: avoidPlayersArg,
|
|
128
133
|
first_mover: z
|
|
129
134
|
.enum(['me', 'opponent'])
|
|
130
135
|
.optional()
|
|
@@ -133,7 +138,7 @@ export function registerCheckPlanTool(server, ctx) {
|
|
|
133
138
|
view: viewArg(VIEWS, `compact (default) gives the verdict, the worst reply and up to ${COMPACT_OTHERS} more; "full" adds every ` +
|
|
134
139
|
'reply listed, each order\'s result unanswered and the rules assumed.'),
|
|
135
140
|
}),
|
|
136
|
-
}, async ({ game_id, player, orders, enemy_deploy, first_mover, view }) => {
|
|
141
|
+
}, async ({ game_id, player, orders, enemy_deploy, known_income, avoid_territories, avoid_players, first_mover, view }) => {
|
|
137
142
|
const feed = await ctx.client.getGame(game_id, { settings: true });
|
|
138
143
|
requireTurnPhase(feed);
|
|
139
144
|
const map = mapOf(feed);
|
|
@@ -142,6 +147,12 @@ export function registerCheckPlanTool(server, ctx) {
|
|
|
142
147
|
// The teams: GameFeed's, else the game list's (asked once per game, kept).
|
|
143
148
|
const { game, me, source: teamSource, known: teamsKnown } = await resolveTeamsFor(ctx, feed, seat);
|
|
144
149
|
const turn = currentTurn(game);
|
|
150
|
+
// #386: the avoid targets and stated incomes warapp_record_intel kept, as warapp_plan_turn applies them.
|
|
151
|
+
const intel = resolveIntel(ctx.dataDir ? (await readLedger(ctx.dataDir, game.id, me.id))?.intel : undefined, turn, {
|
|
152
|
+
...(known_income !== undefined ? { knownIncome: known_income } : {}),
|
|
153
|
+
...(avoid_territories !== undefined ? { avoidTerritories: avoid_territories } : {}),
|
|
154
|
+
...(avoid_players !== undefined ? { avoidPlayers: avoid_players } : {}),
|
|
155
|
+
});
|
|
145
156
|
const [{ territories, info }, history] = await Promise.all([loadLiveGame(ctx, game), boardHistory(ctx, game, me, turn)]);
|
|
146
157
|
const graph = graphOf(map);
|
|
147
158
|
// As warapp_plan_turn does (#166): the opponent's starts the award of picks proves stand on
|
|
@@ -294,7 +305,14 @@ export function registerCheckPlanTool(server, ctx) {
|
|
|
294
305
|
staticSeats: staticSeats(game.players, game.endRules, me.id),
|
|
295
306
|
});
|
|
296
307
|
const untrustedOf = new Map(trip.tripwires.map((w) => [w.player, untrustedDeploy(w, income)]));
|
|
308
|
+
// #368: an income the caller knows replaces the estimate (a Reinforcement card the clock adds on top),
|
|
309
|
+
// before an untrusted mark; enemy_deploy, a what-if for everyone, wins over both. The commander check
|
|
310
|
+
// below keeps the submit's sizing, so it never calls safe what warapp_submit_turn refuses.
|
|
311
|
+
const knownOf = new Map((enemy_deploy === undefined ? (intel.knownIncome ?? []) : []).map((k) => [k.player, k.income]));
|
|
297
312
|
const opponents = so.opponents.map((o) => {
|
|
313
|
+
const known = knownOf.get(o.id);
|
|
314
|
+
if (known !== undefined)
|
|
315
|
+
return { ...o, deploy: known + (o.card ?? 0) };
|
|
298
316
|
const untrusted = untrustedOf.get(o.id);
|
|
299
317
|
return enemy_deploy !== undefined || untrusted === undefined ? o : { ...o, deploy: Math.max(untrusted, o.deploy) };
|
|
300
318
|
});
|
|
@@ -313,7 +331,10 @@ export function registerCheckPlanTool(server, ctx) {
|
|
|
313
331
|
? r.enforcedUntil === undefined || turn === null || turn < r.enforcedUntil
|
|
314
332
|
: teams.size === 0 && (r.state === 'active' || r.state === 'notice') && (r.endsTurn === undefined || turn === null || turn < r.endsTurn)));
|
|
315
333
|
// D3: the deploy total is checked against my income under the Sanctions on me.
|
|
316
|
-
|
|
334
|
+
// #332: a commerce game's gold, read from the standing, already carries any Sanctions (war.app pays it).
|
|
335
|
+
const sanction = so.commerce?.source === 'standing'
|
|
336
|
+
? { income, warnings: [], applied: false }
|
|
337
|
+
: sanctionMyIncome(income, effect, { localDeployments: settings.localDeployments === true });
|
|
317
338
|
const report = stressPlan({
|
|
318
339
|
graph,
|
|
319
340
|
board,
|
|
@@ -481,6 +502,7 @@ export function registerCheckPlanTool(server, ctx) {
|
|
|
481
502
|
opponent: who(e.opponent),
|
|
482
503
|
bonusesLost: e.bonusesLost.map((b) => bonusOf(b.id)),
|
|
483
504
|
incomeLost: e.incomeLost,
|
|
505
|
+
...(e.breaksTruce ? { breaksTruce: true } : {}),
|
|
484
506
|
});
|
|
485
507
|
const orderView = (e) => ({
|
|
486
508
|
order: e.index + 1,
|
|
@@ -498,9 +520,15 @@ export function registerCheckPlanTool(server, ctx) {
|
|
|
498
520
|
? ` ${report.blindBorders.length} of your territories border the fog and were not tested.`
|
|
499
521
|
: '';
|
|
500
522
|
const inexact = report.exact ? '' : ' Battles are not exact in this game (luck or weighted rounding): each was resolved at its expectation.';
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
523
|
+
// #376: an exposure only a truce break reaches is counted apart, after the real ones.
|
|
524
|
+
const reachable = report.exposedNextTurn.filter((x) => !x.breaksTruce);
|
|
525
|
+
const ifBroken = report.exposedNextTurn.length - reachable.length;
|
|
526
|
+
const brokenLine = ifBroken ? ` ${ifBroken} more only if a truce breaks.` : '';
|
|
527
|
+
const ahead = reachable.length
|
|
528
|
+
? ` Next turn: ${reachable.length} ${plural(reachable.length, 'territory is', 'territories are')} within reach of a stack two steps away if you add nothing (see exposedNextTurn). First: ${exposure(reachable[0])}${brokenLine}`
|
|
529
|
+
: ifBroken
|
|
530
|
+
? ` Next turn: ${ifBroken} ${plural(ifBroken, 'territory is', 'territories are')} within reach of a stack two steps away only if a truce breaks (see exposedNextTurn).`
|
|
531
|
+
: '';
|
|
504
532
|
// #180: stacks you attack that can step out of the way first.
|
|
505
533
|
const escapes = report.dodges.filter((d) => d.took && d.escaped > 0);
|
|
506
534
|
const escapingStacks = new Set(escapes.map((d) => d.stack)).size;
|
|
@@ -539,9 +567,21 @@ export function registerCheckPlanTool(server, ctx) {
|
|
|
539
567
|
});
|
|
540
568
|
// #275 pattern 3: each border these orders leave below what the default plan leaves there (one plan per call).
|
|
541
569
|
const belowPlan = await bordersBelowPlan(ctx, { game, map, me, turn, territories, info, history, teamsKnown, given: { deploys, moves } });
|
|
570
|
+
// #375: an order into a territory to avoid, or one an avoided player holds.
|
|
571
|
+
const avoidT = new Set((intel.avoidTerritories ?? []).map((t) => resolveTerritory(map, t).id));
|
|
572
|
+
const avoidP = new Set(intel.avoidPlayers ?? []);
|
|
573
|
+
const ownerOf = (id) => {
|
|
574
|
+
const o = board.territories.find((t) => t.territoryId === id)?.owner;
|
|
575
|
+
return o?.kind === 'player' ? o.playerId : undefined;
|
|
576
|
+
};
|
|
577
|
+
const avoidedHits = [...new Set(moves.map((m) => m.to))].filter((to) => !mine.has(to) && (avoidT.has(to) || avoidP.has(ownerOf(to) ?? Number.NaN)));
|
|
542
578
|
const warnings = [
|
|
543
579
|
// The owner, 2026-11-17: while an older build stands in for a client this server cannot read, say so first.
|
|
544
580
|
...[standInLine(standInOf(ctx))].filter((w) => w !== undefined),
|
|
581
|
+
...intel.warnings,
|
|
582
|
+
...(avoidedHits.length
|
|
583
|
+
? [`These orders attack ${avoidedHits.map((t) => name(t)).join(', ')}, which you asked to avoid (avoid_territories / avoid_players).`]
|
|
584
|
+
: []),
|
|
545
585
|
// #275 (b): an untrusted estimate is the first thing said (not under an explicit enemy_deploy).
|
|
546
586
|
...(enemy_deploy === undefined ? tripwireWarnings(trip.tripwires, (w) => untrustedOf.get(w.player) ?? untrustedDeploy(w, income), (p) => estimates.find((x) => x.playerId === p)?.estimate) : []),
|
|
547
587
|
...(award ? assumedWarning(award) : []),
|
|
@@ -563,7 +603,8 @@ export function registerCheckPlanTool(server, ctx) {
|
|
|
563
603
|
...effect.unsure,
|
|
564
604
|
...[claimedCardWarning(claimedCardUses(uses, claimed))].filter((w) => w !== undefined),
|
|
565
605
|
...unsimulatedCards,
|
|
566
|
-
|
|
606
|
+
// #332: in a commerce game a smaller deploy saves gold, so only a larger one is worth a line.
|
|
607
|
+
...(deployed !== sanction.income && !(so.commerce && deployed < sanction.income)
|
|
567
608
|
? [
|
|
568
609
|
`The orders deploy ${deployed} and your income is ${sanction.income}: the test used the orders as given (a Reinforcement card adds to the income; otherwise war.app refuses a wrong total).`,
|
|
569
610
|
]
|
|
@@ -596,16 +637,19 @@ export function registerCheckPlanTool(server, ctx) {
|
|
|
596
637
|
// #166: what the award of picks showed, the move order it implies included (absent with no pick list kept).
|
|
597
638
|
...(award ? { award: awardView(award, game, turn, name) } : {}),
|
|
598
639
|
orderPriority,
|
|
599
|
-
|
|
640
|
+
// #277: what I may deploy this turn, after any Sanctions on me (as warapp_plan_turn reports it).
|
|
641
|
+
income: sanction.income,
|
|
600
642
|
deployed,
|
|
601
643
|
warnings,
|
|
644
|
+
// #386: the intel warapp_record_intel kept and what this check did with it (absent when none is kept).
|
|
645
|
+
...(intel.report ? { intel: intel.report } : {}),
|
|
602
646
|
// Only an opponent with a stack in view can be given a reply; the others are named apart.
|
|
603
647
|
enemyDeploy: opponents
|
|
604
648
|
.filter((o) => inView.has(o.id))
|
|
605
649
|
.map((o) => ({
|
|
606
650
|
player: { id: o.id, name: playerName.get(o.id) ?? String(o.id) },
|
|
607
651
|
deploy: o.deploy,
|
|
608
|
-
source: enemy_deploy !== undefined ? 'enemy_deploy' : untrustedOf.has(o.id) ? 'untrusted' : 'estimate',
|
|
652
|
+
source: enemy_deploy !== undefined ? 'enemy_deploy' : knownOf.has(o.id) ? 'known_income' : untrustedOf.has(o.id) ? 'untrusted' : 'estimate',
|
|
609
653
|
})),
|
|
610
654
|
// #180: in a free-for-all, whether you lead (any two opponents are then tried together).
|
|
611
655
|
leader,
|
|
@@ -655,7 +699,7 @@ export function registerCheckPlanTool(server, ctx) {
|
|
|
655
699
|
jointFalls: report.jointFalls.slice(0, LIST_MAX).map(jointView),
|
|
656
700
|
...(report.jointFalls.length > LIST_MAX ? { jointFallsMore: report.jointFalls.length - LIST_MAX } : {}),
|
|
657
701
|
// #275 (a): each border's headroom, the weakest first (compact: the first few).
|
|
658
|
-
headroom: headroomView(headroom, map, income, rung === 'full', !teamsKnown),
|
|
702
|
+
headroom: headroomView(headroom, map, income, rung === 'full', !teamsKnown, (p) => estimates.find((e) => e.playerId === p)?.estimate),
|
|
659
703
|
...(rung !== 'full' && headroom.length > HEADROOM_COMPACT ? { headroomMore: headroom.length - HEADROOM_COMPACT } : {}),
|
|
660
704
|
// #275 pattern 3: absent when the default plan could not be made.
|
|
661
705
|
...(belowPlan
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
// #332: a commerce game's deploy this turn, for every tool that checks or plans a deploy total (warapp_plan_turn,
|
|
2
|
+
// warapp_submit_turn, warapp_check_plan): one computation, so the three never disagree.
|
|
3
|
+
import { commerceDeploy, commerceRules } from '../commerce.js';
|
|
4
|
+
import { inGameOf, standingGold } from '../live.js';
|
|
5
|
+
/**
|
|
6
|
+
* The armies my gold buys at the game's army price: from the standing's gold (`standingGold`) when it reads — it
|
|
7
|
+
* already holds what was saved and any Sanctions, since war.app pays it — else from `modelGold` (the income model).
|
|
8
|
+
* `undefined` outside a commerce game, or when its settings were not read.
|
|
9
|
+
*/
|
|
10
|
+
export function commerceDeployOf(game, me, info, modelGold) {
|
|
11
|
+
const rules = commerceRules(game.settings);
|
|
12
|
+
if (!rules)
|
|
13
|
+
return undefined;
|
|
14
|
+
const id = inGameOf(me);
|
|
15
|
+
return commerceDeploy(rules, id === undefined ? undefined : standingGold(info, id), modelGold);
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* What `warapp_submit_turn` checks a commerce deploy against (#353 review). Gold read from the board is authoritative,
|
|
19
|
+
* so it is the deploy budget (`commerce`: deploying more than it buys is refused, error 597; less saves gold). Gold
|
|
20
|
+
* from the income model leaves out what was saved on earlier turns, so it is not enforced: it adds an `uncertain`
|
|
21
|
+
* reason instead, and a different total is a warning, as an uncertain income always was.
|
|
22
|
+
*/
|
|
23
|
+
export function submitCommerceCheck(c) {
|
|
24
|
+
if (!c)
|
|
25
|
+
return { uncertain: [] };
|
|
26
|
+
if (c.source === 'standing')
|
|
27
|
+
return { commerce: { gold: c.gold, armyCostMultiplier: c.armyCostMultiplier }, uncertain: [] };
|
|
28
|
+
return {
|
|
29
|
+
uncertain: [
|
|
30
|
+
`Your gold could not be read from the board, so the check uses the income model's ${c.gold}, which leaves out gold saved from earlier turns.`,
|
|
31
|
+
],
|
|
32
|
+
};
|
|
33
|
+
}
|
package/dist/tools/common.js
CHANGED
|
@@ -7,6 +7,37 @@ export const readAnnotations = (title) => toolAnnotations({ title, readOnly: tru
|
|
|
7
7
|
export const gameIdArg = z
|
|
8
8
|
.union([z.number(), z.string()])
|
|
9
9
|
.describe('The war.app game id — the number after GameID= in the game URL (war.app/MultiPlayer?GameID=<n>).');
|
|
10
|
+
/**
|
|
11
|
+
* #368: per-player incomes the caller knows (warapp_plan_turn's and warapp_check_plan's `known_income`):
|
|
12
|
+
* each replaces that opponent's estimate.
|
|
13
|
+
*/
|
|
14
|
+
export const knownIncomeArg = z
|
|
15
|
+
.array(z.object({
|
|
16
|
+
player: z.coerce.number().int().describe('The player\'s GameFeed id (as warapp_get_game lists it).'),
|
|
17
|
+
income: z.coerce.number().int().min(0).max(10_000).describe('The income it earns per turn, card armies aside.'),
|
|
18
|
+
}))
|
|
19
|
+
.max(50)
|
|
20
|
+
.optional()
|
|
21
|
+
.describe('Per-player incomes you know (what a player said in diplomacy chat, say), by GameFeed id: each replaces that ' +
|
|
22
|
+
"opponent's estimate (a Reinforcement card the card clock adds stays on top), and the plan's warning says it was " +
|
|
23
|
+
'supplied. Taken as given, never checked against the board. Given, it replaces the incomes warapp_record_intel kept for this call. `enemy_deploy`, a what-if ' +
|
|
24
|
+
'for every opponent, wins over it; a player with none of its territories in view is named as unused.');
|
|
25
|
+
/** #375: territories never to attack (warapp_plan_turn's and warapp_check_plan's `avoid_territories`). */
|
|
26
|
+
export const avoidTerritoriesArg = z
|
|
27
|
+
.array(z.union([z.string(), z.number()]))
|
|
28
|
+
.max(200)
|
|
29
|
+
.optional()
|
|
30
|
+
.describe('Territories (ids or names) never to attack this turn, whoever holds them: a neutral promised to someone, say. ' +
|
|
31
|
+
'warapp_plan_turn plans around them; warapp_check_plan warns when the orders attack one. Given, it replaces the territories ' +
|
|
32
|
+
'warapp_record_intel kept, for this call (`[]`: none); omitted, those apply.');
|
|
33
|
+
/** #375: players never to attack (warapp_plan_turn's and warapp_check_plan's `avoid_players`). */
|
|
34
|
+
export const avoidPlayersArg = z
|
|
35
|
+
.array(z.coerce.number().int())
|
|
36
|
+
.max(50)
|
|
37
|
+
.optional()
|
|
38
|
+
.describe('Players (GameFeed ids) never to attack this turn: peace promised outside a recorded truce. warapp_plan_turn ' +
|
|
39
|
+
'attacks none of their territories; warapp_check_plan warns when the orders do. Given, it replaces the players ' +
|
|
40
|
+
'warapp_record_intel kept, for this call (`[]`: none); omitted, those apply.');
|
|
10
41
|
/**
|
|
11
42
|
* Who writes the text these tools return: player and game names, chat, and
|
|
12
43
|
* map / territory / bonus names (maps are user-designed). None of it is the user.
|
|
@@ -355,10 +355,12 @@ export const sweepWindow = (keep = MAX_FINISHED_RECORDS) => Math.max(1, Math.flo
|
|
|
355
355
|
* the newest {@link sweepWindow} games (half the record bound): older ones are never its candidates.
|
|
356
356
|
* Its writes never prune a record of a game in that window (`protectIds`), and each call refreshes the
|
|
357
357
|
* window's records, so the records the harness and the reports read stay the newest games'. A game the
|
|
358
|
-
* sweep processed is so never read again (P2).
|
|
358
|
+
* sweep processed is so never read again (P2). `window` widens (or narrows) it for warapp_backfill_history,
|
|
359
|
+
* at most `keep` games.
|
|
359
360
|
*/
|
|
360
|
-
export async function sweepFinished(deps, me, gameIds, { limit = END_OF_GAME_PER_CALL, keep = MAX_FINISHED_RECORDS } = {}) {
|
|
361
|
-
|
|
361
|
+
export async function sweepFinished(deps, me, gameIds, { limit = END_OF_GAME_PER_CALL, keep = MAX_FINISHED_RECORDS, window: size, } = {}) {
|
|
362
|
+
// warapp_backfill_history may widen the window, never past the record bound (every game in it is protected).
|
|
363
|
+
const window = gameIds.slice(0, Math.max(1, Math.min(size ?? sweepWindow(keep), keep)));
|
|
362
364
|
const todo = [];
|
|
363
365
|
for (const id of window)
|
|
364
366
|
if (await needsEndOfGame(deps.dataDir, deps.env, id, me))
|
package/dist/tools/index.js
CHANGED
|
@@ -34,6 +34,8 @@ import { registerTurnTools } from './turn.js';
|
|
|
34
34
|
import { registerUncommitTool } from './uncommit.js';
|
|
35
35
|
import { registerLeaveGameTool } from './leave-game.js';
|
|
36
36
|
import { registerWhereTool } from './where.js';
|
|
37
|
+
import { registerStateTools } from './state.js';
|
|
38
|
+
import { blobStoreFromEnv } from '@chrischall/mcp-utils/export';
|
|
37
39
|
import { registerProfileOpponentsTool } from './profile-opponents.js';
|
|
38
40
|
import { pushListenerFor } from '../push/listener.js';
|
|
39
41
|
import { pushWebSocketLeg } from '../push/websocket.js';
|
|
@@ -152,6 +154,11 @@ export function registerAllTools(server, deps = {}) {
|
|
|
152
154
|
...(env ? { env } : {}),
|
|
153
155
|
});
|
|
154
156
|
registerPushTools(server, live, push, deps.env ? { env: deps.env } : {});
|
|
157
|
+
// Moving a local install's history in (hosted: only with mcp-host's blob store) and the end-of-game backfill.
|
|
158
|
+
registerStateTools(server, live, {
|
|
159
|
+
...(deps.env ? { env: deps.env } : {}),
|
|
160
|
+
store: deps.blobStore === undefined ? blobStoreFromEnv(deps.env ?? process.env) : deps.blobStore,
|
|
161
|
+
});
|
|
155
162
|
// Hosted only: the war.app sign-in mcp-host's authFlow captures the AuthToken from (#333 part B).
|
|
156
163
|
// Locally warapp_link_session stays the way to the direct transport.
|
|
157
164
|
if (hosted)
|