@hadoku/game-server 0.1.178 → 0.1.180

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (43) hide show
  1. package/dist/base-path.d.ts +1 -3
  2. package/dist/base-path.js +1 -2
  3. package/dist/busy.d.ts +0 -1
  4. package/dist/busy.js +0 -1
  5. package/dist/config.d.ts +0 -5
  6. package/dist/config.js +0 -3
  7. package/dist/edge-auth.d.ts +3 -2
  8. package/dist/edge-auth.js +3 -2
  9. package/dist/gate.d.ts +0 -12
  10. package/dist/gate.js +0 -2
  11. package/dist/http/client-events.d.ts +2 -3
  12. package/dist/http/page.d.ts +1 -1
  13. package/dist/http/page.js +2 -1
  14. package/dist/http/room-core.d.ts +5 -5
  15. package/dist/http/room-core.js +33 -12
  16. package/dist/http/usage.d.ts +3 -6
  17. package/dist/http/usage.js +1 -2
  18. package/dist/log.d.ts +0 -8
  19. package/dist/log.js +1 -8
  20. package/dist/play/engine-runtime.d.ts +7 -32
  21. package/dist/play/engine-runtime.js +0 -9
  22. package/dist/play/host.d.ts +7 -6
  23. package/dist/play/host.js +82 -14
  24. package/dist/play/jvm-transport.d.ts +5 -0
  25. package/dist/play/local-jvm.d.ts +5 -6
  26. package/dist/play/local-jvm.js +10 -46
  27. package/dist/play/runtimes/relay-match.d.ts +2 -0
  28. package/dist/play/runtimes/relay-match.js +3 -0
  29. package/dist/play/runtimes/streamed.d.ts +2 -24
  30. package/dist/play/runtimes/streamed.js +2 -37
  31. package/dist/relay-game.d.ts +4 -1
  32. package/dist/relay-game.js +16 -3
  33. package/dist/room/lobby.d.ts +6 -7
  34. package/dist/room/lobby.js +11 -9
  35. package/dist/room/session.d.ts +1 -1
  36. package/dist/room/session.js +1 -1
  37. package/dist/room/watching.d.ts +7 -0
  38. package/dist/room/watching.js +28 -6
  39. package/dist/telemetry.d.ts +6 -6
  40. package/dist/telemetry.js +2 -2
  41. package/package.json +5 -5
  42. package/dist/erase/legacy-ids.d.ts +0 -9
  43. package/dist/erase/legacy-ids.js +0 -33
@@ -16,9 +16,7 @@
16
16
  *
17
17
  * So: compare them here, once, at boot, and say precisely what to change.
18
18
  */
19
- import { type BasePathVerdict, sendIndex } from '@wolffm/service-kernel/http';
20
- export type { BasePathVerdict };
21
- export { sendIndex };
19
+ import { type BasePathVerdict } from '@wolffm/service-kernel/http';
22
20
  /**
23
21
  * The embed bundle's two fixed-name files (D21): `apps/ui/vite.embed.config.ts`
24
22
  * emits them, watchparty imports the `.js`. Every other file in the bundle is
package/dist/base-path.js CHANGED
@@ -16,8 +16,7 @@
16
16
  *
17
17
  * So: compare them here, once, at boot, and say precisely what to change.
18
18
  */
19
- import { diagnosticPage as kernelDiagnosticPage, sendIndex } from '@wolffm/service-kernel/http';
20
- export { sendIndex };
19
+ import { diagnosticPage as kernelDiagnosticPage } from '@wolffm/service-kernel/http';
21
20
  /**
22
21
  * The embed bundle's two fixed-name files (D21): `apps/ui/vite.embed.config.ts`
23
22
  * emits them, watchparty imports the `.js`. Every other file in the bundle is
package/dist/busy.d.ts CHANGED
@@ -22,7 +22,6 @@
22
22
  * until its deadline — at which point the deadline kills the real match anyway.
23
23
  */
24
24
  import type { BusyReport } from '@wolffm/service-kernel/lifecycle';
25
- export { isLocalProbe, type BusyReport, type BusyRun } from '@wolffm/service-kernel/lifecycle';
26
25
  export interface BusySources {
27
26
  matches(): ReadonlyArray<{
28
27
  id: string;
package/dist/busy.js CHANGED
@@ -1,4 +1,3 @@
1
- export { isLocalProbe } from '@wolffm/service-kernel/lifecycle';
2
1
  const BUSY_MATCH = new Set(['starting', 'running']);
3
2
  export function busyReport(src) {
4
3
  const runs = [];
package/dist/config.d.ts CHANGED
@@ -38,11 +38,6 @@ import { type Tier } from '@wolffm/service-kernel/auth';
38
38
  */
39
39
  export declare const APP_ROOT: string;
40
40
  /** Resolve a configured path against the package root unless it is absolute. */
41
- /** The in-clone paths a state dir replaces, for the boot move (`state-dir.ts`). */
42
- export declare const LEGACY_STATE: {
43
- readonly dataDir: string;
44
- readonly logDir: string;
45
- };
46
41
  export interface CreateConfigOptions {
47
42
  /** Every env var this factory reads is `<envPrefix>_<NAME>`. Default `'CARDTABLE'`. */
48
43
  envPrefix?: string;
package/dist/config.js CHANGED
@@ -40,9 +40,6 @@ const HERE = dirname(fileURLToPath(import.meta.url));
40
40
  * tsx) it is `packages/game-server/src/`, and the app it configures is `apps/server` beside it.
41
41
  */
42
42
  export const APP_ROOT = basename(HERE) === 'dist' ? dirname(HERE) : resolve(HERE, '../../../apps/server');
43
- /** Resolve a configured path against the package root unless it is absolute. */
44
- /** The in-clone paths a state dir replaces, for the boot move (`state-dir.ts`). */
45
- export const LEGACY_STATE = { dataDir: resolve(APP_ROOT, 'data'), logDir: resolve(APP_ROOT, 'logs') };
46
43
  /** Everything a game-server app needs that is not specific to any one game (w119 §C). */
47
44
  export function createConfig(options = {}) {
48
45
  const prefix = options.envPrefix ?? 'CARDTABLE';
@@ -1,8 +1,9 @@
1
1
  /**
2
2
  * Edge provenance and the tier floor — cardtable's binding of the platform
3
3
  * kernel (`@hadoku/service-kernel/auth`). The shared `createEdgeAuth`/`createGate`
4
- * instances live in `kernel.ts` (w93-Z); this file keeps every export's old
5
- * name and signature, so the rest of the app needs no edit.
4
+ * instances live in `kernel.ts` (w93-Z). The plain re-exports stay: some thirty
5
+ * files here and bomberman's server (`accountIdOf`, through the published
6
+ * `@wolffm/game-server/edge-auth`) import them from this path.
6
7
  *
7
8
  * edge-router resolves the caller's tier once and stamps every request it
8
9
  * proxies with X-Edge-Auth: <EDGE_AUTH_SECRET> plus X-Hadoku-Tier / X-User-Id /
package/dist/edge-auth.js CHANGED
@@ -1,8 +1,9 @@
1
1
  /**
2
2
  * Edge provenance and the tier floor — cardtable's binding of the platform
3
3
  * kernel (`@hadoku/service-kernel/auth`). The shared `createEdgeAuth`/`createGate`
4
- * instances live in `kernel.ts` (w93-Z); this file keeps every export's old
5
- * name and signature, so the rest of the app needs no edit.
4
+ * instances live in `kernel.ts` (w93-Z). The plain re-exports stay: some thirty
5
+ * files here and bomberman's server (`accountIdOf`, through the published
6
+ * `@wolffm/game-server/edge-auth`) import them from this path.
6
7
  *
7
8
  * edge-router resolves the caller's tier once and stamps every request it
8
9
  * proxies with X-Edge-Auth: <EDGE_AUTH_SECRET> plus X-Hadoku-Tier / X-User-Id /
package/dist/gate.d.ts CHANGED
@@ -6,18 +6,6 @@
6
6
  * HTTP's own copy is `requireMinTier`, bound in `edge-auth.ts` — both files
7
7
  * bind the one shared `createGate` instance in `kernel.ts` (w93-Z).
8
8
  */
9
- /** HTTP gates itself via `requireMinTier` (`edge-auth.ts`), which calls {@link floor} directly. */
10
- export type GateSurface = 'draft-socket' | 'play-socket' | 'stream';
11
- /** `minTier`: `CONFIG.minTier` in production. `surface`: the `reportSealRefused` label. */
12
- export interface GateOptions {
13
- minTier: string;
14
- surface: GateSurface;
15
- }
16
- /** Sanitize `headers` in place against edge provenance, then rank the result against `minTier`. */
17
- export declare const floor: (headers: Record<string, unknown>, minTier: string) => {
18
- ok: boolean;
19
- tier: string;
20
- };
21
9
  /** Provenance + the floor on a socket.io handshake. `next(new Error('not found'))` is the client's `connect_error`. */
22
10
  export declare const gateSocketIo: (io: import("socket.io").Server, opts: import("@wolffm/service-kernel/http").GateOptions) => void;
23
11
  /** The floor for a raw upgrade: no middleware chain runs, so the caller answers the refusal itself. */
package/dist/gate.js CHANGED
@@ -7,8 +7,6 @@
7
7
  * bind the one shared `createGate` instance in `kernel.ts` (w93-Z).
8
8
  */
9
9
  import { gate } from './kernel.js';
10
- /** Sanitize `headers` in place against edge provenance, then rank the result against `minTier`. */
11
- export const floor = gate.floor;
12
10
  /** Provenance + the floor on a socket.io handshake. `next(new Error('not found'))` is the client's `connect_error`. */
13
11
  export const gateSocketIo = gate.gateSocketIo;
14
12
  /** The floor for a raw upgrade: no middleware chain runs, so the caller answers the refusal itself. */
@@ -7,9 +7,8 @@
7
7
  * as `client` events, under `svc: 'cardtable-client'`, keyed by page and user. Nothing is stored
8
8
  * and nothing is answered but 204; `perf` lines are also rolled up into the 5-minute `frames` event.
9
9
  *
10
- * Every export and signature below is unchanged from before this moved into the kernel:
11
- * `index.ts` and `play/socket.ts` import this path exactly as they did. The cardtable-specific
12
- * bits are `@hadoku/platform-wire/telemetry`'s schema, path and per-second cap, bound here — the kernel itself
10
+ * `malformedFacts` is re-exported only until `play/socket.ts` imports it from the kernel. The
11
+ * cardtable-specific bits are `@hadoku/platform-wire/telemetry`'s schema, path and per-second cap, bound here — the kernel itself
13
12
  * never imports it.
14
13
  *
15
14
  * Read them with `grep -a '"svc":"cardtable-client"' ~/.pm2/logs/cardtable-ppe-out.log` (PPE) or
@@ -13,7 +13,7 @@
13
13
  */
14
14
  import type { RateLimitConfig } from '@wolffm/rooms-server';
15
15
  import type { Express } from 'express';
16
- import { type BasePathVerdict } from '../base-path.js';
16
+ import { type BasePathVerdict } from '@wolffm/service-kernel/http';
17
17
  export declare const PAGE_LOAD_RATE_LIMIT: RateLimitConfig;
18
18
  export interface PageDeps {
19
19
  indexHtml: string;
package/dist/http/page.js CHANGED
@@ -11,7 +11,8 @@
11
11
  * eight hours) is refused with a 429 and `rate-limited` telemetry naming it,
12
12
  * while the busiest real caller (20 a minute) never meets the ceiling.
13
13
  */
14
- import { diagnosticPage, sendIndex } from '../base-path.js';
14
+ import { sendIndex } from '@wolffm/service-kernel/http';
15
+ import { diagnosticPage } from '../base-path.js';
15
16
  import { perCallerLimit } from './request.js';
16
17
  export const PAGE_LOAD_RATE_LIMIT = {
17
18
  capacity: 30,
@@ -181,9 +181,8 @@ export declare const JOIN_RATE_LIMIT: RateLimitConfig;
181
181
  export declare const ROOM_CREATE_RATE_LIMIT: RateLimitConfig;
182
182
  /**
183
183
  * The seat ops every member and the leader take on a room's own game seats (`room/lobby.ts`'s
184
- * `RoomLobby`): sit, stand, close or open an empty seat, give the AI one or take it back. A game whose
185
- * room IS its seats (`plainRoomType`) hands its lobby to `RoomCoreDeps.seatRoutes`; Magic seats its
186
- * pods through routes of its own and does not.
184
+ * `RoomLobby`): sit, stand, close or open an empty seat, give the AI one or take it back. Every game
185
+ * hands its lobby to `RoomCoreDeps.seatRoutes`: Magic's pods and a plain room sit through the same routes.
187
186
  */
188
187
  export interface SeatRouteLobby<V> {
189
188
  sitSeat(roomId: string, callerId: string, seat?: number): {
@@ -218,8 +217,9 @@ export interface SeatRouteLobby<V> {
218
217
  export interface RoomCoreDeps<V extends RoomViewCore, C, P extends object, G = never> {
219
218
  /**
220
219
  * Serve the seat routes on this lobby: `/:id/seats/sit` `{ seat? }`, `/:id/seats/stand` `{}`,
221
- * `/:id/seats/close` `{ seat, closed }` (the leader's) and `/:id/seats/bot-off` `{ seat }` (the
222
- * leader's; `/seats/bot` puts one in). Absent: none of the four is registered.
220
+ * `/:id/seats/close` `{ seat, closed }`, `/:id/seats/bot-on` `{ seat }` (an open seat only) and
221
+ * `/:id/seats/bot-off` `{ seat }` (the last three the leader's; `/seats/bot` also takes a human's
222
+ * seat). No body at all is `{}`. Absent: none of the five is registered.
223
223
  */
224
224
  seatRoutes?: SeatRouteLobby<V>;
225
225
  /**
@@ -23,11 +23,12 @@
23
23
  import { Router } from 'express';
24
24
  import { MultiRateLimiter } from '@wolffm/rooms-server';
25
25
  import { isDurableParticipantId } from '@wolffm/rooms-protocol';
26
+ import { SEATS_OPEN_BEFORE_MS } from '@wolffm/platform-wire/events';
26
27
  import { edgeTierOf, isAdmin } from '../edge-auth.js';
27
28
  import { tierAdmits } from '../room/tier-floor.js';
28
- import { bodyErrors, callerOf, parseBody, perCallerLimit } from './request.js';
29
+ import { bodyErrors, callerOf, parseBody, perCallerLimit, readBody } from './request.js';
29
30
  import { isWatchpartyRoomId, watchpartyRoomId } from '../room/watchparty-link.js';
30
- import { jsonLogger } from '../log.js';
31
+ import { jsonLogger } from '@wolffm/service-kernel/log';
31
32
  /**
32
33
  * `{ settings }`' refusals, by the lobby's reason: the leader's alone to change (403), and a lock
33
34
  * that holds (409, with the lock's reason so a page can tell which). A game whose locks have
@@ -52,13 +53,16 @@ function field(check, message) {
52
53
  },
53
54
  };
54
55
  }
55
- const removeFromSeatBody = field((v) => typeof v === 'object' && v !== null && typeof v.memberId === 'string', 'memberId must be a string');
56
- const lowerCapacityBody = field((v) => typeof v === 'object' && v !== null && Number.isInteger(v.count), 'count must be an integer');
57
- const sitSeatBody = field((v) => typeof v === 'object' && v !== null && (v.seat === undefined || (Number.isInteger(v.seat) && (v.seat >= 0))), 'seat must be a non-negative integer, or absent');
58
- const emptyBody = field((v) => typeof v === 'object' && v !== null && Object.keys(v).length === 0, 'expected an empty body');
59
- const closeSeatBody = field((v) => typeof v === 'object' && v !== null && Number.isInteger(v.seat) && v.seat >= 0 && typeof v.closed === 'boolean', 'seat must be a non-negative integer and closed a boolean');
60
- const botReplacesHumanBody = field((v) => typeof v === 'object' && v !== null && Number.isInteger(v.seat), 'seat must be an integer');
61
- /** Every one of the leader's three seat ops' own refusal, mapped to a status. `'no-room'`/`no such room` reuses the create/join answer on purpose: never telling a non-member whether a room id exists. */
56
+ /** A JSON object body, never an array. */
57
+ const isObject = (v) => typeof v === 'object' && v !== null && !Array.isArray(v);
58
+ const isSeat = (v) => Number.isInteger(v) && v >= 0;
59
+ const removeFromSeatBody = field((v) => isObject(v) && typeof v.memberId === 'string', 'memberId must be a string');
60
+ const lowerCapacityBody = field((v) => isObject(v) && Number.isInteger(v.count), 'count must be an integer');
61
+ const sitSeatBody = field((v) => isObject(v) && (v.seat === undefined || isSeat(v.seat)), 'seat must be a non-negative integer, or absent');
62
+ const emptyBody = field((v) => isObject(v) && Object.keys(v).length === 0, 'expected an empty body');
63
+ const closeSeatBody = field((v) => isObject(v) && isSeat(v.seat) && typeof v.closed === 'boolean', 'seat must be a non-negative integer and closed a boolean');
64
+ const botReplacesHumanBody = field((v) => isObject(v) && Number.isInteger(v.seat), 'seat must be an integer');
65
+ /** Every seat op's own refusal, mapped to a status. `'no-room'`/`no such room` reuses the create/join answer on purpose: never telling a non-member whether a room id exists. */
62
66
  function seatOpStatus(res, reason) {
63
67
  if (reason === 'no-room')
64
68
  return noMatch(res);
@@ -88,6 +92,18 @@ function seatOpStatus(res, reason) {
88
92
  res.status(409).json({ error: 'this room has no seat the bot can take' });
89
93
  return;
90
94
  }
95
+ if (reason === 'seat-taken') {
96
+ res.status(409).json({ error: 'that seat is already taken' });
97
+ return;
98
+ }
99
+ if (reason === 'pod-full') {
100
+ res.status(409).json({ error: 'every seat is taken' });
101
+ return;
102
+ }
103
+ if (reason === 'not-open') {
104
+ res.status(409).json({ error: `seats open ${String(SEATS_OPEN_BEFORE_MS / 60_000)} minutes before the event starts` });
105
+ return;
106
+ }
91
107
  res.status(400).json({ error: reason });
92
108
  }
93
109
  /** Every one of the leader's three seat ops, per caller: a burst of 10, then one every 10 s — the same shape as a join attempt, spent only by a leader who is actually a member of the room (checked before this is asked). */
@@ -403,12 +419,16 @@ export function attachRoomCore(api, deps, opts = {}) {
403
419
  });
404
420
  const seats = deps.seatRoutes;
405
421
  if (seats !== undefined) {
406
- // Opted in (`RoomCoreDeps.seatRoutes`): a member sits and stands; the leader closes, opens and takes the AI back out.
422
+ // Opted in (`RoomCoreDeps.seatRoutes`): a member sits and stands; the leader closes, opens, and puts the AI in an open seat or takes it back out.
407
423
  const seatRoute = (path, schema, leaders, run) => {
408
424
  rooms.post(`/:id/seats/${path}`, (req, res) => {
409
- const body = parseBody(schema, req, res);
425
+ // No body at all is `{}`, as it is for every other room route.
426
+ const read = readBody(schema, req.body ?? {});
427
+ if (!read.ok)
428
+ return void res.status(400).json({ error: read.error });
429
+ const body = read.value;
410
430
  // The leader's ops spend the seat-op limit, as `remove`/`capacity`/`bot` do; a member's own sit and stand do not.
411
- if (body === null || (leaders && !seatOpLimit(req, res)))
431
+ if (leaders && !seatOpLimit(req, res))
412
432
  return;
413
433
  const caller = callerOf(req);
414
434
  const id = String(req.params.id);
@@ -423,6 +443,7 @@ export function attachRoomCore(api, deps, opts = {}) {
423
443
  seatRoute('sit', sitSeatBody, false, (id, callerId, body) => seats.sitSeat(id, callerId, body.seat));
424
444
  seatRoute('stand', emptyBody, false, (id, callerId) => seats.standSeat(id, callerId));
425
445
  seatRoute('close', closeSeatBody, true, (id, callerId, body, override) => seats.closeSeat(id, callerId, body.seat, body.closed, override));
446
+ seatRoute('bot-on', botReplacesHumanBody, true, (id, callerId, body, override) => seats.aiSeat(id, callerId, body.seat, true, override));
426
447
  seatRoute('bot-off', botReplacesHumanBody, true, (id, callerId, body, override) => seats.aiSeat(id, callerId, body.seat, false, override));
427
448
  }
428
449
  // The leader hands the room to another member, seated or watching. Spends the seat-op limit.
@@ -6,15 +6,12 @@
6
6
  * with their own ordered trail. The tier reported is the edge's (`edgeTierOf`), so a member reads
7
7
  * as a member, not as the friend cardtable's gates treat them as. Nothing is answered but 204.
8
8
  *
9
- * Every export and signature below is unchanged from before this moved into the kernel:
10
- * `index.ts` imports this path exactly as it did. The cardtable-specific bits are
11
- * `@hadoku/platform-wire/telemetry`'s schema and path, bound here — the kernel itself never imports it.
9
+ * The cardtable-specific bits are `@hadoku/platform-wire/telemetry`'s schema and path, bound here —
10
+ * the kernel itself never imports it.
12
11
  */
13
12
  import type { Router } from 'express';
14
- import { MAX_BATCHES_PER_MINUTE, USAGE_TOP, USAGE_TRAIL_MAX, USAGE_WINDOW_MS, type UsageCounter } from '@wolffm/service-kernel/relays';
13
+ import { type UsageCounter } from '@wolffm/service-kernel/relays';
15
14
  import { type Report } from '../telemetry.js';
16
- export { MAX_BATCHES_PER_MINUTE, USAGE_TOP, USAGE_TRAIL_MAX, USAGE_WINDOW_MS };
17
- export type { UsageCounter };
18
15
  export interface UsageDeps {
19
16
  report?: Report;
20
17
  now?: () => number;
@@ -1,8 +1,7 @@
1
1
  import { USAGE_PATH, UsageBatchSchema } from '@wolffm/platform-wire/telemetry';
2
- import { attachUsage as kernelAttachUsage, MAX_BATCHES_PER_MINUTE, USAGE_TOP, USAGE_TRAIL_MAX, USAGE_WINDOW_MS, } from '@wolffm/service-kernel/relays';
2
+ import { attachUsage as kernelAttachUsage } from '@wolffm/service-kernel/relays';
3
3
  import { edgeTierOf, userIdOf, userNameOf } from '../edge-auth.js';
4
4
  import { report as defaultReport } from '../telemetry.js';
5
- export { MAX_BATCHES_PER_MINUTE, USAGE_TOP, USAGE_TRAIL_MAX, USAGE_WINDOW_MS };
6
5
  export function attachUsage(api, deps = {}) {
7
6
  return kernelAttachUsage(api, {
8
7
  schema: UsageBatchSchema,
package/dist/log.d.ts CHANGED
@@ -1,9 +1 @@
1
- /**
2
- * Adapter: cardtable's binding of `@hadoku/service-kernel/log`. `jsonLogger`
3
- * and `JsonLog` are fully generic (no cardtable value baked in), so this is a
4
- * pure re-export kept at this path for its one remaining importer,
5
- * `http/rooms.ts` — claimed by another session (w95b) this wave, so its
6
- * import line was not repointed. Every other importer now binds
7
- * `@hadoku/service-kernel/log` directly (w93-Z).
8
- */
9
1
  export { jsonLogger, type JsonLog } from '@wolffm/service-kernel/log';
package/dist/log.js CHANGED
@@ -1,9 +1,2 @@
1
- /**
2
- * Adapter: cardtable's binding of `@hadoku/service-kernel/log`. `jsonLogger`
3
- * and `JsonLog` are fully generic (no cardtable value baked in), so this is a
4
- * pure re-export kept at this path for its one remaining importer,
5
- * `http/rooms.ts` — claimed by another session (w95b) this wave, so its
6
- * import line was not repointed. Every other importer now binds
7
- * `@hadoku/service-kernel/log` directly (w93-Z).
8
- */
1
+ /* Until `http/room-core.ts` and `room/session.ts` import `@hadoku/service-kernel/log` themselves; then this file goes. */
9
2
  export { jsonLogger } from '@wolffm/service-kernel/log';
@@ -12,10 +12,7 @@
12
12
  import { type ChildProcess } from 'node:child_process';
13
13
  /**
14
14
  * A process `EngineRuntime.spawn` handed back: just the pid and the two edges `local-jvm.ts`'s
15
- * `LocalJvm` needs to watch — nothing of `node:child_process`'s own shape leaks past this, so an
16
- * engine that is not a `child_process` at all (a streamed desktop's "process" is a docker
17
- * container `scripts/stream/container.sh` starts, not a pid this server forks) can still describe
18
- * itself this way without pretending to BE a `ChildProcess`.
15
+ * `LocalJvm` needs to watch — nothing of `node:child_process`'s own shape leaks past this.
19
16
  */
20
17
  export interface EngineProcess {
21
18
  readonly pid: number;
@@ -27,37 +24,22 @@ export interface EngineProcess {
27
24
  dispose(): void;
28
25
  }
29
26
  /**
30
- * What the host asks of any engine it runs matches through: the process it spawns and what that
31
- * process costs. `local-jvm.ts`'s `LocalJvm` launches through `forgeEngineRuntime`'s `spawn`
32
- * (the actual `child_process.spawn` call lives there, not in `LocalJvm`, which only builds the
33
- * argv and hands it over) instead of building the child process itself. The coordinator itself
34
- * (`host.ts`) still places matches through `localJvmLauncher`'s `JvmLauncher`, never through
35
- * `EngineRuntime` directly — lifting the POOL onto this seam, so a non-JVM engine shares the same
36
- * coordinator, is still ahead of this.
27
+ * How the host launches an engine process: its argv and its spawn. `local-jvm.ts`'s `LocalJvm`
28
+ * launches through `forgeEngineRuntime` (the actual `child_process.spawn` call lives there, not in
29
+ * `LocalJvm`, which only builds the argv and hands it over). The coordinator itself (`host.ts`)
30
+ * still places matches through `localJvmLauncher`'s `JvmLauncher`, never through this directly.
37
31
  */
38
32
  export interface EngineRuntime {
39
- /** Paths (or other identifiers) of what the process needs, keyed for logging. */
40
- artifacts: Record<string, string>;
41
33
  /** The full argv (after the executable) to launch one process in run directory `dir`, sized to `size`. */
42
34
  argv(dir: string, size: {
43
35
  memoryMb: number;
44
36
  }): string[];
45
- /** RAM one idle process costs beyond what it hosts. */
46
- overheadMb: number;
47
- /** Matches (or jobs) one process hosts at most. */
48
- perProcess: number;
49
- /** Is the process in `dir` still healthy, or due for a recycle? */
50
- health?(dir: string): {
51
- recycle: boolean;
52
- };
53
37
  /**
54
38
  * Launch `argv` (after the executable) with `cwd` and these three stdio fds — never a Node
55
39
  * pipe; `local-jvm.ts`'s header says why a JVM's stdio has to be fds on named pipes, not
56
- * something that dies with this process. Optional: an engine whose "process" is not one this
57
- * server forks at all (a container another script starts) leaves it unset and is launched some
58
- * other way.
40
+ * something that dies with this process.
59
41
  */
60
- spawn?(argv: string[], cwd: string, io: {
42
+ spawn(argv: string[], cwd: string, io: {
61
43
  stdin: number;
62
44
  stdout: number;
63
45
  stderr: number;
@@ -146,8 +128,6 @@ export declare const PID_POLL_MS = 1000;
146
128
  * stops existing (`process.exit` a statement away), where there is no later tick to confirm in.
147
129
  */
148
130
  export declare function sleepSync(ms: number): void;
149
- /** SIGKILL a pid we own, or say nothing: it may have gone between the check and here. */
150
- export declare function killPid(pid: number): void;
151
131
  /** One run directory under a `workDir`, as a real path. */
152
132
  export interface RunDirEntry {
153
133
  name: string;
@@ -199,11 +179,6 @@ export interface SweepResult {
199
179
  run: string;
200
180
  startedAt: string;
201
181
  }[];
202
- /**
203
- * Live directories the sweep ENDED: a legacy one-process-per-run-dir layout nothing re-attaches
204
- * any more, named by its own record's pid.
205
- */
206
- killed: string[];
207
182
  /** Set when the sweep did nothing, and why. */
208
183
  skipped?: string;
209
184
  }
@@ -236,15 +236,6 @@ export const PID_POLL_MS = 1000;
236
236
  export function sleepSync(ms) {
237
237
  Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, ms);
238
238
  }
239
- /** SIGKILL a pid we own, or say nothing: it may have gone between the check and here. */
240
- export function killPid(pid) {
241
- try {
242
- process.kill(pid, 'SIGKILL');
243
- }
244
- catch {
245
- // ESRCH — already gone, which is the outcome we wanted.
246
- }
247
- }
248
239
  /** Marks a pruned-down run directory as a crash record rather than scaffolding to remove outright. */
249
240
  export const CRASH_MARKER = 'crash.json';
250
241
  /** Our run directories directly under `workDir`, as real paths, matching `namePattern`. */
@@ -60,7 +60,9 @@
60
60
  * comes back identical. A line is kept as the bridge wrote it, `match` stamp and all, through
61
61
  * a descriptor held open for the match's life; each append is synchronous, so the file is
62
62
  * whole for any reader the moment `persist` returns — this process's own `attach`, or the next
63
- * server's after a crash.
63
+ * server's after a crash. A match that ends takes its stream with it; a JVM whose launcher
64
+ * does not settle its directory (a claw's mirror) takes that directory at its exit, and one left
65
+ * by a JVM that ended under no server goes once discovery has answered (`sweepMirrors`).
64
66
  * - **One record per JVM**, `<dir>/jvm.json` (`JvmRecord`): its host id, when it started, when it
65
67
  * was handed over, and every match on it with its epoch, its seats' owners and its spec. A
66
68
  * client therefore resyncs on the cursor it already held, and seat 2 cannot come back as seat 1.
@@ -118,10 +120,9 @@
118
120
  * stdin. Its class comment has the list. Stdout carries nothing else, so a line that is not JSON
119
121
  * is a bug and is logged, not parsed.
120
122
  */
121
- export { bridgeDiagnostics } from './diagnostics.js';
122
123
  import type { JvmLauncher } from './jvm-transport.js';
123
124
  import { type JvmHostConfig } from './local-jvm.js';
124
- export { BRIDGE_CACHE_MAX_AGE_MS, BRIDGE_JVM_FLAGS, CRASH_RECORD_FILES, CRASH_RECORD_MAX_AGE_MS, CRASH_RECORDS_KEPT, FORGE_HEARTBEAT_TIMEOUT_S, FORGE_JVM_FLAGS, FORGE_PREFERENCES, JVM_HEAP_MB, MATCHES_PER_JVM, bridgeLaunch, bridgeVersion, jvmHostConfig, liveJvmCount, stageRunDir, sweepRunDirs, writeFileAtomic, type JvmAvailability, type JvmHostConfig, } from './local-jvm.js';
125
+ export { FORGE_PREFERENCES, jvmHostConfig } from './local-jvm.js';
125
126
  export interface SeatSpec {
126
127
  /** Forge's player name. Shown to both seats, so never an identity. */
127
128
  name: string;
@@ -291,9 +292,9 @@ export interface MatchHost<C extends {
291
292
  * its epoch, so a re-attached client resyncs on the cursor it holds, and which participant owns
292
293
  * each seat, so a re-attach cannot seat someone at the wrong hand. `checkpoint` is w105's: a
293
294
  * per-engine mid-game save, opaque to the host — whatever `GameAdapter.classify`'s `{ t:
294
- * 'checkpoint' }` line carried last (`match/shell.ts`'s `latestCheckpoint`), written down beside
295
- * Forge's own {@link TurnSnapshot} (`MatchRecord.snapshot`, kept unchanged this wave) rather than
296
- * replacing it. Absent before a match's first checkpoint. `readJvmRecord`/`hostFace`'s `remember`
295
+ * 'checkpoint' }` line carried last (`match/shell.ts`'s `latestCheckpoint`), beside Forge's own
296
+ * {@link TurnSnapshot} (`MatchRecord.snapshot`); when the two are the same value, `jvm.json` holds
297
+ * it once (`recordEntry`). Absent before a match's first checkpoint. `readJvmRecord`/`hostFace`'s `remember`
297
298
  * pass through whatever the caller sent, never forcing it to `null` themselves.
298
299
  */
299
300
  export interface Durable {