@chrischall/warapp-mcp 0.26.0 → 0.27.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 +2 -2
- package/.claude-plugin/plugin.json +1 -1
- package/dist/analysis/fog-view.js +35 -0
- package/dist/bundle.js +506 -152
- package/dist/calibration-source.js +39 -4
- package/dist/fog-history.js +246 -0
- package/dist/history-window.js +85 -0
- package/dist/protocol/methods.js +8 -0
- package/dist/tools/calibration-harness.js +26 -11
- package/dist/tools/fog-capture.js +35 -0
- package/dist/tools/game.js +49 -6
- package/dist/tools/turn.js +7 -0
- package/dist/version.js +1 -1
- package/manifest.json +1 -1
- package/package.json +1 -1
- package/server.json +2 -2
package/dist/bundle.js
CHANGED
|
@@ -1814,12 +1814,12 @@ var require_checks = __commonJS({
|
|
|
1814
1814
|
exports.$ZodCheckNumberFormat = core.$constructor("$ZodCheckNumberFormat", (inst, def) => {
|
|
1815
1815
|
exports.$ZodCheck.init(inst, def);
|
|
1816
1816
|
def.format = def.format || "float64";
|
|
1817
|
-
const
|
|
1818
|
-
const origin =
|
|
1817
|
+
const isInt29 = def.format?.includes("int");
|
|
1818
|
+
const origin = isInt29 ? "int" : "number";
|
|
1819
1819
|
const [minimum, maximum] = util.NUMBER_FORMAT_RANGES[def.format];
|
|
1820
1820
|
inst._zod.check = (payload) => {
|
|
1821
1821
|
const input2 = payload.value;
|
|
1822
|
-
if (
|
|
1822
|
+
if (isInt29) {
|
|
1823
1823
|
if (!Number.isInteger(input2)) {
|
|
1824
1824
|
payload.issues.push({
|
|
1825
1825
|
expected: origin,
|
|
@@ -4607,14 +4607,14 @@ var require_schemas = __commonJS({
|
|
|
4607
4607
|
function leafPattern2(schema) {
|
|
4608
4608
|
const def = schema._zod.def;
|
|
4609
4609
|
let pattern = def.pattern;
|
|
4610
|
-
let
|
|
4610
|
+
let isInt29 = !!def.format?.includes("int");
|
|
4611
4611
|
let minimum;
|
|
4612
4612
|
let maximum;
|
|
4613
4613
|
for (const ch of def.checks ?? []) {
|
|
4614
4614
|
const d = ch._zod.def;
|
|
4615
4615
|
if (d.pattern)
|
|
4616
4616
|
pattern = d.pattern;
|
|
4617
|
-
|
|
4617
|
+
isInt29 || (isInt29 = !!d.format?.includes("int"));
|
|
4618
4618
|
const lo = d.minimum ?? d.length;
|
|
4619
4619
|
const hi = d.maximum ?? d.length;
|
|
4620
4620
|
if (lo !== void 0 && (minimum === void 0 || lo > minimum))
|
|
@@ -4629,7 +4629,7 @@ var require_schemas = __commonJS({
|
|
|
4629
4629
|
if (minimum !== void 0 || maximum !== void 0)
|
|
4630
4630
|
return regexes.string({ minimum, maximum }).source;
|
|
4631
4631
|
const own2 = schema._zod.pattern;
|
|
4632
|
-
return (
|
|
4632
|
+
return (isInt29 && own2 === regexes.number ? regexes.integer : own2)?.source;
|
|
4633
4633
|
}
|
|
4634
4634
|
function partPattern2(schema) {
|
|
4635
4635
|
const def = schema._zod.def;
|
|
@@ -18897,8 +18897,8 @@ var require_json_schema_processors = __commonJS({
|
|
|
18897
18897
|
exports.stringProcessor = stringProcessor2;
|
|
18898
18898
|
var numberProcessor2 = (schema, ctx, _json, params) => {
|
|
18899
18899
|
const json2 = _json;
|
|
18900
|
-
const { minimum, maximum, multipleOf, exclusiveMaximum, exclusiveMinimum, isInt:
|
|
18901
|
-
json2.type =
|
|
18900
|
+
const { minimum, maximum, multipleOf, exclusiveMaximum, exclusiveMinimum, isInt: isInt29 } = aggregateChecks2(schema);
|
|
18901
|
+
json2.type = isInt29 ? "integer" : "number";
|
|
18902
18902
|
const exMin = typeof exclusiveMinimum === "number" && exclusiveMinimum >= (minimum ?? Number.NEGATIVE_INFINITY);
|
|
18903
18903
|
const exMax = typeof exclusiveMaximum === "number" && exclusiveMaximum <= (maximum ?? Number.POSITIVE_INFINITY);
|
|
18904
18904
|
const legacy = ctx.target === "draft-04" || ctx.target === "openapi-3.0";
|
|
@@ -20767,8 +20767,8 @@ var require_schemas2 = __commonJS({
|
|
|
20767
20767
|
return Math.min(maximum ?? Number.POSITIVE_INFINITY, exclusiveMaximum ?? Number.POSITIVE_INFINITY);
|
|
20768
20768
|
},
|
|
20769
20769
|
isInt: (inst) => {
|
|
20770
|
-
const { isInt:
|
|
20771
|
-
return !!
|
|
20770
|
+
const { isInt: isInt29, multipleOf } = processors.aggregateChecks(inst);
|
|
20771
|
+
return !!isInt29 || !!multipleOf?.some(Number.isSafeInteger);
|
|
20772
20772
|
},
|
|
20773
20773
|
format: (inst) => processors.aggregateChecks(inst).format ?? null
|
|
20774
20774
|
}, {
|
|
@@ -45745,7 +45745,7 @@ var require_snapshot_utils = __commonJS({
|
|
|
45745
45745
|
var require_snapshot_recorder = __commonJS({
|
|
45746
45746
|
"node_modules/undici/lib/mock/snapshot-recorder.js"(exports, module) {
|
|
45747
45747
|
"use strict";
|
|
45748
|
-
var { writeFile:
|
|
45748
|
+
var { writeFile: writeFile19, readFile: readFile28, mkdir: mkdir20 } = __require("node:fs/promises");
|
|
45749
45749
|
var { dirname: dirname4, resolve: resolve6 } = __require("node:path");
|
|
45750
45750
|
var { setTimeout: setTimeout2, clearTimeout: clearTimeout2 } = __require("node:timers");
|
|
45751
45751
|
var { InvalidArgumentError, UndiciError } = require_errors4();
|
|
@@ -45963,7 +45963,7 @@ var require_snapshot_recorder = __commonJS({
|
|
|
45963
45963
|
throw new InvalidArgumentError("Snapshot path is required");
|
|
45964
45964
|
}
|
|
45965
45965
|
try {
|
|
45966
|
-
const data2 = await
|
|
45966
|
+
const data2 = await readFile28(resolve6(path), "utf8");
|
|
45967
45967
|
const parsed = JSON.parse(data2);
|
|
45968
45968
|
if (Array.isArray(parsed)) {
|
|
45969
45969
|
this.#snapshots.clear();
|
|
@@ -45993,12 +45993,12 @@ var require_snapshot_recorder = __commonJS({
|
|
|
45993
45993
|
throw new InvalidArgumentError("Snapshot path is required");
|
|
45994
45994
|
}
|
|
45995
45995
|
const resolvedPath = resolve6(path);
|
|
45996
|
-
await
|
|
45996
|
+
await mkdir20(dirname4(resolvedPath), { recursive: true });
|
|
45997
45997
|
const data2 = Array.from(this.#snapshots.entries()).map(([hash2, snapshot]) => ({
|
|
45998
45998
|
hash: hash2,
|
|
45999
45999
|
snapshot
|
|
46000
46000
|
}));
|
|
46001
|
-
await
|
|
46001
|
+
await writeFile19(resolvedPath, JSON.stringify(data2, null, 2), { flush: true });
|
|
46002
46002
|
}
|
|
46003
46003
|
/**
|
|
46004
46004
|
* Clears all recorded snapshots
|
|
@@ -76974,12 +76974,12 @@ var $ZodCheckMultipleOf = /* @__PURE__ */ $constructor("$ZodCheckMultipleOf", (i
|
|
|
76974
76974
|
var $ZodCheckNumberFormat = /* @__PURE__ */ $constructor("$ZodCheckNumberFormat", (inst, def) => {
|
|
76975
76975
|
$ZodCheck.init(inst, def);
|
|
76976
76976
|
def.format = def.format || "float64";
|
|
76977
|
-
const
|
|
76978
|
-
const origin =
|
|
76977
|
+
const isInt29 = def.format?.includes("int");
|
|
76978
|
+
const origin = isInt29 ? "int" : "number";
|
|
76979
76979
|
const [minimum, maximum] = NUMBER_FORMAT_RANGES[def.format];
|
|
76980
76980
|
inst._zod.check = (payload) => {
|
|
76981
76981
|
const input2 = payload.value;
|
|
76982
|
-
if (
|
|
76982
|
+
if (isInt29) {
|
|
76983
76983
|
if (!Number.isInteger(input2)) {
|
|
76984
76984
|
payload.issues.push({
|
|
76985
76985
|
expected: origin,
|
|
@@ -79642,14 +79642,14 @@ function handleReadonlyResult(payload) {
|
|
|
79642
79642
|
function leafPattern(schema) {
|
|
79643
79643
|
const def = schema._zod.def;
|
|
79644
79644
|
let pattern = def.pattern;
|
|
79645
|
-
let
|
|
79645
|
+
let isInt29 = !!def.format?.includes("int");
|
|
79646
79646
|
let minimum;
|
|
79647
79647
|
let maximum;
|
|
79648
79648
|
for (const ch of def.checks ?? []) {
|
|
79649
79649
|
const d = ch._zod.def;
|
|
79650
79650
|
if (d.pattern)
|
|
79651
79651
|
pattern = d.pattern;
|
|
79652
|
-
|
|
79652
|
+
isInt29 || (isInt29 = !!d.format?.includes("int"));
|
|
79653
79653
|
const lo = d.minimum ?? d.length;
|
|
79654
79654
|
const hi = d.maximum ?? d.length;
|
|
79655
79655
|
if (lo !== void 0 && (minimum === void 0 || lo > minimum))
|
|
@@ -79664,7 +79664,7 @@ function leafPattern(schema) {
|
|
|
79664
79664
|
if (minimum !== void 0 || maximum !== void 0)
|
|
79665
79665
|
return string4({ minimum, maximum }).source;
|
|
79666
79666
|
const own2 = schema._zod.pattern;
|
|
79667
|
-
return (
|
|
79667
|
+
return (isInt29 && own2 === number4 ? integer : own2)?.source;
|
|
79668
79668
|
}
|
|
79669
79669
|
function partPattern(schema) {
|
|
79670
79670
|
const def = schema._zod.def;
|
|
@@ -91089,8 +91089,8 @@ var stringProcessor = (schema, ctx, _json, _params) => {
|
|
|
91089
91089
|
};
|
|
91090
91090
|
var numberProcessor = (schema, ctx, _json, params) => {
|
|
91091
91091
|
const json2 = _json;
|
|
91092
|
-
const { minimum, maximum, multipleOf, exclusiveMaximum, exclusiveMinimum, isInt:
|
|
91093
|
-
json2.type =
|
|
91092
|
+
const { minimum, maximum, multipleOf, exclusiveMaximum, exclusiveMinimum, isInt: isInt29 } = aggregateChecks(schema);
|
|
91093
|
+
json2.type = isInt29 ? "integer" : "number";
|
|
91094
91094
|
const exMin = typeof exclusiveMinimum === "number" && exclusiveMinimum >= (minimum ?? Number.NEGATIVE_INFINITY);
|
|
91095
91095
|
const exMax = typeof exclusiveMaximum === "number" && exclusiveMaximum <= (maximum ?? Number.POSITIVE_INFINITY);
|
|
91096
91096
|
const legacy = ctx.target === "draft-04" || ctx.target === "openapi-3.0";
|
|
@@ -92619,8 +92619,8 @@ var ZodNumber = /* @__PURE__ */ $constructor(
|
|
|
92619
92619
|
return Math.min(maximum ?? Number.POSITIVE_INFINITY, exclusiveMaximum ?? Number.POSITIVE_INFINITY);
|
|
92620
92620
|
},
|
|
92621
92621
|
isInt: (inst) => {
|
|
92622
|
-
const { isInt:
|
|
92623
|
-
return !!
|
|
92622
|
+
const { isInt: isInt29, multipleOf } = aggregateChecks(inst);
|
|
92623
|
+
return !!isInt29 || !!multipleOf?.some(Number.isSafeInteger);
|
|
92624
92624
|
},
|
|
92625
92625
|
format: (inst) => aggregateChecks(inst).format ?? null
|
|
92626
92626
|
}, {
|
|
@@ -94778,14 +94778,14 @@ function createPendingCallStore(options = {}) {
|
|
|
94778
94778
|
entries2.delete(token2);
|
|
94779
94779
|
total -= entry.bytes;
|
|
94780
94780
|
};
|
|
94781
|
-
const
|
|
94781
|
+
const prune4 = (now) => {
|
|
94782
94782
|
for (const [token2, { call }] of entries2)
|
|
94783
94783
|
if (call.expiresAt < now)
|
|
94784
94784
|
remove(token2);
|
|
94785
94785
|
};
|
|
94786
94786
|
return {
|
|
94787
94787
|
put(token2, call) {
|
|
94788
|
-
|
|
94788
|
+
prune4(Date.now());
|
|
94789
94789
|
const bytes = Buffer.byteLength(JSON.stringify(call.args) ?? "", "utf8") + Buffer.byteLength(token2, "utf8");
|
|
94790
94790
|
if (bytes > maxEntryBytes || bytes > maxBytes)
|
|
94791
94791
|
return false;
|
|
@@ -94801,11 +94801,11 @@ function createPendingCallStore(options = {}) {
|
|
|
94801
94801
|
return true;
|
|
94802
94802
|
},
|
|
94803
94803
|
get(token2) {
|
|
94804
|
-
|
|
94804
|
+
prune4(Date.now());
|
|
94805
94805
|
return entries2.get(token2)?.call;
|
|
94806
94806
|
},
|
|
94807
94807
|
take(token2) {
|
|
94808
|
-
|
|
94808
|
+
prune4(Date.now());
|
|
94809
94809
|
const call = entries2.get(token2)?.call;
|
|
94810
94810
|
remove(token2);
|
|
94811
94811
|
return call;
|
|
@@ -106821,7 +106821,7 @@ function closestBonus(pc, ps, input2, prev, hd) {
|
|
|
106821
106821
|
standing.set(p.bonusId, credit);
|
|
106822
106822
|
return credit;
|
|
106823
106823
|
};
|
|
106824
|
-
const
|
|
106824
|
+
const turnsOf3 = (p) => {
|
|
106825
106825
|
const left = Math.max(0, p.cost - standingBeside(p));
|
|
106826
106826
|
return income > 0 ? Math.max(Math.ceil(left / income), depthOf(p)) : left;
|
|
106827
106827
|
};
|
|
@@ -106838,10 +106838,10 @@ function closestBonus(pc, ps, input2, prev, hd) {
|
|
|
106838
106838
|
};
|
|
106839
106839
|
const foggedOf = (p) => p.fogged + (p.fogNeutral?.count ?? 0);
|
|
106840
106840
|
const byCloseness = committing ? [...plans].sort(
|
|
106841
|
-
(a, b) => Number(b.focus) - Number(a.focus) ||
|
|
106841
|
+
(a, b) => Number(b.focus) - Number(a.focus) || turnsOf3(a) - turnsOf3(b) || perArmy(b) - perArmy(a) || a.cost - b.cost || foggedOf(a) - foggedOf(b) || Number(advancedLast.has(b.bonusId)) - Number(advancedLast.has(a.bonusId)) || scoreRank.get(a.bonusId) - scoreRank.get(b.bonusId)
|
|
106842
106842
|
) : plans;
|
|
106843
106843
|
const turnsText = (p) => {
|
|
106844
|
-
const n =
|
|
106844
|
+
const n = turnsOf3(p);
|
|
106845
106845
|
const deep = n > Math.max(1, Math.ceil(Math.max(0, p.cost - standingBeside(p)) / income)) ? ` (${n} layers deep)` : "";
|
|
106846
106846
|
return income > 0 ? `${n} turn${n === 1 ? "" : "s"}${deep}` : "no income";
|
|
106847
106847
|
};
|
|
@@ -106861,7 +106861,7 @@ function closestBonus(pc, ps, input2, prev, hd) {
|
|
|
106861
106861
|
for (const p of byCloseness) {
|
|
106862
106862
|
const all2 = completesWith(p);
|
|
106863
106863
|
const key = [...p.remaining].sort((x, y) => x - y).join(",");
|
|
106864
|
-
const rivals = byCloseness.some((q) => !all2.includes(q) && !q.focus &&
|
|
106864
|
+
const rivals = byCloseness.some((q) => !all2.includes(q) && !q.focus && turnsOf3(q) === turnsOf3(p));
|
|
106865
106865
|
if (all2.length < 2 || !rivals || said2.has(key)) continue;
|
|
106866
106866
|
said2.add(key);
|
|
106867
106867
|
const names2 = all2.map((q) => bonusName(q.bonusId));
|
|
@@ -106874,7 +106874,7 @@ function closestBonus(pc, ps, input2, prev, hd) {
|
|
|
106874
106874
|
rationale.push(
|
|
106875
106875
|
`${bonusName(p.bonusId)} keeps priority: I advanced it last turn, and no bonus is strictly closer to completion.`
|
|
106876
106876
|
);
|
|
106877
|
-
else if (top && !p.focus &&
|
|
106877
|
+
else if (top && !p.focus && turnsOf3(top) < turnsOf3(p))
|
|
106878
106878
|
rationale.push(
|
|
106879
106879
|
`${bonusName(p.bonusId)}, advanced last turn, gives way to ${bonusName(top.bonusId)}: it is strictly closer to completion (${turnsText(top)} to finish against ${turnsText(p)}).`
|
|
106880
106880
|
);
|
|
@@ -106895,7 +106895,7 @@ function closestBonus(pc, ps, input2, prev, hd) {
|
|
|
106895
106895
|
const take = toTake(survivors);
|
|
106896
106896
|
return take !== null && take <= counter ? `${label3(t)} can be retaken after it breaks ${bonusName(bonusId)}: ${survivors} survivors need ${take} to take, against ~${counter} next turn.` : void 0;
|
|
106897
106897
|
};
|
|
106898
|
-
return { holdsBonus, neutralsInReach, committing, advancedLast, fromMine, depthOf, turnsOf:
|
|
106898
|
+
return { holdsBonus, neutralsInReach, committing, advancedLast, fromMine, depthOf, turnsOf: turnsOf3, scoreRank, byCloseness, turnsText, spreadNearest, retakeChecks, retakeWarning };
|
|
106899
106899
|
}
|
|
106900
106900
|
|
|
106901
106901
|
// src/analysis/plan/after-leftover.ts
|
|
@@ -116245,7 +116245,7 @@ function serverBuild() {
|
|
|
116245
116245
|
}
|
|
116246
116246
|
|
|
116247
116247
|
// src/version.ts
|
|
116248
|
-
var VERSION2 = "0.
|
|
116248
|
+
var VERSION2 = "0.27.0";
|
|
116249
116249
|
|
|
116250
116250
|
// src/decision-log.ts
|
|
116251
116251
|
var DECISION_LOG_VERSION = 1;
|
|
@@ -116845,9 +116845,9 @@ async function recordGameEvent(dir, gameId, playerId, ev, o = {}, opts = {}) {
|
|
|
116845
116845
|
return false;
|
|
116846
116846
|
}
|
|
116847
116847
|
}
|
|
116848
|
-
async function recordJoin(dir, gameId, playerId,
|
|
116848
|
+
async function recordJoin(dir, gameId, playerId, join33, opts = {}) {
|
|
116849
116849
|
try {
|
|
116850
|
-
const kept = encodeValue(
|
|
116850
|
+
const kept = encodeValue(join33);
|
|
116851
116851
|
return await updateDecisionLog(dir, gameId, playerId, (log) => ({ ...log, join: kept }), opts);
|
|
116852
116852
|
} catch {
|
|
116853
116853
|
return false;
|
|
@@ -120876,6 +120876,9 @@ function writeRetrieveChatParams(w, p) {
|
|
|
120876
120876
|
function writeRetrievePrivateMessageHistoryParams(w, p) {
|
|
120877
120877
|
w.int32(p.gameId).string(beforeMarker(p.before)).int32(p.counterpart);
|
|
120878
120878
|
}
|
|
120879
|
+
function writeGetTurnsParams(w, p) {
|
|
120880
|
+
w.int32(p.gameId).bool(true).list(p.turns, (x, t) => x.int32(t)).bool(true);
|
|
120881
|
+
}
|
|
120879
120882
|
function writeRetrieveGameGroupMessageHistoryParams(w, p) {
|
|
120880
120883
|
w.int32(p.gameId).string(beforeMarker(p.before)).int32(p.group);
|
|
120881
120884
|
}
|
|
@@ -140477,9 +140480,9 @@ async function captureGameEvent(ctx, gameId, me, ev, o = {}) {
|
|
|
140477
140480
|
if (!ctx.dataDir) return;
|
|
140478
140481
|
await recordGameEvent(ctx.dataDir, gameId, me, ev, o, modeOf2(ctx));
|
|
140479
140482
|
}
|
|
140480
|
-
async function captureJoin(ctx, gameId, me,
|
|
140483
|
+
async function captureJoin(ctx, gameId, me, join33) {
|
|
140481
140484
|
if (!ctx.dataDir) return;
|
|
140482
|
-
await recordJoin(ctx.dataDir, gameId, me,
|
|
140485
|
+
await recordJoin(ctx.dataDir, gameId, me, join33, modeOf2(ctx));
|
|
140483
140486
|
}
|
|
140484
140487
|
async function captureOpponentRead(ctx, gameId, me, player2, read) {
|
|
140485
140488
|
if (!ctx.dataDir) return;
|
|
@@ -145496,8 +145499,8 @@ function pickingNeutrals(board) {
|
|
|
145496
145499
|
}
|
|
145497
145500
|
|
|
145498
145501
|
// src/tools/team-source.ts
|
|
145499
|
-
import { readdir as
|
|
145500
|
-
import { join as
|
|
145502
|
+
import { readdir as readdir15, readFile as readFile25, stat as stat14, unlink as unlink16 } from "node:fs/promises";
|
|
145503
|
+
import { join as join30 } from "node:path";
|
|
145501
145504
|
|
|
145502
145505
|
// src/mail.ts
|
|
145503
145506
|
var DISCUSSION_FOR_CLIENT = "warlight.shared.discussions.DiscussionForClient";
|
|
@@ -152226,7 +152229,7 @@ async function readOpponents(o) {
|
|
|
152226
152229
|
const opponents = profiledOpponents(game, me);
|
|
152227
152230
|
const stored = on2 && dataDir2 ? await readProfileTurns(dataDir2, game.id, me.id, env) : /* @__PURE__ */ new Map();
|
|
152228
152231
|
const fresh = observeBoards({ gameId: game.id, me: me.id, graph: graphOf(mapOf(game)), settings: observeSettings(game), ...cardsInPlay(game), opponents, boards });
|
|
152229
|
-
const
|
|
152232
|
+
const turnsOf3 = (id) => {
|
|
152230
152233
|
const byTurn = /* @__PURE__ */ new Map();
|
|
152231
152234
|
for (const t of stored.get(id) ?? []) byTurn.set(t.turn, t);
|
|
152232
152235
|
for (const [t, m] of fresh) {
|
|
@@ -152242,7 +152245,7 @@ async function readOpponents(o) {
|
|
|
152242
152245
|
const turn = boards.length ? Math.max(...boards.map((b) => b.turn)) : null;
|
|
152243
152246
|
const reads = opponents.map((id) => {
|
|
152244
152247
|
const p = players.get(id);
|
|
152245
|
-
const turns =
|
|
152248
|
+
const turns = turnsOf3(id);
|
|
152246
152249
|
const habits = habitsOf(turns);
|
|
152247
152250
|
const estimates = estimateHabits(habits, priorsOf(known2, format, id, Boolean(p?.isAI)));
|
|
152248
152251
|
const last = lastAttackTurn(turns);
|
|
@@ -155168,6 +155171,212 @@ function nextIncomeLow(a) {
|
|
|
155168
155171
|
return { low: Math.max(0, a.nextIncome - lost), falls, belowEstimate };
|
|
155169
155172
|
}
|
|
155170
155173
|
|
|
155174
|
+
// src/fog-history.ts
|
|
155175
|
+
import { randomUUID as randomUUID10 } from "node:crypto";
|
|
155176
|
+
import { mkdir as mkdir19, readdir as readdir14, readFile as readFile24, rename as rename19, rm as rm6, stat as stat13, writeFile as writeFile18 } from "node:fs/promises";
|
|
155177
|
+
import { join as join29 } from "node:path";
|
|
155178
|
+
var FOG_HISTORY_VERSION = 1;
|
|
155179
|
+
var MAX_FOG_HISTORIES = 200;
|
|
155180
|
+
var FOG_CAPTURE_TURNS2 = 200;
|
|
155181
|
+
var fogHistoryDir = (dir) => join29(dir, "fog-history");
|
|
155182
|
+
var fogHistoryPath = (dir, gameId, playerId) => join29(fogHistoryDir(dir), `${gameId}-${playerId}.json`);
|
|
155183
|
+
var isInt20 = (v) => typeof v === "number" && Number.isInteger(v);
|
|
155184
|
+
var TERRITORY_STANDING2 = /\.TerritoryStanding$/;
|
|
155185
|
+
var ARMIES3 = /\.Armies$/;
|
|
155186
|
+
var GAME_TURN3 = /\.GameTurn$/;
|
|
155187
|
+
var GAME_STANDING2 = /\.GameStanding$/;
|
|
155188
|
+
function cellOf(v) {
|
|
155189
|
+
if (!isObj(v) || typeof v.$type !== "string" || !TERRITORY_STANDING2.test(v.$type)) return void 0;
|
|
155190
|
+
const [fog, territory2, armies, owner] = fields(v);
|
|
155191
|
+
const level = isInt20(fog) ? fog : isObj(fog) ? fields(fog).find(isInt20) : void 0;
|
|
155192
|
+
if (level === void 0 || !isInt20(territory2) || !isInt20(owner) || !isObj(armies) || typeof armies.$type !== "string" || !ARMIES3.test(armies.$type)) return void 0;
|
|
155193
|
+
const af = fields(armies);
|
|
155194
|
+
const hidden = af.find((x) => typeof x === "boolean") === true;
|
|
155195
|
+
const count4 = af.find(isInt20);
|
|
155196
|
+
return [territory2, level, owner, hidden || count4 === void 0 ? null : count4];
|
|
155197
|
+
}
|
|
155198
|
+
function standingCells(s) {
|
|
155199
|
+
const out = [];
|
|
155200
|
+
for (const f of fields(s)) {
|
|
155201
|
+
const entries2 = f instanceof Map ? [...f.entries()] : Array.isArray(f) ? f : [];
|
|
155202
|
+
for (const e of entries2) {
|
|
155203
|
+
const v = Array.isArray(e) ? e[1] : e;
|
|
155204
|
+
const c = cellOf(v);
|
|
155205
|
+
if (c) out.push(c);
|
|
155206
|
+
}
|
|
155207
|
+
if (out.length) break;
|
|
155208
|
+
}
|
|
155209
|
+
return out.sort((a, b) => a[0] - b[0]);
|
|
155210
|
+
}
|
|
155211
|
+
function readTurnsReturn(ret) {
|
|
155212
|
+
if (!isObj(ret)) return void 0;
|
|
155213
|
+
const lists = fields(ret).filter((v) => Array.isArray(v));
|
|
155214
|
+
const standings2 = lists.flat().filter((v) => isObj(v) && typeof v.$type === "string" && GAME_STANDING2.test(v.$type));
|
|
155215
|
+
const gameTurns = lists.flat().filter((v) => isObj(v) && typeof v.$type === "string" && GAME_TURN3.test(v.$type));
|
|
155216
|
+
if (!standings2.length && !gameTurns.length) return void 0;
|
|
155217
|
+
const turns = {};
|
|
155218
|
+
for (const t of gameTurns) {
|
|
155219
|
+
const own2 = fields(t);
|
|
155220
|
+
const index = own2.find(isInt20);
|
|
155221
|
+
const orders = own2.filter((v) => Array.isArray(v)).at(-1) ?? [];
|
|
155222
|
+
if (index === void 0) continue;
|
|
155223
|
+
const cells = [];
|
|
155224
|
+
for (const o of orders) {
|
|
155225
|
+
if (!isObj(o)) continue;
|
|
155226
|
+
const d = decodeOrder(o);
|
|
155227
|
+
if (d?.kind === "deploy") {
|
|
155228
|
+
cells.push(["d", d.territoryId, d.armies]);
|
|
155229
|
+
continue;
|
|
155230
|
+
}
|
|
155231
|
+
const card = cardEntry(o);
|
|
155232
|
+
if (card) {
|
|
155233
|
+
cells.push(card);
|
|
155234
|
+
continue;
|
|
155235
|
+
}
|
|
155236
|
+
for (const f of fields(o)) if (Array.isArray(f)) for (const x of f) {
|
|
155237
|
+
const c = cellOf(x);
|
|
155238
|
+
if (c) cells.push(c);
|
|
155239
|
+
}
|
|
155240
|
+
}
|
|
155241
|
+
turns[String(index + 1)] = cells;
|
|
155242
|
+
}
|
|
155243
|
+
const start = standings2.length ? standingCells(standings2.at(-1)) : void 0;
|
|
155244
|
+
return { ...start?.length ? { start } : {}, turns };
|
|
155245
|
+
}
|
|
155246
|
+
var CARD_PLAY = /\.GameOrderPlayCard(Airlift|Blockade|Abandon|Bomb)$/;
|
|
155247
|
+
function cardEntry(o) {
|
|
155248
|
+
const m = typeof o.$type === "string" ? CARD_PLAY.exec(o.$type) : null;
|
|
155249
|
+
if (!m) return void 0;
|
|
155250
|
+
const f = fields(o);
|
|
155251
|
+
const guid3 = f.findIndex((v) => typeof v === "string");
|
|
155252
|
+
const own2 = guid3 >= 0 ? f.slice(0, guid3) : f;
|
|
155253
|
+
const ints5 = own2.filter(isInt20);
|
|
155254
|
+
if (m[1] === "Airlift") {
|
|
155255
|
+
const result2 = f.find((v) => isObj(v) && typeof v.$type === "string" && /AirliftResult$/.test(v.$type));
|
|
155256
|
+
const flew = result2 ? fields(result2).find((v) => isObj(v) && typeof v.$type === "string" && ARMIES3.test(v.$type)) : void 0;
|
|
155257
|
+
const n = flew ? fields(flew).find(isInt20) : void 0;
|
|
155258
|
+
return ints5.length >= 2 && n !== void 0 ? ["a", ints5[0], ints5.at(-1), n] : void 0;
|
|
155259
|
+
}
|
|
155260
|
+
if (!ints5.length) return void 0;
|
|
155261
|
+
return [m[1] === "Blockade" ? "b" : m[1] === "Abandon" ? "e" : "h", ints5[0]];
|
|
155262
|
+
}
|
|
155263
|
+
function wallMultipliers(raw) {
|
|
155264
|
+
const of = (key) => {
|
|
155265
|
+
const r = raw?.[key];
|
|
155266
|
+
const m = typeof r === "object" && r !== null ? Number(r.MultiplyAmount) : Number.NaN;
|
|
155267
|
+
return Number.isFinite(m) && m > 0 ? m : void 0;
|
|
155268
|
+
};
|
|
155269
|
+
const blockade = of("BlockadeCard");
|
|
155270
|
+
const abandon = of("EmergencyBlockadeCard");
|
|
155271
|
+
return { ...blockade !== void 0 ? { blockade } : {}, ...abandon !== void 0 ? { abandon } : {} };
|
|
155272
|
+
}
|
|
155273
|
+
function fogBoards(h, players, walls = {}) {
|
|
155274
|
+
const byInGame = /* @__PURE__ */ new Map();
|
|
155275
|
+
for (const p of players) {
|
|
155276
|
+
const g = inGameOf(p);
|
|
155277
|
+
if (g !== void 0) byInGame.set(g, p.id);
|
|
155278
|
+
}
|
|
155279
|
+
const cur = new Map(h.start.map((c) => [c[0], c]));
|
|
155280
|
+
const out = [];
|
|
155281
|
+
const snapshot = (turn) => out.push({ turn, board: { source: "browser", verified: true, territories: [...cur.values()].sort((a, b) => a[0] - b[0]).map((c) => stateOf(c, byInGame)) } });
|
|
155282
|
+
snapshot(1);
|
|
155283
|
+
const numbers = Object.keys(h.turns).map(Number).filter((n) => n >= 1).sort((a, b) => a - b);
|
|
155284
|
+
for (let n = 1; n <= (numbers.at(-1) ?? 0); n++) {
|
|
155285
|
+
const updates = h.turns[String(n)];
|
|
155286
|
+
if (!updates) break;
|
|
155287
|
+
const add = (t, n2) => {
|
|
155288
|
+
const was = cur.get(t);
|
|
155289
|
+
if (was && was[3] !== null) cur.set(t, [was[0], was[1], was[2], Math.max(0, was[3] + n2)]);
|
|
155290
|
+
};
|
|
155291
|
+
const wall = (t, m) => {
|
|
155292
|
+
const was = cur.get(t);
|
|
155293
|
+
if (was) cur.set(t, [was[0], was[1], 0, was[3] === null || m === void 0 ? null : roundHalfDown2(was[3] * m)]);
|
|
155294
|
+
};
|
|
155295
|
+
for (const c of updates) {
|
|
155296
|
+
if (c[0] === "d") add(c[1], c[2]);
|
|
155297
|
+
else if (c[0] === "a") {
|
|
155298
|
+
add(c[1], -c[3]);
|
|
155299
|
+
add(c[2], c[3]);
|
|
155300
|
+
} else if (c[0] === "b") wall(c[1], walls.blockade);
|
|
155301
|
+
else if (c[0] === "e") wall(c[1], walls.abandon);
|
|
155302
|
+
else if (c[0] === "h") {
|
|
155303
|
+
const was = cur.get(c[1]);
|
|
155304
|
+
if (was && was[3] !== null) cur.set(c[1], [was[0], was[1], was[2], Math.floor(was[3] / 2)]);
|
|
155305
|
+
} else if (typeof c[0] === "number") cur.set(c[0], c);
|
|
155306
|
+
}
|
|
155307
|
+
snapshot(n + 1);
|
|
155308
|
+
}
|
|
155309
|
+
return out;
|
|
155310
|
+
}
|
|
155311
|
+
var FOG_NAMES = { 1: "You", 2: "Visible", 3: "OwnerOnly", 4: "Fogged" };
|
|
155312
|
+
function stateOf([territoryId, fog, owner, armies], byInGame) {
|
|
155313
|
+
const fogLevel = FOG_NAMES[fog] ?? String(fog);
|
|
155314
|
+
if (fog >= 4) return { territoryId, owner: { kind: "unknown" }, armies: null, fogLevel };
|
|
155315
|
+
const o = owner === 0 ? { kind: "neutral" } : owner > 0 && byInGame.has(owner) ? { kind: "player", playerId: byInGame.get(owner) } : { kind: "unknown" };
|
|
155316
|
+
return { territoryId, owner: o, armies: fog >= 3 ? null : armies, fogLevel };
|
|
155317
|
+
}
|
|
155318
|
+
async function readFogHistory(dir, gameId, playerId) {
|
|
155319
|
+
try {
|
|
155320
|
+
const v = JSON.parse(await readFile24(fogHistoryPath(dir, gameId, playerId), "utf8"));
|
|
155321
|
+
return v && v.version === FOG_HISTORY_VERSION && v.gameId === gameId && v.playerId === playerId && Array.isArray(v.start) && v.turns && typeof v.turns === "object" ? v : void 0;
|
|
155322
|
+
} catch {
|
|
155323
|
+
return void 0;
|
|
155324
|
+
}
|
|
155325
|
+
}
|
|
155326
|
+
async function mergeFogHistory(dir, gameId, playerId, got) {
|
|
155327
|
+
const path = fogHistoryPath(dir, gameId, playerId);
|
|
155328
|
+
try {
|
|
155329
|
+
return await withPathLock(path, async () => {
|
|
155330
|
+
const was = await readFogHistory(dir, gameId, playerId);
|
|
155331
|
+
const start = got.start ?? was?.start;
|
|
155332
|
+
if (!start) return false;
|
|
155333
|
+
const next = { version: FOG_HISTORY_VERSION, gameId, playerId, start, turns: { ...was?.turns ?? {}, ...got.turns } };
|
|
155334
|
+
await mkdir19(fogHistoryDir(dir), { recursive: true, mode: 448 });
|
|
155335
|
+
const tmp = `${path}.${randomUUID10()}.tmp`;
|
|
155336
|
+
await writeFile18(tmp, JSON.stringify(next), { mode: 384 });
|
|
155337
|
+
await rename19(tmp, path);
|
|
155338
|
+
await prune3(dir);
|
|
155339
|
+
return true;
|
|
155340
|
+
});
|
|
155341
|
+
} catch {
|
|
155342
|
+
return false;
|
|
155343
|
+
}
|
|
155344
|
+
}
|
|
155345
|
+
async function prune3(dir) {
|
|
155346
|
+
const names2 = (await readdir14(fogHistoryDir(dir)).catch(() => [])).filter((n) => /^\d+-\d+\.json$/.test(n));
|
|
155347
|
+
if (names2.length <= MAX_FOG_HISTORIES) return;
|
|
155348
|
+
const withTimes = await Promise.all(names2.map(async (n) => ({ n, t: (await stat13(join29(fogHistoryDir(dir), n)).catch(() => void 0))?.mtimeMs ?? 0 })));
|
|
155349
|
+
withTimes.sort((a, b) => a.t - b.t);
|
|
155350
|
+
for (const { n } of withTimes.slice(0, names2.length - MAX_FOG_HISTORIES)) await rm6(join29(fogHistoryDir(dir), n), { force: true });
|
|
155351
|
+
}
|
|
155352
|
+
function missingTurns(h, completed) {
|
|
155353
|
+
const out = [];
|
|
155354
|
+
for (let n = 1; n <= completed && out.length < FOG_CAPTURE_TURNS2; n++) if (!h?.turns[String(n)]) out.push(n);
|
|
155355
|
+
return out;
|
|
155356
|
+
}
|
|
155357
|
+
|
|
155358
|
+
// src/tools/fog-capture.ts
|
|
155359
|
+
var GET_TURNS_RETURN = "warlight.shared.GetTurnsReturn";
|
|
155360
|
+
async function captureFogHistory(ctx, game, me) {
|
|
155361
|
+
try {
|
|
155362
|
+
if (!ctx.dataDir || game.state !== "Playing") return 0;
|
|
155363
|
+
const completed = turnsCompleted(game) ?? 0;
|
|
155364
|
+
if (completed < 1) return 0;
|
|
155365
|
+
const have = await readFogHistory(ctx.dataDir, game.id, me);
|
|
155366
|
+
const missing = missingTurns(have, completed);
|
|
155367
|
+
if (!missing.length) return 0;
|
|
155368
|
+
const env = await ctx.rpc.call("GetTurns", Method.GetTurns, (w) => writeGetTurnsParams(w, { gameId: game.id, turns: missing.map((n) => n - 1) }));
|
|
155369
|
+
if (!env.body.bool()) return 0;
|
|
155370
|
+
const got = readTurnsReturn((await ctx.bundle()).readClass(GET_TURNS_RETURN, env.body));
|
|
155371
|
+
if (!got) return 0;
|
|
155372
|
+
const turns = Object.fromEntries(Object.entries(got.turns).filter(([n]) => Number(n) <= completed));
|
|
155373
|
+
if (!Object.keys(turns).length && !got.start) return 0;
|
|
155374
|
+
return await mergeFogHistory(ctx.dataDir, game.id, me, { ...got.start ? { start: got.start } : {}, turns }) ? Object.keys(turns).length : 0;
|
|
155375
|
+
} catch {
|
|
155376
|
+
return 0;
|
|
155377
|
+
}
|
|
155378
|
+
}
|
|
155379
|
+
|
|
155171
155380
|
// src/analysis/headroom.ts
|
|
155172
155381
|
var HEADROOM_CAP = 1e5;
|
|
155173
155382
|
var byNum19 = (a, b) => a - b;
|
|
@@ -157608,6 +157817,7 @@ function registerTurnTools(server, ctx, opts = {}) {
|
|
|
157608
157817
|
// Owner request 2026-11-24: a self-Sanctions boost is measured on the plan's next income.
|
|
157609
157818
|
nextIncome: plan.expected.nextIncome
|
|
157610
157819
|
}) : { view: {}, warnings: [] };
|
|
157820
|
+
let fogCapture;
|
|
157611
157821
|
if (ctx.dataDir && turn !== null) {
|
|
157612
157822
|
if (whatIf) await captureObservation(ctx, game.id, me.id, [{ turn, board: seen2, source: "live" }]);
|
|
157613
157823
|
else
|
|
@@ -157630,6 +157840,7 @@ function registerTurnTools(server, ctx, opts = {}) {
|
|
|
157630
157840
|
cards: { hand: handLog(myCards), advice: cardAdviceLog(advice2.view) },
|
|
157631
157841
|
times: bootTimes(game)
|
|
157632
157842
|
});
|
|
157843
|
+
if (!whatIf) fogCapture = captureFogHistory(ctx, game, me.id);
|
|
157633
157844
|
}
|
|
157634
157845
|
const promised = turn !== null ? await promiseWarnings(ctx, { game, me, turn, graph, board: seen2, moves: plan.moves }) : [];
|
|
157635
157846
|
const myIncome = income - cards2.extraArmies;
|
|
@@ -158049,6 +158260,7 @@ function registerTurnTools(server, ctx, opts = {}) {
|
|
|
158049
158260
|
)
|
|
158050
158261
|
);
|
|
158051
158262
|
const inScope = (p) => !scope.large || scope.near.includes(p);
|
|
158263
|
+
await fogCapture;
|
|
158052
158264
|
return respond(view, VIEWS6, (rung) => ({
|
|
158053
158265
|
game: { id: game.id, name: game.name ?? null, turn: currentTurn(game) },
|
|
158054
158266
|
player: { id: me.id, name: me.name },
|
|
@@ -159730,19 +159942,19 @@ function registerMyGamesTool(server, ctx, deps = {}) {
|
|
|
159730
159942
|
var MAX_TEAM_RECORDS = 200;
|
|
159731
159943
|
var TEAM_RECORD_VERSION = 2;
|
|
159732
159944
|
var TEAM_FILE = /^\d+\.json$/;
|
|
159733
|
-
var teamsDir = (dir) =>
|
|
159734
|
-
var teamRecordPath = (dir, gameId) =>
|
|
159945
|
+
var teamsDir = (dir) => join30(dir, "teams");
|
|
159946
|
+
var teamRecordPath = (dir, gameId) => join30(teamsDir(dir), `${gameId}.json`);
|
|
159735
159947
|
var isRec23 = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
|
|
159736
|
-
var
|
|
159948
|
+
var isInt21 = (v) => typeof v === "number" && Number.isInteger(v);
|
|
159737
159949
|
async function readTeamFile(dir, gameId) {
|
|
159738
159950
|
try {
|
|
159739
|
-
const r = JSON.parse(await
|
|
159951
|
+
const r = JSON.parse(await readFile25(teamRecordPath(dir, gameId), "utf8"));
|
|
159740
159952
|
if (!isRec23(r) || r.version !== TEAM_RECORD_VERSION || r.gameId !== gameId) return void 0;
|
|
159741
|
-
if (!("teams" in r)) return
|
|
159953
|
+
if (!("teams" in r)) return isInt21(r.incompleteTurn) ? { incompleteTurn: r.incompleteTurn } : void 0;
|
|
159742
159954
|
if (!Array.isArray(r.teams)) return void 0;
|
|
159743
159955
|
const out = /* @__PURE__ */ new Map();
|
|
159744
159956
|
for (const e of r.teams) {
|
|
159745
|
-
if (!Array.isArray(e) || e.length !== 2 || !
|
|
159957
|
+
if (!Array.isArray(e) || e.length !== 2 || !isInt21(e[0]) || !isInt21(e[1]) || !carriesTeam(e[1])) return void 0;
|
|
159746
159958
|
out.set(e[0], e[1]);
|
|
159747
159959
|
}
|
|
159748
159960
|
return { teams: out };
|
|
@@ -159757,17 +159969,17 @@ async function readTeamRecord(dir, gameId) {
|
|
|
159757
159969
|
async function pruneTeams(dir, keep) {
|
|
159758
159970
|
const folder = teamsDir(dir);
|
|
159759
159971
|
const files = [];
|
|
159760
|
-
for (const name2 of await
|
|
159972
|
+
for (const name2 of await readdir15(folder)) {
|
|
159761
159973
|
if (!TEAM_FILE.test(name2) || name2 === `${keep}.json`) continue;
|
|
159762
159974
|
try {
|
|
159763
|
-
files.push({ name: name2, at: (await
|
|
159975
|
+
files.push({ name: name2, at: (await stat14(join30(folder, name2))).mtimeMs });
|
|
159764
159976
|
} catch {
|
|
159765
159977
|
}
|
|
159766
159978
|
}
|
|
159767
159979
|
const excess = files.length + 1 - MAX_TEAM_RECORDS;
|
|
159768
159980
|
if (excess <= 0) return;
|
|
159769
159981
|
files.sort((a, b) => a.at - b.at || a.name.localeCompare(b.name));
|
|
159770
|
-
for (const f of files.slice(0, excess)) await unlink16(
|
|
159982
|
+
for (const f of files.slice(0, excess)) await unlink16(join30(folder, f.name)).catch(() => {
|
|
159771
159983
|
});
|
|
159772
159984
|
}
|
|
159773
159985
|
async function writeRecord3(dir, gameId, body) {
|
|
@@ -164001,6 +164213,68 @@ function commanderText(c, replies) {
|
|
|
164001
164213
|
return `${where} falls to ${replies} of the replies tried (${COMMANDER_SIZING}, as warapp_submit_turn sizes them): ${hold}.`;
|
|
164002
164214
|
}
|
|
164003
164215
|
|
|
164216
|
+
// src/history-window.ts
|
|
164217
|
+
var HISTORY_MAX_CHARS = 25e5;
|
|
164218
|
+
var KEY2 = /^(standing|turn)(\d+)$/;
|
|
164219
|
+
function turnsOf(history) {
|
|
164220
|
+
const out = /* @__PURE__ */ new Set();
|
|
164221
|
+
for (const k of Object.keys(history)) {
|
|
164222
|
+
const m = KEY2.exec(k);
|
|
164223
|
+
if (m) out.add(Number(m[2]));
|
|
164224
|
+
}
|
|
164225
|
+
return [...out].sort((a, b) => a - b);
|
|
164226
|
+
}
|
|
164227
|
+
function historyWindow(history, o = {}) {
|
|
164228
|
+
if (!history || typeof history !== "object" || Array.isArray(history)) return { history };
|
|
164229
|
+
const h = history;
|
|
164230
|
+
const turns = turnsOf(h);
|
|
164231
|
+
if (!turns.length) return { history };
|
|
164232
|
+
const max = o.maxChars ?? HISTORY_MAX_CHARS;
|
|
164233
|
+
const first = turns[0];
|
|
164234
|
+
const last = turns[turns.length - 1];
|
|
164235
|
+
const from = Math.max(o.from ?? first, first);
|
|
164236
|
+
const to = Math.min(o.to ?? last, last);
|
|
164237
|
+
const out = {};
|
|
164238
|
+
let chars = 2;
|
|
164239
|
+
const add = (k, v) => {
|
|
164240
|
+
const size = JSON.stringify(k).length + JSON.stringify(v ?? null).length + 2;
|
|
164241
|
+
if (chars + size > max) return false;
|
|
164242
|
+
out[k] = v;
|
|
164243
|
+
chars += size;
|
|
164244
|
+
return true;
|
|
164245
|
+
};
|
|
164246
|
+
const isBoard = (k) => k === "distributionStanding" || k.startsWith("standing");
|
|
164247
|
+
const ordersOf3 = (v) => {
|
|
164248
|
+
if (o.player === void 0 || !v || typeof v !== "object" || !Array.isArray(v.orders)) return v;
|
|
164249
|
+
const t = v;
|
|
164250
|
+
return { ...t, orders: t.orders.filter((x) => !!x && typeof x === "object" && String(x.playerID) === o.player) };
|
|
164251
|
+
};
|
|
164252
|
+
if (from === first) {
|
|
164253
|
+
for (const [k, v] of Object.entries(h)) if (!KEY2.test(k) && !(o.boards === false && isBoard(k))) add(k, v);
|
|
164254
|
+
}
|
|
164255
|
+
let kept = null;
|
|
164256
|
+
let next;
|
|
164257
|
+
for (const n of turns) {
|
|
164258
|
+
if (n < from || n > to) continue;
|
|
164259
|
+
const pair2 = [`standing${n}`, `turn${n}`].filter((k) => k in h && !(o.boards === false && isBoard(k))).map((k) => [k, k.startsWith("turn") ? ordersOf3(h[k]) : h[k]]);
|
|
164260
|
+
const size = pair2.reduce((s, [k, v]) => s + JSON.stringify(k).length + JSON.stringify(v ?? null).length + 2, 0);
|
|
164261
|
+
if (chars + size > max) {
|
|
164262
|
+
next = n;
|
|
164263
|
+
break;
|
|
164264
|
+
}
|
|
164265
|
+
for (const [k, v] of pair2) add(k, v);
|
|
164266
|
+
kept = { first: kept?.first ?? n, last: n };
|
|
164267
|
+
}
|
|
164268
|
+
const window = {
|
|
164269
|
+
turns: kept,
|
|
164270
|
+
of: { first, last },
|
|
164271
|
+
...next !== void 0 ? { next } : {},
|
|
164272
|
+
chars,
|
|
164273
|
+
...next !== void 0 ? { note: `The history is too large for one result: turns ${kept ? `${kept.first}\u2013${kept.last}` : "none"} of ${first}\u2013${last} are here; read on with history_from ${next}.` } : {}
|
|
164274
|
+
};
|
|
164275
|
+
return { history: out, window };
|
|
164276
|
+
}
|
|
164277
|
+
|
|
164004
164278
|
// src/tools/how-lost.ts
|
|
164005
164279
|
var OUT_STATES3 = /* @__PURE__ */ new Set(["Eliminated", "Booted", "SurrenderAccepted"]);
|
|
164006
164280
|
var STATE_CAUSES = {
|
|
@@ -164613,16 +164887,20 @@ function registerGameTool(server, client, dir, env, identity, cards2) {
|
|
|
164613
164887
|
inputSchema: external_exports.object({
|
|
164614
164888
|
game_id: gameIdArg,
|
|
164615
164889
|
include_history: external_exports.boolean().optional().describe(
|
|
164616
|
-
|
|
164890
|
+
"Also fetch past turns (GetHistory; war.app documents it for finished games). The result then says whether the history read (`historyRead`: boards, first and last turn, layout) or why not (`historyUnreadable`: reason and the reply's top-level key names); the turns themselves only in view \"raw\", for an analysis of your own, bounded (#709): whole turns, oldest first, while they fit in about 2.5 MB, with `historyWindow` saying which turns came and, when more did not fit, `next` to pass as `history_from`; `history_player` keeps one player's orders and `history_boards: false` leaves the boards out. Default false."
|
|
164617
164891
|
),
|
|
164618
164892
|
include_chat: external_exports.boolean().optional().describe("Also fetch the game chat (GetChat). Default false."),
|
|
164893
|
+
history_from: external_exports.coerce.number().int().min(0).optional().describe('With include_history in view "raw": the first turn of history to include (default the first; #709).'),
|
|
164894
|
+
history_to: external_exports.coerce.number().int().min(0).optional().describe('With include_history in view "raw": the last turn of history to include (default the last).'),
|
|
164895
|
+
history_player: external_exports.coerce.number().int().positive().optional().describe(`With include_history in view "raw": only this player's orders (GameFeed id); the boards stay whole.`),
|
|
164896
|
+
history_boards: external_exports.boolean().optional().describe('With include_history in view "raw": false leaves out the per-turn boards, the orders alone (default true).'),
|
|
164619
164897
|
view: viewArg(
|
|
164620
164898
|
VIEWS11,
|
|
164621
164899
|
'compact (default) keeps the game state and turn, players with committed flags, a settings digest and a map summary; "full" is every normalized field (all settings as sent, the board standing) with the map summarized; "raw" is the whole normalized game including the full map.'
|
|
164622
164900
|
)
|
|
164623
164901
|
})
|
|
164624
164902
|
},
|
|
164625
|
-
async ({ game_id, include_history, include_chat, view }) => {
|
|
164903
|
+
async ({ game_id, include_history, include_chat, view, history_from, history_to, history_player, history_boards }) => {
|
|
164626
164904
|
const game = await client.getGame(game_id, {
|
|
164627
164905
|
settings: true,
|
|
164628
164906
|
...include_history ? { history: true } : {},
|
|
@@ -164652,10 +164930,25 @@ function registerGameTool(server, client, dir, env, identity, cards2) {
|
|
|
164652
164930
|
};
|
|
164653
164931
|
const report2 = include_history ? historyReport(game) : void 0;
|
|
164654
164932
|
const historyRead = report2 ? "read" in report2 ? { historyRead: report2.read } : { historyUnreadable: report2.unreadable } : {};
|
|
164933
|
+
const bounded2 = () => {
|
|
164934
|
+
if (game.history === void 0) return { game };
|
|
164935
|
+
const w = historyWindow(game.history, {
|
|
164936
|
+
...history_from !== void 0 ? { from: history_from } : {},
|
|
164937
|
+
...history_to !== void 0 ? { to: history_to } : {},
|
|
164938
|
+
// The history names players by in-game id: the GameFeed id less two check digits each end.
|
|
164939
|
+
...history_player !== void 0 ? { player: String(history_player).slice(2, -2) } : {},
|
|
164940
|
+
...history_boards === false ? { boards: false } : {}
|
|
164941
|
+
});
|
|
164942
|
+
return { game: { ...game, history: w.history }, ...w.window ? { historyWindow: w.window } : {} };
|
|
164943
|
+
};
|
|
164655
164944
|
return respond(view, VIEWS11, (rung) => {
|
|
164656
164945
|
if (rung === "compact") return { ...compact(game), ...folded, ...historyRead };
|
|
164657
|
-
if (rung === "full")
|
|
164658
|
-
|
|
164946
|
+
if (rung === "full") {
|
|
164947
|
+
const { history: _h, ...rest } = game;
|
|
164948
|
+
return { game: { ...rest, map: game.map ? mapSummary(game.map) : void 0 }, ...folded, ...historyRead };
|
|
164949
|
+
}
|
|
164950
|
+
const b = bounded2();
|
|
164951
|
+
return { game: b.game, ...b.historyWindow ? { historyWindow: b.historyWindow } : {} };
|
|
164659
164952
|
});
|
|
164660
164953
|
}
|
|
164661
164954
|
);
|
|
@@ -165085,7 +165378,7 @@ function registerJoinGameTool(server, ctx) {
|
|
|
165085
165378
|
}
|
|
165086
165379
|
};
|
|
165087
165380
|
},
|
|
165088
|
-
async execute({ gameId, name: name2, url: url4, team, color, account, join:
|
|
165381
|
+
async execute({ gameId, name: name2, url: url4, team, color, account, join: join33 }) {
|
|
165089
165382
|
await requireApprovedAccount(ctx, account);
|
|
165090
165383
|
const game = { id: gameId, name: name2, url: url4 };
|
|
165091
165384
|
let vacationEnded = false;
|
|
@@ -165123,7 +165416,7 @@ function registerJoinGameTool(server, ctx) {
|
|
|
165123
165416
|
unreadable: () => notShown(),
|
|
165124
165417
|
classify: (seated) => seated ? { status: "joined", outcome: "confirmed", game, ...extra() } : notShown()
|
|
165125
165418
|
});
|
|
165126
|
-
if (result2.outcome === "confirmed" &&
|
|
165419
|
+
if (result2.outcome === "confirmed" && join33) await captureJoin(ctx, gameId, Number(account), join33);
|
|
165127
165420
|
return result2;
|
|
165128
165421
|
}
|
|
165129
165422
|
}
|
|
@@ -165229,7 +165522,7 @@ var NotificationsFormatError = class extends McpToolError {
|
|
|
165229
165522
|
this.name = "NotificationsFormatError";
|
|
165230
165523
|
}
|
|
165231
165524
|
};
|
|
165232
|
-
var
|
|
165525
|
+
var isInt22 = (v) => typeof v === "number" && Number.isInteger(v);
|
|
165233
165526
|
var isStr3 = (v) => v === null || typeof v === "string";
|
|
165234
165527
|
function notificationOf(n) {
|
|
165235
165528
|
if (!isObj(n) || n.$type !== IN_APP_NOTIFICATION) throw new NotificationsFormatError("a notification is not an InAppNotification");
|
|
@@ -165244,10 +165537,10 @@ function notificationOf(n) {
|
|
|
165244
165537
|
const n4 = f[NF.n4];
|
|
165245
165538
|
const title = f[NF.title];
|
|
165246
165539
|
const unread = f[NF.unread];
|
|
165247
|
-
if (!(sent === null || sent instanceof Date) || !isStr3(data2) || !
|
|
165540
|
+
if (!(sent === null || sent instanceof Date) || !isStr3(data2) || !isInt22(n3) || !isStr3(n4) || !isStr3(title) || typeof unread !== "boolean") {
|
|
165248
165541
|
throw new NotificationsFormatError("an InAppNotification lacks its fields");
|
|
165249
165542
|
}
|
|
165250
|
-
const id = typeof rawId === "string" ? rawId.trim() :
|
|
165543
|
+
const id = typeof rawId === "string" ? rawId.trim() : isInt22(rawId) && rawId >= 0 ? String(rawId) : void 0;
|
|
165251
165544
|
if (id === void 0 || !NOTIFICATION_ID.test(id)) throw new NotificationsFormatError("a notification id is not a number");
|
|
165252
165545
|
return { id, sent: sent !== null && Number.isFinite(sent.getTime()) ? sent : null, data: data2, n3, n4, title, unread };
|
|
165253
165546
|
}
|
|
@@ -165258,7 +165551,7 @@ function readInAppNotifications(bundle, body) {
|
|
|
165258
165551
|
const f = fields(ret);
|
|
165259
165552
|
if (f.length !== 2) throw new NotificationsFormatError(`a GetInAppNotificationsReturn has ${f.length} fields, not 2`);
|
|
165260
165553
|
const [list4, total] = f;
|
|
165261
|
-
if (!(list4 === null || Array.isArray(list4)) || !
|
|
165554
|
+
if (!(list4 === null || Array.isArray(list4)) || !isInt22(total)) throw new NotificationsFormatError("no notification list");
|
|
165262
165555
|
const items = (list4 ?? []).filter((n) => n !== null).map(notificationOf);
|
|
165263
165556
|
return { items, total: Math.max(total, items.length) };
|
|
165264
165557
|
}
|
|
@@ -165742,14 +166035,14 @@ var FriendsFormatError = class extends McpToolError {
|
|
|
165742
166035
|
this.name = "FriendsFormatError";
|
|
165743
166036
|
}
|
|
165744
166037
|
};
|
|
165745
|
-
var
|
|
166038
|
+
var isInt23 = (v) => typeof v === "number" && Number.isInteger(v);
|
|
165746
166039
|
function friendOf(p) {
|
|
165747
166040
|
if (!isObj(p) || p.$type !== PLAYER_INFO2) throw new FriendsFormatError("an entry is not a PlayerInfo");
|
|
165748
166041
|
const f = fields(p);
|
|
165749
166042
|
if (f.length !== PLAYER_INFO_FIELDS) throw new FriendsFormatError(`a PlayerInfo has ${f.length} fields, not ${PLAYER_INFO_FIELDS}`);
|
|
165750
166043
|
const name2 = f[PI.name];
|
|
165751
166044
|
const playerId = f[PI.playerId];
|
|
165752
|
-
if (!(name2 === null || typeof name2 === "string") || !
|
|
166045
|
+
if (!(name2 === null || typeof name2 === "string") || !isInt23(playerId)) throw new FriendsFormatError("a PlayerInfo lacks its id or name");
|
|
165753
166046
|
return { playerId, name: name2 };
|
|
165754
166047
|
}
|
|
165755
166048
|
function readFriends(bundle, body) {
|
|
@@ -165770,7 +166063,7 @@ function readBlockedIds(html, bundle) {
|
|
|
165770
166063
|
const blocked = f[IP.blocked];
|
|
165771
166064
|
if (!(product === null || isObj(product) && product.$type === PRODUCT)) return void 0;
|
|
165772
166065
|
if (blocked === null) return [];
|
|
165773
|
-
if (!Array.isArray(blocked) || !blocked.every(
|
|
166066
|
+
if (!Array.isArray(blocked) || !blocked.every(isInt23)) return void 0;
|
|
165774
166067
|
return [...new Set(blocked)];
|
|
165775
166068
|
});
|
|
165776
166069
|
}
|
|
@@ -166524,7 +166817,7 @@ var LadderFormatError = class extends McpToolError {
|
|
|
166524
166817
|
this.name = "LadderFormatError";
|
|
166525
166818
|
}
|
|
166526
166819
|
};
|
|
166527
|
-
var
|
|
166820
|
+
var isInt24 = (v) => typeof v === "number" && Number.isInteger(v);
|
|
166528
166821
|
var isNum4 = (v) => typeof v === "number" && Number.isFinite(v);
|
|
166529
166822
|
var dateOf2 = (v) => v instanceof Date && Number.isFinite(v.getTime()) ? v.toISOString() : null;
|
|
166530
166823
|
function record5(v, type, count4) {
|
|
@@ -166542,7 +166835,7 @@ function list3(v, what) {
|
|
|
166542
166835
|
function namesOf2(v) {
|
|
166543
166836
|
const out = /* @__PURE__ */ new Map();
|
|
166544
166837
|
for (const e of list3(v, "player")) {
|
|
166545
|
-
if (!Array.isArray(e) || e.length !== 2 || !
|
|
166838
|
+
if (!Array.isArray(e) || e.length !== 2 || !isInt24(e[0])) continue;
|
|
166546
166839
|
if (e[1] === null || e[1] === void 0) {
|
|
166547
166840
|
out.set(e[0], null);
|
|
166548
166841
|
continue;
|
|
@@ -166554,8 +166847,8 @@ function namesOf2(v) {
|
|
|
166554
166847
|
}
|
|
166555
166848
|
var LP = { bestLeague: 0, bestRank: 1, bestRating: 2, previousRank: 3, league: 4, rank: 5, rating: 6, since: 8, gamesAtOnce: 9, metadata: 11, playerId: 12 };
|
|
166556
166849
|
var LP_FIELDS = 15;
|
|
166557
|
-
var rankOf = (v) =>
|
|
166558
|
-
var leagueOf = (v) =>
|
|
166850
|
+
var rankOf = (v) => isInt24(v) && v > 0 && v !== NOT_RANKED ? v : null;
|
|
166851
|
+
var leagueOf = (v) => isInt24(v) && v > 0 && v < LEAGUES.length ? LEAGUES[v] : null;
|
|
166559
166852
|
function trueSkillOf(metadata) {
|
|
166560
166853
|
if (typeof metadata !== "string" || metadata.length > 1e4) return null;
|
|
166561
166854
|
try {
|
|
@@ -166571,7 +166864,7 @@ function standingOf3(v, names2) {
|
|
|
166571
166864
|
const f = record5(v, LADDER_PLAYER, LP_FIELDS);
|
|
166572
166865
|
const playerId = f[LP.playerId];
|
|
166573
166866
|
const gamesAtOnce = f[LP.gamesAtOnce];
|
|
166574
|
-
if (!
|
|
166867
|
+
if (!isInt24(playerId) || !isInt24(gamesAtOnce)) throw new LadderFormatError("a LadderPlayer lacks its id");
|
|
166575
166868
|
const bestRating = f[LP.bestRating];
|
|
166576
166869
|
const rating = f[LP.rating];
|
|
166577
166870
|
return {
|
|
@@ -166595,7 +166888,7 @@ var LS = { id: 0, ladder: 1, metadata: 2, number: 3, state: 4, template: 5 };
|
|
|
166595
166888
|
function seasonOf(v, templates) {
|
|
166596
166889
|
const f = record5(v, LADDER_SEASON, 6);
|
|
166597
166890
|
const seasonId = f[LS.id];
|
|
166598
|
-
if (!
|
|
166891
|
+
if (!isInt24(seasonId)) throw new LadderFormatError("a LadderSeason lacks its id");
|
|
166599
166892
|
let meta3 = {};
|
|
166600
166893
|
if (typeof f[LS.metadata] === "string" && f[LS.metadata].length <= 1e5) {
|
|
166601
166894
|
try {
|
|
@@ -166607,19 +166900,19 @@ function seasonOf(v, templates) {
|
|
|
166607
166900
|
const startMs = typeof meta3.StartDate === "string" ? Date.parse(meta3.StartDate) : Number.NaN;
|
|
166608
166901
|
const lengthDays = isNum4(meta3.LengthInDays) ? meta3.LengthInDays : null;
|
|
166609
166902
|
const start = Number.isFinite(startMs) ? new Date(startMs) : null;
|
|
166610
|
-
const templateId =
|
|
166903
|
+
const templateId = isInt24(f[LS.template]) ? f[LS.template] : null;
|
|
166611
166904
|
const state = f[LS.state];
|
|
166612
166905
|
return {
|
|
166613
166906
|
seasonId,
|
|
166614
166907
|
ladder: ladderOf(f[LS.ladder])?.key ?? null,
|
|
166615
|
-
number:
|
|
166616
|
-
state:
|
|
166908
|
+
number: isInt24(f[LS.number]) ? f[LS.number] : null,
|
|
166909
|
+
state: isInt24(state) ? SEASON_STATES[state] ?? null : null,
|
|
166617
166910
|
templateId,
|
|
166618
166911
|
template: templateId !== null ? templates?.get(templateId) ?? null : null,
|
|
166619
166912
|
start: start ? start.toISOString() : null,
|
|
166620
166913
|
end: start && lengthDays !== null ? new Date(start.getTime() + lengthDays * 864e5).toISOString() : null,
|
|
166621
166914
|
lengthDays,
|
|
166622
|
-
gamesInSeason:
|
|
166915
|
+
gamesInSeason: isInt24(meta3.NumberOfGamesInSeason) ? meta3.NumberOfGamesInSeason : null
|
|
166623
166916
|
};
|
|
166624
166917
|
}
|
|
166625
166918
|
function gameOf2(v, names2) {
|
|
@@ -166628,16 +166921,16 @@ function gameOf2(v, names2) {
|
|
|
166628
166921
|
if (game === null || game === void 0) return null;
|
|
166629
166922
|
const g = record5(game, LADDER_GAME, 3);
|
|
166630
166923
|
const gameId = g[1];
|
|
166631
|
-
if (!
|
|
166924
|
+
if (!isInt24(gameId)) throw new LadderFormatError("a LadderGame lacks its id");
|
|
166632
166925
|
return {
|
|
166633
166926
|
gameId,
|
|
166634
|
-
seasonId:
|
|
166927
|
+
seasonId: isInt24(g[2]) ? g[2] : null,
|
|
166635
166928
|
finished: dateOf2(g[0]),
|
|
166636
166929
|
players: list3(players, "game player").filter((p) => p !== null && p !== void 0).map((p) => {
|
|
166637
166930
|
const r = record5(p, LADDER_GAME_PLAYER, 5);
|
|
166638
166931
|
const playerId = r[2];
|
|
166639
|
-
if (!
|
|
166640
|
-
return { playerId, name: names2.get(playerId) ?? null, team:
|
|
166932
|
+
if (!isInt24(playerId)) throw new LadderFormatError("a LadderGamePlayer lacks its id");
|
|
166933
|
+
return { playerId, name: names2.get(playerId) ?? null, team: isInt24(r[3]) ? r[3] : null, won: typeof r[4] === "boolean" ? r[4] : null };
|
|
166641
166934
|
})
|
|
166642
166935
|
};
|
|
166643
166936
|
}
|
|
@@ -166659,7 +166952,7 @@ function readLadderStats(bundle, body) {
|
|
|
166659
166952
|
const f = record5(bundle.readClass(LADDER_STAT, body), LADDER_STAT, 3);
|
|
166660
166953
|
out.push({
|
|
166661
166954
|
ladder: ladderOf(f[0])?.key ?? null,
|
|
166662
|
-
season:
|
|
166955
|
+
season: isInt24(f[2]) ? f[2] : null,
|
|
166663
166956
|
standing: f[1] === null || f[1] === void 0 ? null : standingOf3(f[1], /* @__PURE__ */ new Map())
|
|
166664
166957
|
});
|
|
166665
166958
|
}
|
|
@@ -166671,9 +166964,9 @@ function readLadderSeasons(bundle, body) {
|
|
|
166671
166964
|
if (f.length !== 4) throw new LadderFormatError(`a GetLadderSeasonsReturn has ${f.length} fields, not 4`);
|
|
166672
166965
|
const names2 = namesOf2(f[0]);
|
|
166673
166966
|
const templates = /* @__PURE__ */ new Map();
|
|
166674
|
-
for (const e of list3(f[2], "template")) if (Array.isArray(e) &&
|
|
166967
|
+
for (const e of list3(f[2], "template")) if (Array.isArray(e) && isInt24(e[0]) && typeof e[1] === "string") templates.set(e[0], e[1]);
|
|
166675
166968
|
const winners = /* @__PURE__ */ new Map();
|
|
166676
|
-
for (const e of list3(f[3], "winner")) if (Array.isArray(e) &&
|
|
166969
|
+
for (const e of list3(f[3], "winner")) if (Array.isArray(e) && isInt24(e[0])) winners.set(e[0], list3(e[1], "winner id").filter(isInt24));
|
|
166677
166970
|
return list3(f[1], "season").filter((s) => s !== null && s !== void 0).map((s) => {
|
|
166678
166971
|
const season = seasonOf(s, templates);
|
|
166679
166972
|
return { ...season, winners: (winners.get(season.seasonId) ?? []).map((playerId) => ({ playerId, name: names2.get(playerId) ?? null })) };
|
|
@@ -166692,7 +166985,7 @@ function readLadderSeason(bundle, body) {
|
|
|
166692
166985
|
return {
|
|
166693
166986
|
season: { ...season, template: season.template ?? template },
|
|
166694
166987
|
template,
|
|
166695
|
-
playerCount:
|
|
166988
|
+
playerCount: isInt24(f[4]) ? f[4] : null,
|
|
166696
166989
|
top,
|
|
166697
166990
|
aroundMe: standings(f[0], names2, "player").filter((p) => !shown2.has(p.playerId)),
|
|
166698
166991
|
me: f[9] === null || f[9] === void 0 ? null : standingOf3(f[9], names2),
|
|
@@ -166703,13 +166996,13 @@ function readLadderPlayers(bundle, body) {
|
|
|
166703
166996
|
const f = result(bundle, body, GET_LADDER_PLAYERS_RETURN);
|
|
166704
166997
|
if (!f) return { players: [], total: null };
|
|
166705
166998
|
if (f.length !== 3) throw new LadderFormatError(`a GetLadderPlayersReturn has ${f.length} fields, not 3`);
|
|
166706
|
-
return { players: standings(f[1], namesOf2(f[0]), "player"), total:
|
|
166999
|
+
return { players: standings(f[1], namesOf2(f[0]), "player"), total: isInt24(f[2]) ? f[2] : null };
|
|
166707
167000
|
}
|
|
166708
167001
|
function readLadderGames(bundle, body) {
|
|
166709
167002
|
const f = result(bundle, body, GET_LADDER_GAMES_RETURN);
|
|
166710
167003
|
if (!f) return { games: [], total: null };
|
|
166711
167004
|
if (f.length !== 4) throw new LadderFormatError(`a GetLadderGamesReturn has ${f.length} fields, not 4`);
|
|
166712
|
-
return { games: gamesOf(f[0], namesOf2(f[1])), total:
|
|
167005
|
+
return { games: gamesOf(f[0], namesOf2(f[1])), total: isInt24(f[3]) ? f[3] : null };
|
|
166713
167006
|
}
|
|
166714
167007
|
function recordOf2(games, playerId) {
|
|
166715
167008
|
const rec2 = { wins: 0, losses: 0, inProgress: 0, of: 0 };
|
|
@@ -166734,14 +167027,14 @@ function readLadderPlayer(bundle, body, playerId) {
|
|
|
166734
167027
|
const byId2 = new Map(players.map((p) => [p.playerId, p]));
|
|
166735
167028
|
if (f[6] === null || f[6] === void 0) throw new LadderFormatError("no LadderSeason");
|
|
166736
167029
|
const games = gamesOf(f[5], names2);
|
|
166737
|
-
const history = list3(f[0], "history").map((h) => record5(h, HISTORY_ITEM, 3)).filter((h) =>
|
|
167030
|
+
const history = list3(f[0], "history").map((h) => record5(h, HISTORY_ITEM, 3)).filter((h) => isInt24(h[0])).map((h) => ({ point: h[0], rank: rankOf(h[1]), rating: isNum4(h[2]) ? h[2] : null })).sort((a, b) => a.point - b.point).slice(-MAX_HISTORY_POINTS);
|
|
166738
167031
|
return {
|
|
166739
167032
|
season: seasonOf(f[6]),
|
|
166740
167033
|
player: player2,
|
|
166741
|
-
teammates: list3(f[8], "teammate").filter(
|
|
167034
|
+
teammates: list3(f[8], "teammate").filter(isInt24).map((id) => byId2.get(id)).filter((p) => p !== void 0),
|
|
166742
167035
|
notableWins: list3(f[3], "notable win").map((n) => {
|
|
166743
167036
|
const r = record5(n, NOTABLE_WIN, 3);
|
|
166744
|
-
if (!
|
|
167037
|
+
if (!isInt24(r[1])) throw new LadderFormatError("a notable win lacks its game id");
|
|
166745
167038
|
return { gameId: r[1], at: dateOf2(r[0]), opponent: r[2] === null || r[2] === void 0 ? null : standingOf3(r[2], names2) };
|
|
166746
167039
|
}),
|
|
166747
167040
|
ratingHistory: history,
|
|
@@ -167201,13 +167494,13 @@ var ClanFormatError = class extends McpToolError {
|
|
|
167201
167494
|
this.name = "ClanFormatError";
|
|
167202
167495
|
}
|
|
167203
167496
|
};
|
|
167204
|
-
var
|
|
167497
|
+
var isInt25 = (v) => typeof v === "number" && Number.isInteger(v);
|
|
167205
167498
|
var isNum5 = (v) => typeof v === "number" && Number.isFinite(v);
|
|
167206
167499
|
var strOf = (v) => typeof v === "string" ? v : null;
|
|
167207
167500
|
var dateOf3 = (v) => v instanceof Date && Number.isFinite(v.getTime()) ? v.toISOString() : null;
|
|
167208
|
-
var intOrNull3 = (v) =>
|
|
167501
|
+
var intOrNull3 = (v) => isInt25(v) ? v : null;
|
|
167209
167502
|
var arr = (v) => Array.isArray(v) ? v : [];
|
|
167210
|
-
var ints4 = (v) => Array.isArray(v) ? v.filter(
|
|
167503
|
+
var ints4 = (v) => Array.isArray(v) ? v.filter(isInt25) : [];
|
|
167211
167504
|
var shortType = (type) => type.split(".").pop();
|
|
167212
167505
|
function record6(v, type, count4) {
|
|
167213
167506
|
if (!isObj(v) || v.$type !== type) throw new ClanFormatError(`expected a ${shortType(type)}`);
|
|
@@ -167227,7 +167520,7 @@ function dict(v) {
|
|
|
167227
167520
|
function clanOf(v) {
|
|
167228
167521
|
const f = record6(v, CLAN, COUNT.clan);
|
|
167229
167522
|
const clanId = f[C.id];
|
|
167230
|
-
if (!
|
|
167523
|
+
if (!isInt25(clanId)) throw new ClanFormatError("a Clan has no id");
|
|
167231
167524
|
return {
|
|
167232
167525
|
clanId,
|
|
167233
167526
|
name: strOf(f[C.name]),
|
|
@@ -167286,7 +167579,7 @@ function readClan(bundle, body) {
|
|
|
167286
167579
|
manager: managers.includes(playerId)
|
|
167287
167580
|
};
|
|
167288
167581
|
});
|
|
167289
|
-
const warRanks = [...dict(f[CFC.warRanks])].filter((e) =>
|
|
167582
|
+
const warRanks = [...dict(f[CFC.warRanks])].filter((e) => isInt25(e[0]) && isInt25(e[1])).map(([season, rank]) => ({ season, rank })).sort((a, b) => a.season - b.season);
|
|
167290
167583
|
return {
|
|
167291
167584
|
...clan,
|
|
167292
167585
|
tagline: data2 ? strOf(data2[CD.tagline]) : null,
|
|
@@ -167306,7 +167599,7 @@ function readClanWars(bundle, body) {
|
|
|
167306
167599
|
(v) => {
|
|
167307
167600
|
const f = record6(v, CLAN_WAR_INFO, COUNT.warInfo);
|
|
167308
167601
|
const warId = f[CWI.season];
|
|
167309
|
-
if (!
|
|
167602
|
+
if (!isInt25(warId)) throw new ClanFormatError("a ClanWarInfo has no id");
|
|
167310
167603
|
const name2 = strOf(f[CWI.winnerName]);
|
|
167311
167604
|
return { warId, inProgress: name2 === null, winner: name2 === null ? null : { clanId: intOrNull3(f[CWI.winnerClan]), name: name2 } };
|
|
167312
167605
|
}
|
|
@@ -167319,7 +167612,7 @@ function readClanWar(bundle, body) {
|
|
|
167319
167612
|
if (f[CWR.war] === null) return null;
|
|
167320
167613
|
const war = record6(f[CWR.war], CLAN_WAR, COUNT.war);
|
|
167321
167614
|
const warId = war[CW.id];
|
|
167322
|
-
if (!
|
|
167615
|
+
if (!isInt25(warId)) throw new ClanFormatError("a ClanWar has no id");
|
|
167323
167616
|
const names2 = /* @__PURE__ */ new Map();
|
|
167324
167617
|
for (const c of arr(f[CWR.clans])) {
|
|
167325
167618
|
if (c === null) continue;
|
|
@@ -167329,7 +167622,7 @@ function readClanWar(bundle, body) {
|
|
|
167329
167622
|
const standings2 = arr(f[CWR.standings]).filter((v) => v !== null).map((v) => {
|
|
167330
167623
|
const s = record6(v, CLAN_WAR_CLAN, COUNT.warClan);
|
|
167331
167624
|
const clanId = s[CWC.clan];
|
|
167332
|
-
if (!
|
|
167625
|
+
if (!isInt25(clanId)) throw new ClanFormatError("a ClanWarClan has no clan id");
|
|
167333
167626
|
const before = s[CWC.pointsBefore];
|
|
167334
167627
|
const today = s[CWC.pointsToday];
|
|
167335
167628
|
return {
|
|
@@ -167381,14 +167674,14 @@ function readClanWarGames(bundle, body) {
|
|
|
167381
167674
|
leftover(body);
|
|
167382
167675
|
const players = /* @__PURE__ */ new Map();
|
|
167383
167676
|
for (const [id, p] of dict(f[GCWG.players])) {
|
|
167384
|
-
if (!
|
|
167677
|
+
if (!isInt25(id) || p === null || p === void 0) continue;
|
|
167385
167678
|
players.set(id, strOf(record6(p, PLAYER_INFO_2, COUNT.playerInfo2)[PI2_NAME]));
|
|
167386
167679
|
}
|
|
167387
167680
|
const templates = dict(f[GCWG.templates]);
|
|
167388
167681
|
const games = arr(f[GCWG.games]).filter((v) => v !== null).map((v) => {
|
|
167389
167682
|
const g = record6(v, CLAN_WAR_GAME, COUNT.game);
|
|
167390
167683
|
const id = g[CWG.id];
|
|
167391
|
-
if (!
|
|
167684
|
+
if (!isInt25(id)) throw new ClanFormatError("a ClanWarGame has no id");
|
|
167392
167685
|
const templateId = intOrNull3(g[CWG.template]);
|
|
167393
167686
|
return {
|
|
167394
167687
|
id,
|
|
@@ -167820,7 +168113,7 @@ var QuickmatchFormatError = class extends McpToolError {
|
|
|
167820
168113
|
this.name = "QuickmatchFormatError";
|
|
167821
168114
|
}
|
|
167822
168115
|
};
|
|
167823
|
-
var
|
|
168116
|
+
var isInt26 = (v) => typeof v === "number" && Number.isInteger(v);
|
|
167824
168117
|
var isNum6 = (v) => typeof v === "number" && Number.isFinite(v);
|
|
167825
168118
|
var short = (type) => type.split(".").pop();
|
|
167826
168119
|
function record7(v, type, count4) {
|
|
@@ -167831,7 +168124,7 @@ function record7(v, type, count4) {
|
|
|
167831
168124
|
}
|
|
167832
168125
|
function int2(f, i2, what) {
|
|
167833
168126
|
const v = f[i2];
|
|
167834
|
-
if (!
|
|
168127
|
+
if (!isInt26(v)) throw new QuickmatchFormatError(`no ${what}`);
|
|
167835
168128
|
return v;
|
|
167836
168129
|
}
|
|
167837
168130
|
var listOf = (v) => Array.isArray(v) ? v.filter((x) => x !== null && x !== void 0) : [];
|
|
@@ -167844,7 +168137,7 @@ function templateInfoOf(v) {
|
|
|
167844
168137
|
const f = record7(v, GAME_TEMPLATE_INFO, COUNTS.templateInfo);
|
|
167845
168138
|
const name2 = f[TI.name];
|
|
167846
168139
|
const mapId = f[TI.mapId];
|
|
167847
|
-
return { id: int2(f, TI.id, "template id"), name: typeof name2 === "string" ? name2 : null, mapId:
|
|
168140
|
+
return { id: int2(f, TI.id, "template id"), name: typeof name2 === "string" ? name2 : null, mapId: isInt26(mapId) ? mapId : null };
|
|
167848
168141
|
}
|
|
167849
168142
|
var SETTING_NAMES = new Map(
|
|
167850
168143
|
Object.entries(QUICKMATCH_TEMPLATE_SETTINGS).map(([k, v]) => [v, k])
|
|
@@ -167920,7 +168213,7 @@ function votingTemplateOf(v) {
|
|
|
167920
168213
|
return {
|
|
167921
168214
|
templateId: int2(f, QT.templateId, "template id"),
|
|
167922
168215
|
votes: int2(f, QT.votes, "vote count"),
|
|
167923
|
-
rank:
|
|
168216
|
+
rank: isInt26(rank) ? rank : null,
|
|
167924
168217
|
fixedRank: f[QT.fixedRank] === true,
|
|
167925
168218
|
created: created instanceof Date && Number.isFinite(created.getTime()) ? created.toISOString() : null
|
|
167926
168219
|
};
|
|
@@ -167944,7 +168237,7 @@ function readTemplateVoters(bundle, body) {
|
|
|
167944
168237
|
const f = record7(bundle.readClass(GET_VOTES_RETURN, body), GET_VOTES_RETURN, COUNTS.votesReturn);
|
|
167945
168238
|
const names2 = /* @__PURE__ */ new Map();
|
|
167946
168239
|
for (const e of Array.isArray(f[0]) ? f[0] : []) {
|
|
167947
|
-
if (Array.isArray(e) && e.length === 2 &&
|
|
168240
|
+
if (Array.isArray(e) && e.length === 2 && isInt26(e[0])) names2.set(e[0], nameOf2(e[1]));
|
|
167948
168241
|
}
|
|
167949
168242
|
return listOf(f[1]).map(voteOf).filter((v) => v.votes !== 0).map((v) => ({ playerId: v.playerId, name: names2.get(v.playerId) ?? null, votes: v.votes }));
|
|
167950
168243
|
}
|
|
@@ -169035,10 +169328,10 @@ var NEVER_MS3 = 922336666814565;
|
|
|
169035
169328
|
var TOURNAMENT_TYPES = ["single-elimination", "double-elimination", "round-robin", "cup"];
|
|
169036
169329
|
var TOURNAMENT_STATES = ["not-started", "in-progress", "finished", "cancelled"];
|
|
169037
169330
|
var TOURNAMENT_PLAYER_STATES = ["invited", "joined", "declined", "removed"];
|
|
169038
|
-
var
|
|
169331
|
+
var isInt27 = (v) => typeof v === "number" && Number.isInteger(v);
|
|
169039
169332
|
var isNum7 = (v) => typeof v === "number" && Number.isFinite(v);
|
|
169040
169333
|
var optStr = (v) => v === null || typeof v === "string";
|
|
169041
|
-
var optInt3 = (v) => v === null ||
|
|
169334
|
+
var optInt3 = (v) => v === null || isInt27(v);
|
|
169042
169335
|
var TournamentFormatError = class extends McpToolError {
|
|
169043
169336
|
constructor(detail2) {
|
|
169044
169337
|
super(`war.app's tournament data arrived in an unexpected shape (${detail2}).`, {
|
|
@@ -169054,7 +169347,7 @@ function record8(v, type, count4) {
|
|
|
169054
169347
|
if (f.length !== count4) throw new TournamentFormatError(`a ${type.split(".").pop()} has ${f.length} fields, not ${count4}`);
|
|
169055
169348
|
return f;
|
|
169056
169349
|
}
|
|
169057
|
-
var named3 = (list4, code2) =>
|
|
169350
|
+
var named3 = (list4, code2) => isInt27(code2) ? list4[code2] ?? null : null;
|
|
169058
169351
|
function bootOf(v) {
|
|
169059
169352
|
if (!isNum7(v) || v <= 0 || v >= NEVER_MS3) return null;
|
|
169060
169353
|
return { minutes: Math.round(v / 6e4), shown: formatDuration(v) };
|
|
@@ -169078,7 +169371,7 @@ function readTournamentInfo(v) {
|
|
|
169078
169371
|
const joined = f[TI2.joined];
|
|
169079
169372
|
const rounds = f[TI2.rounds];
|
|
169080
169373
|
const myState = f[TI2.myState];
|
|
169081
|
-
if (!
|
|
169374
|
+
if (!isInt27(id) || !optStr(name2) || !isInt27(teamSize) || !isInt27(perGame) || !isInt27(joined) || !optInt3(rounds) || !optInt3(myState)) {
|
|
169082
169375
|
throw new TournamentFormatError("a TournamentInfo lacks its id, name or sizes");
|
|
169083
169376
|
}
|
|
169084
169377
|
const type = named3(TOURNAMENT_TYPES, f[TI2.type]);
|
|
@@ -169087,7 +169380,7 @@ function readTournamentInfo(v) {
|
|
|
169087
169380
|
const coins = f[TI2.coins];
|
|
169088
169381
|
if (coins !== null) {
|
|
169089
169382
|
const c = record8(coins, TOURNAMENT_COINS, TC_FIELDS);
|
|
169090
|
-
if (
|
|
169383
|
+
if (isInt27(c[TC.entryFee])) entryFee = c[TC.entryFee];
|
|
169091
169384
|
}
|
|
169092
169385
|
return {
|
|
169093
169386
|
id,
|
|
@@ -169099,7 +169392,7 @@ function readTournamentInfo(v) {
|
|
|
169099
169392
|
realTime: f[TI2.realTime] === true,
|
|
169100
169393
|
directBoot: bootOf(f[TI2.directBoot]),
|
|
169101
169394
|
autoBoot: bootOf(f[TI2.autoBoot]),
|
|
169102
|
-
mapId:
|
|
169395
|
+
mapId: isInt27(f[TI2.mapId]) ? f[TI2.mapId] : null,
|
|
169103
169396
|
teamSize,
|
|
169104
169397
|
perGame,
|
|
169105
169398
|
rounds,
|
|
@@ -169125,15 +169418,15 @@ function readOpenTournaments(bundle, body) {
|
|
|
169125
169418
|
function readMyTournaments(bundle, body) {
|
|
169126
169419
|
if (!body.bool()) return { mine: [], open: [], total: 0 };
|
|
169127
169420
|
const f = record8(bundle.readClass(MY_TOURNAMENTS_RETURN, body), MY_TOURNAMENTS_RETURN, 4);
|
|
169128
|
-
return { total:
|
|
169421
|
+
return { total: isInt27(f[0]) ? f[0] : 0, open: infoList(f[1]), mine: infoList(f[3]) };
|
|
169129
169422
|
}
|
|
169130
|
-
var dictKeys = (v) => Array.isArray(v) ? v.map((e) => Array.isArray(e) ? e[0] : void 0).filter(
|
|
169423
|
+
var dictKeys = (v) => Array.isArray(v) ? v.map((e) => Array.isArray(e) ? e[0] : void 0).filter(isInt27) : [];
|
|
169131
169424
|
function readTemplate(v) {
|
|
169132
169425
|
if (v === null) return null;
|
|
169133
169426
|
const f = record8(v, TOURNAMENT_SETTINGS, TS_FIELDS);
|
|
169134
169427
|
const bool2 = (k) => typeof f[TS[k]] === "boolean" ? f[TS[k]] : null;
|
|
169135
169428
|
const str = (k) => typeof f[TS[k]] === "string" && f[TS[k]] !== "" ? f[TS[k]] : null;
|
|
169136
|
-
const int4 = (k) =>
|
|
169429
|
+
const int4 = (k) => isInt27(f[TS[k]]) ? f[TS[k]] : null;
|
|
169137
169430
|
const banking = int4("banking");
|
|
169138
169431
|
return {
|
|
169139
169432
|
templateId: int4("templateId"),
|
|
@@ -169161,25 +169454,25 @@ function readTemplate(v) {
|
|
|
169161
169454
|
function readPlayer(v) {
|
|
169162
169455
|
const f = record8(v, TOURNAMENT_PLAYER, TP_FIELDS);
|
|
169163
169456
|
const id = f[TP.id];
|
|
169164
|
-
if (!
|
|
169457
|
+
if (!isInt27(id)) throw new TournamentFormatError("a TournamentPlayer lacks its id");
|
|
169165
169458
|
return {
|
|
169166
169459
|
playerId: id,
|
|
169167
169460
|
name: nameOf3(f[TP.info]),
|
|
169168
169461
|
state: named3(TOURNAMENT_PLAYER_STATES, f[TP.state]),
|
|
169169
|
-
team:
|
|
169462
|
+
team: isInt27(f[TP.team]) ? f[TP.team] : -1
|
|
169170
169463
|
};
|
|
169171
169464
|
}
|
|
169172
169465
|
function readGame(v) {
|
|
169173
169466
|
const f = record8(v, TOURNAMENT_GAME, TG_FIELDS);
|
|
169174
169467
|
const id = f[TG.id];
|
|
169175
169468
|
const gameId = f[TG.gameId];
|
|
169176
|
-
if (!
|
|
169469
|
+
if (!isInt27(id) || !optInt3(gameId)) throw new TournamentFormatError("a TournamentGame lacks its id");
|
|
169177
169470
|
let players = null;
|
|
169178
169471
|
let stateCode = null;
|
|
169179
169472
|
if (f[TG.info] !== null) {
|
|
169180
169473
|
const g = record8(f[TG.info], TOURNAMENT_GAME_INFO, TGI_FIELDS);
|
|
169181
169474
|
players = g[0] === null ? null : dictKeys(g[0]);
|
|
169182
|
-
stateCode =
|
|
169475
|
+
stateCode = isInt27(g[1]) ? g[1] : null;
|
|
169183
169476
|
}
|
|
169184
169477
|
return { id, gameId, bye: f[TG.bye] !== null, players, stateCode };
|
|
169185
169478
|
}
|
|
@@ -169194,7 +169487,7 @@ function readTournamentDetails(bundle, body) {
|
|
|
169194
169487
|
const perGame = f[TN.perGame];
|
|
169195
169488
|
const rounds = f[TN.rounds];
|
|
169196
169489
|
const reason = f[TN.cancelReason];
|
|
169197
|
-
if (!
|
|
169490
|
+
if (!isInt27(id) || !isInt27(teamSize) || !isInt27(perGame) || !optInt3(rounds) || !optStr(reason)) {
|
|
169198
169491
|
throw new TournamentFormatError("a Tournament lacks its id or sizes");
|
|
169199
169492
|
}
|
|
169200
169493
|
const playersDict = f[TN.players];
|
|
@@ -169209,7 +169502,7 @@ function readTournamentDetails(bundle, body) {
|
|
|
169209
169502
|
teamSize,
|
|
169210
169503
|
perGame,
|
|
169211
169504
|
rounds,
|
|
169212
|
-
groups:
|
|
169505
|
+
groups: isInt27(f[TN.groups]) ? f[TN.groups] : 0,
|
|
169213
169506
|
startsAt: dateOf4(f[TN.startsAt]),
|
|
169214
169507
|
cancelReason: reason === "" ? null : reason,
|
|
169215
169508
|
players,
|
|
@@ -169226,12 +169519,12 @@ function readFavoriteTournaments(bundle, body) {
|
|
|
169226
169519
|
if (!(names2 === null || Array.isArray(names2)) || !(favs === null || Array.isArray(favs)) || !(placed === null || Array.isArray(placed))) {
|
|
169227
169520
|
throw new TournamentFormatError("no favourites lists");
|
|
169228
169521
|
}
|
|
169229
|
-
const favSet = new Set((favs ?? []).filter(
|
|
169522
|
+
const favSet = new Set((favs ?? []).filter(isInt27));
|
|
169230
169523
|
const placeOf = /* @__PURE__ */ new Map();
|
|
169231
|
-
for (const e of placed ?? []) if (Array.isArray(e) &&
|
|
169524
|
+
for (const e of placed ?? []) if (Array.isArray(e) && isInt27(e[0]) && isInt27(e[1])) placeOf.set(e[0], e[1]);
|
|
169232
169525
|
const out = [];
|
|
169233
169526
|
for (const e of names2 ?? []) {
|
|
169234
|
-
if (!Array.isArray(e) || !
|
|
169527
|
+
if (!Array.isArray(e) || !isInt27(e[0])) continue;
|
|
169235
169528
|
out.push({ id: e[0], name: typeof e[1] === "string" ? e[1] : null, favorite: favSet.has(e[0]), placed: placeOf.get(e[0]) ?? null });
|
|
169236
169529
|
}
|
|
169237
169530
|
for (const id of favSet) if (!out.some((t) => t.id === id)) out.push({ id, name: null, favorite: true, placed: placeOf.get(id) ?? null });
|
|
@@ -172645,7 +172938,7 @@ var InviteCodeFormatError = class extends McpToolError {
|
|
|
172645
172938
|
this.name = "InviteCodeFormatError";
|
|
172646
172939
|
}
|
|
172647
172940
|
};
|
|
172648
|
-
var
|
|
172941
|
+
var isInt28 = (v) => typeof v === "number" && Number.isInteger(v);
|
|
172649
172942
|
function readGameInviteCode2(bundle, body) {
|
|
172650
172943
|
if (!body.bool()) return void 0;
|
|
172651
172944
|
const rec2 = bundle.readClass(GAME_INVITE_CODE, body);
|
|
@@ -172657,10 +172950,10 @@ function readGameInviteCode2(bundle, body) {
|
|
|
172657
172950
|
const code2 = f[GC.code];
|
|
172658
172951
|
const gameId = f[GC.gameId];
|
|
172659
172952
|
const max = f[GC.maxPlayers];
|
|
172660
|
-
if (!(code2 === null || typeof code2 === "string") || !(gameId === null ||
|
|
172953
|
+
if (!(code2 === null || typeof code2 === "string") || !(gameId === null || isInt28(gameId))) {
|
|
172661
172954
|
throw new InviteCodeFormatError("a GameInviteCode lacks its fields");
|
|
172662
172955
|
}
|
|
172663
|
-
return { code: code2, gameId, maxPlayers:
|
|
172956
|
+
return { code: code2, gameId, maxPlayers: isInt28(max) ? max : null };
|
|
172664
172957
|
}
|
|
172665
172958
|
|
|
172666
172959
|
// src/tools/invites.ts
|
|
@@ -172815,7 +173108,7 @@ function registerAcceptInviteTool(server, ctx) {
|
|
|
172815
173108
|
}
|
|
172816
173109
|
};
|
|
172817
173110
|
},
|
|
172818
|
-
async execute({ gameId, name: name2, url: url4, color, account, join:
|
|
173111
|
+
async execute({ gameId, name: name2, url: url4, color, account, join: join33 }) {
|
|
172819
173112
|
await requireApprovedAccount(ctx, account);
|
|
172820
173113
|
const game = { id: gameId, name: untrustedText(name2), url: url4 };
|
|
172821
173114
|
let vacationEnded = false;
|
|
@@ -172848,7 +173141,7 @@ function registerAcceptInviteTool(server, ctx) {
|
|
|
172848
173141
|
unreadable: () => notShown(),
|
|
172849
173142
|
classify: (seated) => seated ? { status: "accepted", outcome: "confirmed", game, ...extra() } : notShown()
|
|
172850
173143
|
});
|
|
172851
|
-
if (result2.outcome === "confirmed" &&
|
|
173144
|
+
if (result2.outcome === "confirmed" && join33) await captureJoin(ctx, gameId, Number(account), join33);
|
|
172852
173145
|
return result2;
|
|
172853
173146
|
}
|
|
172854
173147
|
}
|
|
@@ -173888,7 +174181,7 @@ var CRC_TABLE = (() => {
|
|
|
173888
174181
|
var EXPORT_BLOB_MAX_BYTES = 256 * 1024 * 1024;
|
|
173889
174182
|
|
|
173890
174183
|
// node_modules/@chrischall/mcp-utils/dist/export/upload.js
|
|
173891
|
-
import { randomUUID as
|
|
174184
|
+
import { randomUUID as randomUUID11 } from "node:crypto";
|
|
173892
174185
|
var UPLOAD_KEY_PREFIX = "uploads";
|
|
173893
174186
|
var UPLOAD_SLOT_DEFAULT_TTL_MS = 30 * 60 * 1e3;
|
|
173894
174187
|
var MIB = 1024 * 1024;
|
|
@@ -174004,7 +174297,7 @@ function mintUploadSlot(store, req, opts = {}) {
|
|
|
174004
174297
|
checkPrefix(prefix);
|
|
174005
174298
|
const filename = sanitizeUploadFilename(req.filename);
|
|
174006
174299
|
const mimeType = resolveUploadMime(filename, req.mimeType);
|
|
174007
|
-
const blobKey = `${prefix}/${
|
|
174300
|
+
const blobKey = `${prefix}/${randomUUID11()}/${Buffer.from(filename, "utf8").toString("base64url")}`;
|
|
174008
174301
|
const { url: url4, expiresAtMs } = store.signPutUrl(blobKey, mimeType, {
|
|
174009
174302
|
ttlMs: opts.ttlMs ?? UPLOAD_SLOT_DEFAULT_TTL_MS,
|
|
174010
174303
|
...opts.now !== void 0 ? { now: opts.now } : {}
|
|
@@ -174858,21 +175151,61 @@ function benchmarkByEra(entries2) {
|
|
|
174858
175151
|
return { basis, eras };
|
|
174859
175152
|
}
|
|
174860
175153
|
|
|
175154
|
+
// src/analysis/fog-view.ts
|
|
175155
|
+
var OWNERS_EVERYWHERE = /* @__PURE__ */ new Set(["LightFog", "ModerateFog"]);
|
|
175156
|
+
var OWN_ONLY = /* @__PURE__ */ new Set(["VeryFoggy", "ExtremeFog"]);
|
|
175157
|
+
function fogView(graph, board, me, fog, allies = /* @__PURE__ */ new Set()) {
|
|
175158
|
+
const mode = fog ?? "Foggy";
|
|
175159
|
+
if (mode === "NoFog") return { ...board, territories: board.territories.map((t) => ({ ...t, fogLevel: "Visible" })) };
|
|
175160
|
+
const own2 = (t) => t.owner.kind === "player" && (t.owner.playerId === me || allies.has(t.owner.playerId));
|
|
175161
|
+
const mine3 = new Set(board.territories.filter(own2).map((t) => t.territoryId));
|
|
175162
|
+
const seen2 = new Set(mine3);
|
|
175163
|
+
if (!OWN_ONLY.has(mode)) for (const t of mine3) for (const n of neighborsOf(graph, t)) seen2.add(n);
|
|
175164
|
+
const ownersShown = OWNERS_EVERYWHERE.has(mode);
|
|
175165
|
+
return {
|
|
175166
|
+
...board,
|
|
175167
|
+
territories: board.territories.map((t) => {
|
|
175168
|
+
if (mine3.has(t.territoryId)) return { ...t, fogLevel: "You" };
|
|
175169
|
+
if (seen2.has(t.territoryId)) return { ...t, fogLevel: "Visible" };
|
|
175170
|
+
if (ownersShown) return { territoryId: t.territoryId, owner: t.owner, armies: null, fogLevel: "OwnerOnly" };
|
|
175171
|
+
return { territoryId: t.territoryId, owner: { kind: "unknown" }, armies: null, fogLevel: "Fogged" };
|
|
175172
|
+
})
|
|
175173
|
+
};
|
|
175174
|
+
}
|
|
175175
|
+
|
|
174861
175176
|
// src/calibration-source.ts
|
|
174862
|
-
import { readdir as
|
|
174863
|
-
import { join as
|
|
175177
|
+
import { readdir as readdir16, readFile as readFile26 } from "node:fs/promises";
|
|
175178
|
+
import { join as join31 } from "node:path";
|
|
175179
|
+
function boardsFor(input2) {
|
|
175180
|
+
const have = new Set(input2.cached.map((b) => b.turn));
|
|
175181
|
+
const lastTruth = Math.max(-1, ...input2.history.boards.map((b) => b.turn));
|
|
175182
|
+
const fill = input2.captured.filter((b) => !have.has(b.turn) && b.turn - 1 <= lastTruth);
|
|
175183
|
+
if (fill.length) {
|
|
175184
|
+
const cached5 = [...input2.cached, ...fill.map((b) => ({ turn: b.turn, board: b.board }))].sort((a, b) => a.turn - b.turn);
|
|
175185
|
+
return { cached: cached5, boards: input2.cached.length ? "cache+capture" : "capture", capturedTurns: fill.length };
|
|
175186
|
+
}
|
|
175187
|
+
if (input2.cached.length) return { cached: input2.cached, boards: "cache", capturedTurns: 0 };
|
|
175188
|
+
if (!input2.history.boards.length) return { cached: [], boards: "none", capturedTurns: 0 };
|
|
175189
|
+
const graph = buildGraph(input2.map);
|
|
175190
|
+
const me = input2.history.players.find((p) => p.id === input2.history.me);
|
|
175191
|
+
const allies = new Set(
|
|
175192
|
+
input2.history.players.filter((p) => p.id !== input2.history.me && typeof me?.team === "number" && me.team >= 0 && p.team === me.team).map((p) => p.id)
|
|
175193
|
+
);
|
|
175194
|
+
const cached4 = input2.history.boards.map((b) => ({ turn: b.turn + 1, board: fogView(graph, b.board, input2.history.me, input2.fog, allies) }));
|
|
175195
|
+
return { cached: cached4, boards: "rebuilt", capturedTurns: 0 };
|
|
175196
|
+
}
|
|
174864
175197
|
var count3 = (o, k) => {
|
|
174865
175198
|
o[k] = (o[k] ?? 0) + 1;
|
|
174866
175199
|
};
|
|
174867
175200
|
async function cachedGames(dir) {
|
|
174868
175201
|
const out = /* @__PURE__ */ new Map();
|
|
174869
175202
|
for (const sub of ["boards", "outlook", "decisions"]) {
|
|
174870
|
-
const names2 = await
|
|
175203
|
+
const names2 = await readdir16(join31(dir, sub)).catch(() => []);
|
|
174871
175204
|
for (const n of names2.filter((x) => /^\d+\.json$/.test(x)).sort()) {
|
|
174872
175205
|
const id = Number(n.slice(0, -5));
|
|
174873
175206
|
if (out.has(id)) continue;
|
|
174874
175207
|
try {
|
|
174875
|
-
const v = JSON.parse(await
|
|
175208
|
+
const v = JSON.parse(await readFile26(join31(dir, sub, n), "utf8"));
|
|
174876
175209
|
const o = v;
|
|
174877
175210
|
if (o && o.gameId === id && typeof o.playerId === "number") out.set(id, o.playerId);
|
|
174878
175211
|
} catch {
|
|
@@ -174882,7 +175215,7 @@ async function cachedGames(dir) {
|
|
|
174882
175215
|
return [...out].map(([gameId, playerId]) => ({ gameId, playerId }));
|
|
174883
175216
|
}
|
|
174884
175217
|
async function settingsRecordIds(dir) {
|
|
174885
|
-
const names2 = await
|
|
175218
|
+
const names2 = await readdir16(gamesDir(dir)).catch(() => []);
|
|
174886
175219
|
return names2.filter((n) => /^\d+\.json$/.test(n)).map((n) => Number(n.slice(0, -5))).sort((a, b) => a - b);
|
|
174887
175220
|
}
|
|
174888
175221
|
async function calibrationSources(dir) {
|
|
@@ -174929,13 +175262,21 @@ async function calibrationSources(dir) {
|
|
|
174929
175262
|
count3(out.skipped, "no-map");
|
|
174930
175263
|
continue;
|
|
174931
175264
|
}
|
|
174932
|
-
const
|
|
175265
|
+
const seenCached = fromReplay && replay.playerId === history.me ? replay.boards.map((b) => {
|
|
174933
175266
|
const o = replay.orders.get(b.turn);
|
|
174934
175267
|
return { turn: b.turn, board: b.board, ...o ? { orders: o } : {} };
|
|
174935
175268
|
}) : [];
|
|
174936
175269
|
const recovered = fromReplay ? void 0 : named4.get(path);
|
|
174937
175270
|
const gameId = fromReplay ? replay.game.id : recovered?.gameId;
|
|
174938
|
-
const
|
|
175271
|
+
const fog = fromReplay && replay.playerId === history.me ? await readFogHistory(dir, replay.game.id, replay.playerId) : void 0;
|
|
175272
|
+
const { cached: cached4, boards, capturedTurns } = boardsFor({
|
|
175273
|
+
cached: seenCached,
|
|
175274
|
+
captured: fog ? fogBoards(fog, replay.game.players, wallMultipliers(settings.raw)) : [],
|
|
175275
|
+
history,
|
|
175276
|
+
map: map2,
|
|
175277
|
+
fog: settings.fog
|
|
175278
|
+
});
|
|
175279
|
+
const sentTurns = seenCached.length ? seenCached.flatMap((b) => b.orders ? [b.turn] : []) : recovered ? [...(await readCachedOrders(dir, recovered.gameId, recovered.playerId)).keys()] : [];
|
|
174939
175280
|
const opening = {
|
|
174940
175281
|
...gameId !== void 0 ? { gameId } : {},
|
|
174941
175282
|
planned: rec2.outlook !== void 0,
|
|
@@ -174943,7 +175284,7 @@ async function calibrationSources(dir) {
|
|
|
174943
175284
|
failedAttackTurns: [...new Set((rec2.failedAttacks ?? []).map((f) => f.turn))].sort((a, b) => a - b),
|
|
174944
175285
|
sentTurns: [...new Set(sentTurns)].sort((a, b) => a - b)
|
|
174945
175286
|
};
|
|
174946
|
-
out.inputs.push({ source: fromReplay ? "settings-record" : "record-only", history, settings, map: map2, cached: cached4, opening });
|
|
175287
|
+
out.inputs.push({ source: fromReplay ? "settings-record" : "record-only", history, settings, map: map2, cached: cached4, boards, capturedTurns, opening });
|
|
174947
175288
|
}
|
|
174948
175289
|
for (const path of byPath.keys()) if (!seen2.has(path)) count3(out.statuses, "missing");
|
|
174949
175290
|
return out;
|
|
@@ -174963,8 +175304,9 @@ var HARNESS_APPROXIMATIONS = [
|
|
|
174963
175304
|
var yieldToLoop = () => new Promise((resolve6) => setImmediate(resolve6));
|
|
174964
175305
|
async function calibrationHarness(dir, opts = {}) {
|
|
174965
175306
|
const src = await calibrationSources(dir);
|
|
174966
|
-
const counts = { histories: src.statuses, skipped: src.skipped, scored: 0, recordOnly: 0, benchmarked: 0, samples: 0 };
|
|
175307
|
+
const counts = { histories: src.statuses, skipped: src.skipped, scored: 0, recordOnly: 0, benchmarked: 0, samples: 0, boards: {}, capturedTurns: 0, rebuiltScored: 0, rebuiltSamples: 0 };
|
|
174967
175308
|
const byFormat = {};
|
|
175309
|
+
const rebuiltByFormat = {};
|
|
174968
175310
|
const benchByFormat = {};
|
|
174969
175311
|
const eraEntries = [];
|
|
174970
175312
|
const lossEntries = [];
|
|
@@ -174973,6 +175315,8 @@ async function calibrationHarness(dir, opts = {}) {
|
|
|
174973
175315
|
opts.signal?.throwIfAborted();
|
|
174974
175316
|
const { history: h, settings, map: map2, cached: cached4 } = input2;
|
|
174975
175317
|
if (input2.source === "record-only") counts.recordOnly++;
|
|
175318
|
+
counts.boards[input2.boards] = (counts.boards[input2.boards] ?? 0) + 1;
|
|
175319
|
+
counts.capturedTurns += input2.capturedTurns;
|
|
174976
175320
|
const me = h.me;
|
|
174977
175321
|
const graph = graphOf(applyBonusOverrides(map2, settings));
|
|
174978
175322
|
const seated = h.players.filter((p) => holdsSeat(p.state));
|
|
@@ -174994,10 +175338,15 @@ async function calibrationHarness(dir, opts = {}) {
|
|
|
174994
175338
|
players: asPlaying,
|
|
174995
175339
|
opponents
|
|
174996
175340
|
});
|
|
174997
|
-
|
|
174998
|
-
|
|
175341
|
+
if (input2.boards === "rebuilt") {
|
|
175342
|
+
counts.rebuiltSamples += samples.length;
|
|
175343
|
+
if (samples.length) counts.rebuiltScored++;
|
|
175344
|
+
} else {
|
|
175345
|
+
counts.samples += samples.length;
|
|
175346
|
+
if (samples.length) counts.scored++;
|
|
175347
|
+
}
|
|
174999
175348
|
const agg = aggregateEstimates(samples);
|
|
175000
|
-
const f = byFormat[format] ??= {};
|
|
175349
|
+
const f = (input2.boards === "rebuilt" ? rebuiltByFormat : byFormat)[format] ??= {};
|
|
175001
175350
|
for (const [k, c] of Object.entries(agg)) f[k] = addCalibration(f[k] ?? {}, c);
|
|
175002
175351
|
const bench = openingBenchmark({
|
|
175003
175352
|
graph,
|
|
@@ -175041,29 +175390,34 @@ async function calibrationHarness(dir, opts = {}) {
|
|
|
175041
175390
|
await yieldToLoop();
|
|
175042
175391
|
}
|
|
175043
175392
|
opts.signal?.throwIfAborted();
|
|
175044
|
-
const
|
|
175045
|
-
|
|
175046
|
-
for (const [
|
|
175047
|
-
for (const [
|
|
175393
|
+
const summarize = (from) => {
|
|
175394
|
+
const out = {};
|
|
175395
|
+
for (const [format, ests] of Object.entries(from))
|
|
175396
|
+
for (const [k, c] of Object.entries(ests))
|
|
175397
|
+
for (const [band, stats] of Object.entries(c)) ((out[format] ??= {})[k] ??= {})[band] = ratioSummary(stats);
|
|
175398
|
+
return out;
|
|
175399
|
+
};
|
|
175400
|
+
const calibration = summarize(byFormat);
|
|
175401
|
+
const calibrationRebuilt = summarize(rebuiltByFormat);
|
|
175048
175402
|
const benchmark = {};
|
|
175049
175403
|
for (const [format, list4] of Object.entries(benchByFormat)) benchmark[format] = aggregateBenchmarks(list4);
|
|
175050
175404
|
benchmark.all = aggregateBenchmarks(Object.values(benchByFormat).flat());
|
|
175051
|
-
return { counts, calibration, benchmark, byEra: benchmarkByEra(eraEntries), earlyLosses: earlyLossesByEra(lossEntries) };
|
|
175405
|
+
return { counts, calibration, calibrationRebuilt, benchmark, byEra: benchmarkByEra(eraEntries), earlyLosses: earlyLossesByEra(lossEntries) };
|
|
175052
175406
|
}
|
|
175053
175407
|
|
|
175054
175408
|
// src/tools/calibration-job.ts
|
|
175055
175409
|
import { existsSync as existsSync4 } from "node:fs";
|
|
175056
|
-
import { readFile as
|
|
175057
|
-
import { join as
|
|
175410
|
+
import { readFile as readFile27 } from "node:fs/promises";
|
|
175411
|
+
import { join as join32 } from "node:path";
|
|
175058
175412
|
import { fileURLToPath as fileURLToPath2 } from "node:url";
|
|
175059
175413
|
import { Worker } from "node:worker_threads";
|
|
175060
175414
|
var HARNESS_LIMIT_MS = 3 * 60 * 60 * 1e3;
|
|
175061
|
-
var harnessFolder = (dir) =>
|
|
175062
|
-
var harnessResultPath = (dir) =>
|
|
175415
|
+
var harnessFolder = (dir) => join32(dir, "calibration");
|
|
175416
|
+
var harnessResultPath = (dir) => join32(harnessFolder(dir), "harness.json");
|
|
175063
175417
|
var jobs = /* @__PURE__ */ new Map();
|
|
175064
175418
|
async function readSaved(dir) {
|
|
175065
175419
|
try {
|
|
175066
|
-
const v = JSON.parse(await
|
|
175420
|
+
const v = JSON.parse(await readFile27(harnessResultPath(dir), "utf8"));
|
|
175067
175421
|
return typeof v.finishedAt === "string" && typeof v.result === "object" && v.result !== null ? v : void 0;
|
|
175068
175422
|
} catch {
|
|
175069
175423
|
return void 0;
|
|
@@ -175356,7 +175710,7 @@ function historyTurn(log, turn, opts = {}) {
|
|
|
175356
175710
|
...opts.full && e.firstMover !== void 0 ? { firstMover: e.firstMover } : {}
|
|
175357
175711
|
};
|
|
175358
175712
|
}
|
|
175359
|
-
var
|
|
175713
|
+
var turnsOf2 = (log) => Object.keys(log.turns).filter((k) => /^\d+$/.test(k)).map(Number).sort((a, b) => a - b);
|
|
175360
175714
|
function registerTurnHistoryTool(server, ctx) {
|
|
175361
175715
|
server.registerTool(
|
|
175362
175716
|
"warapp_turn_history",
|
|
@@ -175402,7 +175756,7 @@ function registerTurnHistoryTool(server, ctx) {
|
|
|
175402
175756
|
`No turn history is kept for game ${gameId}${me !== void 0 ? " for the signed-in account" : ""}.`,
|
|
175403
175757
|
"History is kept from the turns this server sees: plan or track a turn (warapp_plan_turn, warapp_track_opponents) first."
|
|
175404
175758
|
);
|
|
175405
|
-
const kept =
|
|
175759
|
+
const kept = turnsOf2(log);
|
|
175406
175760
|
if (!kept.length) refuse(`No turn of game ${gameId} is kept yet.`, "Plan or track a turn first.");
|
|
175407
175761
|
const hi = to_turn ?? kept.at(-1);
|
|
175408
175762
|
const lo = from_turn ?? Math.max(1, hi - DEFAULT_HISTORY_TURNS + 1);
|