@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
@@ -83,6 +83,27 @@
83
83
  // LOW_COVERAGE, or none measured, under fog is thin evidence, and the basis says "even" is then not safe.
84
84
  // Reporting only: the state never reads it.
85
85
  //
86
+ // #436 (owner decision of 2026-11-20): the outlook follows both incomes and their trend. Each turn reads my
87
+ // side's income against the strongest opponent side's income (`income`): its range under fog — `low` the
88
+ // income the tracker reads (its visible income at least), `high` the most the likely high lets it earn a turn
89
+ // while its frontier read is thin (else `low`) — and its ESTIMATE, the tracked figure divided by the
90
+ // estimate ÷ truth past games measured in its coverage band (`calibration`, from lessons.json, a band with
91
+ // at least MIN_CALIBRATION_SAMPLES), never below its visible income; uncalibrated, the tracked figure. Its
92
+ // lean: `unknown` when the range spans both thresholds (mine ÷ high at most INCOME_BEHIND_RATIO and mine ÷
93
+ // low at least INCOME_AHEAD_RATIO), `behind` / `ahead` when the whole range, else the estimate, is past one,
94
+ // else `even` — unless each side's income, moved one more turn at its change per turn over the turns judged
95
+ // (`trend`), crosses a threshold the ratio is already heading to (`byTrend`). No lead is claimed at low
96
+ // coverage (any opponent's evidence thin, #304): an `ahead` lean reads `unknown`, and a win on the likely
97
+ // high alone is not read (`noLeadClaim`); a win on the bound still is. #454: the state keeps its four values
98
+ // (winning, losing, even, stalemate — the tool contract); a lean (`ahead`, `behind` or `unknown`) beside an
99
+ // `even` state rides in the additive `lean` field, per turn and on the outlook, and every internal reader of the
100
+ // finer reading uses {@link readingOf}; the planner acts on winning and losing only (#201). `pace` is the income line: both incomes and
101
+ // their change per turn over the turns judged. `surrenderLine` is ADVICE ONLY (the server never acts on it):
102
+ // crossed when my income stayed under INCOME_BEHIND_RATIO × the strongest's estimate for SURRENDER_TURNS
103
+ // consecutive turns and no bonus in reach closes the gap (`bonusesInReach`: a positive bonus I do not hold
104
+ // whose every missing member borders my land and whose visible defenders are fewer than my armies beside them
105
+ // plus my income; it closes the gap when my income plus its value reaches the line).
106
+ //
86
107
  // OUTLOOK_RATIO (2.4×) is borrowed from a published bot's "lost" rule and has never been measured
87
108
  // for war.app: the outlook is a basis for a decision, not a verdict. The planner acts on it in one
88
109
  // way only (#201): once winning or losing, its payback tests count the turns the game has left.
@@ -99,6 +120,7 @@ import { BEHIND_RATIO, STRENGTH_INCOME_TURNS } from './profile.js';
99
120
  import { FORECAST_TURNS, forecastBorder, mainFront } from './exchange.js';
100
121
  import { specialUnitStrength } from './combat.js';
101
122
  import { coverageText, LOW_COVERAGE } from './plan/shared.js';
123
+ import { coverageBucket } from './game-lessons.js';
102
124
  /** Turns a state must hold before it is reported. */
103
125
  export const OUTLOOK_TURNS = 3;
104
126
  /** Winning at this strength ratio or more, losing at its inverse or less (borrowed, unmeasured). */
@@ -121,6 +143,30 @@ export const LIKELY_LOSING_RATIO = 1 / (OUTLOOK_RATIO * LIKELY_INCOME_MARGIN);
121
143
  export function peerPace(p) {
122
144
  return Math.max(p.floor ?? 0, Math.min(p.ceiling, Math.max(p.base, LIKELY_INCOME_MARGIN * Math.max(p.mine, p.peers))));
123
145
  }
146
+ const STATES = new Set(['winning', 'losing', 'even', 'stalemate']);
147
+ const LEANS = new Set(['ahead', 'behind', 'unknown']);
148
+ /** #454: the finer reading of a state and its lean (`null`: no state). */
149
+ export function readingOf(o) {
150
+ return o.lean ?? o.state;
151
+ }
152
+ /**
153
+ * #454: a reading split back into the contract's state and the additive lean. #453 wrote the lean as the state
154
+ * for a few hours (outlook log, decision log, finished records): `ahead`, `behind` and `unknown` read as `even`
155
+ * — exact, since a lean only ever replaced an even state — with that lean. An unrecognised value reads `null`.
156
+ */
157
+ export function splitReading(r) {
158
+ if (typeof r === 'string' && LEANS.has(r))
159
+ return { state: 'even', lean: r };
160
+ return { state: typeof r === 'string' && STATES.has(r) ? r : null };
161
+ }
162
+ /** #436: behind on incomes at this share of the strongest opponent's or less — the owner's surrender line (two-thirds). */
163
+ export const INCOME_BEHIND_RATIO = 2 / 3;
164
+ /** #436: ahead on incomes at this multiple of the strongest opponent's or more (the line's inverse). */
165
+ export const INCOME_AHEAD_RATIO = 1.5;
166
+ /** #436: consecutive turns under the line before the surrender line is crossed (owner). */
167
+ export const SURRENDER_TURNS = 3;
168
+ /** #436: the samples a coverage band needs before its estimate ÷ truth calibrates an estimate (unmeasured). */
169
+ export const MIN_CALIBRATION_SAMPLES = 5;
124
170
  const round2 = (n) => Math.round(n * 100) / 100;
125
171
  /** The armies the special units on a territory fight as (commanders), as the planner counts them. */
126
172
  const unitsOn = (b, id) => specialUnitStrength(b.territories.find((t) => t.territoryId === id)?.specialUnits);
@@ -341,14 +387,15 @@ export function gameOutlook(input) {
341
387
  const seen = { armies: a, income };
342
388
  const none = { likely: undefined, source: undefined, why: undefined };
343
389
  if (open)
344
- return { playerId, low, high: low, seen, ...none };
390
+ return { playerId, low, high: low, seen, paceIncome: income, capIncome: income, ...none };
391
+ // #436: the most it could earn this turn (never below what it visibly earns): no income estimate exceeds it.
392
+ const cap = Math.max(income, turnCap(turn, playerId));
345
393
  if (start === null || likelyStart === null || cardsBound === undefined)
346
- return { playerId, low, high: null, seen, ...none };
394
+ return { playerId, low, high: null, seen, paceIncome: cap, capIncome: cap, ...none };
347
395
  // Each turn's could-earn cap: from that turn's board when I have it, else the ceiling.
348
396
  let received = start;
349
397
  for (let t = 1; t <= turn; t++)
350
398
  received += turnCap(t, playerId);
351
- const cap = Math.max(income, turnCap(turn, playerId));
352
399
  // Cards: what the clock lets it have played by now, and over the next k turns.
353
400
  const now = cardsBound ? cardArmiesBy(cardsBound, turn) : 0;
354
401
  const ahead = cardsBound ? cardArmiesBy(cardsBound, turn + k) - now : 0;
@@ -378,7 +425,9 @@ export function gameOutlook(input) {
378
425
  for (let t = last.turn + 1; t <= turn; t++)
379
426
  since += Math.min(turnCap(t, playerId), paceAt(t));
380
427
  const likely = Math.max(a, likelyReceived + now, since) + k * Math.max(income, last?.income ?? 0, Math.min(cap, pace)) + ahead;
381
- return { playerId, low, high, seen, likely: Math.min(high, Math.max(low, likely)), source, why };
428
+ // #436: the most it likely earns a turn, as the likely high counts it.
429
+ const paceIncome = Math.max(income, last?.income ?? 0, Math.min(cap, pace));
430
+ return { playerId, low, high, seen, paceIncome, capIncome: cap, likely: Math.min(high, Math.max(low, likely)), source, why };
382
431
  });
383
432
  // PLAN-TEAMS C3: an enemy team is one side, its figures summed; elsewhere a side is a player.
384
433
  const teamOf = (p) => {
@@ -567,6 +616,96 @@ export function gameOutlook(input) {
567
616
  opponents: evidenceRows,
568
617
  thin: evidenceRows.some((r) => r.thin),
569
618
  };
619
+ // #436: each opponent's income range and estimate, summed per side; the strongest side by estimate.
620
+ const calibrationFor = (share) => {
621
+ const c = input.calibration?.[coverageBucket(share)];
622
+ return c && c.n >= MIN_CALIBRATION_SAMPLES && c.geoMean > 0 ? c.geoMean : undefined;
623
+ };
624
+ const incomeSides = new Map();
625
+ for (const r of rows) {
626
+ const tr = trackedOf(r.playerId);
627
+ const row = evidenceRows.find((x) => x.playerId === r.playerId);
628
+ const low = row.income;
629
+ const factor = tr?.income != null ? calibrationFor(tr.coverage?.share ?? null) : undefined;
630
+ // The calibrated estimate and the top of the range never pass what it could earn this turn (`capIncome`, the
631
+ // bound `paceIncome` keeps to): dividing a low-coverage reading by ~0.3 must not read an income it cannot reach.
632
+ const capped = (n) => Math.min(Math.max(r.capIncome, low), n);
633
+ const estimate = open ? low : factor !== undefined ? capped(Math.max(r.seen.income, Math.round(tr.income / factor))) : low;
634
+ const high = open ? low : capped(Math.max(estimate, low, row.thin ? r.paceIncome : low));
635
+ const t = teamOf(r.playerId);
636
+ const key = t === undefined ? `p${r.playerId}` : `t${t}`;
637
+ const side = incomeSides.get(key);
638
+ if (!side)
639
+ incomeSides.set(key, {
640
+ playerId: r.playerId,
641
+ ...(t !== undefined ? { team: t, players: [r.playerId] } : {}),
642
+ low: Math.min(low, estimate),
643
+ high,
644
+ estimate,
645
+ calibrated: factor !== undefined,
646
+ });
647
+ else {
648
+ side.low += Math.min(low, estimate);
649
+ side.high += high;
650
+ side.estimate += estimate;
651
+ side.calibrated ||= factor !== undefined;
652
+ side.players.push(r.playerId);
653
+ }
654
+ }
655
+ const theirs = [...incomeSides.values()].sort((a, b) => b.estimate - a.estimate || b.high - a.high || a.playerId - b.playerId)[0];
656
+ const income = theirs
657
+ ? {
658
+ mine: myNow,
659
+ theirs: {
660
+ playerId: theirs.playerId,
661
+ ...(theirs.team !== undefined ? { team: theirs.team, players: theirs.players } : {}),
662
+ low: theirs.low,
663
+ high: theirs.high,
664
+ estimate: theirs.estimate,
665
+ },
666
+ ratio: {
667
+ low: theirs.high > 0 ? round2(myNow / theirs.high) : null,
668
+ high: theirs.low > 0 ? round2(myNow / theirs.low) : null,
669
+ estimate: theirs.estimate > 0 ? round2(myNow / theirs.estimate) : null,
670
+ },
671
+ calibrated: theirs.calibrated,
672
+ lean: 'even',
673
+ }
674
+ : undefined;
675
+ // #436: the bonuses I could complete next turn (the latest turn only: the surrender line reads them).
676
+ const bonusesInReach = [];
677
+ if (turn === run.at(-1)) {
678
+ const side = new Set([me, ...mates]);
679
+ const ownerOfT = (id) => ownerById.get(id);
680
+ const isMine = (id) => {
681
+ const o = ownerOfT(id);
682
+ return o?.kind === 'player' && side.has(o.playerId);
683
+ };
684
+ for (const bonus of [...g.bonusById.values()].sort((a, b) => a.id - b.id)) {
685
+ if (bonus.value <= 0)
686
+ continue;
687
+ const ts = bonusTerritories(g, bonus.id);
688
+ const missing = ts.filter((t) => !isMine(t));
689
+ if (!ts.length || !missing.length)
690
+ continue;
691
+ const beside = new Set();
692
+ let reachable = true;
693
+ for (const t of missing) {
694
+ const mineNext = neighborsOf(g, t).filter(isMine);
695
+ if (!mineNext.length)
696
+ reachable = false;
697
+ for (const n of mineNext)
698
+ beside.add(n);
699
+ }
700
+ if (!reachable)
701
+ continue;
702
+ const defenders = missing.reduce((n, t) => n + (armiesById.get(t) ?? 0) + unitsOn(board, t), 0);
703
+ const attackers = [...beside].reduce((n, t) => n + (armiesById.get(t) ?? 0), 0) + myNow;
704
+ if (defenders < attackers)
705
+ bonusesInReach.push({ bonus: bonus.id, value: bonus.value, defenders });
706
+ }
707
+ bonusesInReach.sort((a, b) => b.value - a.value || a.bonus - b.bonus);
708
+ }
570
709
  // #368: the bonuses my side held in full on the board before and does not now.
571
710
  const bonusesLost = prev
572
711
  ? (() => {
@@ -591,7 +730,11 @@ export function gameOutlook(input) {
591
730
  return lost;
592
731
  })()
593
732
  : [];
594
- const state = bound || estimated
733
+ // #436: no lead is claimed at low coverage — a win on the likely high alone needs evidence that is not thin.
734
+ const claimWin = estimated && !evidence.thin;
735
+ if (income && estimated && !claimWin)
736
+ income.noLeadClaim = true;
737
+ const state = bound || claimWin
595
738
  ? 'winning'
596
739
  : lostOnBound || lostOnEstimate
597
740
  ? 'losing'
@@ -609,19 +752,103 @@ export function gameOutlook(input) {
609
752
  changed,
610
753
  ...(forecast ? { front: forecast } : {}),
611
754
  state,
612
- ...(estimated || lostOnEstimate ? { estimated: true } : {}),
755
+ ...(claimWin || lostOnEstimate ? { estimated: true } : {}),
613
756
  ...(lowLikely ? { lowLikely: { myIncome: myNow, mostTracked: mostTracked(), groundDown, losing: lostOnEstimate } } : {}),
614
757
  evidence,
615
758
  ...(bonusesLost.length ? { bonusesLost } : {}),
759
+ ...(income ? { income } : {}),
760
+ ...(bonusesInReach.length ? { bonusesInReach } : {}),
616
761
  };
617
762
  });
763
+ // #436: each turn's income lean, with each side's change per turn over the turns judged up to it; it
764
+ // replaces an `even` state (winning, losing and stalemate keep their own tests).
765
+ // Calibration deepens a deficit the tracked figure shows, never creates one: a behind lean on the
766
+ // calibrated estimate (or its trend), and a turn under the surrender line, need my income under the
767
+ // tracked figure (the range's low) too. In-sample, on 10 lost games, past games' estimate ÷ truth alone put
768
+ // 5 of 25 truly-even turns past the surrender line; with this rule 1 (see CLAUDE.md, #436).
769
+ const trackedBehind = (inc) => inc.mine < inc.theirs.low;
770
+ const first = turns[0];
771
+ for (const t of turns) {
772
+ const inc = t.income;
773
+ if (!inc)
774
+ continue;
775
+ if (first && first !== t && first.income) {
776
+ const span = t.turn - first.turn;
777
+ inc.trend = { mine: round2((inc.mine - first.income.mine) / span), theirs: round2((inc.theirs.estimate - first.income.theirs.estimate) / span) };
778
+ }
779
+ const r = inc.ratio;
780
+ const spans = r.low !== null && r.low <= INCOME_BEHIND_RATIO && (r.high === null || r.high >= INCOME_AHEAD_RATIO);
781
+ let lean;
782
+ if (spans)
783
+ lean = 'unknown';
784
+ else if (r.high !== null && r.high <= INCOME_BEHIND_RATIO)
785
+ lean = 'behind';
786
+ else if (r.low === null || r.low >= INCOME_AHEAD_RATIO)
787
+ lean = 'ahead';
788
+ else if (r.estimate !== null && r.estimate <= INCOME_BEHIND_RATIO) {
789
+ if (trackedBehind(inc))
790
+ lean = 'behind';
791
+ else {
792
+ lean = 'unknown';
793
+ inc.calibratedOnly = true;
794
+ }
795
+ }
796
+ else if (r.estimate === null || r.estimate >= INCOME_AHEAD_RATIO)
797
+ lean = 'ahead';
798
+ else {
799
+ lean = 'even';
800
+ // The trend: one more turn at each side's change per turn, toward a threshold the ratio is heading to.
801
+ if (inc.trend && r.estimate !== null) {
802
+ const mineNext = Math.max(0, inc.mine + inc.trend.mine);
803
+ const theirsNext = Math.max(0, inc.theirs.estimate + inc.trend.theirs);
804
+ const next = theirsNext > 0 ? mineNext / theirsNext : null;
805
+ if (next !== null && r.estimate < 1 && next <= INCOME_BEHIND_RATIO && trackedBehind(inc))
806
+ lean = 'behind';
807
+ else if ((next === null || next >= INCOME_AHEAD_RATIO) && r.estimate > 1)
808
+ lean = 'ahead';
809
+ if (lean !== 'even')
810
+ inc.byTrend = true;
811
+ }
812
+ }
813
+ if (lean === 'ahead' && t.evidence?.thin) {
814
+ lean = 'unknown';
815
+ inc.noLeadClaim = true;
816
+ delete inc.byTrend;
817
+ }
818
+ inc.lean = lean;
819
+ // #454: beside the even state, never in it.
820
+ if (t.state === 'even' && lean !== 'even')
821
+ t.lean = lean;
822
+ }
618
823
  const last = turns.at(-1);
824
+ // #436: an income lean moves from turn to turn; the turns that read even on strength are one run, so a
825
+ // lean that changes (even, behind, behind on a slide) does not reset the hold. The run reports its lean
826
+ // when every turn judged read it, else `even`.
827
+ const evenOnStrength = (t) => t.state === 'even';
828
+ /** #454: a turn's finer reading (its lean, else its state). */
829
+ const fine = (t) => t.lean ?? t.state;
830
+ const sameRun = (t) => (last && evenOnStrength(last) ? evenOnStrength(t) : t.state === last?.state);
619
831
  let heldTurns = 0;
620
- for (let i = turns.length - 1; i >= 0 && turns[i].state === last?.state; i--)
832
+ for (let i = turns.length - 1; i >= 0 && sameRun(turns[i]); i--)
621
833
  heldTurns++;
622
- const state = last && heldTurns >= OUTLOOK_TURNS ? last.state : null;
623
- // #368: even for OUTLOOK_TURNS turns running while a bonus of mine fell on each: leaning behind.
624
- const leaning = state === 'even' && turns.length >= OUTLOOK_TURNS && turns.every((t) => t.bonusesLost?.length)
834
+ const held = turns.slice(turns.length - heldTurns);
835
+ const fineState = !last || heldTurns < OUTLOOK_TURNS
836
+ ? null
837
+ : evenOnStrength(last)
838
+ ? held.every((t) => fine(t) === fine(last))
839
+ ? fine(last)
840
+ : 'even'
841
+ : last.state;
842
+ // #454: the contract's state, and the lean beside it.
843
+ const { state, lean } = splitReading(fineState);
844
+ // #368: even on strength for OUTLOOK_TURNS turns running while a bonus of mine fell on each: leaning
845
+ // behind. #436: whatever the income lean (the lean is the incomes; the slide is the board), unless the run
846
+ // already reads behind.
847
+ const leaning = state !== null &&
848
+ fineState !== 'behind' &&
849
+ turns.length >= OUTLOOK_TURNS &&
850
+ turns.every(evenOnStrength) &&
851
+ turns.every((t) => t.bonusesLost?.length)
625
852
  ? {
626
853
  toward: 'behind',
627
854
  turns: turns.length,
@@ -631,6 +858,54 @@ export function gameOutlook(input) {
631
858
  })),
632
859
  }
633
860
  : undefined;
861
+ // #436: the pace line, over the turns judged.
862
+ const lastIncome = last?.income;
863
+ const firstIncome = turns[0]?.income;
864
+ const pace = last && lastIncome && firstIncome && turns.length >= 2 && lastIncome.trend
865
+ ? {
866
+ from: turns[0].turn,
867
+ to: last.turn,
868
+ mine: { income: lastIncome.mine, perTurn: lastIncome.trend.mine },
869
+ theirs: {
870
+ playerId: lastIncome.theirs.playerId,
871
+ ...(lastIncome.theirs.team !== undefined ? { team: lastIncome.theirs.team } : {}),
872
+ income: lastIncome.theirs.estimate,
873
+ perTurn: lastIncome.trend.theirs,
874
+ },
875
+ }
876
+ : undefined;
877
+ // #436: the surrender line (advice only): my income under the line for SURRENDER_TURNS turns running.
878
+ const below = (t) => !!t.income && t.income.mine < INCOME_BEHIND_RATIO * t.income.theirs.estimate && trackedBehind(t.income);
879
+ let turnsBelow = 0;
880
+ for (let i = turns.length - 1; i >= 0 && below(turns[i]) && (i === turns.length - 1 || turns[i + 1].turn === turns[i].turn + 1); i--)
881
+ turnsBelow++;
882
+ let surrenderLine;
883
+ if (last && lastIncome && turnsBelow > 0) {
884
+ const line = round2(INCOME_BEHIND_RATIO * lastIncome.theirs.estimate);
885
+ const closer = (last.bonusesInReach ?? []).find((b) => lastIncome.mine + b.value >= line);
886
+ const crossed = turnsBelow >= SURRENDER_TURNS && !closer;
887
+ const who = lastIncome.theirs.team !== undefined ? `team ${lastIncome.theirs.team}` : `player ${lastIncome.theirs.playerId}`;
888
+ const est = `${who}'s ~${lastIncome.theirs.estimate} (${lastIncome.calibrated ? "calibrated on past games' estimate ÷ truth" : 'the tracked figure, uncalibrated'})`;
889
+ const mineText = `my ${teamGame ? "team's " : ''}income ${lastIncome.mine}`;
890
+ const advice = crossed
891
+ ? `Surrender line crossed (advice only; the server never acts on it): ${mineText} has stayed below two-thirds of ${est} for ${turnsBelow} turns running (the line is ${line}), and no bonus in reach closes the gap.`
892
+ : closer
893
+ ? `Under the surrender line for ${turnsBelow} turn${turnsBelow === 1 ? '' : 's'} (advice only): ${mineText} is below two-thirds of ${est} (the line is ${line}), but bonus ${closer.bonus} (+${closer.value}) is in reach and would close the gap.`
894
+ : `Under the surrender line for ${turnsBelow} of the ${SURRENDER_TURNS} turns it needs (advice only): ${mineText} is below two-thirds of ${est} (the line is ${line}).`;
895
+ surrenderLine = {
896
+ crossed,
897
+ turnsBelow,
898
+ needed: SURRENDER_TURNS,
899
+ myIncome: lastIncome.mine,
900
+ theirIncome: lastIncome.theirs.estimate,
901
+ playerId: lastIncome.theirs.playerId,
902
+ ...(lastIncome.theirs.team !== undefined ? { team: lastIncome.theirs.team } : {}),
903
+ line,
904
+ calibrated: lastIncome.calibrated,
905
+ ...(closer ? { closer } : {}),
906
+ advice,
907
+ };
908
+ }
634
909
  const measure = teamGame
635
910
  ? `Strength = armies + ${k} × income; an opponent's is a range under fog (low: what is in view; high: the most it could have received and earn). By team: my team's strength (mine and my teammates' still playing) against the strongest enemy team's, each the sum of its players'; summed, a teammate's transfers stay inside its team's high.`
636
911
  : `Strength = armies + ${k} × income; an opponent's is a range under fog (low: what is in view; high: the most it could have received and earn). Per player: my strength alone against the single strongest opponent, teams not summed.`;
@@ -658,15 +933,19 @@ export function gameOutlook(input) {
658
933
  : `each turn at most ${LIKELY_INCOME_MARGIN}× the income the tracker reads off my boards`;
659
934
  let est = '';
660
935
  if (l && (l.high !== s?.high || l.source === 'prior'))
661
- est = ` The likely high — an estimate, not a bound: ${rests} — is ${sideName(l)} at ${l.high}, ratio ${l.ratio}×${last.estimated ? `; ${last.state} rests on it` : ''}.`;
936
+ est = ` The likely high — an estimate, not a bound: ${rests} — is ${sideName(l)} at ${l.high}, ratio ${l.ratio}×${last.estimated ? `; ${fine(last)} rests on it` : ''}.`;
662
937
  if (l && l.high > 0 && last.state !== 'winning')
663
938
  est += ` ${cap(sideName(l))} blocks a win on the estimate: winning needs mine at ${OUTLOOK_RATIO}× its likely high (${round2(OUTLOOK_RATIO * l.high)}), and mine is ${last.mine}.`;
664
939
  reading =
665
940
  turns.length < OUTLOOK_TURNS
666
941
  ? `Only ${turns.length} turn${turns.length === 1 ? '' : 's'} of boards in a row (${OUTLOOK_TURNS} needed), so no state yet; ${figures}.`
667
- : state
668
- ? `${state[0].toUpperCase()}${state.slice(1)} for ${OUTLOOK_TURNS} turns running; ${figures}.`
669
- : `${last.state[0].toUpperCase()}${last.state.slice(1)} for ${heldTurns} of the ${OUTLOOK_TURNS} turns (${turns.map((t) => t.state).join(', ')}), so no state yet; ${figures}.`;
942
+ : evenOnStrength(last) && !held.every((t) => fine(t) === fine(last))
943
+ ? fineState
944
+ ? `Even on strength for ${OUTLOOK_TURNS} turns running, the incomes reading ${turns.map(fine).join(', ')}; ${figures}.`
945
+ : `Even on strength for ${heldTurns} of the ${OUTLOOK_TURNS} turns (${turns.map(fine).join(', ')}), so no state yet; ${figures}.`
946
+ : fineState
947
+ ? `${fineState[0].toUpperCase()}${fineState.slice(1)} for ${OUTLOOK_TURNS} turns running; ${figures}.`
948
+ : `${fine(last)[0].toUpperCase()}${fine(last).slice(1)} for ${heldTurns} of the ${OUTLOOK_TURNS} turns (${turns.map(fine).join(', ')}), so no state yet; ${figures}.`;
670
949
  // #304: the incomes compared and each opponent's frontier read, said beside the state, and thin
671
950
  // evidence named so that "even" does not read as safe.
672
951
  const ev = last.evidence;
@@ -682,9 +961,33 @@ export function gameOutlook(input) {
682
961
  .filter((r) => r.thin)
683
962
  .map((r) => `player ${r.playerId} (${r.coverage === null ? 'not measured' : `${Math.round(r.coverage * 100)}%`})`)
684
963
  .join(', ');
685
- reading += ` Thin evidence: the income of ${which} was read from under ${pct}% of its frontier, so "${last.state}" is not a safe reading: an opponent may be stronger than the fog shows.`;
964
+ reading += ` Thin evidence: the income of ${which} was read from under ${pct}% of its frontier, so "${fine(last)}" is not a safe reading: an opponent may be stronger than the fog shows.`;
686
965
  }
687
966
  reading += est;
967
+ // #436: the incomes, their range and lean, and the pace line.
968
+ const inc = last.income;
969
+ if (inc) {
970
+ const t = inc.theirs;
971
+ const whose = t.team !== undefined ? `team ${t.team}` : `player ${t.playerId}`;
972
+ const range = t.low === t.high ? `${t.estimate}` : `~${t.estimate} (range ${t.low}–${t.high})`;
973
+ const leanText = inc.lean === 'unknown'
974
+ ? inc.noLeadClaim
975
+ ? 'unknown: the evidence is thin, so no lead is claimed'
976
+ : inc.calibratedOnly
977
+ ? `unknown: only the calibrated estimate reads behind (mine under ${round2(INCOME_BEHIND_RATIO)}× of it), not the tracked ${t.low}, so it is not counted against the surrender line`
978
+ : `unknown: the range spans both thresholds (${round2(INCOME_BEHIND_RATIO)}× and ${INCOME_AHEAD_RATIO}×)`
979
+ : `${inc.lean}${inc.byTrend ? ' on the trend' : ''}`;
980
+ reading += ` On incomes: ${teamGame ? "my team's" : 'mine'} ${inc.mine} against the strongest, ${whose}, at ${range}${inc.calibrated ? ", calibrated on past games' estimate ÷ truth" : ''}: ${leanText}.`;
981
+ if (inc.noLeadClaim && inc.lean !== 'unknown')
982
+ reading += ' No lead is claimed on the likely high: the evidence is thin.';
983
+ }
984
+ if (pace) {
985
+ const sign = (n) => (n >= 0 ? `+${n}` : `${n}`);
986
+ const gap = pace.mine.perTurn > pace.theirs.perTurn ? 'my income gains on it' : pace.mine.perTurn < pace.theirs.perTurn ? 'its income gains on mine' : 'both move alike';
987
+ reading += ` Pace: my income ${pace.mine.income} (${sign(pace.mine.perTurn)}/turn over turns ${pace.from}–${pace.to}) against ${pace.theirs.team !== undefined ? `team ${pace.theirs.team}` : `player ${pace.theirs.playerId}`}'s ~${pace.theirs.income} (${sign(pace.theirs.perTurn)}/turn): ${gap}.`;
988
+ }
989
+ if (surrenderLine)
990
+ reading += ` ${surrenderLine.advice}`;
688
991
  // #228: a likely ratio far below parity, said with what it took (or lacked) to read losing.
689
992
  const low = last.lowLikely;
690
993
  if (low) {
@@ -703,8 +1006,8 @@ export function gameOutlook(input) {
703
1006
  reading += ` Leaning behind: even for ${leaning.turns} turns running while I lost bonuses on each (${leaning.lost.map((x) => `turn ${x.turn} +${x.value}`).join(', ')}): the strength ratio lags a slide the board already shows, so read "even" as falling behind.`;
704
1007
  // #228: the plan's profile standing is a different measure (incomes, then the armies in view).
705
1008
  const standing = input.standing;
706
- if ((last.state === 'even' || last.state === 'stalemate') && (standing === 'ahead' || standing === 'behind'))
707
- reading += ` The profile's standing reads ${standing} (my income against the strongest opponent's estimate, overruled by the armies in view); this outlook reads ${last.state} because neither the winning nor the losing threshold was met on strength (armies + ${k} × income, and the likely high), a stricter test for a decided game.`;
1009
+ if ((fine(last) === 'even' || fine(last) === 'stalemate') && (standing === 'ahead' || standing === 'behind'))
1010
+ reading += ` The profile's standing reads ${standing} (my income against the strongest opponent's estimate, overruled by the armies in view); this outlook reads ${fine(last)} because neither the winning nor the losing threshold was met on strength (armies + ${k} × income, and the likely high), a stricter test for a decided game.`;
708
1011
  // #218: the main front, said with what it assumes, so it reads with the plan's front outlook.
709
1012
  const fr = last.front;
710
1013
  if (fr) {
@@ -723,6 +1026,7 @@ export function gameOutlook(input) {
723
1026
  }
724
1027
  return {
725
1028
  state,
1029
+ ...(lean ? { lean } : {}),
726
1030
  heldTurns,
727
1031
  turns,
728
1032
  k,
@@ -730,5 +1034,7 @@ export function gameOutlook(input) {
730
1034
  basis: `${reading} ${measure} ${thresholdsText}`,
731
1035
  ...(last?.evidence ? { evidence: last.evidence } : {}),
732
1036
  ...(leaning ? { leaning } : {}),
1037
+ ...(pace ? { pace } : {}),
1038
+ ...(surrenderLine ? { surrenderLine } : {}),
733
1039
  };
734
1040
  }