@hadoku/service-kernel 0.1.73 → 0.1.75

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.
@@ -34,9 +34,16 @@ export interface HealthInput {
34
34
  ok: boolean;
35
35
  reason: string;
36
36
  };
37
+ /** What the game adds (`GameServerConfig.health`): its own fields, and anything else that keeps it from serving. */
38
+ game?: HealthExtra;
37
39
  }
38
- /** The HTTP status and body `/health` answers. */
39
- export declare function healthResponse({ service, commit, bundle }: HealthInput, now?: Date): {
40
+ /** A game's part of `/health`: fields beside the kernel's, and the problems that make it degraded. */
41
+ export interface HealthExtra {
42
+ fields?: Record<string, unknown>;
43
+ /** Each one a sentence; any at all answers 503 `degraded`, as a bundle nobody can load does. */
44
+ problems?: readonly string[];
45
+ }
46
+ export declare function healthResponse({ service, commit, bundle, game }: HealthInput, now?: Date): {
40
47
  code: number;
41
48
  body: Record<string, unknown>;
42
49
  };
@@ -37,16 +37,18 @@ export function readCommit(repoRoot) {
37
37
  export function serviceIdOf(basePrefix, fallback) {
38
38
  return basePrefix.replace(/^\/+|\/+$/g, '') || fallback;
39
39
  }
40
- /** The HTTP status and body `/health` answers. */
41
- export function healthResponse({ service, commit, bundle }, now = new Date()) {
40
+ export function healthResponse({ service, commit, bundle, game }, now = new Date()) {
41
+ const reasons = [...(bundle.ok ? [] : [`the UI bundle is not servable (bundle: ${bundle.reason})`]), ...(game?.problems ?? [])];
42
+ const healthy = reasons.length === 0;
42
43
  const body = {
43
- status: bundle.ok ? 'ok' : 'degraded',
44
+ status: healthy ? 'ok' : 'degraded',
44
45
  service,
45
46
  commit: commit.commit,
46
47
  ...(commit.commit === null ? { commit_error: commit.commit_error } : {}),
47
- ...(bundle.ok ? {} : { reason: `the UI bundle is not servable (bundle: ${bundle.reason})` }),
48
+ ...(healthy ? {} : { reason: reasons.join('; ') }),
48
49
  bundle: bundle.reason,
50
+ ...game?.fields,
49
51
  timestamp: now.toISOString(),
50
52
  };
51
- return { code: bundle.ok ? 200 : 503, body };
53
+ return { code: healthy ? 200 : 503, body };
52
54
  }
@@ -1 +1 @@
1
- export { healthResponse, readCommit, serviceIdOf, type Commit, type HealthInput } from './health.js';
1
+ export { healthResponse, readCommit, serviceIdOf, type Commit, type HealthExtra, type HealthInput } from './health.js';
@@ -7,7 +7,7 @@
7
7
  */
8
8
  import { readFileSync } from 'node:fs';
9
9
  import { createServer } from 'node:http';
10
- import { sep } from 'node:path';
10
+ import { basename, dirname, sep } from 'node:path';
11
11
  import express from 'express';
12
12
  /** One gate, bound to an app's auth functions and its `reportSealRefused`. */
13
13
  export function createGate(deps) {
@@ -106,7 +106,13 @@ export function isEmbedEntry(filePath, embedEntries) {
106
106
  * for: change an option here and the boot check changes with it.
107
107
  */
108
108
  export function sendIndex(res, indexHtmlPath, done) {
109
- res.set('Cache-Control', 'no-store').type('html').sendFile(indexHtmlPath, (err) => done(err));
109
+ // `root` + the bare file name: `send` refuses a path with any dot-segment in it (`dotfiles:
110
+ // 'ignore'`), so an absolute path under a dot-directory — every agent worktree,
111
+ // `.claude/worktrees/<task>/…` — 404ed the page. With `root`, only the name is checked.
112
+ res
113
+ .set('Cache-Control', 'no-store')
114
+ .type('html')
115
+ .sendFile(basename(indexHtmlPath), { root: dirname(indexHtmlPath) }, (err) => done(err));
110
116
  }
111
117
  /**
112
118
  * The HTTP status `sendIndex` actually produces for this file, measured over a
@@ -151,8 +157,7 @@ export async function checkBundle(indexHtmlPath, basePrefix) {
151
157
  offenders: [],
152
158
  detail: `index.html is at ${indexHtmlPath} and reads fine, but serving it answered ${status}. ` +
153
159
  (dotSegments.length > 0
154
- ? `The path has a dot-segment (${dotSegments.join(', ')}), and express's sendFile refuses those ` +
155
- `(send's dotfiles: 'ignore'). Run the server from a copy outside it — an e2e harness usually does.`
160
+ ? `The path has a dot-segment (${dotSegments.join(', ')}); sendIndex serves from the file's own directory, so check that the file name itself is not a dotfile.`
156
161
  : `express's sendFile refused a file that exists; check its permissions and sendIndex's options.`),
157
162
  };
158
163
  }
@@ -3,6 +3,7 @@ import { type Express, type Router } from 'express';
3
3
  import { Server as SocketIOServer } from 'socket.io';
4
4
  import { type EdgeAuth } from '../auth/index.js';
5
5
  import { type EraseStep } from '../erase/index.js';
6
+ import { type HealthExtra } from '../health/index.js';
6
7
  import { type BasePathVerdict, type Gate } from '../http/index.js';
7
8
  import { type BusyRun } from '../lifecycle/index.js';
8
9
  import type { JsonLog } from '../log/index.js';
@@ -36,6 +37,8 @@ export interface GameServerConfig {
36
37
  };
37
38
  /** This instance's checkout, for `/health`'s commit. */
38
39
  repoRoot: string;
40
+ /** The game's part of `/health`, read on every probe: its own fields, and what else keeps it from serving. */
41
+ health?: () => HealthExtra;
39
42
  /** The socket event that tells every client the server is restarting. */
40
43
  restartEvent: string;
41
44
  /** Built and installed after the `bundle` phase, before any plugin's route. Absent: events go nowhere. */
@@ -121,7 +121,8 @@ export async function createGameServer({ id, config, state, plugins }) {
121
121
  });
122
122
  // Public: the monitoring probe has no key. A server up but serving a bundle nobody can load says so.
123
123
  app.get('/health', (_req, res) => {
124
- const { code, body } = healthResponse({ service, commit, bundle: verdict ?? { ok: false, reason: 'missing' } });
124
+ const game = config.health?.();
125
+ const { code, body } = healthResponse({ service, commit, bundle: verdict ?? { ok: false, reason: 'missing' }, ...(game === undefined ? {} : { game }) });
125
126
  res.status(code).json(body);
126
127
  });
127
128
  // Local only, and a bare 404 to anyone else: the deploy asks it before stopping us.
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@hadoku/service-kernel",
3
- "version": "0.1.73",
4
- "gitHead": "01e4b514259bb37d2b1e397ee20e092a53a10848",
3
+ "version": "0.1.75",
4
+ "gitHead": "ba602183061ee25158e7aa66723ac902b94e3698",
5
5
  "type": "module",
6
6
  "license": "MIT",
7
7
  "description": "The server parts any game keeps: edge auth and the tier gate, base path and bundle check, health and the busy probe, lifecycle, the JSON logger, the state directory, telemetry and capacity, per-caller limits, the browser relays, the erase registry, and createGameServer, which boots a game from its config and plugins. Knows no game; the app binds its service id, prefix and env names. MIT; imports only node built-ins, express, socket.io and @wolffm/*.",