Zero-dependency TypeScript multi-agent harness + pluggable hidden-information board games.
Provable hand isolation · Event-driven live debate · Byte-exact replay · Wilson CI & Brier evaluation.
Live Tabletop Archive · 2D Council Reader · 3D One Night Stage · Core API Docs
This repository is built as a clean two-layer architecture:
- The Harness —
@endless-werewolf/coreA zero-runtime-dependency TypeScript execution core (Node 18+ and browsers) for tool-using agents operating in shared, partial-information environments. Start with the standalone single-agent example if you want only the harness—no game or UI is required. - Pluggable Board Games —
games/Self-contained rule plugins implementingGame<State, Result>againstTable. Every plugin inherits capability-scoped tools, seat workspaces & personas, generic canary leak testing (findLeaks()), live open-floor debate (runLive()), cassette record/replay, and rotated-seat tournaments without touching core.
| Plugin | Seats | What it exercises in @endless-werewolf/core |
Viewer |
|---|---|---|---|
games/classic-werewolf |
8 | Multi-night deduction, private wolf pack chat & hunt agreement, private seer checks, runLive open floor with draft review, simultaneous ballots, bilingual titled cast (data/classic_cast.json), strictly spoiler-free public report |
2D Council Reader |
games/werewolf (one-night-werewolf) |
6 + 3 center | Hidden role swaps (Seer, Robber, Troublemaker, Tanner, Minion, Insomniac), structured stance/claim tracking, suspicion Brier calibration, paired --ablation benchmarks, inline bilingual tool calls |
2D Reader & 3D Stage |
games/liars-dice |
2–6 | Minimal ~130 LOC reference plugin proving core extensibility: hidden dice cups, raise validation via ToolRejected, generic findLeaks(), plus a probability-aware heuristic policy beating random 200/200 |
CLI / Tournament |
flowchart LR
subgraph Core["@endless-werewolf/core (zero runtime deps · Node & browser)"]
Table["Table & Live Engine<br/>tell · broadcast · say<br/>ask · askAll · floor · runLive"]
Agent["Agent Loop & Workspaces<br/>LLMPlayer · Scripted · Remote · Human<br/>SeatSpec.persona · notebook · self-repair"]
Log["Visibility EventLog<br/>public · gm · [seat]<br/>findLeaks() canary tests"]
Prov["Providers & Cassettes<br/>OpenAI-compat (native/json)<br/>mock · record · strict replay"]
end
Plugins["Game Plugins<br/>Classic Werewolf · One Night<br/>Liar's Dice · Your Game"] --> Table
Table <--> Agent --> Prov
Table --> Log
Log --> Eval["Evaluation & Tournaments<br/>Wilson 95% CI · Brier calibration<br/>guardrail recovery · paired ablations"]
Log --> Viewers["Optional Static Viewers<br/>Tabletop Homepage · 2D Council Log<br/>Three.js 3D One Night Stage"]
What separates a tabletop agent harness from a prompt wrapper:
| Invariant | How it works | Verification |
|---|---|---|
| Capability-scoped tools | Tools are dealt per act. A Villager never sees seer_inspect_player; on the final step of an act budget, only turn-ending tools are offered. |
games/werewolf/test/werewolf.test.ts |
| Provable hand isolation | Every event carries visibility: "public" | "gm" | SeatId[]. findLeaks(game, seats) injects a unique canary per seat and asserts no other seat's transcript ever contains it—for any game plugin. |
packages/core/src/testing.ts |
| Event-driven live debate | runLive() replaces rigid turn order with a virtual clock driven by measured model latency. Agents wake on speech, address, or self-scheduled timers, queue FIFO, and can keep, replace, or withdraw queued drafts. |
packages/core/src/live.ts |
| Schema-validated self-repair | Tool arguments are validated against typed JSON schemas (t.object, t.oneOf, …). Rejected moves (bad targets, language violations, duplicate speeches) bounce back for model self-repair; exhausted budgets fall back explicitly. |
packages/core/test/core.test.ts |
| Untrusted table talk | Player speech flows through table.say and is delivered to peers as single-line «…» quotes, structurally separated from [moderator] directives and backed by a standing table protocol. |
injectorPolicy tests |
| Seat workspaces & personas | Each seat gets an isolated in-memory workspace (rules.md, character.md, private notebook) plus optional SeatSpec.persona voice shaping without leaking hidden alignments. |
packages/core/test/workspace.test.ts |
| Byte-exact replay | --record seals cassette.jsonl (request digests, completions, latencies); --replay reproduces runs offline identically and aborts (ReplayDivergence) on drift. |
packages/core/src/providers.ts |
| Rigorous evaluation | Per-model win rates with 95% Wilson CIs, suspicion Brier score + calibration curves, guardrail self-correction rate, and paired same-seed --ablation benchmarks. |
packages/core/src/eval.ts |
A game plugin implements just three hooks (setup, systemPrompt, play) against Table—no provider plumbing, retry loops, or leak guards to re-implement:
import { t, ToolRejected, type Game, type Table } from "@endless-werewolf/core";
export function myBoardGame(): Game<MyState, MyResult> {
return {
name: "my-board-game",
setup(seats, rng) {
// Deal private cards/dice deterministically from rng
return dealInitialState(seats, rng);
},
systemPrompt(seat, state) {
return `You are ${seat.name}. Play to win within the rules.`;
},
async play(table: Table, state: MyState) {
for (const seat of table.seats) {
// Private hand: structurally invisible to every other seat
table.tell(seat.id, `Your secret card is ${state.cards[seat.id]}.`);
}
const bid = await table.ask(table.seats[0].id, {
prompt: "Make an opening move.",
tools: [{
name: "submit_bid",
description: "Place a legal bid",
terminal: true,
params: t.object({ amount: t.int({ min: 1, max: 10 }) }),
handler: ({ amount }) => {
if (amount <= state.currentBid) throw new ToolRejected("Bid must raise the table.");
return amount;
},
}],
});
table.broadcast(`${table.seats[0].name} bids ${bid}.`);
return resolveGame(state, bid);
},
};
}See games/liars-dice/src/index.ts (~130 LOC) for a complete runnable plugin with a heuristic baseline and automated leak test.
Requires Node 22.6+ for direct .ts execution in development (the compiled @endless-werewolf/core package targets Node 18+ and browsers).
npm install
npm run check # build core + typecheck + 89 offline tests
npm run endless-werewolf -- run classic-werewolf --mock --seed 7
npm run endless-werewolf -- run one-night-werewolf --mock --seed 7
npm run endless-werewolf -- tournament liars-dice --seats heuristic,random --games 8
npm run eval:werewolf -- --run --ablation notebook --games 6 --mock --out /tmp/ablationCopy .env.example to .env (gitignored) and define any OpenAI-compatible provider as <NAME>_BASE_URL, <NAME>_API_KEY, and <NAME>_MODEL (plus optional <NAME>_TOOL_MODE=json and <NAME>_REASONING_EFFORT=low|medium|high|off, defaulting to "low"). Providers are discovered automatically—nothing is hardcoded:
# 1. Verify connectivity, native tool calling, nullable schemas & latency
npm run endless-werewolf -- probe
# 2. Run real bilingual games with cassette recording
npm run endless-werewolf -- run classic-werewolf --inline-bilingual --seats deepseek,hydrogen,neon --live-acts 5 --record --out /tmp/archive
npm run endless-werewolf -- run one-night-werewolf --inline-bilingual --seats deepseek,hydrogen,neon --live-acts 5 --record --out /tmp/archive
# 3. Inspect God view vs Seat 2's private transcript (verifies hand isolation)
npm run endless-werewolf -- inspect /tmp/archive/classic_000001/events.jsonl --seat 2
# 4. Strict offline replay from recorded cassette
npm run endless-werewolf -- run classic-werewolf --inline-bilingual --live-acts 5 --seed 7 --replay /tmp/archive/classic_000001/cassette.jsonl
# 5. Build a standalone local site (Homepage + 2D Reader + 3D One Night Stage)
python3 scripts/build_pages.py --games-dir /tmp/archive --site-dir /tmp/site
python3 -m http.server 8000 --bind 127.0.0.1 --directory /tmp/site- Inline bilingual tool calls (
--inline-bilingual): Asks each live player for paired English and written Traditional Chinese (zh_Hant) in the same tool call. Only canonical English table talk is relayed to peers; structural votes, targets, and outcomes remain identical across locales. - Seat workspace API: Games can mount seat-specific virtual files in
setupand expose read/note tools explicitly per act:const ws = table.workspace(seatId); ws.mount("rules.md", publicRules); ws.mount("character.md", privateStartingCard); const tools = [...ws.tools({ notebook: true }), submitAction];
- Open discussion & draft review:
runLiverecords seat-privatelive_wakereasons (opening,speech,address,timer,idle,draft_review). Use--event-onlyto disable idle wakes or--no-draft-reviewfor paired ablations. - Classic pacing & first-hunt experiments:
python3 games/classic-werewolf/compare_pacing.py baseline/archive trial/archivecompares private pacing diagnostics (voluntary listen vs. clock cutoff vs. stale aired speech).--first-hunt-order shuffledshuffles Night-1choose_targetordering per wolf;node --experimental-strip-types games/classic-werewolf/compare-first-hunt.ts ARCHIVE NEW_OUTPUT --liveruns paired private pre-hunt replays.
Neither viewer is a dependency of @endless-werewolf/core; both consume static JSON built by scripts/build_pages.py (never copying private event traces or provider cassettes):
docs/index.html— Collector tabletop homepage featuring interactive 3D-flipping visibility cards, live archive telemetry, an unedited Day-1 transcript excerpt, bilingual character decks, and a filterable tournament scorepad.docs/2d.html— Spoiler-free 2D council log reader supporting both Classic Werewolf and One Night Werewolf, with circular seating ring, vote/stance arrows, player focus filtering, and step-by-step playback.docs/3d.html— Standalone Three.js 3D round-table replay for One Night Werewolf with animated characters, ballot arcs, model badges, live claim/suspicion dynamics graph, and guided story mode.
After editing docs/app.js or docs/styles.css, rebuild minified bundles and run full pre-publish checks:
bash scripts/build_assets.sh
bash scripts/prepublish_check.shpackages/core/ @endless-werewolf/core (zero runtime deps; compiles to dist/*.js + *.d.ts)
src/schema.ts typed tool-arg builders (t.object, t.oneOf …) + validator + sampler
src/providers.ts OpenAI-compatible (native/json tools), mock, record, strict replay
src/agent.ts Tool, Player interface, LLMPlayer (agent loop, AgentHooks, budgets)
src/players.ts ScriptedPlayer (random, injector), RemotePlayer (HTTP BYOA), HumanPlayer
src/events.ts visibility-scoped EventLog, live subscriptions, formatEvent
src/table.ts tell / broadcast / say / record / ask / askAll / floor / personaPrompt
src/live.ts event-driven live debate on a virtual clock (FIFO floor queue + review)
src/game.ts Game interface + runGame
src/testing.ts findLeaks() generic canary leak verifier
src/eval.ts Wilson 95% CI, Brier score + calibration, guardrail reliability
src/tournament.ts game-agnostic rotated-seat tournament & paired ablation runner
src/node/ .env + cassette file helpers (Node-only subpath)
games/classic-werewolf/ 8-seat multi-night Classic Werewolf plugin (spoiler-free public report)
games/werewolf/ 6-seat One Night Ultimate Werewolf plugin + eval CLI + replay exporter
games/liars-dice/ ~130 LOC reference plugin + probability-aware heuristic baseline
scripts/endless-werewolf.ts Unified CLI (probe, run, tournament, inspect)
scripts/build_pages.py Builds docs/data/ or a standalone local viewer site
scripts/prepublish_check.sh Full offline test, language audit, safety & bundle freshness gate
data/ Cast definitions (classic_cast.json, players.json), roles, recorded games
docs/ Tabletop homepage (index.html), 2D reader (2d.html), 3D stage (3d.html)
The npm release target is @endless-werewolf/core (public, ESM). The workspace root and games/* plugins remain private:
npm ci && npm run check
node scripts/check_packed_core.mjs
npm publish --workspace=@endless-werewolf/core --dry-run
# Actual release (requires authorized npm account / 2FA):
npm publish --workspace=@endless-werewolf/coreEndless Werewolf 是一套以「多代理框架 + 可插拔桌遊插件」為核心的開源專案(線上精裝桌遊對局館):
- 零依賴核心框架(
@endless-werewolf/core):提供按回合授權工具、可證明的資訊與手牌隔離(findLeaks())、事件驅動實時辯論(runLive())、Schema 驗證退回自我修正、座位專屬人設與工作區、逐位元組卡帶重播(cassette.jsonl),以及 Wilson 95% 信賴區間與 Brier 校準評測。 - 三款內建遊戲插件(
games/):8 人多夜傳統狼人殺、6 人一夜狼人殺,以及僅約 130 行的**大話骰(Liar's Dice)**範例插件;只需實作setup、systemPrompt、play三個介面即可擴充任何隱藏資訊桌遊。 - 公開雙語重播檢視器(
docs/):首頁(精裝桌遊與 3D 翻牌隔離演示)、2D 無劇透戰報閱讀器(/2d.html),以及一夜狼人專屬的 Three.js 3D 圓桌舞台(/3d.html)。
