@chrischall/warapp-mcp 0.6.0 → 0.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (111) hide show
  1. package/.claude-plugin/marketplace.json +2 -2
  2. package/.claude-plugin/plugin.json +1 -1
  3. package/README.md +100 -7
  4. package/dist/analysis/accept-surrender.js +20 -2
  5. package/dist/analysis/calibrate.js +1 -0
  6. package/dist/analysis/card-support.js +187 -20
  7. package/dist/analysis/card-threats.js +68 -3
  8. package/dist/analysis/chat-advice.js +182 -0
  9. package/dist/analysis/chat-blocks.js +106 -0
  10. package/dist/analysis/chat-intent.js +559 -0
  11. package/dist/analysis/chat-read.js +159 -0
  12. package/dist/analysis/coalition.js +55 -0
  13. package/dist/analysis/decision-replay.js +279 -0
  14. package/dist/analysis/decision-truth.js +146 -0
  15. package/dist/analysis/finished-game.js +62 -3
  16. package/dist/analysis/game-lessons.js +12 -6
  17. package/dist/analysis/local-deploy.js +14 -0
  18. package/dist/analysis/opponent-profile.js +46 -3
  19. package/dist/analysis/opponents.js +246 -19
  20. package/dist/analysis/outlook.js +323 -17
  21. package/dist/analysis/picks.js +270 -37
  22. package/dist/analysis/plan/after-leftover.js +28 -3
  23. package/dist/analysis/plan/captures.js +80 -16
  24. package/dist/analysis/plan/completed.js +8 -1
  25. package/dist/analysis/plan/conceded-out.js +16 -11
  26. package/dist/analysis/plan/deploy-estimates.js +513 -0
  27. package/dist/analysis/plan/doomed-out.js +135 -0
  28. package/dist/analysis/plan/estimates.js +73 -7
  29. package/dist/analysis/plan/free-capture.js +34 -0
  30. package/dist/analysis/plan/guard-off.js +2 -1
  31. package/dist/analysis/plan/holds.js +85 -313
  32. package/dist/analysis/plan/horizon.js +42 -0
  33. package/dist/analysis/plan/leftover.js +188 -10
  34. package/dist/analysis/plan/observe.js +896 -0
  35. package/dist/analysis/plan/orders.js +35 -1
  36. package/dist/analysis/plan/relations.js +115 -2
  37. package/dist/analysis/plan/report.js +10 -4
  38. package/dist/analysis/plan/shared.js +7 -1189
  39. package/dist/analysis/plan/stand-still.js +7 -5
  40. package/dist/analysis/plan/state.js +12 -0
  41. package/dist/analysis/plan/stockpile.js +104 -0
  42. package/dist/analysis/plan/strike-stack.js +467 -0
  43. package/dist/analysis/plan/strike.js +8 -441
  44. package/dist/analysis/plan/targets.js +374 -72
  45. package/dist/analysis/plan/threats.js +120 -9
  46. package/dist/analysis/plan/transfers.js +35 -1
  47. package/dist/analysis/plan/two-move.js +70 -0
  48. package/dist/analysis/plan/vacated.js +124 -2
  49. package/dist/analysis/plan/withdraw.js +316 -0
  50. package/dist/analysis/planner.js +356 -53
  51. package/dist/analysis/player.js +4 -0
  52. package/dist/analysis/relations.js +8 -2
  53. package/dist/analysis/since-last.js +18 -5
  54. package/dist/analysis/stress.js +1 -1
  55. package/dist/board.js +36 -2
  56. package/dist/build-id.js +106 -0
  57. package/dist/bundle.js +15863 -10242
  58. package/dist/chat-automation.js +22 -0
  59. package/dist/client.js +14 -0
  60. package/dist/decision-log.js +1093 -0
  61. package/dist/finished-store.js +5 -1
  62. package/dist/lessons-store.js +322 -21
  63. package/dist/my-games.js +2 -0
  64. package/dist/open-games.js +122 -18
  65. package/dist/outlook-log.js +42 -1
  66. package/dist/protocol/methods.js +4 -2
  67. package/dist/review-export.js +198 -0
  68. package/dist/state-bundle.js +62 -3
  69. package/dist/state-cli.js +5 -3
  70. package/dist/strategy/notes.js +56 -0
  71. package/dist/tools/accept-surrender.js +23 -9
  72. package/dist/tools/award.js +5 -1
  73. package/dist/tools/card-advice.js +102 -33
  74. package/dist/tools/card-support-advice.js +53 -8
  75. package/dist/tools/chat-advice.js +330 -0
  76. package/dist/tools/chat-inbox.js +15 -4
  77. package/dist/tools/chat.js +41 -11
  78. package/dist/tools/check-plan.js +16 -3
  79. package/dist/tools/commander-check.js +2 -1
  80. package/dist/tools/decision-capture.js +461 -0
  81. package/dist/tools/end-of-game.js +146 -18
  82. package/dist/tools/game-kind.js +92 -0
  83. package/dist/tools/how-lost.js +7 -2
  84. package/dist/tools/index.js +3 -0
  85. package/dist/tools/join-game.js +51 -9
  86. package/dist/tools/live-context.js +6 -0
  87. package/dist/tools/live.js +43 -6
  88. package/dist/tools/map-curves.js +73 -0
  89. package/dist/tools/notifications.js +4 -3
  90. package/dist/tools/open-games.js +2 -2
  91. package/dist/tools/opponents.js +2 -0
  92. package/dist/tools/past-games.js +74 -8
  93. package/dist/tools/picks.js +169 -57
  94. package/dist/tools/profile-hook.js +62 -3
  95. package/dist/tools/profile-opponents.js +2 -0
  96. package/dist/tools/push.js +2 -2
  97. package/dist/tools/relations.js +2 -0
  98. package/dist/tools/scout.js +16 -2
  99. package/dist/tools/state.js +6 -1
  100. package/dist/tools/strategy.js +3 -3
  101. package/dist/tools/stress-opponents.js +2 -0
  102. package/dist/tools/surrender-pending.js +10 -1
  103. package/dist/tools/surrender.js +18 -3
  104. package/dist/tools/turn.js +353 -19
  105. package/dist/tools/where.js +3 -1
  106. package/dist/version.js +1 -1
  107. package/manifest.json +23 -2
  108. package/mint.yaml +23 -0
  109. package/package.json +1 -1
  110. package/server.json +20 -2
  111. package/skills/warapp-mcp/SKILL.md +42 -8
@@ -98,6 +98,10 @@ export function armyCapPoolsUncertainty(c, localDeployments) {
98
98
  }
99
99
  /** What the army cap's figure rests on: six live cases, and the card armies' place (from the client's guide, unverified). */
100
100
  export const ARMY_CAP_BASIS = "the formula is verified by six live cases (2026-11-15: received 41, 49, 25, 27 and 71 where the cap bit, among them the binding case sent through warapp_submit_turn, and a room of 61 it did not bind), the cap taken on this turn's income; Reinforcement card armies are outside it (the client's guide: they are not income and always pay in full, unverified live)";
101
+ /** #433: the game's own base income (`MinimumArmyBonus`; 0 and 3 exist), the default only when it does not say. One accessor for the planner and the stress test. */
102
+ export function gameBaseIncome(settings) {
103
+ return Math.max(0, Math.floor(settings?.baseIncome ?? settings?.minimumArmyBonus ?? DEFAULT_BASE_INCOME));
104
+ }
101
105
  /** {@link IncomeRules} from a game's settings (the defaults when it does not say). */
102
106
  export function incomeRules(settings) {
103
107
  return { base: settings?.minimumArmyBonus ?? DEFAULT_BASE_INCOME, per: settings?.bonusArmyPer ?? 0 };
@@ -1,4 +1,4 @@
1
- import { carriesTeam } from '../teams.js';
1
+ import { carriesTeam, teammatesOf } from '../teams.js';
2
2
  import { bonusTerritories } from './bonuses.js';
3
3
  import { bfsDistances, neighborsOf } from './graph.js';
4
4
  import { ownerShown, OWNERS_SHOWN_FOG, visibleState, } from './plan/shared.js';
@@ -606,7 +606,13 @@ export function planRelationsFrom(input) {
606
606
  card: 'Diplomacy',
607
607
  });
608
608
  }
609
- const open = new Set(input.agreements.filter((a) => !TERMINAL_STATUSES.has(a.status)).map((a) => a.with));
609
+ // #435: a teammate's quiet border is no tacit truce (#246): left out like a partner with an open
610
+ // agreement, as warapp_get_relations already did — plan_turn, check_plan and advise_diplomacy listed them.
611
+ const self = players.find((p) => p.id === me);
612
+ const open = new Set([
613
+ ...input.agreements.filter((a) => !TERMINAL_STATUSES.has(a.status)).map((a) => a.with),
614
+ ...(self ? teammatesOf(players, self).map((p) => p.id) : []),
615
+ ]);
610
616
  return { relations, tacit: tacitTruces({ graph, boards: input.boards, me, exclude: open }) };
611
617
  }
612
618
  // ---------- B3: pricing a deal (docs/PLAN-TEAMS.md section 8 B3) ----------
@@ -1,7 +1,8 @@
1
1
  // Since last turn (#194): this turn's income against the next income the plan of the previous
2
2
  // turn expected, and what changed hands since the previous board — the positive bonuses I held
3
3
  // that are broken now, and the territories I held that are no longer mine (taken by a player,
4
- // neutral again, or out of view). Pure and deterministic (ascending ids); no I/O.
4
+ // neutral again, or out of view), and (#442) the captures that plan expected and did not make, with
5
+ // who holds each now. Pure and deterministic (ascending ids); no I/O.
5
6
  //
6
7
  // The expected figure is the plan's `expected.nextIncome` as it stood when the previous turn was
7
8
  // planned: it assumed the plan's orders were sent and every kept border held, so a shortfall says
@@ -39,12 +40,24 @@ export function sinceLastTurn(input) {
39
40
  .map(({ b }) => ({ bonusId: b.id, value: b.value }))
40
41
  .sort((x, y) => x.bonusId - y.bonusId);
41
42
  const ownerNow = new Map(current.territories.map((t) => [t.territoryId, t.owner]));
43
+ const toOf = (territoryId) => {
44
+ const o = ownerNow.get(territoryId);
45
+ return o?.kind === 'player' ? o.playerId : null;
46
+ };
47
+ const ownerBefore = new Map(previous.territories.map((t) => [t.territoryId, t.owner]));
48
+ if (input.expectedCaptures)
49
+ out.capturesMissed = [...new Set(input.expectedCaptures)]
50
+ .filter((id) => graph.territoryById.has(id) && !now.has(id) && !before.has(id))
51
+ .sort(byNum)
52
+ .map((territoryId) => {
53
+ const to = toOf(territoryId);
54
+ const was = ownerBefore.get(territoryId);
55
+ const fresh = to !== null && !(was?.kind === 'player' && was.playerId === to);
56
+ return { territoryId, to, ...(fresh ? { fresh: true } : {}) };
57
+ });
42
58
  out.territoriesLost = [...before]
43
59
  .filter((id) => !now.has(id))
44
60
  .sort(byNum)
45
- .map((territoryId) => {
46
- const o = ownerNow.get(territoryId);
47
- return { territoryId, to: o?.kind === 'player' ? o.playerId : null };
48
- });
61
+ .map((territoryId) => ({ territoryId, to: toOf(territoryId) }));
49
62
  return out;
50
63
  }
@@ -134,7 +134,7 @@ export function stressPlan(input) {
134
134
  const pools = input.localDeployments ? couldHoldBonusPools(graph, input.opponents.map((o) => o.id), shownOwner) : undefined;
135
135
  const deployOn = (opp, on) => {
136
136
  const all = Math.max(0, Math.floor(opp.deploy));
137
- return pools ? enemyDeployReaching(all, freeIncome(opp.base ?? 0, DEFAULT_BASE_INCOME, opp.card ?? 0), pools.get(opp.id) ?? [], [on], input.perTerritoryIncome === true) : all;
137
+ return pools ? enemyDeployReaching(all, freeIncome(opp.base ?? 0, input.baseIncome ?? DEFAULT_BASE_INCOME, opp.card ?? 0), pools.get(opp.id) ?? [], [on], input.perTerritoryIncome === true) : all;
138
138
  };
139
139
  /** Luck-free: `sent` armies (and a commander, when it goes along) take `t` as it stands. */
140
140
  const breaks = (sent, withCommander, t) => breaksLuckFree(sent, withCommander, t, { offensiveKillRate: off, defensiveKillRate: def });
package/dist/board.js CHANGED
@@ -48,17 +48,48 @@ function armiesOf(v) {
48
48
  return armiesOf(pick(v, ['numArmies', 'NumArmies', 'armies']));
49
49
  return asInt(v) ?? null;
50
50
  }
51
+ /** #437: the unit tags GameFeed's history writes after the bar; only `cmdr` is VERIFIED live (2026-11-20). */
52
+ const UNIT_TAGS = { cmdr: 'commander' };
53
+ /**
54
+ * #437, VERIFIED live 2026-11-20 (a finished Commanders game's GameFeed history): a territory where a special
55
+ * unit stands sends `armies` as `"<N>|cmdr,<GUID>,<owner id>,"` — N the plain armies alone (every start read 5,
56
+ * the commander's too, and 0 once its armies left), then per unit its tag, GUID and owner (a GameFeed id),
57
+ * each followed by a comma. Returns `undefined` for any other value; units that do not read are dropped.
58
+ */
59
+ function unitArmiesOf(v) {
60
+ if (typeof v !== 'string')
61
+ return undefined;
62
+ const bar = v.indexOf('|');
63
+ if (bar < 0)
64
+ return undefined;
65
+ const armies = asInt(v.slice(0, bar).trim()) ?? null;
66
+ const fields = v.slice(bar + 1).split(',');
67
+ const units = [];
68
+ for (let i = 0; i + 2 < fields.length; i += 3) {
69
+ const tag = fields[i].trim();
70
+ const id = fields[i + 1].trim();
71
+ const playerId = asInt(fields[i + 2].trim());
72
+ if (!tag || !id || playerId === undefined)
73
+ break;
74
+ units.push({ kind: UNIT_TAGS[tag] ?? 'unknown', id, playerId });
75
+ }
76
+ return { armies, units };
77
+ }
51
78
  function entryOf(raw, fallbackId) {
52
79
  if (!isRec(raw))
53
80
  return undefined;
54
81
  const territoryId = asInt(pick(raw, ID_KEYS)) ?? fallbackId;
55
82
  if (territoryId === undefined)
56
83
  return undefined;
84
+ const rawArmies = pick(raw, ARMY_KEYS);
85
+ const withUnits = unitArmiesOf(rawArmies);
57
86
  const entry = {
58
87
  territoryId,
59
88
  owner: ownerOf(pick(raw, OWNER_KEYS)),
60
- armies: armiesOf(pick(raw, ARMY_KEYS)),
89
+ armies: withUnits ? withUnits.armies : armiesOf(rawArmies),
61
90
  };
91
+ if (withUnits?.units.length)
92
+ entry.specialUnits = withUnits.units;
62
93
  const fog = pick(raw, FOG_KEYS);
63
94
  if ((typeof fog === 'string' && fog) || typeof fog === 'number') {
64
95
  const level = String(fog).trim();
@@ -70,9 +101,12 @@ function entryOf(raw, fallbackId) {
70
101
  if (/fog/i.test(level) || level === '4') {
71
102
  entry.owner = { kind: 'unknown' };
72
103
  entry.armies = null;
104
+ delete entry.specialUnits;
73
105
  }
74
- else if (/owneronly/i.test(level) || level === '3')
106
+ else if (/owneronly/i.test(level) || level === '3') {
75
107
  entry.armies = null;
108
+ delete entry.specialUnits;
109
+ }
76
110
  }
77
111
  return entry;
78
112
  }
@@ -0,0 +1,106 @@
1
+ // The build the server runs (#437 task 1), for the decision log beside `planner.version`: the git commit
2
+ // when it runs from a checkout of this package (read from `.git` directly, no process spawned; a worktree's
3
+ // `.git` file and its common dir followed, a packed ref read too), else a hash of the running module file
4
+ // (`dist/bundle.js` once bundled). Only the package root's own `.git` is read: installed inside another
5
+ // project's checkout, that project's commit is never taken for ours. Read once per process (`serverBuild`).
6
+ import { createHash } from 'node:crypto';
7
+ import { existsSync, readFileSync, statSync } from 'node:fs';
8
+ import { dirname, join, resolve } from 'node:path';
9
+ import { fileURLToPath } from 'node:url';
10
+ const PACKAGE_NAME = '@chrischall/warapp-mcp';
11
+ const SHA = /^[0-9a-f]{40}(?:[0-9a-f]{24})?$/;
12
+ const readText = (path) => {
13
+ try {
14
+ return readFileSync(path, 'utf8');
15
+ }
16
+ catch {
17
+ return undefined;
18
+ }
19
+ };
20
+ /** The commit HEAD names in the checkout at `root`; `undefined` when there is none or it does not read. */
21
+ export function gitCommit(root) {
22
+ let gitDir = join(root, '.git');
23
+ try {
24
+ if (statSync(gitDir).isFile()) {
25
+ const m = /^gitdir:\s*(.+?)\s*$/m.exec(readText(gitDir) ?? '');
26
+ if (!m)
27
+ return undefined;
28
+ gitDir = resolve(root, m[1]);
29
+ }
30
+ }
31
+ catch {
32
+ return undefined;
33
+ }
34
+ const head = readText(join(gitDir, 'HEAD'))?.trim();
35
+ if (!head)
36
+ return undefined;
37
+ if (SHA.test(head))
38
+ return head;
39
+ const ref = /^ref:\s*(refs\/\S+)$/.exec(head)?.[1];
40
+ if (!ref || ref.split('/').includes('..'))
41
+ return undefined;
42
+ const commonDir = readText(join(gitDir, 'commondir'))?.trim();
43
+ const common = commonDir ? resolve(gitDir, commonDir) : gitDir;
44
+ for (const d of [gitDir, common]) {
45
+ const v = readText(join(d, ref))?.trim();
46
+ if (v && SHA.test(v))
47
+ return v;
48
+ }
49
+ for (const line of (readText(join(common, 'packed-refs')) ?? '').split('\n')) {
50
+ const [sha, name] = line.trim().split(/\s+/);
51
+ if (name === ref && sha && SHA.test(sha))
52
+ return sha;
53
+ }
54
+ return undefined;
55
+ }
56
+ /** The nearest folder at or above `from` holding a package.json, and whether it is this package's. */
57
+ function packageRoot(from) {
58
+ let d = from;
59
+ for (let i = 0; i < 64; i++) {
60
+ const pkg = join(d, 'package.json');
61
+ if (existsSync(pkg)) {
62
+ try {
63
+ return { root: d, ours: JSON.parse(readFileSync(pkg, 'utf8')).name === PACKAGE_NAME };
64
+ }
65
+ catch {
66
+ return { root: d, ours: false };
67
+ }
68
+ }
69
+ const up = dirname(d);
70
+ if (up === d)
71
+ return undefined;
72
+ d = up;
73
+ }
74
+ return undefined;
75
+ }
76
+ /**
77
+ * The build of the server whose module file is `moduleFile`: `git:<sha>` from this package's own checkout,
78
+ * else `sha256:<16 hex>` of the module file; `undefined` when neither reads. Never throws.
79
+ */
80
+ export function readBuild(moduleFile) {
81
+ try {
82
+ const pkg = packageRoot(dirname(moduleFile));
83
+ const commit = pkg?.ours ? gitCommit(pkg.root) : undefined;
84
+ if (commit)
85
+ return `git:${commit}`;
86
+ return `sha256:${createHash('sha256').update(readFileSync(moduleFile)).digest('hex').slice(0, 16)}`;
87
+ }
88
+ catch {
89
+ return undefined;
90
+ }
91
+ }
92
+ let cached;
93
+ /** {@link readBuild} of the running server, read once per process. */
94
+ export function serverBuild() {
95
+ if (!cached) {
96
+ let file;
97
+ try {
98
+ file = fileURLToPath(import.meta.url);
99
+ }
100
+ catch {
101
+ file = undefined;
102
+ }
103
+ cached = { build: file ? readBuild(file) : undefined };
104
+ }
105
+ return cached.build;
106
+ }