@chrischall/warapp-mcp 0.3.0 → 0.4.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/dist/bundle.js CHANGED
@@ -37974,7 +37974,7 @@ var require_proxy_agent = __commonJS({
37974
37974
  return this.#client.destroy(err);
37975
37975
  }
37976
37976
  };
37977
- var ProxyAgent = class extends DispatcherBase {
37977
+ var ProxyAgent2 = class extends DispatcherBase {
37978
37978
  constructor(opts) {
37979
37979
  if (!opts || typeof opts === "object" && !(opts instanceof URL) && !opts.uri) {
37980
37980
  throw new InvalidArgumentError("Proxy uri is mandatory");
@@ -38148,7 +38148,7 @@ var require_proxy_agent = __commonJS({
38148
38148
  throw new InvalidArgumentError("Proxy-Authorization should be sent in ProxyAgent constructor");
38149
38149
  }
38150
38150
  }
38151
- module.exports = ProxyAgent;
38151
+ module.exports = ProxyAgent2;
38152
38152
  }
38153
38153
  });
38154
38154
 
@@ -38158,7 +38158,7 @@ var require_env_http_proxy_agent = __commonJS({
38158
38158
  "use strict";
38159
38159
  var DispatcherBase = require_dispatcher_base();
38160
38160
  var { kClose, kDestroy, kClosed, kDestroyed, kDispatch, kNoProxyAgent, kHttpProxyAgent, kHttpsProxyAgent } = require_symbols();
38161
- var ProxyAgent = require_proxy_agent();
38161
+ var ProxyAgent2 = require_proxy_agent();
38162
38162
  var Agent2 = require_agent();
38163
38163
  var DEFAULT_PORTS = {
38164
38164
  "http:": 80,
@@ -38175,13 +38175,13 @@ var require_env_http_proxy_agent = __commonJS({
38175
38175
  this[kNoProxyAgent] = new Agent2(agentOpts);
38176
38176
  const HTTP_PROXY = httpProxy ?? process.env.http_proxy ?? process.env.HTTP_PROXY;
38177
38177
  if (HTTP_PROXY) {
38178
- this[kHttpProxyAgent] = new ProxyAgent({ ...agentOpts, uri: HTTP_PROXY });
38178
+ this[kHttpProxyAgent] = new ProxyAgent2({ ...agentOpts, uri: HTTP_PROXY });
38179
38179
  } else {
38180
38180
  this[kHttpProxyAgent] = this[kNoProxyAgent];
38181
38181
  }
38182
38182
  const HTTPS_PROXY = httpsProxy ?? process.env.https_proxy ?? process.env.HTTPS_PROXY;
38183
38183
  if (HTTPS_PROXY) {
38184
- this[kHttpsProxyAgent] = new ProxyAgent({ ...agentOpts, uri: HTTPS_PROXY });
38184
+ this[kHttpsProxyAgent] = new ProxyAgent2({ ...agentOpts, uri: HTTPS_PROXY });
38185
38185
  } else {
38186
38186
  this[kHttpsProxyAgent] = this[kHttpProxyAgent];
38187
38187
  }
@@ -53716,7 +53716,7 @@ var require_undici = __commonJS({
53716
53716
  var BalancedPool = require_balanced_pool();
53717
53717
  var RoundRobinPool = require_round_robin_pool();
53718
53718
  var Agent2 = require_agent();
53719
- var ProxyAgent = require_proxy_agent();
53719
+ var ProxyAgent2 = require_proxy_agent();
53720
53720
  var Socks5ProxyAgent = require_socks5_proxy_agent();
53721
53721
  var EnvHttpProxyAgent = require_env_http_proxy_agent();
53722
53722
  var RetryAgent = require_retry_agent();
@@ -53743,7 +53743,7 @@ var require_undici = __commonJS({
53743
53743
  module.exports.BalancedPool = BalancedPool;
53744
53744
  module.exports.RoundRobinPool = RoundRobinPool;
53745
53745
  module.exports.Agent = Agent2;
53746
- module.exports.ProxyAgent = ProxyAgent;
53746
+ module.exports.ProxyAgent = ProxyAgent2;
53747
53747
  module.exports.Socks5ProxyAgent = Socks5ProxyAgent;
53748
53748
  module.exports.EnvHttpProxyAgent = EnvHttpProxyAgent;
53749
53749
  module.exports.RetryAgent = RetryAgent;
@@ -117350,6 +117350,25 @@ var WarappBundle = class {
117350
117350
  interp;
117351
117351
  /** Loaded from the cache because the current version could not be looked up. */
117352
117352
  fallback = false;
117353
+ /** Set when this is the pinned known-good client standing in for a refused current one. */
117354
+ standInFor;
117355
+ /** Set while this build stands in for a refused current client: the window (see {@link StandInWindow}). */
117356
+ standIn;
117357
+ /** The SHA-256 of this build's bytes (set by {@link loadBundle}); a build without one is never recorded. */
117358
+ digest;
117359
+ /** Records this build as one that decoded a live board (set by {@link loadBundle}). */
117360
+ recorder;
117361
+ recorded;
117362
+ /**
117363
+ * A live board decoded with this build, every byte consumed: record it as a build that works, so a
117364
+ * later client this server cannot read is stood in for by it (the owner, 2026-11-17: fall back
117365
+ * gracefully). Once per loaded bundle; never throws.
117366
+ */
117367
+ markDecoded() {
117368
+ if (this.recorded) return this.recorded.then((r) => r === "recorded" ? "unchanged" : r);
117369
+ this.recorded = this.recorder ? this.recorder().catch(() => "failed") : Promise.resolve("unchanged");
117370
+ return this.recorded;
117371
+ }
117353
117372
  /** The built-in reader helpers checked against this bundle's own definitions at load. */
117354
117373
  dialectCheck;
117355
117374
  /** What this bundle's decoding rests on, for the tools to show (#148). */
@@ -117358,7 +117377,9 @@ var WarappBundle = class {
117358
117377
  return {
117359
117378
  bundleVersion: this.version,
117360
117379
  fallback: this.fallback,
117361
- helpers: { verified: [...verified], unverified: [...unverified], ...reasons ? { reasons: { ...reasons } } : {} }
117380
+ helpers: { verified: [...verified], unverified: [...unverified], ...reasons ? { reasons: { ...reasons } } : {} },
117381
+ ...this.standInFor ? { standInFor: { ...this.standInFor } } : {},
117382
+ ...this.standIn ? { standIn: { ...this.standIn } } : {}
117362
117383
  };
117363
117384
  }
117364
117385
  /** Whether a type name is registered in this bundle. */
@@ -117381,6 +117402,11 @@ var WarappBundle = class {
117381
117402
  return this.interp.readClass(typeNameOrVar, reader2, budget);
117382
117403
  }
117383
117404
  };
117405
+ var KNOWN_GOOD_BUNDLE = {
117406
+ version: "639294131571648437",
117407
+ digest: "dec5cf174f6affb9e4c08802534cf8c6c6496eff977847aaf1497535e3371404"
117408
+ };
117409
+ var bundleUrlOf = (version3) => `https://${BUNDLE_HOST}${BUNDLE_PATH}?v=${version3}`;
117384
117410
  var BUNDLE_FILE = /^([A-Za-z0-9._-]{1,64})\.([0-9a-f]{64})\.js$/;
117385
117411
  var LEGACY_FILE = /^[A-Za-z0-9._-]{1,64}\.js(?:\.sha256)?$/;
117386
117412
  var PARTIAL_FILE = /^[A-Za-z0-9._-]{1,64}(?:\.[0-9a-f]{64})?\.js(?:\.sha256)?\.tmp-(\d+)(?:-[0-9a-f]+)?$/;
@@ -117407,7 +117433,7 @@ async function abandoned(file2, pid) {
117407
117433
  async function pruneBundles(dir, keep) {
117408
117434
  try {
117409
117435
  for (const name of await readdir4(dir)) {
117410
- if (name === keep) continue;
117436
+ if (keep.includes(name)) continue;
117411
117437
  const partial2 = PARTIAL_FILE.exec(name);
117412
117438
  if (!partial2 && !BUNDLE_FILE.test(name) && !LEGACY_FILE.test(name)) continue;
117413
117439
  if (partial2 && !await abandoned(join7(dir, name), Number(partial2[1]))) continue;
@@ -117473,18 +117499,143 @@ async function readVerified(file2, digest) {
117473
117499
  await rm(file2, { force: true });
117474
117500
  return null;
117475
117501
  }
117502
+ var isDialectRefusal = (e) => e instanceof BundleError && (e.kind === "dialect-mismatch" || e.kind === "dialect-unverified");
117503
+ async function cacheBundle(dataDir2, dir, name, src) {
117504
+ await ensurePrivateDir(dataDir2);
117505
+ await ensurePrivateDir(dir);
117506
+ await writePrivateAtomic(join7(dir, name), Buffer.from(src, "utf8"));
117507
+ }
117508
+ var KNOWN_GOOD_FILE = "known-good.json";
117509
+ var STAND_IN_FILE = "stand-in.json";
117510
+ var MAX_KNOWN_GOOD = 3;
117511
+ var DIGEST = /^[0-9a-f]{64}$/;
117512
+ var isRecorded = (v) => {
117513
+ if (typeof v !== "object" || v === null) return false;
117514
+ const r = v;
117515
+ return typeof r.version === "string" && SAFE_VERSION.test(r.version) && typeof r.digest === "string" && DIGEST.test(r.digest) && typeof r.verifiedAt === "string";
117516
+ };
117517
+ async function readKnownGood(dir) {
117518
+ let text;
117519
+ try {
117520
+ text = await readFile4(join7(dir, KNOWN_GOOD_FILE), "utf8");
117521
+ } catch (e) {
117522
+ return e.code === "ENOENT" ? [] : "unreadable";
117523
+ }
117524
+ try {
117525
+ const parsed = JSON.parse(text);
117526
+ const builds = parsed?.builds;
117527
+ if (!Array.isArray(builds)) return "unreadable";
117528
+ return builds.filter(isRecorded);
117529
+ } catch {
117530
+ return "unreadable";
117531
+ }
117532
+ }
117533
+ async function recordKnownGood(dataDir2, entry) {
117534
+ if (!isRecorded(entry)) return "failed";
117535
+ const dir = join7(dataDir2, "bundle");
117536
+ const file2 = join7(dir, KNOWN_GOOD_FILE);
117537
+ return withPathLock(file2, async () => {
117538
+ const builds = await readKnownGood(dir);
117539
+ if (builds === "unreadable") return "unreadable";
117540
+ const rest = builds.filter((b) => !(b.version === entry.version && b.digest === entry.digest));
117541
+ const next = [entry, ...rest].slice(0, MAX_KNOWN_GOOD);
117542
+ try {
117543
+ await ensurePrivateDir(dataDir2);
117544
+ await ensurePrivateDir(dir);
117545
+ await writePrivateAtomic(file2, `${JSON.stringify({ builds: next }, null, 2)}
117546
+ `);
117547
+ return "recorded";
117548
+ } catch {
117549
+ return "failed";
117550
+ }
117551
+ });
117552
+ }
117553
+ async function readWindow(dir) {
117554
+ try {
117555
+ const w = JSON.parse(await readFile4(join7(dir, STAND_IN_FILE), "utf8"));
117556
+ if (typeof w.refusedVersion === "string" && typeof w.since === "string" && !Number.isNaN(Date.parse(w.since))) {
117557
+ return { refusedVersion: w.refusedVersion, since: w.since };
117558
+ }
117559
+ } catch {
117560
+ }
117561
+ return void 0;
117562
+ }
117563
+ async function openWindow(dataDir2, dir, refusedVersion, reason, now) {
117564
+ const kept = await readWindow(dir);
117565
+ if (kept?.refusedVersion === refusedVersion) return kept.since;
117566
+ const since = new Date(now).toISOString();
117567
+ try {
117568
+ await ensurePrivateDir(dataDir2);
117569
+ await ensurePrivateDir(dir);
117570
+ await writePrivateAtomic(join7(dir, STAND_IN_FILE), `${JSON.stringify({ refusedVersion, since, reason }, null, 2)}
117571
+ `);
117572
+ } catch {
117573
+ }
117574
+ return since;
117575
+ }
117576
+ async function closeWindow(dir) {
117577
+ await rm(join7(dir, STAND_IN_FILE), { force: true }).catch(() => void 0);
117578
+ }
117579
+ async function loadPinned(opts, dir, kg) {
117580
+ const name = bundleName(kg.version, kg.digest);
117581
+ let src = await readVerified(join7(dir, name), kg.digest);
117582
+ if (src === null) {
117583
+ let fetched;
117584
+ try {
117585
+ fetched = await opts.fetchText(bundleUrlOf(kg.version));
117586
+ } catch {
117587
+ return void 0;
117588
+ }
117589
+ if (sha256(Buffer.from(fetched, "utf8")) !== kg.digest || !looksLikeBundle(fetched)) return void 0;
117590
+ try {
117591
+ await cacheBundle(opts.dataDir, dir, name, fetched);
117592
+ } catch {
117593
+ return void 0;
117594
+ }
117595
+ src = fetched;
117596
+ }
117597
+ try {
117598
+ const bundle = new WarappBundle(src, kg.version, opts.interp);
117599
+ bundle.digest = kg.digest;
117600
+ return { bundle, name };
117601
+ } catch {
117602
+ return void 0;
117603
+ }
117604
+ }
117605
+ function withRecorder(opts, bundle) {
117606
+ const now = opts.now ?? Date.now;
117607
+ bundle.recorder = async () => {
117608
+ if (!bundle.digest) return "unchanged";
117609
+ return recordKnownGood(opts.dataDir, { version: bundle.version, digest: bundle.digest, verifiedAt: new Date(now()).toISOString() });
117610
+ };
117611
+ return bundle;
117612
+ }
117613
+ async function recordedNames(dir) {
117614
+ const builds = await readKnownGood(dir);
117615
+ return builds === "unreadable" ? [] : builds.map((b) => bundleName(b.version, b.digest));
117616
+ }
117476
117617
  async function loadBundle(opts) {
117477
117618
  const pageUrl = opts.pageUrl ?? DEFAULT_PAGE_URL;
117478
117619
  const dir = join7(opts.dataDir, "bundle");
117620
+ const kg = opts.knownGood === void 0 ? KNOWN_GOOD_BUNDLE : opts.knownGood;
117621
+ const now = opts.now ?? Date.now;
117479
117622
  let source;
117480
117623
  try {
117481
117624
  source = discoverBundleUrl(await opts.fetchText(pageUrl), pageUrl);
117482
117625
  } catch (e) {
117483
- const cached4 = await newestVerified(dir);
117484
- if (!cached4) throw e;
117485
- const b = new WarappBundle(cached4.src, cached4.version, opts.interp);
117486
- b.fallback = true;
117487
- return b;
117626
+ for (const c of await cachedNewestFirst(dir)) {
117627
+ const src2 = await readVerified(c.file, c.digest);
117628
+ if (src2 === null) continue;
117629
+ try {
117630
+ const b = new WarappBundle(src2, c.version, opts.interp);
117631
+ b.fallback = true;
117632
+ b.digest = c.digest;
117633
+ return withRecorder(opts, b);
117634
+ } catch (err) {
117635
+ if (!isDialectRefusal(err)) throw err;
117636
+ }
117637
+ }
117638
+ throw e;
117488
117639
  }
117489
117640
  const { url: url4, version: version3 } = source;
117490
117641
  const cached3 = await newestVerified(dir, version3);
@@ -117497,17 +117648,39 @@ async function loadBundle(opts) {
117497
117648
  if (!looksLikeBundle(src)) {
117498
117649
  throw new BundleError("bad-bundle", `${url4} does not look like the war.app client bundle`);
117499
117650
  }
117500
- await ensurePrivateDir(opts.dataDir);
117501
- await ensurePrivateDir(dir);
117502
- const bytes = Buffer.from(src, "utf8");
117503
- name = bundleName(version3, sha256(bytes));
117504
- await writePrivateAtomic(join7(dir, name), bytes);
117651
+ name = bundleName(version3, sha256(Buffer.from(src, "utf8")));
117652
+ await cacheBundle(opts.dataDir, dir, name, src);
117505
117653
  }
117506
- const bundle = new WarappBundle(src, version3, opts.interp);
117507
- await pruneBundles(dir, name);
117508
- return bundle;
117654
+ const keepKnownGood = kg ? [bundleName(kg.version, kg.digest)] : [];
117655
+ const keepRecorded = await recordedNames(dir);
117656
+ let bundle;
117657
+ try {
117658
+ bundle = new WarappBundle(src, version3, opts.interp);
117659
+ } catch (e) {
117660
+ if (!isDialectRefusal(e)) throw e;
117661
+ const recorded = await readKnownGood(dir);
117662
+ const candidates = [
117663
+ ...recorded === "unreadable" ? [] : recorded.map(({ version: v, digest }) => ({ version: v, digest })),
117664
+ ...kg ? [kg] : []
117665
+ ].filter((c, i2, all2) => c.version !== version3 && all2.findIndex((o) => o.version === c.version && o.digest === c.digest) === i2);
117666
+ for (const c of candidates) {
117667
+ const standIn = await loadPinned(opts, dir, c);
117668
+ if (!standIn) continue;
117669
+ const since = await openWindow(opts.dataDir, dir, version3, e.message, now());
117670
+ standIn.bundle.standInFor = { version: version3, reason: e.message };
117671
+ standIn.bundle.standIn = { version: c.version, refusedVersion: version3, since, reason: e.message };
117672
+ await pruneBundles(dir, [name, standIn.name, ...keepKnownGood, ...keepRecorded]);
117673
+ return withRecorder(opts, standIn.bundle);
117674
+ }
117675
+ throw e;
117676
+ }
117677
+ bundle.digest = name.slice(version3.length + 1, -".js".length);
117678
+ await closeWindow(dir);
117679
+ await pruneBundles(dir, [name, ...keepKnownGood, ...keepRecorded]);
117680
+ return withRecorder(opts, bundle);
117509
117681
  }
117510
117682
  var FALLBACK_RETRY_MS = 5 * 6e4;
117683
+ var STAND_IN_RETRY_MS = 60 * 6e4;
117511
117684
  var BundleProvider = class {
117512
117685
  constructor(opts) {
117513
117686
  this.opts = opts;
@@ -117524,11 +117697,13 @@ var BundleProvider = class {
117524
117697
  this.pending = p;
117525
117698
  p.then(
117526
117699
  (b) => {
117527
- if (b.fallback && this.pending === p) this.fallbackUntil = now() + FALLBACK_RETRY_MS;
117700
+ if (this.pending !== p) return;
117701
+ if (b.standInFor) this.fallbackUntil = now() + STAND_IN_RETRY_MS;
117702
+ else if (b.fallback) this.fallbackUntil = now() + FALLBACK_RETRY_MS;
117528
117703
  },
117529
117704
  (e) => {
117530
117705
  if (this.pending !== p) return;
117531
- if (e instanceof BundleError && (e.kind === "dialect-mismatch" || e.kind === "dialect-unverified")) {
117706
+ if (isDialectRefusal(e)) {
117532
117707
  this.fallbackUntil = now() + FALLBACK_RETRY_MS;
117533
117708
  } else this.pending = null;
117534
117709
  }
@@ -117550,6 +117725,8 @@ function methodTakesAuth(methodId) {
117550
117725
  return !NO_AUTH_METHODS.has(methodId);
117551
117726
  }
117552
117727
  var SERVER_ERROR_MESSAGES = {
117728
+ // AuthFailed (live 2026-11-17): war.app's answer when the request's session is not signed in.
117729
+ 3: "war.app refused the request as not signed in (AuthFailed): the war.app session this server uses is signed out.",
117553
117730
  10: "war.app refused the order sequence \u2014 card plays must come in turn-phase order.",
117554
117731
  11: "Your orders deploy more or fewer armies than you are receiving this turn. Please verify your orders deploy the correct number.",
117555
117732
  51: "You hold more cards than this game allows, so war.app requires you to play or discard one this turn.",
@@ -117563,6 +117740,17 @@ var SERVER_ERROR_MESSAGES = {
117563
117740
  750: "Sorry, the slot you joined is no longer available. Please try again with a different slot."
117564
117741
  };
117565
117742
  var MAX_SERVER_MESSAGE = 200;
117743
+ var ProtocolVersionError = class extends McpToolError {
117744
+ constructor(methodName, answered) {
117745
+ super(`war.app answered ${methodName} in protocol version ${answered}; this server reads version ${PROTOCOL_VERSION}.`, {
117746
+ kind: "unknown",
117747
+ hint: "The war.app client may have changed; this server needs an update to read it."
117748
+ });
117749
+ this.answered = answered;
117750
+ }
117751
+ answered;
117752
+ name = "ProtocolVersionError";
117753
+ };
117566
117754
  var WarappServerError = class extends McpToolError {
117567
117755
  constructor(code2, message) {
117568
117756
  super(message, { kind: "unknown" });
@@ -117644,10 +117832,7 @@ var WarappRpc = class {
117644
117832
  );
117645
117833
  }
117646
117834
  if (env.version !== PROTOCOL_VERSION) {
117647
- throw new McpToolError(
117648
- `war.app answered ${methodName} in protocol version ${env.version}; this server reads version ${PROTOCOL_VERSION}.`,
117649
- { kind: "unknown", hint: "The war.app client may have changed; this server needs an update to read it." }
117650
- );
117835
+ throw new ProtocolVersionError(methodName, env.version);
117651
117836
  }
117652
117837
  if (env.method !== methodId) {
117653
117838
  throw new McpToolError(`war.app answered ${methodName} (method ${methodId}) with method ${env.method}.`, {
@@ -124776,7 +124961,7 @@ async function captureBearerHeader(opts) {
124776
124961
  }
124777
124962
 
124778
124963
  // src/version.ts
124779
- var VERSION2 = "0.3.0";
124964
+ var VERSION2 = "0.4.0";
124780
124965
 
124781
124966
  // src/transport-bridge.ts
124782
124967
  var SERVER_NAME = "warapp-mcp";
@@ -125168,15 +125353,52 @@ function beginFirstError(game) {
125168
125353
  async function loadLiveTerritories(ctx, game) {
125169
125354
  return (await loadLiveGame(ctx, game)).territories;
125170
125355
  }
125356
+ var PROTOCOL_UPDATE_ISSUE = "https://github.com/chrischall/warapp-mcp/issues/340";
125357
+ function standInLine(w) {
125358
+ if (!w) return void 0;
125359
+ return `war.app ships a client this server cannot read yet (${w.refusedVersion}), so the client build ${w.version}, which war.app still answers, stands in and decodes the board (since ${w.since}). Boards still decode exactly; war.app may stop answering the old build at any time, and this server then needs its update (#340, ${PROTOCOL_UPDATE_ISSUE}).`;
125360
+ }
125361
+ function standInOf(ctx) {
125362
+ return ctx.decoderReport()?.standIn;
125363
+ }
125364
+ var StandInClosedError = class extends McpToolError {
125365
+ constructor(window, cause) {
125366
+ const why = cause instanceof Error ? cause.message : String(cause);
125367
+ super(
125368
+ `war.app no longer answers the client build ${window.version} this server has decoded with since ${window.since} (standing in for ${window.refusedVersion}, which this server cannot read yet): ${why} Nothing was decoded; the old client is no longer accepted, so this server needs the protocol update (#340).`,
125369
+ {
125370
+ kind: "unknown",
125371
+ hint: `The old client is no longer accepted: this server needs the protocol update (${PROTOCOL_UPDATE_ISSUE}). Play in the war.app web client until then.`,
125372
+ cause
125373
+ }
125374
+ );
125375
+ this.window = window;
125376
+ }
125377
+ window;
125378
+ name = "StandInClosedError";
125379
+ };
125380
+ var isLayoutFailure = (e) => e instanceof ProtocolVersionError || e instanceof LiveBoardFormatError || e instanceof ProtocolError3 || e instanceof InterpError;
125381
+ async function windowClosed(ctx, bundle, e) {
125382
+ if (!isLayoutFailure(e)) return e;
125383
+ const b = bundle ?? await ctx.bundle().catch(() => void 0);
125384
+ const w = b?.report?.().standIn;
125385
+ return w ? new StandInClosedError(w, e) : e;
125386
+ }
125387
+ async function readLatestBoard(ctx, gameId) {
125388
+ let bundle;
125389
+ try {
125390
+ const env = await ctx.rpc.call("GetLatestGameInfo", Method.GetLatestGameInfo, (w) => writeGetLatestGameInfoParams(w, gameId));
125391
+ bundle = await ctx.bundle();
125392
+ const info = readLatestGameInfo(bundle, env.body);
125393
+ const territories = standingFromInfo(info);
125394
+ if (territories) await bundle.markDecoded?.();
125395
+ return { info, territories };
125396
+ } catch (e) {
125397
+ throw await windowClosed(ctx, bundle, e);
125398
+ }
125399
+ }
125171
125400
  async function loadLiveGame(ctx, game) {
125172
- const env = await ctx.rpc.call(
125173
- "GetLatestGameInfo",
125174
- Method.GetLatestGameInfo,
125175
- (w) => writeGetLatestGameInfoParams(w, game.id)
125176
- );
125177
- const bundle = await ctx.bundle();
125178
- const info = readLatestGameInfo(bundle, env.body);
125179
- const territories = standingFromInfo(info);
125401
+ const { info, territories } = await readLatestBoard(ctx, game.id);
125180
125402
  if (!territories) {
125181
125403
  if (awaitsBegin(game)) throw beginFirstError(game);
125182
125404
  throw new McpToolError(`war.app has no board for game ${game.id} yet (game state: ${game.state}).`, {
@@ -125344,6 +125566,43 @@ async function fetchPublic(url4, opts = {}) {
125344
125566
  }
125345
125567
  }
125346
125568
 
125569
+ // src/direct/egress.ts
125570
+ var import_undici2 = __toESM(require_undici(), 1);
125571
+ var EGRESS_PROXY_ENV = ["HTTPS_PROXY", "https_proxy"];
125572
+ var EGRESS_PROXY_INVALID = "HTTPS_PROXY is set but is not a usable http(s) proxy URL";
125573
+ var defaultProxyAgent = (url4) => new import_undici2.ProxyAgent(url4.href);
125574
+ var rawProxy = (env) => {
125575
+ for (const key of EGRESS_PROXY_ENV) {
125576
+ const v = readEnvVar(key, { env });
125577
+ if (v !== void 0) return v;
125578
+ }
125579
+ return void 0;
125580
+ };
125581
+ function egressProxyConfigured(env = process.env) {
125582
+ return rawProxy(env) !== void 0;
125583
+ }
125584
+ function egressProxyUrl(env = process.env) {
125585
+ const raw = rawProxy(env);
125586
+ if (raw === void 0) return void 0;
125587
+ let url4;
125588
+ try {
125589
+ url4 = new URL(raw);
125590
+ } catch {
125591
+ url4 = void 0;
125592
+ }
125593
+ if (!url4 || url4.protocol !== "http:" && url4.protocol !== "https:" || !url4.hostname) {
125594
+ throw new McpToolError(`${EGRESS_PROXY_INVALID}, so nothing was sent to war.app.`, {
125595
+ kind: "unknown",
125596
+ hint: "Set HTTPS_PROXY to a proxy URL such as http://127.0.0.1:8080, or unset it to connect directly."
125597
+ });
125598
+ }
125599
+ return url4;
125600
+ }
125601
+ function egressDispatcher(env = process.env, make = defaultProxyAgent) {
125602
+ const url4 = egressProxyUrl(env);
125603
+ return url4 ? make(url4) : void 0;
125604
+ }
125605
+
125347
125606
  // src/direct/transport.ts
125348
125607
  var TRANSPORT_ENV = "WARAPP_TRANSPORT";
125349
125608
  var MAX_DIRECT_BODY_BYTES = 16 * 1024 * 1024;
@@ -125410,18 +125669,28 @@ function toDirectResult(res) {
125410
125669
  }
125411
125670
  return out;
125412
125671
  }
125413
- var fetchViaPublic = async (url4, init) => {
125414
- const res = await fetchPublic(url4, {
125415
- ...directFetchOptions(init.method),
125416
- method: init.method,
125417
- headers: init.headers,
125418
- maxBytes: MAX_DIRECT_BODY_BYTES,
125419
- timeoutMs: DIRECT_TIMEOUT_MS,
125420
- ...init.body !== void 0 ? { body: init.body } : {},
125421
- ...init.signal ? { signal: init.signal } : {}
125422
- });
125423
- return toDirectResult(res);
125424
- };
125672
+ function createDirectFetch(opts = {}) {
125673
+ return async (url4, init) => {
125674
+ const proxy = egressDispatcher(opts.env ?? process.env, opts.proxyAgent);
125675
+ try {
125676
+ const res = await fetchPublic(url4, {
125677
+ ...directFetchOptions(init.method),
125678
+ method: init.method,
125679
+ headers: init.headers,
125680
+ maxBytes: MAX_DIRECT_BODY_BYTES,
125681
+ timeoutMs: DIRECT_TIMEOUT_MS,
125682
+ ...init.body !== void 0 ? { body: init.body } : {},
125683
+ ...init.signal ? { signal: init.signal } : {},
125684
+ ...proxy ? { dispatcher: proxy } : {}
125685
+ });
125686
+ return toDirectResult(res);
125687
+ } finally {
125688
+ await proxy?.close().catch(() => {
125689
+ });
125690
+ }
125691
+ };
125692
+ }
125693
+ var fetchViaPublic = createDirectFetch();
125425
125694
  function warappUrl(path) {
125426
125695
  const raw = /^https?:\/\//i.test(path) ? path : `https://${SESSION_HOST}${path.startsWith("/") ? "" : "/"}${path}`;
125427
125696
  let u;
@@ -125479,6 +125748,45 @@ function looksSignedOut(requestedUrl, res) {
125479
125748
  if (/\/services\b/i.test(reqPath) && !looksLikeHexFrame(res.body)) return true;
125480
125749
  return false;
125481
125750
  }
125751
+ var SIGNED_IN_PROBE_URL = `${SESSION_ORIGIN}/InviteToken`;
125752
+ var AUTH_FAILED_CODE = 3;
125753
+ var INVITE_TOKEN_TEXT = /Your invite token is\s*\d{5,20}/;
125754
+ function signInVerdict(res) {
125755
+ let path = "";
125756
+ try {
125757
+ path = new URL(res.url).pathname;
125758
+ } catch {
125759
+ path = "";
125760
+ }
125761
+ if (SIGNIN_PATH.test(path)) return "signed-out";
125762
+ if (res.status !== 200) return "unknown";
125763
+ if (INVITE_TOKEN_TEXT.test(res.body)) return "signed-in";
125764
+ if (hasPasswordInput(res.body)) return "signed-out";
125765
+ return "unknown";
125766
+ }
125767
+ function isAuthFailedReply(body) {
125768
+ if (!looksLikeHexFrame(body)) return false;
125769
+ try {
125770
+ return decodeReplyEnvelope(fromHex(body.trim())).error?.code === AUTH_FAILED_CODE;
125771
+ } catch {
125772
+ return false;
125773
+ }
125774
+ }
125775
+ var isServicesUrl = (url4) => {
125776
+ try {
125777
+ return /\/services\b/i.test(new URL(url4).pathname);
125778
+ } catch {
125779
+ return false;
125780
+ }
125781
+ };
125782
+ var isProbeUrl = (url4) => {
125783
+ try {
125784
+ const u = new URL(url4);
125785
+ return u.origin === SESSION_ORIGIN && u.pathname === new URL(SIGNED_IN_PROBE_URL).pathname;
125786
+ } catch {
125787
+ return false;
125788
+ }
125789
+ };
125482
125790
  var DirectBridge = class {
125483
125791
  constructor(store, fetchImpl = fetchViaPublic, hostSignIn = false) {
125484
125792
  this.store = store;
@@ -125488,6 +125796,24 @@ var DirectBridge = class {
125488
125796
  store;
125489
125797
  fetchImpl;
125490
125798
  hostSignIn;
125799
+ /** One GET of {@link SIGNED_IN_PROBE_URL} with the session; `none` when no session is linked. Never throws. */
125800
+ async checkSignedIn(signal) {
125801
+ const sess = await this.store.read();
125802
+ if (!sess) return "none";
125803
+ return this.probe(sess.authToken, signal);
125804
+ }
125805
+ async probe(token, signal) {
125806
+ try {
125807
+ const res = await this.fetchImpl(SIGNED_IN_PROBE_URL, {
125808
+ method: "GET",
125809
+ headers: { cookie: `AuthToken=${token}` },
125810
+ ...signal ? { signal } : {}
125811
+ });
125812
+ return signInVerdict(res);
125813
+ } catch {
125814
+ return "unknown";
125815
+ }
125816
+ }
125491
125817
  async fetch(init, signal) {
125492
125818
  const sess = await this.store.read();
125493
125819
  if (!sess) throw new SessionNotLinkedError(this.hostSignIn ? { hostSignIn: true } : {});
@@ -125516,13 +125842,19 @@ var DirectBridge = class {
125516
125842
  });
125517
125843
  }
125518
125844
  }
125519
- if (looksSignedOut(url4, res)) {
125520
- throw new SessionExpiredError({ capturedAt: sess.capturedAt, hostSignIn: this.hostSignIn || sess.origin === "host" });
125845
+ const suspect = looksSignedOut(url4, res) || answered && isServicesUrl(url4) && isAuthFailedReply(res.body);
125846
+ if (suspect) {
125847
+ const verdict = isProbeUrl(url4) && isSafeToReplay(init.method) ? signInVerdict(res) : await this.probe(token, signal);
125848
+ if (verdict !== "signed-in") {
125849
+ throw new SessionExpiredError({ capturedAt: sess.capturedAt, hostSignIn: this.hostSignIn || sess.origin === "host" });
125850
+ }
125521
125851
  }
125522
125852
  return { status: res.status, body: res.body, url: res.url };
125523
125853
  }
125524
125854
  };
125525
125855
  var RELINK_CHECK_MS = 5e3;
125856
+ var WALL_RETRY_BASE_MS = 6e4;
125857
+ var WALL_RETRY_MAX_MS = 30 * 6e4;
125526
125858
  function createDirectFirstBridge(opts) {
125527
125859
  const env = opts.env ?? process.env;
125528
125860
  const hosted = isHosted(env);
@@ -125531,16 +125863,21 @@ function createDirectFirstBridge(opts) {
125531
125863
  const mode = pinned ? "fetchproxy" : opts.mode ?? readTransportMode(TRANSPORT_ENV, opts.env ? { env: opts.env } : {});
125532
125864
  const store = hosted ? { read: async () => hostSession } : opts.store;
125533
125865
  const hostSignIn = hostSession !== null;
125534
- const direct = new DirectBridge(store, opts.directFetch, hostSignIn);
125866
+ const direct = new DirectBridge(store, opts.directFetch ?? createDirectFetch({ env }), hostSignIn);
125535
125867
  const log = opts.log ?? ((m) => console.error(m));
125536
125868
  const now = opts.now ?? Date.now;
125537
125869
  let wall = null;
125538
125870
  let stale = false;
125539
125871
  let lastRelinkCheck = Number.NEGATIVE_INFINITY;
125872
+ let wallsInARow = 0;
125540
125873
  const onFallback = ({ error: error62 }) => {
125541
- const next = error62 instanceof SessionExpiredError ? { kind: "session", capturedAt: error62.capturedAt ?? null } : error62 instanceof SessionNotLinkedError ? { kind: "session", capturedAt: null } : { kind: "edge" };
125542
- wall = next;
125543
125874
  const why = error62 instanceof SessionExpiredError ? "the linked war.app session is signed out" : error62 instanceof SessionNotLinkedError ? "no war.app session is linked" : "the site edge refused the direct request";
125875
+ const since = now();
125876
+ wallsInARow += 1;
125877
+ const retryAt = hosted ? since + Math.min(WALL_RETRY_BASE_MS * 2 ** (wallsInARow - 1), WALL_RETRY_MAX_MS) : null;
125878
+ const timing = { reason: why, since, retryAt };
125879
+ const next = error62 instanceof SessionExpiredError ? { kind: "session", capturedAt: error62.capturedAt ?? null, ...timing } : error62 instanceof SessionNotLinkedError ? { kind: "session", capturedAt: null, ...timing } : { kind: "edge", ...timing };
125880
+ wall = next;
125544
125881
  log(
125545
125882
  `[warapp-mcp] Direct transport unavailable (${why}) \u2014 switching to the ContextMint Bridge browser bridge. Keep a ${SESSION_HOST} tab open and approve the pairing prompt in the extension if one appears` + (next.kind !== "session" ? "." : hostSignIn ? `. ${HOST_SIGN_IN_ADVICE}` : hosted ? "." : "; run warapp_link_session to return to the direct transport.")
125546
125883
  );
@@ -125556,11 +125893,15 @@ function createDirectFirstBridge(opts) {
125556
125893
  onFallback
125557
125894
  });
125558
125895
  let legs = build2();
125559
- const liftSessionWall = () => {
125560
- if (wall?.kind !== "session") return;
125896
+ const liftWall = () => {
125897
+ if (!wall) return;
125561
125898
  wall = null;
125562
125899
  legs = build2();
125563
125900
  };
125901
+ const liftSessionWall = () => {
125902
+ if (wall?.kind !== "session") return;
125903
+ liftWall();
125904
+ };
125564
125905
  const relinkedSinceWall = async () => {
125565
125906
  if (wall?.kind !== "session") return false;
125566
125907
  const t = now();
@@ -125574,12 +125915,16 @@ function createDirectFirstBridge(opts) {
125574
125915
  liftSessionWall();
125575
125916
  stale = false;
125576
125917
  }
125918
+ if (mode === "auto" && wall?.retryAt != null && now() >= wall.retryAt) liftWall();
125577
125919
  let reached;
125578
125920
  return legs.run(async (leg, ctx) => {
125579
125921
  if (leg === direct) {
125580
125922
  try {
125581
125923
  const res = await direct.fetch(init, ctx.signal);
125582
- if (res.status === 200) stale = false;
125924
+ if (res.status === 200) {
125925
+ stale = false;
125926
+ wallsInARow = 0;
125927
+ }
125583
125928
  return res;
125584
125929
  } catch (err) {
125585
125930
  if (err instanceof SessionExpiredError) {
@@ -125601,6 +125946,23 @@ function createDirectFirstBridge(opts) {
125601
125946
  bridgeTransport: () => legs.bridgeTransport(),
125602
125947
  stats: () => legs.stats(),
125603
125948
  sessionStale: () => stale,
125949
+ wall: () => wall ? {
125950
+ kind: wall.kind,
125951
+ reason: wall.reason,
125952
+ since: new Date(wall.since).toISOString(),
125953
+ retryAt: wall.retryAt === null ? null : new Date(wall.retryAt).toISOString()
125954
+ } : null,
125955
+ checkSession: async () => {
125956
+ const verdict = await direct.checkSignedIn();
125957
+ if (verdict === "signed-in") {
125958
+ stale = false;
125959
+ wallsInARow = 0;
125960
+ if (mode === "auto") liftWall();
125961
+ } else if (verdict === "signed-out") {
125962
+ stale = true;
125963
+ }
125964
+ return verdict;
125965
+ },
125604
125966
  sessionLinked: () => {
125605
125967
  stale = false;
125606
125968
  if (mode === "auto") liftSessionWall();
@@ -125776,12 +126138,7 @@ function beginnable(game, me) {
125776
126138
  requirePlaying(game, mySeat(game, me));
125777
126139
  }
125778
126140
  async function liveBoard(ctx, gameId) {
125779
- const env = await ctx.rpc.call(
125780
- "GetLatestGameInfo",
125781
- Method.GetLatestGameInfo,
125782
- (w) => writeGetLatestGameInfoParams(w, gameId)
125783
- );
125784
- return standingFromInfo(readLatestGameInfo(await ctx.bundle(), env.body)) ?? void 0;
126141
+ return (await readLatestBoard(ctx, gameId)).territories ?? void 0;
125785
126142
  }
125786
126143
  function registerBeginTurnTool(server, ctx) {
125787
126144
  defineGatedWrite(
@@ -137973,6 +138330,8 @@ function registerTurnTools(server, ctx, opts = {}) {
137973
138330
  const guessOrders = guess ? guessOrdersOf(orders, guess) : void 0;
137974
138331
  const owedLine = surrenderOwedLine(surrenders);
137975
138332
  if (owedLine) warnings.unshift(owedLine);
138333
+ const standInNote = standInLine(standInOf(ctx));
138334
+ if (standInNote) warnings.unshift(standInNote);
137976
138335
  const paceRecord = PACE_TURNS.includes(turnsCompleted(game)) ? await mapRecordFor(ctx.dataDir, opts.env, game.settings?.mapId) : void 0;
137977
138336
  const pace = paceRecord && paceRecord !== "unreadable" ? paceView(paceRecord, turnsCompleted(game), myIncome) : void 0;
137978
138337
  return respond(view, VIEWS6, (rung) => ({
@@ -138599,6 +138958,8 @@ function registerTurnTools(server, ctx, opts = {}) {
138599
138958
  })
138600
138959
  );
138601
138960
  if (belowPlan) warnings.push(belowPlan);
138961
+ const standInNote = standInLine(standInOf(ctx));
138962
+ if (standInNote) warnings.unshift(standInNote);
138602
138963
  const merged = /* @__PURE__ */ new Map();
138603
138964
  for (const d of deploys) {
138604
138965
  const m = merged.get(d.territory.id);
@@ -141234,6 +141595,8 @@ function registerCheckPlanTool(server, ctx) {
141234
141595
  });
141235
141596
  const belowPlan = await bordersBelowPlan(ctx, { game, map: map2, me, turn, territories, info, history, teamsKnown, given: { deploys, moves } });
141236
141597
  const warnings = [
141598
+ // The owner, 2026-11-17: while an older build stands in for a client this server cannot read, say so first.
141599
+ ...[standInLine(standInOf(ctx))].filter((w) => w !== void 0),
141237
141600
  // #275 (b): an untrusted estimate is the first thing said (not under an explicit enemy_deploy).
141238
141601
  ...enemy_deploy === void 0 ? tripwireWarnings(trip.tripwires, (w) => untrustedOf.get(w.player) ?? untrustedDeploy(w, income), (p) => estimates.find((x) => x.playerId === p)?.estimate) : [],
141239
141602
  ...award ? assumedWarning(award) : [],
@@ -141582,6 +141945,10 @@ function registerGameTool(server, client, dir, env, identity) {
141582
141945
  // src/tools/healthcheck.ts
141583
141946
  var PROBE_PATH = `/API/GameFeed?GameID=${PROBE_GAME_ID}&GetMap=false`;
141584
141947
  var BRIDGE_PROBE_PATH = "/";
141948
+ function withStandIn(health, deps) {
141949
+ const w = deps.standIn?.();
141950
+ return w ? { ...health, standIn: w } : health;
141951
+ }
141585
141952
  function sessionSummary(env, now) {
141586
141953
  const s = readSessionSync(env);
141587
141954
  if (!s) return { linked: false };
@@ -141594,6 +141961,24 @@ function transportHealth(status, env, now) {
141594
141961
  }
141595
141962
  function registerHealthcheckTool(server, bridge2, direct, deps = {}) {
141596
141963
  const now = deps.now ?? Date.now;
141964
+ let lastCheck = {};
141965
+ const checkSession = async () => {
141966
+ lastCheck = {};
141967
+ if (!direct.checkSession || direct.status().mode === "fetchproxy") return void 0;
141968
+ if (!readSessionSync(deps.env)) return void 0;
141969
+ const verdict = await direct.checkSession().catch(() => "unknown");
141970
+ if (verdict === "none") return void 0;
141971
+ const wall = direct.wall?.() ?? null;
141972
+ lastCheck = { sessionCheck: verdict, ...wall ? { wall } : {} };
141973
+ return verdict;
141974
+ };
141975
+ const health = () => withStandIn({ ...transportHealth(direct.status(), deps.env, now), ...lastCheck }, deps);
141976
+ const signedOut = () => new SessionExpiredError({ hostSignIn: readSessionSync(deps.env)?.origin === "host" });
141977
+ const classifySignedOut = (err) => err instanceof SessionExpiredError ? {
141978
+ kind: "session_expired",
141979
+ hint: "war.app shows the session the live tools use as signed out. " + (err.hostSignIn ? HOST_SIGN_IN_ADVICE : "Run warapp_link_session to relink.")
141980
+ } : void 0;
141981
+ let resolvedVerdict;
141597
141982
  registerAdaptiveHealthcheckTool({
141598
141983
  server,
141599
141984
  prefix: "warapp",
@@ -141608,32 +141993,42 @@ function registerHealthcheckTool(server, bridge2, direct, deps = {}) {
141608
141993
  bridge: {
141609
141994
  probePath: BRIDGE_PROBE_PATH,
141610
141995
  transport: () => bridge2.transport(),
141611
- path: () => transportHealth(direct.status(), deps.env, now),
141996
+ path: health,
141612
141997
  probeFn: async (path) => {
141613
- const res = await (await bridge2.ready()).fetch({ method: "GET", path });
141998
+ const verdict = await checkSession();
141999
+ if (verdict === "signed-out") throw signedOut();
142000
+ const viaRouter = verdict === "signed-in" && direct.ready !== void 0;
142001
+ const leg = viaRouter ? await direct.ready() : await bridge2.ready();
142002
+ const res = await leg.fetch({ method: "GET", path });
141614
142003
  if (res.status !== 200) {
141615
- throw new McpToolError(`war.app answered HTTP ${res.status} through the bridge.`, {
142004
+ throw new McpToolError(`war.app answered HTTP ${res.status}${viaRouter ? "" : " through the bridge"}.`, {
141616
142005
  status: res.status,
141617
142006
  kind: "http"
141618
142007
  });
141619
142008
  }
141620
142009
  return res.body;
141621
- }
142010
+ },
142011
+ classifyThrown: classifySignedOut
141622
142012
  },
141623
142013
  credential: {
141624
142014
  probePath: PROBE_PATH,
141625
142015
  resolveCredential: async () => {
141626
- const health = transportHealth(direct.status(), deps.env, now);
142016
+ resolvedVerdict = await checkSession();
142017
+ const detail2 = health();
141627
142018
  try {
141628
142019
  readCredentials(deps.env);
141629
- return { source: "env", detail: health };
142020
+ return { source: "env", detail: detail2 };
141630
142021
  } catch (e) {
141631
- if (e instanceof WarappConfigError) return { source: null, detail: { ...health, reason: e.message } };
142022
+ if (e instanceof WarappConfigError) return { source: null, detail: { ...detail2, reason: e.message } };
141632
142023
  throw e;
141633
142024
  }
141634
142025
  },
141635
- probeFn: () => new WarappClient(deps).probeAuth(),
141636
- classifyThrown: (err) => err instanceof McpToolError && err.kind === "credential_rejected" ? { kind: "credential_rejected", hint: AUTH_FAILED_HINT } : void 0,
142026
+ probeFn: async () => {
142027
+ const res = await new WarappClient(deps).probeAuth();
142028
+ if (resolvedVerdict === "signed-out") throw signedOut();
142029
+ return res;
142030
+ },
142031
+ classifyThrown: (err) => err instanceof McpToolError && err.kind === "credential_rejected" ? { kind: "credential_rejected", hint: AUTH_FAILED_HINT } : classifySignedOut(err),
141637
142032
  hints: { no_credential: `Set WARAPP_EMAIL and WARAPP_API_TOKEN (token from ${TOKEN_URL}).` }
141638
142033
  }
141639
142034
  });
@@ -142206,7 +142601,9 @@ function registerSessionTools(server, deps) {
142206
142601
  return {
142207
142602
  decoder: {
142208
142603
  ...d,
142209
- ...d.fallback ? { note: "A cached copy of war.app's client is decoding boards: the current version could not be looked up." } : {}
142604
+ ...d.standInFor ? {
142605
+ note: `war.app's current client (${d.standInFor.version}) cannot be read by this server, so the client release it was written for (still served by war.app) is decoding boards; war.app answers this server in that layout.`
142606
+ } : d.fallback ? { note: "A cached copy of war.app's client is decoding boards: the current version could not be looked up." } : {}
142210
142607
  }
142211
142608
  };
142212
142609
  };
@@ -142224,11 +142621,13 @@ function registerSessionTools(server, deps) {
142224
142621
  async () => {
142225
142622
  if (hosted && hostToken === "ok") {
142226
142623
  const pt2 = deps.pushTransport?.();
142624
+ const wall = deps.transport.wall?.() ?? null;
142227
142625
  const base = {
142228
142626
  hosted: true,
142229
142627
  linked: true,
142230
142628
  linkedBy: "host",
142231
142629
  activeTransport: deps.transport.activeLeg(),
142630
+ ...wall ? { wall } : {},
142232
142631
  ...pt2 ? { pushTransport: pt2 } : {},
142233
142632
  ...decoderView(),
142234
142633
  hostedNote: NOTE_HOSTED_DIRECT
@@ -142257,7 +142656,16 @@ function registerSessionTools(server, deps) {
142257
142656
  return respond(void 0, ["compact"], () => {
142258
142657
  if (!session) return { linked: false, activeTransport, ...push, hint: HINT_NOT_LINKED };
142259
142658
  const ageSeconds = Math.max(0, Math.round((now() - Date.parse(session.capturedAt)) / 1e3));
142260
- const base = { linked: true, host: session.host, capturedAt: session.capturedAt, ageSeconds, activeTransport, ...push };
142659
+ const wall = deps.transport.wall?.() ?? null;
142660
+ const base = {
142661
+ linked: true,
142662
+ host: session.host,
142663
+ capturedAt: session.capturedAt,
142664
+ ageSeconds,
142665
+ activeTransport,
142666
+ ...wall ? { wall } : {},
142667
+ ...push
142668
+ };
142261
142669
  return deps.transport.sessionStale() ? { ...base, sessionExpired: true, hint: HINT_EXPIRED } : base;
142262
142670
  });
142263
142671
  }
@@ -145856,9 +146264,9 @@ function websocketUrl(sid) {
145856
146264
  if (!/^[A-Za-z0-9_-]+$/.test(sid)) throw new Error("war.app returned an unusable push-socket session id.");
145857
146265
  return `wss://${WS_HOST}/socket.io/1/websocket/${sid}`;
145858
146266
  }
145859
- function pushWebSocketLeg(bridge2, readSession2, seams = {}) {
146267
+ function pushWebSocketLeg(bridge2, readSession2, seams = {}, env = process.env) {
145860
146268
  return {
145861
- select: () => bridge2.status().transport === "direct",
146269
+ select: () => bridge2.status().transport === "direct" && !egressProxyConfigured(env),
145862
146270
  session: readSession2,
145863
146271
  ...seams
145864
146272
  };
@@ -146584,7 +146992,7 @@ function pushListenerFor(key, opts) {
146584
146992
  }
146585
146993
 
146586
146994
  // src/direct/sign-in.ts
146587
- var import_undici2 = __toESM(require_undici(), 1);
146995
+ var import_undici3 = __toESM(require_undici(), 1);
146588
146996
  var ORIGIN = `https://${SESSION_HOST}`;
146589
146997
  var SIGN_IN_URL = `${ORIGIN}/LogIn`;
146590
146998
  var AUTH_COOKIE2 = "AuthToken";
@@ -146594,10 +147002,12 @@ var SIGN_IN_TIMEOUT_MS = 3e4;
146594
147002
  var SIGN_IN_MAX_BODY_BYTES = 2 * 1024 * 1024;
146595
147003
  function createSignInFetch(opts = {}) {
146596
147004
  const maxBytes = opts.maxBytes ?? SIGN_IN_MAX_BODY_BYTES;
147005
+ const proxy = opts.dispatcher ? void 0 : egressProxyUrl(opts.env ?? process.env);
147006
+ const makeProxy = opts.proxyAgent ?? defaultProxyAgent;
146597
147007
  return async (url4, init) => {
146598
- const owned = opts.dispatcher ? void 0 : createPublicOnlyDispatcher();
147008
+ const owned = opts.dispatcher ? void 0 : proxy ? makeProxy(proxy) : createPublicOnlyDispatcher();
146599
147009
  try {
146600
- const res = await (0, import_undici2.fetch)(url4, {
147010
+ const res = await (0, import_undici3.fetch)(url4, {
146601
147011
  method: init.method,
146602
147012
  headers: init.headers,
146603
147013
  ...init.body !== void 0 ? { body: init.body } : {},
@@ -146693,7 +147103,7 @@ async function exchange(creds, jar, opts) {
146693
147103
  if (!creds.email.trim() || !creds.password) {
146694
147104
  throw refusal2("no_credential", "Signing in to war.app needs both the email and the password; nothing was sent.");
146695
147105
  }
146696
- const fetchHop = opts.fetch ?? createSignInFetch();
147106
+ const fetchHop = opts.fetch ?? createSignInFetch(opts.env ? { env: opts.env } : {});
146697
147107
  const timeoutMs = opts.timeoutMs ?? SIGN_IN_TIMEOUT_MS;
146698
147108
  const timeout = AbortSignal.timeout(timeoutMs);
146699
147109
  const signal = opts.signal ? AbortSignal.any([opts.signal, timeout]) : timeout;
@@ -146845,7 +147255,7 @@ function registerAllTools(server, deps = {}) {
146845
147255
  // The cached signed-in account is discarded whenever the account behind the router may have changed.
146846
147256
  identity: () => bridge2.identityState()
146847
147257
  });
146848
- registerHealthcheckTool(server, fetchproxy, bridge2, deps);
147258
+ registerHealthcheckTool(server, fetchproxy, bridge2, { ...deps, standIn: () => live.decoderReport()?.standIn });
146849
147259
  registerGameTool(server, client, () => dataDir(deps.env), deps.env, () => live.myInviteToken());
146850
147260
  registerMapTool(server, client, live);
146851
147261
  registerMapStatsTool(server, {
@@ -146887,13 +147297,14 @@ function registerAllTools(server, deps = {}) {
146887
147297
  registerDiplomacyTool(server, live, deps.env ? { env: deps.env } : {});
146888
147298
  const push = deps.push ?? pushListenerFor(fetchproxy, {
146889
147299
  transport: () => bridge2.ready(),
146890
- webSocket: pushWebSocketLeg(bridge2, () => readSession(deps.env)),
147300
+ webSocket: pushWebSocketLeg(bridge2, () => readSession(deps.env), {}, deps.env ?? process.env),
146891
147301
  extras: () => live.rpc.extras
146892
147302
  });
146893
147303
  registerSessionTools(server, {
146894
147304
  transport: {
146895
147305
  activeLeg: () => bridge2.status().transport,
146896
147306
  sessionStale: () => bridge2.sessionStale(),
147307
+ wall: () => bridge2.wall(),
146897
147308
  sessionLinked: () => bridge2.sessionLinked()
146898
147309
  },
146899
147310
  pushTransport: () => push.status().transport,