@chrischall/warapp-mcp 0.6.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.
Files changed (90) hide show
  1. package/.claude-plugin/marketplace.json +2 -2
  2. package/.claude-plugin/plugin.json +1 -1
  3. package/README.md +99 -6
  4. package/dist/analysis/accept-surrender.js +20 -2
  5. package/dist/analysis/calibrate.js +1 -0
  6. package/dist/analysis/card-support.js +175 -16
  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/decision-replay.js +279 -0
  13. package/dist/analysis/decision-truth.js +146 -0
  14. package/dist/analysis/finished-game.js +62 -3
  15. package/dist/analysis/game-lessons.js +12 -6
  16. package/dist/analysis/opponent-profile.js +46 -3
  17. package/dist/analysis/opponents.js +245 -19
  18. package/dist/analysis/outlook.js +323 -17
  19. package/dist/analysis/plan/after-leftover.js +4 -1
  20. package/dist/analysis/plan/captures.js +4 -3
  21. package/dist/analysis/plan/estimates.js +70 -6
  22. package/dist/analysis/plan/guard-off.js +2 -1
  23. package/dist/analysis/plan/holds.js +79 -6
  24. package/dist/analysis/plan/leftover.js +145 -5
  25. package/dist/analysis/plan/relations.js +115 -2
  26. package/dist/analysis/plan/shared.js +201 -11
  27. package/dist/analysis/plan/stand-still.js +2 -2
  28. package/dist/analysis/plan/stockpile.js +104 -0
  29. package/dist/analysis/plan/strike.js +34 -7
  30. package/dist/analysis/plan/targets.js +168 -53
  31. package/dist/analysis/plan/threats.js +108 -5
  32. package/dist/analysis/plan/transfers.js +11 -0
  33. package/dist/analysis/plan/two-move.js +70 -0
  34. package/dist/analysis/plan/vacated.js +124 -2
  35. package/dist/analysis/planner.js +302 -42
  36. package/dist/analysis/since-last.js +18 -5
  37. package/dist/board.js +36 -2
  38. package/dist/build-id.js +106 -0
  39. package/dist/bundle.js +14943 -10146
  40. package/dist/chat-automation.js +22 -0
  41. package/dist/client.js +14 -0
  42. package/dist/decision-log.js +1093 -0
  43. package/dist/finished-store.js +5 -1
  44. package/dist/lessons-store.js +322 -21
  45. package/dist/open-games.js +36 -16
  46. package/dist/outlook-log.js +42 -1
  47. package/dist/protocol/methods.js +4 -2
  48. package/dist/review-export.js +198 -0
  49. package/dist/state-bundle.js +62 -3
  50. package/dist/state-cli.js +5 -3
  51. package/dist/strategy/notes.js +56 -0
  52. package/dist/tools/accept-surrender.js +23 -9
  53. package/dist/tools/award.js +5 -1
  54. package/dist/tools/card-advice.js +77 -23
  55. package/dist/tools/card-support-advice.js +36 -7
  56. package/dist/tools/chat-advice.js +330 -0
  57. package/dist/tools/chat-inbox.js +15 -4
  58. package/dist/tools/chat.js +41 -11
  59. package/dist/tools/check-plan.js +14 -2
  60. package/dist/tools/decision-capture.js +459 -0
  61. package/dist/tools/end-of-game.js +146 -18
  62. package/dist/tools/game-kind.js +92 -0
  63. package/dist/tools/how-lost.js +7 -2
  64. package/dist/tools/index.js +3 -0
  65. package/dist/tools/join-game.js +10 -4
  66. package/dist/tools/live-context.js +6 -0
  67. package/dist/tools/live.js +10 -1
  68. package/dist/tools/map-curves.js +73 -0
  69. package/dist/tools/notifications.js +4 -3
  70. package/dist/tools/opponents.js +2 -0
  71. package/dist/tools/past-games.js +74 -8
  72. package/dist/tools/picks.js +49 -10
  73. package/dist/tools/profile-hook.js +62 -3
  74. package/dist/tools/profile-opponents.js +2 -0
  75. package/dist/tools/push.js +2 -2
  76. package/dist/tools/relations.js +2 -0
  77. package/dist/tools/scout.js +16 -2
  78. package/dist/tools/state.js +6 -1
  79. package/dist/tools/strategy.js +3 -3
  80. package/dist/tools/stress-opponents.js +2 -0
  81. package/dist/tools/surrender-pending.js +10 -1
  82. package/dist/tools/surrender.js +18 -3
  83. package/dist/tools/turn.js +313 -18
  84. package/dist/tools/where.js +3 -1
  85. package/dist/version.js +1 -1
  86. package/manifest.json +23 -2
  87. package/mint.yaml +23 -0
  88. package/package.json +1 -1
  89. package/server.json +20 -2
  90. package/skills/warapp-mcp/SKILL.md +42 -8
@@ -455,9 +455,11 @@ export const TARGETED_CARD_PLAYS = new Set([
455
455
  /**
456
456
  * The card plays whose encoding is read from the bundle but not yet sent live (V9): the preview warns
457
457
  * and the result carries `cardPlayCheck`. Airlift left it once verified live 2026-11-16 (#296), Diplomacy
458
- * once verified live 2026-11-18 (#369: played through warapp_submit_turn, read in force on later boards).
458
+ * once verified live 2026-11-18 (#369: played through warapp_submit_turn, read in force on later boards),
459
+ * Reconnaissance once war.app accepted it live 2026-11-20 (#443: a turn with the play committed, no error;
460
+ * withdrawn before it resolved, so the reveal itself is not yet seen).
459
461
  */
460
- const VERIFIED_CARD_PLAYS = new Set(['Airlift', 'Diplomacy']);
462
+ const VERIFIED_CARD_PLAYS = new Set(['Airlift', 'Diplomacy', 'Reconnaissance']);
461
463
  export const UNVERIFIED_CARD_PLAYS = new Set([...TARGETED_CARD_PLAYS].filter((kind) => !VERIFIED_CARD_PLAYS.has(kind)));
462
464
  function need(v, card, what) {
463
465
  if (v === undefined)
@@ -0,0 +1,198 @@
1
+ // The review export (#437 task 5, `scripts/review-export.mjs`, a LOCAL dev script: never a tool, never in
2
+ // CI). A strategy review reads one file per game instead of reconstructing it from six stores: this joins,
3
+ // for each game, what this server kept of it — the decision log (#412, with #437's per-turn additions, its
4
+ // events, seats, join context, opponents and picks phase), the end-of-game record (src/finished-store.ts:
5
+ // outcome, kinds, the history's truth), the game's entry in its map's record and in the lessons
6
+ // (src/lessons-store.ts, by `finishedGameKey`), the settings record (src/replay.ts: state, turns, seats by
7
+ // id) and the stored map's name and size — plus an `index.json` of every game with which sources exist.
8
+ //
9
+ // Name-free: every store it reads is (player ids, the map's own names, HMAC keys); the settings record's
10
+ // player names are never read back (`readGameRecord` puts the id in their place) and only ids are written.
11
+ // The decision log's encoded boards and the planner's replay `input` are left out (`hasInput` says whether
12
+ // a turn kept one: `scripts/replay-decisions.mjs` replays those); `boards: true` adds each logged turn's
13
+ // board rebuilt whole (`boardAt`). It makes no request and writes nothing to the data dir. The export is
14
+ // 0600 files in a 0700 folder; an existing folder others can read is refused, never chmod-ed.
15
+ import { existsSync } from 'node:fs';
16
+ import { chmod, mkdir, readdir, rename, stat, unlink, writeFile } from 'node:fs/promises';
17
+ import { join } from 'node:path';
18
+ import { randomBytes } from 'node:crypto';
19
+ import { profileFormatOf } from './analysis/opponent-profile.js';
20
+ import { boardAt, decisionLogPath, decisionsDir, readDecisionLog, } from './decision-log.js';
21
+ import { finishedPath, readFinishedRecord } from './finished-store.js';
22
+ import { lessonsPath, mapRecordPath, readLessons, readMapRecord, } from './lessons-store.js';
23
+ import { readStoredMap } from './map-store.js';
24
+ import { finishedGameKey, playerRecordSalt } from './player-record-store.js';
25
+ import { gameRecordPath, gamesDir, readGameRecord } from './replay.js';
26
+ import { readCachedPlayer } from './trend.js';
27
+ const idsIn = async (folder) => (await readdir(folder).catch(() => [])).filter((n) => /^\d{1,12}\.json$/.test(n)).map((n) => Number(n.slice(0, -5)));
28
+ /** Every game with a decision log (readable or not) or a settings record, ascending. Never throws. */
29
+ export async function reviewGameIds(dir) {
30
+ const ids = new Set([...(await idsIn(decisionsDir(dir))), ...(await idsIn(gamesDir(dir)))]);
31
+ return [...ids].sort((a, b) => a - b);
32
+ }
33
+ function reviewTurns(log, boards) {
34
+ const out = {};
35
+ for (const [k, e] of Object.entries(log.turns)) {
36
+ const { board, input, ...rest } = e;
37
+ const t = { ...rest, hasInput: input !== undefined };
38
+ if (boards && board)
39
+ t.board = boardAt(log, Number(k)) ?? null;
40
+ out[k] = t;
41
+ }
42
+ return out;
43
+ }
44
+ const gameOf = (g) => ({
45
+ state: g.state,
46
+ ...(g.numberOfTurns !== undefined ? { numberOfTurns: g.numberOfTurns } : {}),
47
+ players: g.players.map((p) => ({
48
+ id: p.id,
49
+ ...(p.team !== undefined ? { team: p.team } : {}),
50
+ ...(p.state !== undefined ? { state: p.state } : {}),
51
+ ...(p.isAI ? { ai: true } : {}),
52
+ })),
53
+ });
54
+ const newestTurn = (log) => {
55
+ const ks = Object.keys(log.turns).filter((k) => /^\d+$/.test(k)).map(Number);
56
+ return ks.length ? Math.max(...ks) : null;
57
+ };
58
+ /**
59
+ * The finished record for `gameId`: tried as `me` when known, else as each seat of the settings record
60
+ * (a legacy game keeps no log or board cache naming my account; the record's name is an HMAC, so only a
61
+ * seat id can match it). Never throws.
62
+ */
63
+ async function findFinished(dir, salt, gameId, me, game) {
64
+ if (!salt)
65
+ return { record: 'missing' };
66
+ const candidates = me !== undefined ? [me] : (game?.players.map((p) => p.id) ?? []);
67
+ for (const id of candidates) {
68
+ const r = await readFinishedRecord(finishedPath(dir, salt, id, gameId));
69
+ if (r !== 'missing')
70
+ return { me: id, record: r };
71
+ }
72
+ return { record: 'missing' };
73
+ }
74
+ /** What a store keyed by `finishedGameKey` holds for the game: its entry, or that it was counted apart. */
75
+ function keyedEntry(path, store, key) {
76
+ if (store === 'unreadable')
77
+ return { state: 'unreadable', value: null };
78
+ if (!key || !existsSync(path))
79
+ return { state: 'missing', value: null };
80
+ const entry = store.entries.find((e) => e.key === key);
81
+ if (entry)
82
+ return { state: 'present', value: { entry } };
83
+ const apart = store.excluded?.keys.find((k) => k.key === key);
84
+ if (apart)
85
+ return { state: 'excluded', value: { entry: null, excluded: apart.kind } };
86
+ return { state: 'missing', value: null };
87
+ }
88
+ /** One game joined from the data dir; `undefined` when it has neither a decision log nor a settings record. Never throws. */
89
+ export async function reviewGame(dir, gameId, opts = {}) {
90
+ const logExists = existsSync(decisionLogPath(dir, gameId));
91
+ const log = logExists ? await readDecisionLog(dir, gameId) : undefined;
92
+ const game = await readGameRecord(dir, gameId);
93
+ if (!logExists && !game && !existsSync(gameRecordPath(dir, gameId)))
94
+ return undefined;
95
+ const salt = await playerRecordSalt(dir).catch(() => undefined);
96
+ const cached = log?.playerId ?? (await readCachedPlayer(dir, gameId));
97
+ const found = await findFinished(dir, salt, gameId, cached, game);
98
+ const me = cached ?? found.me;
99
+ const finished = typeof found.record === 'object' ? found.record : null;
100
+ const mapId = finished?.mapId ?? game?.settings?.mapId;
101
+ const stored = mapId !== undefined ? await readStoredMap(dir, mapId, { maxAgeMs: Number.POSITIVE_INFINITY }) : undefined;
102
+ const key = salt && me !== undefined ? finishedGameKey(salt, me, gameId) : undefined;
103
+ const mapRecord = mapId !== undefined ? keyedEntry(mapRecordPath(dir, mapId), await readMapRecord(dir, mapId), key) : { state: 'missing', value: null };
104
+ const lessons = keyedEntry(lessonsPath(dir), await readLessons(dir), key);
105
+ const format = finished?.format ?? log?.join?.flags.format ?? (game?.players.length ? profileFormatOf(game.players) : null);
106
+ return {
107
+ version: 1,
108
+ gameId,
109
+ playerId: me ?? null,
110
+ kinds: finished?.kinds ?? null,
111
+ format,
112
+ map: mapId !== undefined ? { id: mapId, ...(stored ? { name: stored.name, territories: stored.territories.length } : {}) } : null,
113
+ outcome: finished?.outcome ?? null,
114
+ turns: finished?.outcome?.turn ?? game?.numberOfTurns ?? (log ? newestTurn(log) : null),
115
+ game: game ? gameOf(game) : null,
116
+ decisionLog: log
117
+ ? {
118
+ status: log.status,
119
+ turns: reviewTurns(log, opts.boards === true),
120
+ ...(log.accuracySummary ? { accuracySummary: log.accuracySummary } : {}),
121
+ ...(log.truthMissing ? { truthMissing: log.truthMissing } : {}),
122
+ }
123
+ : null,
124
+ events: log?.events ?? null,
125
+ ...(log?.eventsDropped ? { eventsDropped: log.eventsDropped } : {}),
126
+ seats: log?.seats ?? null,
127
+ join: log?.join ?? null,
128
+ opponents: log?.opponents ?? null,
129
+ picks: log?.picks ?? null,
130
+ finished,
131
+ mapRecord: mapRecord.value,
132
+ lessons: lessons.value,
133
+ sources: {
134
+ decisionLog: log ? 'present' : logExists ? 'unreadable' : 'missing',
135
+ finished: found.record === 'unreadable' ? 'unreadable' : finished ? 'present' : 'missing',
136
+ settingsRecord: game ? 'present' : 'missing',
137
+ map: stored ? 'present' : 'missing',
138
+ mapRecord: mapRecord.state,
139
+ lessons: lessons.state,
140
+ },
141
+ };
142
+ }
143
+ const indexEntry = (g) => ({
144
+ gameId: g.gameId,
145
+ kinds: g.kinds,
146
+ format: g.format,
147
+ mapId: g.map?.id ?? null,
148
+ mapName: g.map?.name ?? null,
149
+ outcome: g.outcome?.result ?? null,
150
+ turns: g.turns,
151
+ sources: g.sources,
152
+ });
153
+ /** The export folder: made 0700, or an existing one only when no one else can read it. Throws otherwise. */
154
+ async function privateFolder(out) {
155
+ const s = await stat(out).catch(() => undefined);
156
+ if (!s) {
157
+ await mkdir(out, { recursive: true, mode: 0o700 });
158
+ // `mode` is masked by the umask: set it outright on the folder made here.
159
+ await chmod(out, 0o700);
160
+ return;
161
+ }
162
+ if (!s.isDirectory())
163
+ throw new Error(`${out} is not a directory`);
164
+ if (s.mode & 0o077)
165
+ throw new Error(`${out} is readable by others: use a new folder or chmod 700 it`);
166
+ }
167
+ async function writePrivate(path, body) {
168
+ const tmp = `${path}.${process.pid}.${randomBytes(4).toString('hex')}.tmp`;
169
+ try {
170
+ await writeFile(tmp, `${JSON.stringify(body, null, 2)}\n`, { mode: 0o600 });
171
+ await chmod(tmp, 0o600);
172
+ await rename(tmp, path);
173
+ }
174
+ catch (e) {
175
+ await unlink(tmp).catch(() => { });
176
+ throw e;
177
+ }
178
+ }
179
+ /**
180
+ * Write `game-<id>.json` per game (every game `reviewGameIds` lists, or `game` alone) and `index.json`
181
+ * into `out`. Throws when the folder is not private or `game` has no data.
182
+ */
183
+ export async function exportReview(dir, out, opts = {}) {
184
+ const ids = opts.game !== undefined ? [opts.game] : await reviewGameIds(dir);
185
+ const games = [];
186
+ for (const id of ids) {
187
+ const g = await reviewGame(dir, id, opts);
188
+ if (g)
189
+ games.push(g);
190
+ }
191
+ if (opts.game !== undefined && !games.length)
192
+ throw new Error(`game ${opts.game}: no data (no decision log or settings record)`);
193
+ await privateFolder(out);
194
+ for (const g of games)
195
+ await writePrivate(join(out, `game-${g.gameId}.json`), g);
196
+ await writePrivate(join(out, 'index.json'), { version: 1, games: games.map(indexEntry) });
197
+ return { games: games.length, out };
198
+ }
@@ -5,7 +5,8 @@
5
5
  // What travels is what war.app cannot give back: the salt behind every hashed key
6
6
  // (`relations/players.salt`; the keys also carry my account id, so a bundle is one account's), the
7
7
  // deal record and the per-game ledgers, the opponent profiles, the lessons, the map records and the
8
- // end-of-game records with their processed marks — and, for games still in play only, the per-game
8
+ // end-of-game records with their processed marks, the decision logs of every game (#412: one account's
9
+ // each, the account read from the file's `playerId`; newest first up to MAX_EXPORT_DECISION_BYTES) — and, for games still in play only, the per-game
9
10
  // files the planner reads (boards, game records, outlook, picks, move order, teams, the per-game
10
11
  // profile turns, siege memory and contested-bonus attempts). Never: credentials (`.env`, `session.json`), the client bundle
11
12
  // cache, the guess salt, chat cursors, the map cache and stats (all rebuilt), nor the per-game files
@@ -29,6 +30,7 @@ import { createHash, randomUUID } from 'node:crypto';
29
30
  import { chmod, link, lstat, mkdir, readdir, readFile, rename, unlink, writeFile } from 'node:fs/promises';
30
31
  import { join } from 'node:path';
31
32
  import { gunzipSync, gzipSync } from 'node:zlib';
33
+ import { decisionLogOwner } from './decision-log.js';
32
34
  import { withPathLock } from './path-lock.js';
33
35
  import { finishedGameKey } from './player-record-store.js';
34
36
  export const STATE_FORMAT = 'warapp-state';
@@ -37,6 +39,13 @@ export const STATE_VERSION = 1;
37
39
  export const MAX_BUNDLE_BYTES = 32 * 1024 * 1024;
38
40
  /** The largest bundle unpacked (a gzip bomb stops here). */
39
41
  export const MAX_UNPACKED_BYTES = 256 * 1024 * 1024;
42
+ /**
43
+ * #412: the decision logs a bundle carries at most (raw bytes, newest first; the rest are counted as left
44
+ * out). Their store may hold far more (src/decision-log.ts MAX_DECISION_BYTES), and base64 inside the
45
+ * bundle's JSON is 4/3 of that: this keeps them, even incompressible, under {@link MAX_BUNDLE_BYTES} and a
46
+ * quarter of {@link MAX_UNPACKED_BYTES}, so they can never make a bundle the import refuses.
47
+ */
48
+ export const MAX_EXPORT_DECISION_BYTES = 16 * 1024 * 1024;
40
49
  /** Where `replace` moves the old stores. */
41
50
  export const BACKUP_DIR = 'state-backups';
42
51
  export class StateBundleError extends Error {
@@ -60,6 +69,7 @@ export const STORES = [
60
69
  'teams',
61
70
  'siege',
62
71
  'bonusAttempts',
72
+ 'decisions',
63
73
  ];
64
74
  const RULES = [
65
75
  { store: 'salt', dir: 'relations', name: /^players\.salt$/ },
@@ -79,6 +89,8 @@ const RULES = [
79
89
  { store: 'siege', dir: 'siege', name: /^(\d{1,12})-(\d{1,20})\.json$/, game: 'game-account' },
80
90
  // #410: the planner's contested-bonus attempt and drop memory (#405, src/bonus-attempt-store.ts).
81
91
  { store: 'bonusAttempts', dir: 'bonus-attempts', name: /^(\d{1,12})-(\d{1,20})\.json$/, game: 'game-account' },
92
+ // #412: the decision log (src/decision-log.ts), one account's per game; kept for finished games too (its truth and accuracy).
93
+ { store: 'decisions', dir: 'decisions', name: /^(\d{1,12})\.json$/, game: 'game', allGames: true, accountInside: true },
82
94
  ];
83
95
  /** Top-level entries keyed by the salt: moved aside whole under `replace` when the salt changes. */
84
96
  const HASHED_ENTRIES = ['relations', 'profiles', 'finished', 'maps-record', 'lessons.json'];
@@ -199,12 +211,22 @@ export async function collectExport(dir, opts = {}) {
199
211
  const finishedGames = new Set();
200
212
  const unknownGames = new Set();
201
213
  let otherAccountFiles = 0;
214
+ // #412: the decision logs, weighed after the walk: newest first, up to their share.
215
+ const decisions = [];
202
216
  for (const p of paths) {
203
217
  const { rule, gameId, account: a } = ruleOf(p);
204
218
  if (a !== undefined && a !== account) {
205
219
  otherAccountFiles++;
206
220
  continue;
207
221
  }
222
+ if (rule.accountInside) {
223
+ // A decision log names its account in its head: only the logs exported are read whole (below).
224
+ const owner = rule.store === 'decisions' ? await decisionLogOwner(join(dir, p), gameId) : (await readJson(join(dir, p)).then((c) => (isRec(c) ? c.playerId : undefined)));
225
+ if (owner !== account) {
226
+ otherAccountFiles++;
227
+ continue;
228
+ }
229
+ }
208
230
  if (gameId !== undefined && !rule.allGames) {
209
231
  const s = await statusOf(gameId);
210
232
  if (s === 'finished') {
@@ -216,9 +238,42 @@ export async function collectExport(dir, opts = {}) {
216
238
  continue;
217
239
  }
218
240
  }
241
+ if (rule.store === 'decisions') {
242
+ const st = await lstat(join(dir, p)).catch(() => undefined);
243
+ if (st)
244
+ decisions.push({ path: p, size: st.size, mtimeMs: st.mtimeMs });
245
+ continue;
246
+ }
219
247
  const bytes = await readFile(join(dir, p));
220
248
  files.push({ path: p, bytes, store: rule.store, sha256: sha256(bytes) });
221
249
  }
250
+ const budget = opts.decisionBytes ?? MAX_EXPORT_DECISION_BYTES;
251
+ let used = 0;
252
+ let decisionLogs = 0;
253
+ decisions.sort((a, b) => b.mtimeMs - a.mtimeMs || a.path.localeCompare(b.path));
254
+ for (const [i, d] of decisions.entries()) {
255
+ const bytes = used + d.size <= budget ? await readFile(join(dir, d.path)) : undefined;
256
+ // Past the share (or grown past it since): this one and every older one stay home.
257
+ if (!bytes || used + bytes.length > budget) {
258
+ decisionLogs = decisions.length - i;
259
+ break;
260
+ }
261
+ // Its head named the account; the whole file must too (one that no longer parses, or names another, stays home).
262
+ let whole;
263
+ try {
264
+ whole = JSON.parse(bytes.toString('utf8'));
265
+ }
266
+ catch {
267
+ whole = undefined;
268
+ }
269
+ if (!isRec(whole) || whole.playerId !== account) {
270
+ otherAccountFiles++;
271
+ continue;
272
+ }
273
+ used += bytes.length;
274
+ files.push({ path: d.path, bytes, store: 'decisions', sha256: sha256(bytes) });
275
+ }
276
+ files.sort((a, b) => (a.path < b.path ? -1 : a.path > b.path ? 1 : 0));
222
277
  return {
223
278
  manifest: {
224
279
  format: STATE_FORMAT,
@@ -228,7 +283,7 @@ export async function collectExport(dir, opts = {}) {
228
283
  files: files.map((f) => ({ path: f.path, sha256: f.sha256, size: f.bytes.length })),
229
284
  },
230
285
  files,
231
- leftOut: { finishedGames: finishedGames.size, unknownGames: unknownGames.size, otherAccountFiles },
286
+ leftOut: { finishedGames: finishedGames.size, unknownGames: unknownGames.size, otherAccountFiles, decisionLogs },
232
287
  };
233
288
  }
234
289
  /** The bundle's bytes: gzipped JSON `{ format, version, manifest, files: { path: base64 } }`. */
@@ -318,12 +373,16 @@ export function decodeBundle(bytes) {
318
373
  if (body.length !== f.size)
319
374
  throw new StateBundleError(`The size of ${path} does not match the manifest.`);
320
375
  if (path.endsWith('.json')) {
376
+ let parsedFile;
321
377
  try {
322
- JSON.parse(body.toString('utf8'));
378
+ parsedFile = JSON.parse(body.toString('utf8'));
323
379
  }
324
380
  catch {
325
381
  throw new StateBundleError(`${path} is not valid JSON.`);
326
382
  }
383
+ if (r.rule.accountInside && (!isRec(parsedFile) || parsedFile.playerId !== accountId)) {
384
+ throw new StateBundleError(`The bundle carries a file of another account (${path}).`);
385
+ }
327
386
  }
328
387
  files.set(path, body);
329
388
  list.push({ path, sha256: f.sha256, size: f.size });
package/dist/state-cli.js CHANGED
@@ -4,7 +4,7 @@
4
4
  // and nothing else — never the env file or a credential, never a request. It prints counts and sizes
5
5
  // only: never the salt, a file's contents, or an id.
6
6
  import { dataDir } from './config.js';
7
- import { collectExport, encodeBundle, humanSize, StateBundleError, STORES, writeBundleFile } from './state-bundle.js';
7
+ import { collectExport, encodeBundle, humanSize, MAX_EXPORT_DECISION_BYTES, StateBundleError, STORES, writeBundleFile } from './state-bundle.js';
8
8
  const USAGE = 'Usage: warapp-mcp export-state --out <file> [--data-dir <dir>] [--account <war.app player id>] [--force]\n' +
9
9
  'Writes this install\'s warapp-mcp history (file mode 0600) for warapp_import_state. The file holds the\n' +
10
10
  'salt behind your hashed history: keep it private and delete it once imported.';
@@ -56,9 +56,11 @@ export async function runExportCli(argv, io = defaultIo) {
56
56
  if (fs.length)
57
57
  io.out(` ${store}: ${fs.length} file${fs.length === 1 ? '' : 's'}, ${humanSize(fs.reduce((n, f) => n + f.bytes.length, 0))}`);
58
58
  }
59
- const { finishedGames, unknownGames, otherAccountFiles } = r.leftOut;
59
+ const { finishedGames, unknownGames, otherAccountFiles, decisionLogs } = r.leftOut;
60
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.`);
61
+ `${otherAccountFiles} file(s) of another account` +
62
+ (decisionLogs ? `, ${decisionLogs} older decision log(s) past the bundle's ${humanSize(MAX_EXPORT_DECISION_BYTES)} share` : '') +
63
+ '; credentials, chat, maps, stats and the bundle cache are never included.');
62
64
  io.out('It holds the salt behind your hashed history: keep it private, and delete it once imported.');
63
65
  return 0;
64
66
  }
@@ -2152,6 +2152,62 @@ export const STRATEGY_NOTES = [
2152
2152
  source: S.diplomacyGames,
2153
2153
  basis: 'source',
2154
2154
  },
2155
+ // ---- diplomacy: chat as game information (#415) ----
2156
+ {
2157
+ id: 'diplomacy-chat-income-check',
2158
+ topic: 'diplomacy',
2159
+ when: on({ format: ['ffa'] }),
2160
+ text: 'An income check in free-for-all chat is mostly a hunt for the leader: a forum poster gives "player X has ' +
2161
+ '1000 income" as the post that turns a game into a popularity contest. Leading or close to it, say little and ' +
2162
+ 'give no figure; when another player clearly leads, your honest income helps the table see it.',
2163
+ source: S.forumFfaChatEtiquette,
2164
+ basis: 'derived',
2165
+ encoded: 'the chat advice (adviseReply, src/analysis/chat-advice.ts, #415)',
2166
+ },
2167
+ {
2168
+ id: 'diplomacy-chat-withhold',
2169
+ topic: 'diplomacy',
2170
+ when: on({ format: ['ffa'] }),
2171
+ text: 'Answering chat is a choice: one forum poster simply ignored a deal offered by mail, while another warns that ' +
2172
+ 'ignoring it hands rivals an edge. Withholding breaks no rule and a vague reply is fine; what you do say should ' +
2173
+ 'be true, so say less rather than invent.',
2174
+ source: S.forumFfaChatEtiquette,
2175
+ basis: 'derived',
2176
+ encoded: 'the chat advice (adviseReply, src/analysis/chat-advice.ts, #415)',
2177
+ },
2178
+ {
2179
+ id: 'diplomacy-chat-gang-up-ask',
2180
+ topic: 'diplomacy',
2181
+ when: on({ format: ['ffa'] }),
2182
+ text: 'The usual pitch is "X wins unless we gang up". Treat it as a deal offer: when X leads and you do not, price it ' +
2183
+ 'with warapp_advise_diplomacy as you would a truce. When you are X, it is a warning that others are being ' +
2184
+ 'turned on you: check the borders facing the asker and its neighbours.',
2185
+ source: S.forumFfaChatEtiquette,
2186
+ basis: 'derived',
2187
+ encoded: 'the chat advice (adviseReply, src/analysis/chat-advice.ts, #415)',
2188
+ },
2189
+ {
2190
+ id: 'diplomacy-chat-threat',
2191
+ topic: 'diplomacy',
2192
+ when: on({ format: ['ffa'] }),
2193
+ text: 'One poster on truce disputes counts threatening moves of any kind as a possible breach. Read a threat in chat ' +
2194
+ 'the same way, as information about where the sender is looking rather than a reason to answer in kind: check ' +
2195
+ 'the borders facing that player before you commit.',
2196
+ source: S.forumTrucePsychology,
2197
+ basis: 'derived',
2198
+ encoded: 'the chat advice (adviseReply, src/analysis/chat-advice.ts, #415)',
2199
+ },
2200
+ {
2201
+ id: 'diplomacy-chat-trust-little',
2202
+ topic: 'diplomacy',
2203
+ when: on({ format: ['ffa'] }),
2204
+ text: 'A forum guide to free-for-alls advises making pacts by private message but trusting a new partner only a ' +
2205
+ 'little at first, since some players betray quickly. Answer a truce offer by pricing it ' +
2206
+ '(warapp_advise_diplomacy) rather than agreeing in the same breath, and keep that border guarded while it is new.',
2207
+ source: S.ffa,
2208
+ basis: 'derived',
2209
+ encoded: 'the chat advice (adviseReply, src/analysis/chat-advice.ts, #415)',
2210
+ },
2155
2211
  {
2156
2212
  id: 'teams-team-chat',
2157
2213
  topic: 'format',
@@ -6,7 +6,8 @@
6
6
  // them and refuses when no surrender is pending from that player or my acceptance is not owed; a
7
7
  // finished game and a game I am not playing are refused first. The preview says what accepting does
8
8
  // here: whose seat, whether its land turns neutral or goes to an AI, who borders that land (from the
9
- // live board when it reads), whether it goes through now or others still owe theirs, whether it
9
+ // live board when it reads; #417: and that its land behind the fog is unknown, the standing carrying no
10
+ // per-player count), whether it goes through now or others still owe theirs, whether it
10
11
  // leaves only my side playing (a win), and in a free-for-all one advice line naming the neighbour
11
12
  // that gains most (strategy note ffa-surrender-veto).
12
13
  //
@@ -15,7 +16,7 @@
15
16
  // which carries no result, and nothing is ever resent.
16
17
  import { CONFIRM_INJECTION_RULE, toolAnnotations } from '@chrischall/mcp-utils';
17
18
  import { z } from 'zod';
18
- import { surrenderLand, winsOnAcceptance } from '../analysis/accept-surrender.js';
19
+ import { hiddenLandLine, surrenderLand, winsOnAcceptance } from '../analysis/accept-surrender.js';
19
20
  import { parseGameId } from '../client.js';
20
21
  import { inGameOf, playersByInGameId } from '../live.js';
21
22
  import { Method, writeAcceptSurrenderParams } from '../protocol/methods.js';
@@ -28,6 +29,7 @@ import { mapOf } from './map.js';
28
29
  import { resolvePlayer } from './resolve.js';
29
30
  import { noBrowserNote } from './session.js';
30
31
  import { readDetailsSeats } from './surrender-pending.js';
32
+ import { captureGameEvent, turnOfGame } from './decision-capture.js';
31
33
  import { resolveTeamsFor } from './team-source.js';
32
34
  import { defineGatedWrite, mySeat, refuse, requireMe, requirePlaying, sendAndVerify, worded } from './write-kit.js';
33
35
  const PLAYING = 'Playing';
@@ -83,15 +85,17 @@ function adviceOf(opts) {
83
85
  return `${cite} Who borders its land is unknown: the live board could not be read.`;
84
86
  const top = opts.land.neighbours[0];
85
87
  const ai = opts.toAI === true ? ' Its land goes to an AI, which keeps playing it, so it is not up for taking at once.' : '';
88
+ // #417: say plainly that its land behind the fog is not counted.
89
+ const hidden = opts.land.hiddenLand === null ? ' Its land behind the fog is unknown (#417): only what is in view is counted.' : '';
86
90
  if (!top)
87
- return `${cite} No player borders its land in view, so no neighbour gains it at once.${ai}`;
91
+ return `${cite} No player borders its land in view, so no neighbour gains it at once.${ai}${hidden}`;
88
92
  const mine = opts.land.neighbours.find((n) => n.inGameId === opts.meInGame)?.bordering ?? 0;
89
93
  const fog = opts.land.hiddenNeighbours ? ` (${opts.land.hiddenNeighbours} territories beside it are hidden by fog)` : '';
90
94
  if (top.inGameId === opts.meInGame) {
91
- return `${cite} You border its land with the most territories (${top.bordering})${fog}, so of its neighbours you gain most from it.${ai}`;
95
+ return `${cite} You border its land with the most territories (${top.bordering})${fog}, so of its neighbours you gain most from it.${ai}${hidden}`;
92
96
  }
93
97
  return (`${cite} ${opts.idOf(top.inGameId)} borders its land with the most territories (${top.bordering}; you: ${mine})${fog}, ` +
94
- `so it gains most from it.${ai}`);
98
+ `so it gains most from it.${ai}${hidden}`);
95
99
  }
96
100
  export function registerAcceptSurrenderTool(server, ctx) {
97
101
  defineGatedWrite(server, {
@@ -104,7 +108,8 @@ export function registerAcceptSurrenderTool(server, ctx) {
104
108
  'player, when your acceptance is not owed (already given, or your seat cannot accept), in a finished game, ' +
105
109
  'and in a game you are not playing. `player` names the surrendering player (name or id); it may be omitted ' +
106
110
  'when one surrender is pending. The preview says what accepting does: whose seat, whether its land turns ' +
107
- 'neutral or goes to an AI, which players border that land (live board), whether it goes through now or ' +
111
+ 'neutral or goes to an AI, which players border that land (live board) and how much of it the fog may hide ' +
112
+ '(the count behind the fog is unknown: only the land in view is counted), whether it goes through now or ' +
108
113
  'others still owe their acceptance, whether it leaves only your side playing (a win), and in a free-for-all ' +
109
114
  `one advice line naming the neighbour that gains most (strategy note ${FFA_SURRENDER_NOTE}). Accepting is the ` +
110
115
  "owner's decision. The outcome is read back from GameFeed and the game details (`accepted`, `pending` — others " +
@@ -222,6 +227,10 @@ export function registerAcceptSurrenderTool(server, ctx) {
222
227
  };
223
228
  }),
224
229
  hiddenNeighbours: land.hiddenNeighbours,
230
+ // #417: what the fog hides of its land: unknown (null) under any fog, said plainly.
231
+ hiddenLand: land.hiddenLand,
232
+ hiddenOnBoard: land.hiddenOnBoard,
233
+ hiddenLine: hiddenLandLine(land),
225
234
  }
226
235
  : null,
227
236
  othersStillToAccept,
@@ -232,14 +241,14 @@ export function registerAcceptSurrenderTool(server, ctx) {
232
241
  untrusted: UNTRUSTED_PREVIEW_NOTE,
233
242
  },
234
243
  },
235
- state: { gameId, name: gameLabel(game), me, player: target.player, inGameId: target.inGameId, alreadyAI },
244
+ state: { gameId, name: gameLabel(game), me, player: target.player, inGameId: target.inGameId, alreadyAI, turn: turnOfGame(game) },
236
245
  };
237
246
  },
238
- async execute({ gameId, name, me, player, inGameId, alreadyAI }) {
247
+ async execute({ gameId, name, me, player, inGameId, alreadyAI, turn }) {
239
248
  await requireApprovedAccount(ctx, writeAccount(me));
240
249
  const game = { id: gameId, name };
241
250
  const who = { player, inGameId };
242
- return sendAndVerify({
251
+ const result = await sendAndVerify({
243
252
  send: async () => {
244
253
  await ctx.rpc.call('AcceptSurrender', Method.AcceptSurrender, (w) => writeAcceptSurrenderParams(w, { gameId, playerId: inGameId, accept: true }));
245
254
  },
@@ -306,6 +315,11 @@ export function registerAcceptSurrenderTool(server, ctx) {
306
315
  };
307
316
  },
308
317
  });
318
+ // #437: my acceptance, once confirmed, into the decision log (by GameFeed id; a seat without one is not kept).
319
+ if (result.outcome === 'confirmed' && player !== null && turn !== undefined) {
320
+ await captureGameEvent(ctx, gameId, me, { turn, kind: 'surrender-accepted-by-me', player }, { create: true });
321
+ }
322
+ return result;
309
323
  },
310
324
  });
311
325
  }
@@ -7,6 +7,7 @@ import { readFirstMover, resolveFirstMover, verifiedFirstMover, writeFirstMover
7
7
  import { readPickRecord, writeAward } from '../pick-list.js';
8
8
  import { pickSettings } from './picks.js';
9
9
  import { isTeamGame, teammatesOf } from '../teams.js';
10
+ import { capturePicksAward } from './decision-capture.js';
10
11
  const isMine = (t, me) => t.owner.kind === 'player' && t.owner.playerId === me;
11
12
  /** The army count every territory of mine holds, when they all hold the same (the starting armies on turn 1). */
12
13
  function uniformArmies(board, me) {
@@ -22,6 +23,7 @@ function uniformArmies(board, me) {
22
23
  * list is kept for this player, the list did not explain the start, or the first board has
23
24
  * passed unread. Reads the award (and keeps it) on turn 1; later turns reuse what was kept.
24
25
  * `write: false` reads it the same way and keeps nothing (#275 pattern 3: a write's preview).
26
+ * The reading kept is logged once into the game's decision log too (#437 task 3, `decisionLog` its mode).
25
27
  * Never throws.
26
28
  */
27
29
  export async function loadAward(dataDir, game, me, board, turn, o = {}) {
@@ -47,8 +49,10 @@ export async function loadAward(dataDir, game, me, board, turn, o = {}) {
47
49
  // A start the board shows as nobody's, mine or a neutral cannot be another player's: the list is not the one awarded from.
48
50
  if (reading?.opponentStarts.some((t) => contradicts(state.get(t), me.id)))
49
51
  reading = null;
50
- if (o.write !== false)
52
+ if (o.write !== false) {
51
53
  await writeAward(dataDir, game.id, me.id, reading);
54
+ await capturePicksAward(dataDir, o.decisionLog, game.id, me.id, turn, reading);
55
+ }
52
56
  }
53
57
  if (!reading)
54
58
  return undefined;