Agent 德州扑克完整交付与最终全量验收(Issue35后续) #75

Open
peng01.guo wants to merge 1 commits from ppanel/71c1c0f7-69c9-487e-98a2-776bd0872c4f/r1-1 into deliveries/agent-poker-final
56 changed files with 13828 additions and 0 deletions

View File

@ -0,0 +1,88 @@
# Agent 德州扑克
当前交付 Issue [#73](https://gitea.d-robotics.cc/peng01.guo/ppanel/issues/73),需求版本 `1`;采用既有候选 `470879a305438fc958acfc6486f1f86bcd94b681`。虚拟筹码 No-Limit Texas Hold'em;服务器发牌、校验行动、比较牌型、分配边池及结算。没有支付功能。
## 安装与启动
Node 24。在仓库根目录运行:
```sh
cd projects/agent-poker
npm ci
npm run build
# 由运行者设置自己的私有目录,禁止使用其他角色目录。
export TMPDIR="<当前角色绝对路径>/tmp"
export TMP="$TMPDIR" TEMP="$TMPDIR" POKER_DATA="$TMPDIR/service"
mkdir -p "$POKER_DATA"
POKER_PORT=18439 node service.mjs
```
服务仅监听 `127.0.0.1:18439`,关闭浏览器或开发会话不终止独立后台进程。状态与完整模型证据存于 `POKER_DATA/state.json`、`POKER_DATA/evidence.jsonl`,权限 `0600`;服务重启恢复牌局且默认暂停,管理员核对后开始。停止服务使用自己保存的 PID。此版单进程、单本机文件持久化:同目录临时文件写入、`fsync`、原子替换并同步目录。中断时保留完整旧版或新版快照,重启忽略残留 `.pending`;不提供多实例或日志与快照之间的跨文件事务。物理断电受操作系统与存储硬件刷盘保证约束。
管理凭据在 `POKER_DATA/admin-token`,由本机管理员读取后填写页面密码框。页面仅在内存保存,不置入链接或浏览器持久化。公网观众无需管理凭据即可观测;控制操作需要管理凭据。请使用 HTTPS 公网地址。
## 邀请与真实模型
页面“建立牌桌”生成三张邀请链接。邀请凭据只放 URL fragment,不发送至静态服务器或 Referer;不要提交 Git 或公开转发。受邀玩家点击“接受邀请”,或者使用 API。模型配置仅从 `/Users/pptg/.d-sre-agent/config/sre-agent.yaml` 加载,复用 D-SRE 的 provider 与 compat 映射,使用 pi SDK `0.85.0`。
- `GET /api/tables`:公开牌桌、行动、历史与筹码。
- `POST /api/tables`:管理员提交 `{ "names": ["甲", "乙", "丙"] }`,返回牌桌 `id` 与邀请链接。
- `GET /api/models`:管理员读取安全模型列表。
- `POST /api/tables/:id/join`:邀请 Bearer 凭据,空对象接入外部 API 玩家;`{ "modelId": "本机模型 id" }` 接入服务内真实 pi Agent 玩家。至少两种模型可分配至三位玩家。
- `GET /api/tables/:id/observation`:邀请 Bearer 凭据,只返回该玩家底牌和公开观察,含 `version`、`legal` 与 `player`。
- `POST /api/tables/:id/action`:邀请 Bearer 凭据,`{ "version": 1, "action": "call", "amount": 0 }`。`bet`/`raise` 的 `amount` 为本下注轮总额;合法范围以观察为准。
- `POST /api/tables/:id/control`:管理员 Bearer 凭据,`{ "action": "start" }` 开始最多三手;`pause` 或 `stop` 停止继续执行。已在途模型响应保留证据,但暂停期间不应用动作。
所有玩家接受邀请后才可开始。模型按自己的私有观察独立调用,不配置固定动作或回退随机动作;非法模型输出使牌桌暂停。每个调用有 90 秒超时。外部玩家不行动会等待,不代替玩家行动。玩家破产导致不足两位时不能开始新手牌。单实例按桌串行调用模型,适用于本演示规模。
## 规则与验证
```sh
npm test
# 以下集成检查会创建独立测试牌桌;使用当前运行者自己的数据目录。
node api-check.mjs
node browser-check.mjs
# 创建三位真实模型玩家,调用本机配置的 DeepSeek 与 GLM;服务每次开始最多三手。
POKER_URL=http://127.0.0.1:18439 node real-check.mjs
```
浏览器检查使用本机 Chrome 与 Playwright,截图写入 `TMPDIR`。`POKER_URL` 可指定 HTTPS 外网地址。规则测试覆盖牌型、轮次、all-in、短加注不重新开放行动、边池、平分、筹码守恒、非当前玩家、非法下注、过期请求与私有投影;HTTP 检查覆盖鉴权与并发重复动作。开发自测不等于独立 CR/QA。
牌型从最多七张牌枚举五张组合,最强牌型按类别及踢脚比较;奇数筹码从按钮左侧获胜玩家开始分配。每手轮转按钮,盲注 10/20,初始每位 1000。`legal.actions` 给出当前允许动作。单个不足最小加注的 all-in 不重新开放加注;累计差额达到最小加注时恢复加注权。弃牌底牌不在公开历史中披露;只有五张公共牌的已结束摊牌展示未弃牌者底牌。
## UI 复用
直接导入仓库 `apps/web/src/theme.css`、`page-layout.css`、`workbench.css`、`components/page-workspace.tsx` 与 `components/ui/button.tsx`;D-SRE 来源见 [复用清单](../../docs/frontend-reuse.md),许可见 [第三方声明](../../apps/web/THIRD_PARTY_NOTICES.md)。`style.css` 仅导入既有主题并用 `@source` 扫描根目录外复用组件的工具类,不含新增视觉规则;牌桌座位使用已有 Tailwind 网格、边框及主题 token,公共状态和历史使用原生语义元素。组件源码与许可未改动。
## 外网与交付限制
仅将本项目端口转发:
```sh
cloudflared tunnel --url http://127.0.0.1:18439 --no-autoupdate
```
先确认该端口响应为本扑克项目,再开隧道。不得转发 PPanel 控制面。临时地址随 cloudflared 生命周期失效,没有稳定域名或可用性保证。当前既有[公网观测地址](https://laws-forming-bare-remedies.trycloudflare.com)转发 `127.0.0.1:4399`,依赖本机、网络与隧道持续运行。源站 Node PID `43920`(2026-09-12 06:01:31 启动)、cloudflared PID `70644`(2026-09-12 01:23:26 启动)由部署者管理;这些是历史启动身份,不能仅凭 PID 停止或替换。开发者自测使用自己独立端口和运行目录。当前公网部署为候选 `470879a`,并非本轮最终 Git SHA 的重新部署;后续独立 CR/QA 与集成仍须绑定最终 SHA。
`evidence.json` 为三手真实对局的安全证据投影:保留模型身份、实际输出、动作、耗时、用量、结算和私有观察摘要,移除底牌;完整私有观察仍保存在开发运行目录,不能用其本机路径替代 Git/Gitea 交接。复现需自行建桌、分配模型并运行三手,不要求复现相同随机牌或模型动作。
## Issue 57 历史运行与限制(非当前部署状态)
本轮服务监听 `127.0.0.1:18459`,独立进程及启动身份、私有日志和状态目录详见 `evidence/verification.json`。`18460` 是独立 HTTP/重启测试服务。所有临时文件位于本角色 `tmp`。测试动作不计入真实对局。
已有[临时公网入口](https://laws-forming-bare-remedies.trycloudflare.com)直连 HTTP 返回 `200`,浏览器异步加载完成后显示另一张已有牌桌,停在第 5 手并提示模型调用或动作失败。指定探针 PID `70638` 已不存在;隧道 PID `70644` 启动身份仍匹配。按照 Issue 的失败分支,没有替换未知源站,没有改动隧道或控制面。该公网入口不代表本轮候选的部署,外网验收仍未完成;代理路径返回 `CONNECT 403`。公网截图与原始响应见 `evidence/issue-57/`。
本轮第三手河牌阶段 GLM 两次超时后,将玩家乙经自身邀请接口切换到 DeepSeek 继续真实决策,见 `evidence/issue-57/model-switch.json`;此前 GLM 的实际动作和失败事件均保留。模型超时不是成功响应。
本轮完成三手真实对局、一手真实摊牌(第三手河牌弃牌结束,不计摊牌),17 次成功模型响应、16 次应用动作,另一次暂停期间返回而未应用;两次超时另记错误事件。三手筹码总额均为 `3000`,重启后三手历史完整保留且默认暂停。
## Issue 73 交付与证据复用
在完整基线 `411cea6bd5a55848791051f4c47da325626ecb76` 上仅采用候选的项目目录,保留基线控制面修复。运行源码、锁文件及直接复用的共享 UI 与候选逐字一致;本轮变更为本文和开发验证证据。核验详见 `evidence/issue-73/`。
[既有独立部署证据](https://gitea.d-robotics.cc/peng01.guo/ppanel/src/commit/0afa4df50967e881a700231022c13f4e30d9d2f1/evidence/issue-35-final)记录三手真实对局、三位 pi Agent、DeepSeek/GLM 两模型、20 次成功响应、19 次应用动作、1 次停止后未应用及 1 次错误,所有历史筹码总额 `3000`。第二手模型失败后通过邀请 API 切换模型继续。第四手停止且未完成,不计数。本轮只从 Git 读取并核对这些事件,无新增模型调用。项目原有 `evidence.json` 另有三手与一次真实摊牌,是 Issue 57 历史证据,不冒称本轮新对局。
本轮本地构建与公网 JavaScript 内容逐字一致,但 CSS 和 HTML 文件哈希不同;本地构建及公网资源摘要分别保留,不声称整个构建逐字一致。真实模型与规则证据复用限于相同运行源码,页面验收以本轮浏览器检查及后续独立 QA 为准。
已知邀请交互:在同一页面仅切换 `#join=` fragment 时,`joined` 是页面级布尔值,按钮可能继续显示前一玩家“已加入”。服务端仍按当前邀请凭据鉴权,不能凭显示状态读取其他玩家底牌;三个独立新页邀请可正常完成。影响是同页连续接入时可能误以为新玩家已加入,导致开始被全员加入门禁拒绝。开发建议后续按邀请身份重置显示状态;本 Issue 明确将是否修复交给产品决定,因此本次保留并报告,不将其隐去或自作最终产品验收结论。当前使用方式是每份邀请独立新页打开。

View File

@ -0,0 +1,72 @@
import assert from "node:assert/strict";
import { readFileSync } from "node:fs";
import { resolve } from "node:path";
const admin = readFileSync(
resolve(process.env.POKER_DATA, "admin-token"),
"utf8",
);
const base = process.env.POKER_URL ?? "http://127.0.0.1:18439";
const request = async (path, body, token) => {
const r = await fetch(base + "/api/" + path, {
method: body ? "POST" : "GET",
headers: {
"Content-Type": "application/json",
...(token ? { Authorization: "Bearer " + token } : {}),
},
...(body ? { body: JSON.stringify(body) } : {}),
});
return { status: r.status, data: await r.json() };
};
assert.equal((await request("models")).status, 403);
assert.equal((await request("tables", { names: ["a", "b"] })).status, 403);
const created = await request(
"tables",
{ names: ["测试甲", "测试乙", "测试丙"] },
admin,
);
assert.equal(created.status, 201);
const { id, invitations } = created.data;
const tokens = invitations.map((i) => i.url.split(".")[1]);
const path = "tables/" + id + "/";
assert.equal((await request(path + "observation", null, "wrong")).status, 403);
assert.equal(
(await request(path + "control", { action: "start" }, tokens[0])).status,
403,
);
for (const token of tokens)
assert.equal((await request(path + "join", {}, token)).status, 200);
assert.equal(
(await request(path + "control", { action: "start" }, admin)).status,
200,
);
await new Promise((r) => setTimeout(r, 1200));
const own = (await request(path + "observation", null, tokens[0])).data;
assert.equal(own.players[0].cards.length, 2);
assert.equal(own.players[1].cards.length, 0);
const publicBefore = (await request("tables")).data;
const serialized = JSON.stringify(publicBefore);
assert(!serialized.includes(admin));
for (const token of tokens) assert(!serialized.includes(token));
assert.equal(
(
await request(
path + "action",
{ action: "fold", version: own.version },
tokens[1],
)
).status,
400,
);
assert.deepEqual((await request("tables")).data, publicBefore);
const results = await Promise.all(
[1, 2].map(() =>
request(
path + "action",
{ action: "call", version: own.version },
tokens[0],
),
),
);
assert.deepEqual(results.map((r) => r.status).sort(), [200, 400]);
await request(path + "control", { action: "pause" }, admin);
console.log("HTTP 鉴权、隐私、非当前玩家与并发重复动作检查通过");

View File

@ -0,0 +1,47 @@
import { chromium } from "@playwright/test";
import { readFileSync, writeFileSync } from "node:fs";
import { resolve } from "node:path";
import assert from "node:assert/strict";
const tmp = process.env.TMPDIR;
if (!tmp) throw Error("请设置 TMPDIR");
const browser = await chromium.launch({ channel: "chrome", headless: true });
const page = await browser.newPage();
const errors = [];
page.on("pageerror", (e) => errors.push(e.message));
const origin = process.env.POKER_URL ?? "http://127.0.0.1:18439";
await page.goto(origin);
await page.getByRole("heading", { name: "在线观测" }).waitFor();
await page.getByText("已完成手牌", { exact: true }).waitFor();
await page.screenshot({ path: resolve(tmp, "observer.png"), fullPage: true });
assert.deepEqual(errors, []);
if (process.env.POKER_DATA) {
const admin = readFileSync(
resolve(process.env.POKER_DATA, "admin-token"),
"utf8",
);
await page.getByLabel("管理凭据").fill(admin);
await page.getByRole("button", { name: "建立牌桌", exact: true }).click();
const link = page.getByRole("link", { name: "玩家 1 邀请地址" });
await link.waitFor();
const href = await link.getAttribute("href");
const guest = await browser.newPage();
await guest.goto(origin + href);
await guest.getByRole("button", { name: "接受邀请", exact: true }).click();
await guest.getByRole("button", { name: "已加入", exact: true }).waitFor();
await guest.screenshot({
path: resolve(tmp, "invitation.png"),
fullPage: true,
});
await guest.close();
}
writeFileSync(
resolve(tmp, "browser.json"),
JSON.stringify({
origin,
errors,
passed: true,
time: new Date().toISOString(),
}),
);
await browser.close();
console.log("浏览器观测、邀请流程通过");

File diff suppressed because it is too large Load Diff

Binary file not shown.

After

Width:  |  Height:  |  Size: 74 KiB

View File

@ -0,0 +1 @@
HTTP 鉴权、隐私、非当前玩家与并发重复动作检查通过

View File

@ -0,0 +1,19 @@
node:internal/modules/run_main:107
triggerUncaughtException(
^
AssertionError [ERR_ASSERTION]: Expected values to be strictly equal:
0 !== 2
at file:///Users/pptg/workspace/demo/ppanel/.ppanel/build/poker-driver/.ppanel/issue-35-control/tasks/c5ce8c73-9e72-4520-be35-cc8453d1521f/developer/d041536b-f1d1-47f3-9ba5-5c6e666cc5be/repo/projects/agent-poker/api-check.mjs:44:8
at process.processTicksAndRejections (node:internal/process/task_queues:104:5) {
generatedMessage: true,
code: 'ERR_ASSERTION',
actual: 0,
expected: 2,
operator: 'strictEqual',
diff: 'simple'
}
Node.js v24.19.0

View File

@ -0,0 +1,20 @@
{
"time": "2026-09-11T21:43:01.646Z",
"public": {
"url": "https://laws-forming-bare-remedies.trycloudflare.com/",
"empty": false,
"candidateDeployment": false,
"observedTable": "08d7e8dd-9b13-4cb6-b46e-b716be677693",
"stage": "flop",
"hand": 5,
"running": false,
"error": "模型调用或动作失败;已暂停,请检查私有证据后重试",
"note": "首次 DOM 读取早于异步加载;最终截图为已加载状态"
},
"local": {
"url": "http://127.0.0.1:18459/",
"pauseResume": true,
"invitation": true,
"privateCardsHidden": true
}
}

View File

@ -0,0 +1,14 @@
> build
> vite build
vite v8.2.2 building client environment for production...
transforming...
✓ 2018 modules transformed.
rendering chunks...
computing gzip size...
dist/index.html 0.33 kB │ gzip: 0.26 kB
dist/assets/index-jRWxiGdW.css 45.36 kB │ gzip: 10.18 kB
dist/assets/index-BITE0LBo.js 288.06 kB │ gzip: 92.73 kB
✓ built in 452ms

View File

@ -0,0 +1,50 @@
- complementary "Agent 扑克":
- heading "Agent 扑克" [level=2]
- button "收起Agent 扑克侧栏":
- paragraph: 虚拟筹码 · 无真钱交易
- button "牌桌 6396f95e · 第 3 手"
- button "牌桌 f3aa163b · 第 1 手"
- text: 管理凭据
- textbox "管理凭据"
- button "建立牌桌"
- paragraph: 管理凭据由本机服务管理员提供,不存入浏览器。
- banner:
- heading "在线观测" [level=1]
- button "开始三手" [disabled]
- button "暂停" [disabled]
- button "停止" [disabled]
- main:
- alert
- heading "第 3 手 · complete · 已暂停" [level=2]
- paragraph
- paragraph: 公共牌:Js 3c 2s 3d 2c
- paragraph: 底池 0 · 当前行动者 —
- article:
- heading "真实甲" [level=2]
- paragraph: 筹码 1160 · 本轮投入 240
- paragraph: 7s Ts
- paragraph: 已接受邀请 · deepseek-v4-flash-openai
- article:
- heading "真实乙" [level=2]
- paragraph: 筹码 1840 · 本轮投入 0
- paragraph: 已弃牌
- paragraph: 已接受邀请 · deepseek-v4-flash-openai
- article:
- heading "真实丙" [level=2]
- paragraph: 筹码 0 · 本轮投入 0
- paragraph: 已弃牌
- paragraph: 已接受邀请 · deepseek-v4-flash-openai
- heading "动作时间线" [level=2]
- paragraph: 2026-09-11T21:43:51.825Z · 真实甲 · raise · 60
- paragraph: 2026-09-11T21:44:23.726Z · 真实乙 · call · 60
- paragraph: 2026-09-11T21:44:48.666Z · 真实乙 · bet · 60
- paragraph: 2026-09-11T21:45:00.666Z · 真实甲 · call · 60
- paragraph: 2026-09-11T21:46:18.531Z · 真实乙 · bet · 120
- paragraph: 2026-09-11T21:47:02.336Z · 真实甲 · call · 120
- paragraph: 2026-09-11T21:51:29.538Z · 真实乙 · check · 0
- paragraph: 2026-09-11T21:52:24.411Z · 真实甲 · bet · 240
- paragraph: 2026-09-11T21:52:46.811Z · 真实乙 · fold · 0
- heading "已完成手牌" [level=2]
- generic "第 1 手 · 筹码核对 3000 · 5s 4d Ts Kd 8d"
- generic "第 2 手 · 筹码核对 3000 ·"
- generic "第 3 手 · 筹码核对 3000 · Js 3c 2s 3d 2c"

View File

@ -0,0 +1,9 @@
{
"time": "2026-09-11T21:51:02.447Z",
"table": "6396f95e-025f-461d-b637-bae4ad620267",
"player": 1,
"from": "66f54b63-ba93-4261-a31a-84347072f5ed",
"to": "deepseek-v4-flash-openai",
"reason": "GLM 河牌连续两次超时;改用另一真实模型依据同一玩家私有观察决策",
"status": 200
}

View File

@ -0,0 +1,4 @@
PID STARTED COMM
30934 Sat Sep 12 05:42:29 2026 /Users/pptg/.nvm/versions/node/v24.19.0/bin/node
37899 Sat Sep 12 05:53:01 2026 /Users/pptg/.nvm/versions/node/v24.19.0/bin/node
70644 Sat Sep 12 01:23:26 2026 cloudflared

View File

@ -0,0 +1,4 @@
<!doctype html><html lang="zh-CN">
<script type="module" crossorigin src="/assets/index-BITE0LBo.js"></script>
<link rel="stylesheet" crossorigin href="/assets/index-jRWxiGdW.css">
<meta charset="UTF-8"><meta name="viewport" content="width=device-width,initial-scale=1"><title>Agent 扑克观测</title><div id="root"></div></html>

View File

@ -0,0 +1,10 @@
HTTP/2 200
date: Fri, 11 Sep 2026 21:40:49 GMT
content-type: text/html; charset=utf-8
cf-ray: a399d53e288d9dfc-LAX
cf-cache-status: DYNAMIC
cache-control: no-store
server: cloudflare
referrer-policy: no-referrer
x-content-type-options: nosniff

View File

@ -0,0 +1,48 @@
- complementary "Agent 扑克":
- heading "Agent 扑克" [level=2]
- button "收起Agent 扑克侧栏":
- paragraph: 虚拟筹码 · 无真钱交易
- button "牌桌 08d7e8dd · 第 5 手"
- button "牌桌 75f77e5a · 第 1 手"
- button "牌桌 93638aa3 · 第 0 手"
- text: 管理凭据
- textbox "管理凭据"
- button "建立牌桌"
- paragraph: 管理凭据由本机服务管理员提供,不存入浏览器。
- banner:
- heading "在线观测" [level=1]
- button "开始三手" [disabled]
- button "暂停" [disabled]
- button "停止" [disabled]
- main:
- alert
- heading "第 5 手 · flop · 已暂停" [level=2]
- paragraph: 模型调用或动作失败;已暂停,请检查私有证据后重试
- paragraph: 公共牌:Ts 8d 8s
- paragraph: 底池 280 · 当前行动者 真实 Agent 乙
- article:
- heading "真实 Agent 甲" [level=2]
- paragraph: 筹码 1020 · 本轮投入 100
- paragraph: 底牌保密
- paragraph: 已接受邀请 · deepseek-v4-flash-openai
- article:
- heading "真实 Agent 乙 · 行动中" [level=2]
- paragraph: 筹码 840 · 本轮投入 0
- paragraph: 底牌保密
- paragraph: 已接受邀请 · 66f54b63-ba93-4261-a31a-84347072f5ed
- article:
- heading "真实 Agent 丙" [level=2]
- paragraph: 筹码 860 · 本轮投入 0
- paragraph: 底牌保密
- paragraph: 已接受邀请 · deepseek-v4-flash-openai
- heading "动作时间线" [level=2]
- paragraph: 2026-09-11T21:36:16.834Z · 真实 Agent 乙 · raise · 60
- paragraph: 2026-09-11T21:36:42.429Z · 真实 Agent 丙 · call · 60
- paragraph: 2026-09-11T21:37:07.618Z · 真实 Agent 甲 · call · 60
- paragraph: 2026-09-11T21:37:16.855Z · 真实 Agent 丙 · check · 0
- paragraph: 2026-09-11T21:37:43.342Z · 真实 Agent 甲 · bet · 100
- heading "已完成手牌" [level=2]
- generic "第 1 手 · 筹码核对 3000 · 7h 4c Qh"
- generic "第 2 手 · 筹码核对 3000 ·"
- generic "第 3 手 · 筹码核对 3000 · Kc 9h 2h"
- generic "第 4 手 · 筹码核对 3000 · 5h 2c Jd"

View File

@ -0,0 +1 @@
curl: (56) CONNECT tunnel failed, response 403

View File

@ -0,0 +1,13 @@
HTTP/1.1 403 Forbidden
Server: squid/3.5.20
Mime-Version: 1.0
Date: Fri, 11 Sep 2026 21:40:03 GMT
Content-Type: text/html;charset=utf-8
Content-Length: 3605
X-Squid-Error: ERR_ACCESS_DENIED 0
Vary: Accept-Language
Content-Language: en
X-Cache: MISS from proxy1080254
X-Cache-Lookup: NONE from proxy1080254:8838
Connection: keep-alive

View File

@ -0,0 +1 @@
{"error":"需要管理凭据"}

View File

@ -0,0 +1,10 @@
HTTP/2 403
date: Fri, 11 Sep 2026 21:47:37 GMT
content-type: application/json; charset=utf-8
cf-ray: a399df36acf7ad7f-LAX
cf-cache-status: DYNAMIC
cache-control: no-store
server: cloudflare
referrer-policy: no-referrer
x-content-type-options: nosniff

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,10 @@
HTTP/2 200
date: Fri, 11 Sep 2026 21:47:38 GMT
content-type: application/json; charset=utf-8
cf-ray: a399df3cdafd170b-LAX
cf-cache-status: DYNAMIC
cache-control: no-store
server: cloudflare
referrer-policy: no-referrer
x-content-type-options: nosniff

Binary file not shown.

After

Width:  |  Height:  |  Size: 85 KiB

View File

@ -0,0 +1 @@
{"hands":3,"showdowns":1,"calls":17,"applied":16,"conserved":3000}

View File

@ -0,0 +1 @@
测试服务重启后公共牌桌、行动与筹码完全一致,默认暂停。

View File

@ -0,0 +1,14 @@
✔ 快照替换完整且私有;替换前进程被杀仍保留旧历史 (49.173333ms)
✔ 牌型、轮子顺子及踢脚比较 (0.412791ms)
✔ 边池与平分奇数筹码 (1.681ms)
✔ 轮次、隐私、重复动作与非法输入均不变更状态 (1.657291ms)
✔ 短 all-in 不重新开放加注;全下自动摊牌守恒 (1.4125ms)
✔ 连续 50 手合法行动筹码守恒 (7.56375ms)
ℹ tests 6
ℹ suites 0
ℹ pass 6
ℹ fail 0
ℹ cancelled 0
ℹ skipped 0
ℹ todo 0
ℹ duration_ms 82.398125

View File

@ -0,0 +1,2 @@
PID STARTED COMM
70644 Sat Sep 12 01:23:26 2026 cloudflared

View File

@ -0,0 +1 @@
HTTP 鉴权、隐私、非当前玩家与并发重复动作检查通过

View File

@ -0,0 +1 @@
{"origin":"http://127.0.0.1:18473","errors":[],"passed":true,"time":"2026-09-11T22:12:44.804Z"}

View File

@ -0,0 +1 @@
浏览器观测、邀请流程通过

View File

@ -0,0 +1,8 @@
{
"javascriptBytesEqual": true,
"localJs": "index-BITE0LBo.js",
"publicJs": "index-BwNhEx3M.js",
"sha256": "df87f0196d551fa33dafb8eb106da6f851f853e4bfa8f0e3e21edb257505911e",
"cssBytesEqual": false,
"note": "CSS 扫描产物不同,不能将现有部署声称为最终 SHA 完整构建;运行源码和 JS 一致。"
}

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,14 @@
> build
> vite build
vite v8.2.2 building client environment for production...
transforming...
✓ 2018 modules transformed.
rendering chunks...
computing gzip size...
dist/index.html 0.33 kB │ gzip: 0.26 kB
dist/assets/index-jRWxiGdW.css 45.36 kB │ gzip: 10.18 kB
dist/assets/index-BITE0LBo.js 288.06 kB │ gzip: 92.73 kB
✓ built in 418ms

View File

@ -0,0 +1 @@
三个独立邀请、未全员加入门禁、开始/暂停/恢复/停止及公网三手历史与禁用控制通过

View File

@ -0,0 +1,39 @@
[
{
"path": "/",
"status": 200,
"sha256": "b2240cfd6130bfa43c0159ae00518c3d9855d5a356aace80096ca50ef7113367"
},
{
"path": "/assets/index-BwNhEx3M.js",
"sha256": "df87f0196d551fa33dafb8eb106da6f851f853e4bfa8f0e3e21edb257505911e"
},
{
"path": "/assets/index-B8wKFYrG.css",
"sha256": "0cd7944b5e82789f068f8683e1808bb3f5ee29c2d58baf3d88b271b7ebcc3dec"
},
{
"path": "/api/models",
"status": 403,
"sha256": "9a05b7731db5086eb3ae2565d33126186b1cc1a0facf9ea0e6f82512f710b3d7"
},
{
"path": "/api/tables",
"status": 200,
"sha256": "6ba068fe5c5768136f4d2e6a46578ad5d329152d0b3f0de60330cd1c1a9fc5cf"
},
{
"tables": [
{
"id": "70adbf3c-412c-45e1-8e82-a18cc539ffb8",
"hands": 3,
"running": false,
"totals": [
3000,
3000,
3000
]
}
]
}
]

Binary file not shown.

After

Width:  |  Height:  |  Size: 72 KiB

View File

@ -0,0 +1,236 @@
{
"candidate": "470879a305438fc958acfc6486f1f86bcd94b681",
"fileChecks": [
{
"path": "projects/agent-poker/README.md",
"matches": true
},
{
"path": "projects/agent-poker/api-check.mjs",
"matches": true
},
{
"path": "projects/agent-poker/browser-check.mjs",
"matches": true
},
{
"path": "projects/agent-poker/evidence.json",
"matches": true
},
{
"path": "projects/agent-poker/evidence/invitation.png",
"matches": true
},
{
"path": "projects/agent-poker/evidence/issue-57/api-isolated.log",
"matches": true
},
{
"path": "projects/agent-poker/evidence/issue-57/api.log",
"matches": true
},
{
"path": "projects/agent-poker/evidence/issue-57/browser.json",
"matches": true
},
{
"path": "projects/agent-poker/evidence/issue-57/build.log",
"matches": true
},
{
"path": "projects/agent-poker/evidence/issue-57/local-dom.txt",
"matches": true
},
{
"path": "projects/agent-poker/evidence/issue-57/model-switch.json",
"matches": true
},
{
"path": "projects/agent-poker/evidence/issue-57/processes-final.txt",
"matches": true
},
{
"path": "projects/agent-poker/evidence/issue-57/public-direct-body.txt",
"matches": true
},
{
"path": "projects/agent-poker/evidence/issue-57/public-direct-error.txt",
"matches": true
},
{
"path": "projects/agent-poker/evidence/issue-57/public-direct-headers.txt",
"matches": true
},
{
"path": "projects/agent-poker/evidence/issue-57/public-dom.txt",
"matches": true
},
{
"path": "projects/agent-poker/evidence/issue-57/public-error.txt",
"matches": true
},
{
"path": "projects/agent-poker/evidence/issue-57/public-headers.txt",
"matches": true
},
{
"path": "projects/agent-poker/evidence/issue-57/public-models-body.txt",
"matches": true
},
{
"path": "projects/agent-poker/evidence/issue-57/public-models-error.txt",
"matches": true
},
{
"path": "projects/agent-poker/evidence/issue-57/public-models-headers.txt",
"matches": true
},
{
"path": "projects/agent-poker/evidence/issue-57/public-tables-body.txt",
"matches": true
},
{
"path": "projects/agent-poker/evidence/issue-57/public-tables-error.txt",
"matches": true
},
{
"path": "projects/agent-poker/evidence/issue-57/public-tables-headers.txt",
"matches": true
},
{
"path": "projects/agent-poker/evidence/issue-57/public.png",
"matches": true
},
{
"path": "projects/agent-poker/evidence/issue-57/real-verification.log",
"matches": true
},
{
"path": "projects/agent-poker/evidence/issue-57/restart.log",
"matches": true
},
{
"path": "projects/agent-poker/evidence/issue-57/tests-final.log",
"matches": true
},
{
"path": "projects/agent-poker/evidence/issue-57/tunnel-process.txt",
"matches": true
},
{
"path": "projects/agent-poker/evidence/observer.png",
"matches": true
},
{
"path": "projects/agent-poker/evidence/verification.json",
"matches": true
},
{
"path": "projects/agent-poker/game.mjs",
"matches": true
},
{
"path": "projects/agent-poker/index.html",
"matches": true
},
{
"path": "projects/agent-poker/models.mjs",
"matches": true
},
{
"path": "projects/agent-poker/package-lock.json",
"matches": true
},
{
"path": "projects/agent-poker/package.json",
"matches": true
},
{
"path": "projects/agent-poker/persistence.mjs",
"matches": true
},
{
"path": "projects/agent-poker/persistence.test.mjs",
"matches": true
},
{
"path": "projects/agent-poker/real-check.mjs",
"matches": true
},
{
"path": "projects/agent-poker/server.mjs",
"matches": true
},
{
"path": "projects/agent-poker/service.mjs",
"matches": true
},
{
"path": "projects/agent-poker/style.css",
"matches": true
},
{
"path": "projects/agent-poker/test.mjs",
"matches": true
},
{
"path": "projects/agent-poker/ui.jsx",
"matches": true
},
{
"path": "projects/agent-poker/vite.config.mjs",
"matches": true
},
{
"path": "apps/web/src/theme.css",
"matches": true
},
{
"path": "apps/web/src/page-layout.css",
"matches": true
},
{
"path": "apps/web/src/workbench.css",
"matches": true
},
{
"path": "apps/web/src/components/page-workspace.tsx",
"matches": true
},
{
"path": "apps/web/src/components/ui/button.tsx",
"matches": true
},
{
"path": "apps/web/src/lib/utils.ts",
"matches": true
},
{
"path": "apps/web/THIRD_PARTY_NOTICES.md",
"matches": true
}
],
"allMatch": true,
"historicalReal": {
"calls": 20,
"applied": 19,
"historyTotals": [
3000,
3000,
3000
],
"models": [
"deepseek-v4-flash",
"glm-5.3"
]
},
"newModelCalls": 0,
"note": "45 个候选文件在 README 编辑前全部匹配;最终仅 README 与本轮新增证据不同。",
"historicalIssue57": {
"calls": 17,
"hands": 3,
"showdownHands": [
1
]
}
}

View File

@ -0,0 +1,18 @@
> test
> node --test test.mjs persistence.test.mjs
✔ 快照替换完整且私有;替换前进程被杀仍保留旧历史 (63.833542ms)
✔ 牌型、轮子顺子及踢脚比较 (0.391959ms)
✔ 边池与平分奇数筹码 (1.483875ms)
✔ 轮次、隐私、重复动作与非法输入均不变更状态 (1.317917ms)
✔ 短 all-in 不重新开放加注;全下自动摊牌守恒 (0.554667ms)
✔ 连续 50 手合法行动筹码守恒 (7.397042ms)
ℹ tests 6
ℹ suites 0
ℹ pass 6
ℹ fail 0
ℹ cancelled 0
ℹ skipped 0
ℹ todo 0
ℹ duration_ms 95.279

Binary file not shown.

After

Width:  |  Height:  |  Size: 84 KiB

View File

@ -0,0 +1,61 @@
{
"issue": 57,
"revision": 1,
"baseSha": "46dca1a8eaf45e67477d2e27d8a3ad44abdd7aba",
"localUrl": "http://127.0.0.1:18459",
"publicUrl": "https://laws-forming-bare-remedies.trycloudflare.com",
"publicCandidateDeployment": false,
"checks": {
"rules": "✔ 快照替换完整且私有;替换前进程被杀仍保留旧历史 (49.173333ms)\n✔ 牌型、轮子顺子及踢脚比较 (0.412791ms)\n✔ 边池与平分奇数筹码 (1.681ms)\n✔ 轮次、隐私、重复动作与非法输入均不变更状态 (1.657291ms)\n✔ 短 all-in 不重新开放加注;全下自动摊牌守恒 (1.4125ms)\n✔ 连续 50 手合法行动筹码守恒 (7.56375ms)\nℹ tests 6\nℹ suites 0\nℹ pass 6\nℹ fail 0\nℹ cancelled 0\nℹ skipped 0\nℹ todo 0\nℹ duration_ms 82.398125\n",
"api": "HTTP 鉴权、隐私、非当前玩家与并发重复动作检查通过\n",
"initialApiFailure": "node:internal/modules/run_main:107\n triggerUncaughtException(\n ^\n\nAssertionError [ERR_ASSERTION]: Expected values to be strictly equal:\n\n0 !== 2\n\n at file:///Users/pptg/workspace/demo/ppanel/.ppanel/build/poker-driver/.ppanel/issue-35-control/tasks/c5ce8c73-9e72-4520-be35-cc8453d1521f/developer/d041536b-f1d1-47f3-9ba5-5c6e666cc5be/repo/projects/agent-poker/api-check.mjs:44:8\n at process.processTicksAndRejections (node:internal/process/task_queues:104:5) {\n generatedMessage: true,\n code: 'ERR_ASSERTION',\n actual: 0,\n expected: 2,\n operator: 'strictEqual',\n diff: 'simple'\n}\n\nNode.js v24.19.0\n",
"restart": "测试服务重启后公共牌桌、行动与筹码完全一致,默认暂停。\n",
"build": "\n> build\n> vite build\n\nvite v8.2.2 building client environment for production...\ntransforming...\n✓ 2018 modules transformed.\nrendering chunks...\ncomputing gzip size...\ndist/index.html 0.33 kB │ gzip: 0.26 kB\ndist/assets/index-jRWxiGdW.css 45.36 kB │ gzip: 10.18 kB\ndist/assets/index-BITE0LBo.js 288.06 kB │ gzip: 92.73 kB\n\n✓ built in 452ms\n",
"publicUnauthorizedModels": "公网 GET /api/models 返回 403,需要管理凭据;原始响应见 evidence/issue-57/public-models-headers.txt 与 public-models-body.txt"
},
"browser": {
"time": "2026-09-11T21:43:01.646Z",
"public": {
"url": "https://laws-forming-bare-remedies.trycloudflare.com/",
"empty": false,
"candidateDeployment": false,
"observedTable": "08d7e8dd-9b13-4cb6-b46e-b716be677693",
"stage": "flop",
"hand": 5,
"running": false,
"error": "模型调用或动作失败;已暂停,请检查私有证据后重试",
"note": "首次 DOM 读取早于异步加载;最终截图为已加载状态"
},
"local": {
"url": "http://127.0.0.1:18459/",
"pauseResume": true,
"invitation": true,
"privateCardsHidden": true
}
},
"processes": " PID STARTED COMM\n30934 Sat Sep 12 05:42:29 2026 /Users/pptg/.nvm/versions/node/v24.19.0/bin/node\n37899 Sat Sep 12 05:53:01 2026 /Users/pptg/.nvm/versions/node/v24.19.0/bin/node\n70644 Sat Sep 12 01:23:26 2026 cloudflared\n",
"privateData": "/Users/pptg/workspace/demo/ppanel/.ppanel/build/poker-driver/.ppanel/issue-35-control/tasks/c5ce8c73-9e72-4520-be35-cc8453d1521f/developer/d041536b-f1d1-47f3-9ba5-5c6e666cc5be/tmp/service",
"privateLog": "/Users/pptg/workspace/demo/ppanel/.ppanel/build/poker-driver/.ppanel/issue-35-control/tasks/c5ce8c73-9e72-4520-be35-cc8453d1521f/developer/d041536b-f1d1-47f3-9ba5-5c6e666cc5be/tmp/server.log",
"sourceSha256": {
"server.mjs": "853ed7b9fe650c18e1db6be251ac679ec8a28529e28aa5592aadc38c002d0561",
"persistence.mjs": "b6dcce720ca30bf53ebb86f55df7b3e75ea79344c4ae765f853ef36ab19f1387",
"models.mjs": "761525ddb254965534e67ed1d9d240a6666f03f1b9a65e9e4d208133b6b56a12",
"game.mjs": "89e1f2ea76032921344a741a25d45ab05534cc74cd54de742b40009cbb2648ee",
"real-check.mjs": "98ac0870c3b1a60f18546f274fb97072a486b4ec20cc2d16a45b859e7845c8dc"
},
"limitations": [
"指定源站探针 PID 70638 已不存在,未替换未知源站;公网为另一已有牌桌,不是本轮候选部署",
"独立 CR 与 QA 尚待控制面分派",
"单进程快照;不提供日志与状态跨文件事务,物理断电仍受操作系统与存储硬件保证约束"
],
"real": {
"hands": 3,
"showdowns": 1,
"calls": 17,
"applied": 16,
"total": 3000,
"restartHistoryPreserved": true,
"fiveCardBoards": 2
},
"realVerification": "{\"hands\":3,\"showdowns\":1,\"calls\":17,\"applied\":16,\"conserved\":3000}\n"
}

View File

@ -0,0 +1,295 @@
import { randomInt } from "node:crypto";
export function rank(cards) {
let best = [];
const compare = (a, b) => {
for (let i = 0; i < Math.max(a.length, b.length); i++) {
if ((a[i] ?? 0) !== (b[i] ?? 0)) return (a[i] ?? 0) - (b[i] ?? 0);
}
return 0;
};
for (let a = 0; a < cards.length - 4; a++)
for (let b = a + 1; b < cards.length - 3; b++)
for (let c = b + 1; c < cards.length - 2; c++)
for (let d = c + 1; d < cards.length - 1; d++)
for (let e = d + 1; e < cards.length; e++) {
const hand = [a, b, c, d, e].map((i) => cards[i]),
values = hand
.map((c) => "23456789TJQKA".indexOf(c[0]) + 2)
.sort((a, b) => b - a);
const groups = [...new Set(values)]
.map((v) => [values.filter((x) => x === v).length, v])
.sort((a, b) => b[0] - a[0] || b[1] - a[1]);
const flush = hand.every((c) => c[1] === hand[0][1]);
const straight =
new Set(values).size === 5
? values[0] - values[4] === 4
? values[0]
: values.join() === "14,5,4,3,2"
? 5
: 0
: 0;
const g = groups;
const score =
flush && straight
? [8, straight]
: g[0][0] === 4
? [7, g[0][1], g[1][1]]
: g[0][0] === 3 && g[1][0] === 2
? [6, g[0][1], g[1][1]]
: flush
? [5, ...values]
: straight
? [4, straight]
: g[0][0] === 3
? [3, ...g.map((x) => x[1])]
: g[0][0] === 2 && g[1][0] === 2
? [2, ...g.map((x) => x[1])]
: g[0][0] === 2
? [1, ...g.map((x) => x[1])]
: [0, ...values];
if (compare(score, best) > 0) best = score;
}
return best.reduce((n, v) => n * 15 + v, 0) * 15 ** (6 - best.length);
}
export function settle(players, board, button) {
const awards = players.map(() => 0),
pots = [];
let previous = 0;
for (const level of [
...new Set(players.map((p) => p.total).filter(Boolean)),
].sort((a, b) => a - b)) {
const contributors = players
.map((p, i) => ({ p, i }))
.filter((x) => x.p.total >= level);
const amount = (level - previous) * contributors.length;
previous = level;
const eligible = contributors.filter((x) => !x.p.folded);
// Uncalled excess belongs to its sole contributor, even after a fold.
const candidates = eligible.length ? eligible : contributors;
const score = (x) =>
board.length === 5 ? rank([...x.p.cards, ...board]) : 0;
const maximum = Math.max(...candidates.map(score));
const winners = candidates
.filter((x) => score(x) === maximum)
.map((x) => x.i)
.sort(
(a, b) =>
((a - button - 1 + players.length) % players.length) -
((b - button - 1 + players.length) % players.length),
);
winners.forEach(
(i, k) =>
(awards[i] +=
Math.floor(amount / winners.length) +
(k < amount % winners.length ? 1 : 0)),
);
pots.push({ amount, winners });
}
return { awards, pots };
}
export class Game {
constructor(names, stacks = names.map(() => 1000)) {
if (names.length < 2 || names.length > 6) throw Error("需要 2–6 位玩家");
this.players = names.map((name, i) => ({
id: i,
name,
stack: stacks[i],
cards: [],
total: 0,
bet: 0,
folded: false,
}));
this.initial = stacks.reduce((a, b) => a + b, 0);
this.hand = 0;
this.version = 0;
this.button = -1;
this.stage = "waiting";
this.board = [];
this.history = [];
this.timeline = [];
this.actor = null;
}
next(i, predicate) {
for (let k = 1; k <= this.players.length; k++) {
const j = (i + k) % this.players.length;
if (predicate(this.players[j], j)) return j;
}
return null;
}
start(deck) {
if (!["waiting", "complete"].includes(this.stage))
throw Error("牌局进行中");
if (this.players.filter((p) => p.stack > 0).length < 2)
throw Error("不足两位有筹码玩家");
this.hand++;
this.version++;
this.board = [];
this.timeline = [];
this.current = 20;
this.minRaise = 20;
this.button = this.next(this.button, (p) => p.stack > 0);
this.players.forEach((p) =>
Object.assign(p, {
cards: [],
total: 0,
bet: 0,
folded: p.stack === 0,
actedAt: null,
}),
);
this.deck = deck
? [...deck]
: [..."23456789TJQKA"].flatMap((v) => [..."shdc"].map((s) => v + s));
if (!deck)
for (let i = this.deck.length - 1; i > 0; i--) {
const j = randomInt(i + 1);
[this.deck[i], this.deck[j]] = [this.deck[j], this.deck[i]];
}
for (let k = 0; k < 2; k++)
this.players.forEach((p) => {
if (!p.folded) p.cards.push(this.deck.pop());
});
const sb =
this.players.filter((p) => !p.folded).length === 2
? this.button
: this.next(this.button, (p) => !p.folded),
bb = this.next(sb, (p) => !p.folded);
this.pay(sb, 10);
this.pay(bb, 20);
this.stage = "preflop";
this.actor = this.next(bb, (p) => !p.folded && p.stack > 0);
this.advance();
}
pay(i, n) {
const p = this.players[i],
amount = Math.min(n, p.stack);
p.stack -= amount;
p.bet += amount;
p.total += amount;
}
legal(i) {
const p = this.players[i];
if (i !== this.actor || !p || p.folded || !p.stack) return null;
const call = Math.max(0, this.current - p.bet),
canRaise =
p.actedAt === null || this.current - p.actedAt >= this.minRaise;
const max = p.bet + p.stack,
min = this.current + this.minRaise;
return {
actions: [
"fold",
...(call ? ["call"] : ["check"]),
...(canRaise && max >= min ? [this.current ? "raise" : "bet"] : []),
...(max <= this.current || canRaise ? ["all-in"] : []),
],
call: Math.min(call, p.stack),
min,
max,
};
}
act(i, action, amount, version) {
if (version !== this.version) throw Error("重复或过期动作");
const l = this.legal(i);
if (!l || !l.actions.includes(action)) throw Error("非法或非当前玩家动作");
const p = this.players[i];
let target = p.bet;
if (action === "call") target = p.bet + l.call;
if (action === "all-in") target = l.max;
if (["bet", "raise"].includes(action)) {
if (!Number.isSafeInteger(amount) || amount < l.min || amount > l.max)
throw Error("非法下注");
target = amount;
}
if (action === "fold") p.folded = true;
else this.pay(i, target - p.bet);
if (target > this.current) {
const delta = target - this.current;
if (delta >= this.minRaise) this.minRaise = delta;
this.current = target;
}
p.actedAt = this.current;
this.timeline.push({
hand: this.hand,
version: this.version,
player: i,
action,
amount: target,
time: new Date().toISOString(),
});
this.version++;
this.actor = this.next(
i,
(p) =>
!p.folded &&
p.stack > 0 &&
(p.actedAt === null || p.bet < this.current),
);
this.advance();
}
advance() {
const alive = this.players.filter((p) => !p.folded),
active = alive.filter((p) => p.stack > 0);
if (alive.length === 1) return this.finish();
if (active.length <= 1 && active.every((p) => p.bet >= this.current)) {
while (this.board.length < 5) this.board.push(this.deck.pop());
return this.finish();
}
if (this.actor !== null) return;
if (this.stage === "river") return this.finish();
this.stage = { preflop: "flop", flop: "turn", turn: "river" }[this.stage];
for (let k = 0; k < (this.stage === "flop" ? 3 : 1); k++)
this.board.push(this.deck.pop());
this.current = 0;
this.minRaise = 20;
this.players.forEach((p) => {
p.bet = 0;
p.actedAt = null;
});
this.actor = this.next(this.button, (p) => !p.folded && p.stack > 0);
if (this.actor === null) this.advance();
}
finish() {
const result = settle(this.players, this.board, this.button);
this.players.forEach((p, i) => (p.stack += result.awards[i]));
this.stage = "complete";
this.actor = null;
this.history.push({
hand: this.hand,
board: [...this.board],
...result,
stacks: this.players.map((p) => p.stack),
total: this.players.reduce((n, p) => n + p.stack, 0),
actions: [...this.timeline],
});
if (this.history.at(-1).total !== this.initial) throw Error("筹码不守恒");
}
view(id) {
return {
hand: this.hand,
version: this.version,
stage: this.stage,
button: this.button,
actor: this.actor,
board: this.board,
pot:
this.stage === "complete"
? 0
: this.players.reduce((n, p) => n + p.total, 0),
players: this.players.map((p) => ({
id: p.id,
name: p.name,
stack: p.stack,
bet: p.bet,
folded: p.folded,
cards:
p.id === id ||
(this.stage === "complete" && this.board.length === 5 && !p.folded)
? p.cards
: [],
})),
legal: this.legal(id),
history: this.history,
timeline: this.timeline,
};
}
}

View File

@ -0,0 +1 @@
<!doctype html><html lang="zh-CN"><meta charset="UTF-8"><meta name="viewport" content="width=device-width,initial-scale=1"><title>Agent 扑克观测</title><div id="root"></div><script type="module" src="/ui.jsx"></script></html>

View File

@ -0,0 +1,90 @@
// Adapted from apps/server/src/config.ts (D-SRE provider mapping).
import { readFileSync } from "node:fs";
import { parse } from "yaml";
import { createModels, createProvider } from "@earendil-works/pi-ai";
import { openAICompletionsApi } from "@earendil-works/pi-ai/api/openai-completions.lazy";
import { openAIResponsesApi } from "@earendil-works/pi-ai/api/openai-responses.lazy";
import { anthropicMessagesApi } from "@earendil-works/pi-ai/api/anthropic-messages.lazy";
import { Agent } from "@earendil-works/pi-agent-core";
export function loadModels() {
const items = parse(
readFileSync("/Users/pptg/.d-sre-agent/config/sre-agent.yaml", "utf8"),
).llm.items;
const models = createModels();
for (const item of items) {
const c = item.compat ?? {};
const api = {
"openai-completions": openAICompletionsApi,
"openai-responses": openAIResponsesApi,
"anthropic-messages": anthropicMessagesApi,
}[item.api];
if (!api) continue;
models.setProvider(
createProvider({
id: item.id,
name: item.name,
baseUrl: item.api_base,
auth: {
apiKey: {
name: item.name,
resolve: async () => ({
auth: { apiKey: item.api_key },
source: "本机 YAML",
}),
},
},
models: [
{
id: item.model,
name: item.name,
api: item.api,
provider: item.id,
baseUrl: item.api_base,
reasoning: item.reasoning ?? false,
input: ["text"],
cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 },
contextWindow: item.context_window ?? 128000,
maxTokens: Math.min(item.max_tokens ?? 4096, 4096),
compat: {
supportsDeveloperRole: c.supportsDeveloperRole,
supportsReasoningEffort: c.supportsReasoningEffort,
supportsUsageInStreaming: c.supportsStreamingUsage,
supportsStrictMode: c.supportsStrictToolSchema,
},
},
],
api: api(),
}),
);
}
return { items, models };
}
export async function decide(cfg, item, observation) {
const agent = new Agent({
streamFn: (model, context, options) =>
cfg.models.streamSimple(model, context, options),
initialState: {
systemPrompt:
'你是一位虚拟筹码德州扑克玩家。仅根据私有观察自主决策,不知道其他底牌。只输出 JSON 对象 {"action":"合法动作名称","amount":整数}。amount 是本轮下注总额,仅 bet/raise 需要。务必选择 legal.actions 内的动作,遵守 min/max。',
model: cfg.models.getModel(item.id, item.model),
thinkingLevel: "off",
tools: [],
},
});
const timer = setTimeout(() => agent.abort(), 90000);
try {
await agent.prompt(JSON.stringify(observation));
} finally {
clearTimeout(timer);
}
const messages = agent.state.messages;
const last = messages.filter((m) => m.role === "assistant").at(-1);
const output =
last?.content
?.filter((c) => c.type === "text")
.map((c) => c.text)
.join("\n") ?? "";
const match = output.match(/\{[\s\S]*\}/);
if (!match) throw Error("模型未返回动作 JSON");
return { action: JSON.parse(match[0]), output, usage: last.usage };
}

3475
projects/agent-poker/package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,29 @@
{
"name": "agent-poker",
"private": true,
"type": "module",
"scripts": {
"test": "node --test test.mjs persistence.test.mjs",
"start": "node server.mjs",
"build": "vite build"
},
"dependencies": {
"@base-ui/react": "1.8.0",
"@earendil-works/pi-agent-core": "0.85.0",
"@earendil-works/pi-ai": "0.85.0",
"class-variance-authority": "^0.7.1",
"clsx": "^2.1.1",
"lucide-react": "^1.42.0",
"react": "19.2.8",
"react-dom": "19.2.8",
"tailwind-merge": "^3.6.0",
"yaml": "^2.8.0"
},
"devDependencies": {
"@playwright/test": "^1.63.0",
"@tailwindcss/vite": "^4.3.3",
"@vitejs/plugin-react": "6.1.1",
"tailwindcss": "^4.3.3",
"vite": "8.2.2"
}
}

View File

@ -0,0 +1,21 @@
import {openSync, writeFileSync, fsyncSync, closeSync, renameSync, rmSync} from 'node:fs';
import {dirname} from 'node:path';
// 单进程快照:同目录临时文件刷盘后替换,读者只看到完整旧版或新版。
export function atomicWrite(file, content) {
const temporary = file + '.pending';
let fd;
try {
fd = openSync(temporary, 'w', 0o600);
writeFileSync(fd, content);
fsyncSync(fd);
closeSync(fd);
fd = undefined;
renameSync(temporary, file);
fd = openSync(dirname(file), 'r');
fsyncSync(fd);
} finally {
if (fd !== undefined) closeSync(fd);
rmSync(temporary, {force:true});
}
}

View File

@ -0,0 +1,29 @@
import test from 'node:test';
import assert from 'node:assert/strict';
import {mkdtempSync, readFileSync, statSync, rmSync} from 'node:fs';
import {join} from 'node:path';
import {spawnSync} from 'node:child_process';
import {atomicWrite} from './persistence.mjs';
test('快照替换完整且私有;替换前进程被杀仍保留旧历史', () => {
assert(process.env.TMPDIR, '必须设置角色私有 TMPDIR');
const dir = mkdtempSync(join(process.env.TMPDIR, 'snapshot-'));
const file = join(dir, 'state.json');
try {
const old = JSON.stringify([{history: [{hand: 1}]}]);
atomicWrite(file, old);
assert.equal(statSync(file).mode & 0o777, 0o600);
const child = spawnSync(process.execPath, ['--input-type=module', '-e', `
import fs from 'node:fs';
import {syncBuiltinESMExports} from 'node:module';
fs.renameSync = () => process.kill(process.pid, 'SIGKILL');
syncBuiltinESMExports();
const {atomicWrite} = await import(${JSON.stringify(new URL('./persistence.mjs', import.meta.url).href)});
atomicWrite(process.argv[1], JSON.stringify([{history: [{hand: 1}, {hand: 2}]}]));
`, file]);
assert.equal(child.signal, 'SIGKILL');
assert.equal(readFileSync(file, 'utf8'), old);
atomicWrite(file, '[{"history":[1,2,3]}]');
assert.deepEqual(JSON.parse(readFileSync(file, 'utf8')), [{history:[1,2,3]}]);
} finally { rmSync(dir, {recursive:true, force:true}); }
});

View File

@ -0,0 +1,33 @@
import { readFileSync, writeFileSync } from 'node:fs';
import { resolve } from 'node:path';
if (!process.env.POKER_DATA || !process.env.TMPDIR)
throw Error('必须设置私有 POKER_DATA 与 TMPDIR');
const base = (process.env.POKER_URL ?? 'http://127.0.0.1:18459') + '/api/';
const admin = readFileSync(resolve(process.env.POKER_DATA, 'admin-token'), 'utf8');
async function request(path, body, token = admin) {
const response = await fetch(base + path, {
method: body ? 'POST' : 'GET',
headers: { 'Content-Type': 'application/json', Authorization: 'Bearer ' + token },
...(body ? { body: JSON.stringify(body) } : {}),
});
const data = await response.json();
if (!response.ok) throw Error(JSON.stringify(data));
return data;
}
const { models } = await request('models');
const selected = models.filter(m => /deepseek|glm/i.test(m.model)).slice(0, 2);
if (new Set(selected.map(m => m.model)).size < 2)
throw Error('缺少两种目标模型');
const table = await request('tables', { names: ['真实甲', '真实乙', '真实丙'] });
writeFileSync(
resolve(process.env.TMPDIR, 'real-table.json'),
JSON.stringify({ id: table.id, models: selected }),
{ mode: 0o600 },
);
for (let i = 0; i < 3; i++) {
await request('tables/' + table.id + '/join',
{ modelId: selected[i % 2].id }, table.invitations[i].url.split('.')[1]);
}
await request('tables/' + table.id + '/control', { action: 'start' });
console.log('真实对局已开始', table.id, selected.map(m => m.model));

View File

@ -0,0 +1,243 @@
import { createServer } from "node:http";
import { randomBytes, randomUUID } from "node:crypto";
import {
readFileSync,
mkdirSync,
existsSync,
appendFileSync,
} from "node:fs";
import { resolve, extname } from "node:path";
import { atomicWrite } from "./persistence.mjs";
import { Game } from "./game.mjs";
import { loadModels, decide } from "./models.mjs";
const data = process.env.POKER_DATA;
if (!data) throw Error("必须设置私有 POKER_DATA");
mkdirSync(data, { recursive: true, mode: 0o700 });
const privateFile = resolve(data, "state.json");
let cfg;
const tables = new Map();
const adminFile = resolve(data, "admin-token");
const admin = existsSync(adminFile)
? readFileSync(adminFile, "utf8")
: randomBytes(32).toString("hex");
atomicWrite(adminFile, admin);
if (existsSync(privateFile))
for (const t of JSON.parse(readFileSync(privateFile, "utf8"))) {
t.game = Object.assign(new Game(["恢复", "状态"]), t.game);
t.running = false;
tables.set(t.id, t);
}
const save = () =>
atomicWrite(privateFile, JSON.stringify([...tables.values()]));
const publicTable = (t) => ({
id: t.id,
running: t.running,
error: t.error,
models: t.seats.map((s) => ({
name: s.name,
model: s.modelId,
joined: s.joined,
})),
...t.game.view(),
});
const audit = (value) =>
appendFileSync(
resolve(data, "evidence.jsonl"),
JSON.stringify({ time: new Date().toISOString(), ...value }) + "\n",
{ mode: 0o600 },
);
let busy = false;
setInterval(async () => {
if (busy) return;
busy = true;
try {
for (const t of tables.values()) {
if (!t.running) continue;
if (t.game.stage === "complete" || t.game.stage === "waiting") {
if (t.game.history.length >= t.limit) {
t.running = false;
save();
continue;
}
try { t.game.start(); } catch { t.running = false; t.error = "不足两位有筹码玩家,演示已停止"; save(); continue; }
save();
}
const seat = t.seats[t.game.actor];
if (!seat?.modelId) continue;
cfg ??= loadModels();
const item = cfg.items.find((i) => i.id === seat.modelId);
const observation = t.game.view(t.game.actor),
version = t.game.version,
id = t.game.actor;
try {
const start = Date.now();
const result = await decide(cfg, item, observation);
audit({
table: t.id,
kind: "model",
player: id,
model: item.model,
provider: item.id,
observation,
...result,
durationMs: Date.now() - start,
});
if (!t.running || t.game.version !== version) continue;
t.game.act(id, result.action.action, result.action.amount, version);
audit({ table: t.id, kind: "state", state: publicTable(t) });
save();
} catch {
t.running = false;
t.error = "模型调用或动作失败;已暂停,请检查私有证据后重试";
audit({ table: t.id, kind: "error", version });
save();
}
}
} finally {
busy = false;
}
}, 1000);
export const server = createServer(async (req, res) => {
res.setHeader("Cache-Control", "no-store");
res.setHeader("Referrer-Policy", "no-referrer");
res.setHeader("X-Content-Type-Options", "nosniff");
const json = (code, obj) => {
res.writeHead(code, { "Content-Type": "application/json; charset=utf-8" });
res.end(JSON.stringify(obj));
};
try {
const url = new URL(req.url, "http://localhost");
let body = {};
if (req.method === "POST") {
let raw = "";
for await (const chunk of req) {
raw += chunk;
if (raw.length > 16384) return json(413, { error: "请求过大" });
}
body = JSON.parse(raw || "{}");
}
const token = (req.headers.authorization ?? "").replace(/^Bearer /, "");
const isAdmin = token === admin;
const parts = url.pathname.split("/").filter(Boolean);
if (parts[0] === "api") {
if (req.method === "GET" && url.pathname === "/api/tables")
return json(200, { tables: [...tables.values()].map(publicTable) });
if (req.method === "GET" && url.pathname === "/api/models") {
if (!isAdmin) return json(403, { error: "需要管理凭据" });
cfg ??= loadModels();
return json(200, {
models: cfg.items.map((i) => ({
id: i.id,
name: i.name,
model: i.model,
})),
});
}
if (req.method === "POST" && url.pathname === "/api/tables") {
if (!isAdmin) return json(403, { error: "需要管理凭据" });
if (
!Array.isArray(body.names) ||
body.names.length < 2 ||
body.names.length > 6 ||
body.names.some(
(n) => typeof n !== "string" || !n.trim() || n.length > 40,
)
)
return json(400, { error: "需要 2–6 个玩家名称" });
const id = randomUUID();
const t = {
id,
game: new Game(body.names),
running: false,
limit: 3,
seats: body.names.map((name) => ({
name,
token: randomBytes(32).toString("hex"),
joined: false,
})),
};
tables.set(id, t);
save();
return json(201, {
id,
invitations: t.seats.map((s, i) => ({
player: i,
url: `/#join=${id}.${s.token}`,
instructions:
"使用 Bearer 凭据 POST /api/tables/" +
id +
"/join,然后 GET observation,POST action 携带 version/action/amount",
})),
});
}
const t = tables.get(parts[2]);
if (!t) return json(404, { error: "牌桌不存在" });
const seat = t.seats.findIndex((s) => s.token === token);
const action = parts[3];
if (req.method === "GET" && action === "observation") {
if (seat < 0) return json(403, { error: "邀请凭据无效" });
return json(200, { ...t.game.view(seat), player: seat });
}
if (req.method === "POST" && action === "join") {
if (seat < 0) return json(403, { error: "邀请凭据无效" });
if (body.modelId) {
cfg ??= loadModels();
if (!cfg.items.some((i) => i.id === body.modelId))
return json(400, { error: "模型不存在" });
}
t.seats[seat].joined = true;
t.seats[seat].modelId = body.modelId ?? null;
save();
return json(200, { player: seat });
}
if (req.method === "POST" && action === "action") {
if (seat < 0 || !t.seats[seat].joined)
return json(403, { error: "邀请凭据无效" });
if (!t.running) return json(409, { error: "牌桌已暂停" });
t.game.act(seat, body.action, body.amount, body.version);
audit({ table: t.id, kind: "external-action", state: publicTable(t) });
save();
return json(200, t.game.view(seat));
}
if (req.method === "POST" && action === "control") {
if (!isAdmin) return json(403, { error: "需要管理凭据" });
if (!["start", "pause", "stop"].includes(body.action))
return json(400, { error: "未知控制动作" });
if (body.action === "start") {
if (!t.seats.every((s) => s.joined))
return json(409, { error: "等待所有玩家接受邀请" });
t.limit = t.game.history.length + 3;
t.error = null;
t.running = true;
} else t.running = false;
save();
return json(200, publicTable(t));
}
return json(404, { error: "接口不存在" });
}
if (req.method !== "GET") return json(405, { error: "方法不允许" });
const path = url.pathname === "/" ? "index.html" : url.pathname.slice(1);
const root = resolve(import.meta.dirname, "dist"),
file = resolve(root, path);
if (!file.startsWith(root + "/")) return json(403, { error: "禁止访问" });
const content = readFileSync(file);
res.writeHead(200, {
"Content-Type":
{
".html": "text/html; charset=utf-8",
".js": "text/javascript",
".css": "text/css",
}[extname(file)] ?? "application/octet-stream",
});
res.end(content);
} catch (e) {
json(400, {
error: e.message?.includes("ENOENT")
? "页面不存在"
: (e.message?.slice(0, 120) ?? "请求失败"),
});
}
});
server.listen(Number(process.env.POKER_PORT ?? 18439), "127.0.0.1", () =>
console.log("扑克服务就绪;管理凭据仅在私有运行目录。"),
);

View File

@ -0,0 +1,11 @@
// Start an independent process and keep credentials/logs in the caller's private directory.
import {spawn} from 'node:child_process';
import {mkdirSync,openSync,writeFileSync} from 'node:fs';
import {resolve} from 'node:path';
const tmp=process.env.TMPDIR,data=process.env.POKER_DATA;
if(!tmp||!data)throw Error('必须设置 TMPDIR 和 POKER_DATA');
mkdirSync(data,{recursive:true,mode:0o700});
const fd=openSync(resolve(tmp,'server.log'),'a',0o600);
const child=spawn(process.execPath,[resolve(import.meta.dirname,'server.mjs')],{cwd:import.meta.dirname,env:process.env,detached:true,stdio:['ignore',fd,fd]});
child.unref();writeFileSync(resolve(tmp,'server.pid'),String(child.pid),{mode:0o600});
console.log(`已启动独立扑克进程 ${child.pid};使用 HTTP 检查确认服务就绪。`);

View File

@ -0,0 +1,3 @@
@import "../../apps/web/src/theme.css";
/* Include reused component utility classes outside this Vite root. No new visual rules. */
@source "../../apps/web/src/components";

View File

@ -0,0 +1,95 @@
import test from "node:test";
import assert from "node:assert/strict";
import { Game, rank, settle } from "./game.mjs";
test("牌型、轮子顺子及踢脚比较", () => {
assert(
rank(["As", "Ks", "Qs", "Js", "Ts"]) > rank(["Ah", "Ad", "Ac", "As", "Kh"]),
);
assert(
rank(["As", "2d", "3c", "4s", "5h"]) > rank(["As", "Ad", "Kc", "Qs", "Jh"]),
);
assert(
rank(["As", "Ad", "Kc", "Qs", "Jh"]) > rank(["As", "Ad", "Kc", "Qs", "Th"]),
);
});
test("边池与平分奇数筹码", () => {
const p = [
{ total: 50, cards: ["As", "Ad"] },
{ total: 100, cards: ["Ks", "Kd"] },
{ total: 100, cards: ["Qs", "Qd"] },
];
assert.deepEqual(
settle(p, ["2s", "3d", "7c", "8s", "9h"], 0).awards,
[150, 100, 0],
);
const split = settle(p, ["Ts", "Js", "Qs", "Ks", "As"], 0);
assert.equal(
split.awards.reduce((a, b) => a + b),
250,
);
assert.deepEqual(split.awards, [50, 100, 100]);
});
test("轮次、隐私、重复动作与非法输入均不变更状态", () => {
const g = new Game(["a", "b", "c"]);
g.start();
assert.equal(g.actor, 0);
assert.deepEqual(
g.view().players.map((p) => p.cards),
[[], [], []],
);
assert.equal(g.view(1).players[1].cards.length, 2);
for (const args of [
[1, "fold", 0, g.version],
[0, "raise", 21, g.version],
[0, "check", 0, g.version],
[0, "call", 0, 0],
]) {
const before = JSON.stringify(g);
assert.throws(() => g.act(...args));
assert.equal(JSON.stringify(g), before);
}
const v = g.version;
g.act(0, "call", 0, v);
assert.throws(() => g.act(0, "call", 0, v));
while (g.stage !== "complete") {
const l = g.legal(g.actor);
g.act(
g.actor,
l.actions.includes("check") ? "check" : "call",
0,
g.version,
);
}
assert.equal(g.board.length, 5);
assert.equal(g.history[0].total, 3000);
});
test("短 all-in 不重新开放加注;全下自动摊牌守恒", () => {
const g = new Game(["a", "b", "c"], [100, 100, 45]);
g.start();
g.act(0, "raise", 40, g.version);
g.act(1, "call", 0, g.version);
g.act(2, "all-in", 0, g.version);
assert(!g.legal(0).actions.includes("raise"));
g.act(0, "call", 0, g.version);
g.act(1, "call", 0, g.version);
while (g.stage !== "complete") {
g.act(g.actor, "all-in", 0, g.version);
}
assert.equal(g.history[0].total, 245);
});
test("连续 50 手合法行动筹码守恒", () => {
const g = new Game(["a", "b", "c"]);
for (let h = 0; h < 50 && g.players.filter((p) => p.stack).length > 1; h++) {
g.start();
while (g.stage !== "complete") {
const l = g.legal(g.actor);
g.act(
g.actor,
l.actions.includes("check") ? "check" : "call",
0,
g.version,
);
}
assert.equal(g.history.at(-1).total, 3000);
}
});

214
projects/agent-poker/ui.jsx Normal file
View File

@ -0,0 +1,214 @@
import React, { useState, useEffect } from "react";
import { createRoot } from "react-dom/client";
import { Button } from "../../apps/web/src/components/ui/button";
import {
PageWorkspace,
PanelHeader,
} from "../../apps/web/src/components/page-workspace";
import "./style.css";
import "../../apps/web/src/page-layout.css";
import "../../apps/web/src/workbench.css";
function App() {
const [tables, setTables] = useState([]),
[selected, select] = useState(""),
[admin, setAdmin] = useState(""),
[error, setError] = useState(""),
[invites, setInvites] = useState([]),
[joined, setJoined] = useState(false);
const join = location.hash.startsWith("#join=")
? location.hash.slice(6).split(".")
: null;
async function api(path, body, token = admin) {
const r = await fetch("/api/" + path, {
method: body ? "POST" : "GET",
headers: {
"Content-Type": "application/json",
...(token ? { Authorization: "Bearer " + token } : {}),
},
...(body ? { body: JSON.stringify(body) } : {}),
});
const data = await r.json();
if (!r.ok) throw Error(data.error);
return data;
}
async function refresh() {
try {
setTables((await api("tables")).tables);
} catch (e) {
setError(e.message);
}
}
useEffect(() => {
refresh();
const timer = setInterval(refresh, 1500);
return () => clearInterval(timer);
}, []);
const table = tables.find((t) => t.id === selected) ?? tables[0];
const run = async (fn) => {
try {
setError("");
await fn();
await refresh();
} catch (e) {
setError(e.message);
}
};
return (
<PageWorkspace
title="Agent 扑克"
sidebarLabel="牌桌列表"
sidebar={
<div className="p-4 space-y-4">
<p>虚拟筹码 · 无真钱交易</p>
{tables.map((t) => (
<Button key={t.id} variant="ghost" onClick={() => select(t.id)}>
牌桌 {t.id.slice(0, 8)} · 第 {t.hand} 手
</Button>
))}
<label className="block">
管理凭据
<input
aria-label="管理凭据"
type="password"
className="border rounded p-2 w-full"
value={admin}
onChange={(e) => setAdmin(e.target.value)}
/>
</label>
<Button
onClick={() =>
run(async () => {
const r = await api("tables", {
names: ["Agent A", "Agent B", "Agent C"],
});
setInvites(r.invitations);
select(r.id);
})
}
>
建立牌桌
</Button>
<p>管理凭据由本机服务管理员提供,不存入浏览器。</p>
</div>
}
>
<PanelHeader
title="在线观测"
actions={
table && (
<>
{["start", "pause", "stop"].map((a, i) => (
<Button
key={a}
disabled={!admin}
onClick={() =>
run(() =>
api("tables/" + table.id + "/control", { action: a }),
)
}
>
{["开始三手", "暂停", "停止"][i]}
</Button>
))}
</>
)
}
/>
<main className="p-6 space-y-6 overflow-auto">
<p role="alert">{error}</p>
{join && (
<section>
<h2>接受玩家邀请</h2>
<p>
邀请凭据仅在地址片段中,请勿转发。接入后可用受控 API
获取自己的观察。
</p>
<Button
onClick={() =>
run(async () => {
await api("tables/" + join[0] + "/join", {}, join[1]);
setJoined(true);
})
}
>
{joined ? "已加入" : "接受邀请"}
</Button>
<pre className="whitespace-pre-wrap">{`GET /api/tables/${join[0]}/observation\nPOST /api/tables/${join[0]}/action\nAuthorization: Bearer <邀请凭据>\n动作字段:version、action、amount`}</pre>
</section>
)}
{invites.map((i) => (
<section key={i.player}>
<a className="underline" href={i.url}>
玩家 {i.player + 1} 邀请地址
</a>
<p>{i.instructions}</p>
</section>
))}
{table ? (
<>
<section>
<h2>
第 {table.hand} 手 · {table.stage} ·{" "}
{table.running ? "运行中" : "已暂停"}
</h2>
<p>{table.error}</p>
<p className="text-2xl">
公共牌:{table.board.join(" ") || "尚未发出"}
</p>
<p>
底池 {table.pot} · 当前行动者{" "}
{table.actor === null ? "—" : table.players[table.actor].name}
</p>
</section>
<section className="grid grid-cols-1 md:grid-cols-3 gap-4">
{table.players.map((p) => (
<article
key={p.id}
className="border border-border rounded-lg p-4"
>
<h2>
{p.name}
{p.id === table.actor ? " · 行动中" : ""}
</h2>
<p>
筹码 {p.stack} · 本轮投入 {p.bet}
</p>
<p>{p.folded ? "已弃牌" : p.cards.join(" ") || "底牌保密"}</p>
<p>
{table.models[p.id].joined ? "已接受邀请" : "等待邀请"} ·{" "}
{table.models[p.id].model ?? "外部 API 玩家"}
</p>
</article>
))}
</section>
<section>
<h2>动作时间线</h2>
{table.timeline.map((a) => (
<p key={a.version}>
{a.time} · {table.players[a.player].name} · {a.action} ·{" "}
{a.amount}
</p>
))}
</section>
<section>
<h2>已完成手牌</h2>
{table.history.map((h) => (
<details key={h.hand}>
<summary>
第 {h.hand} 手 · 筹码核对 {h.total} · {h.board.join(" ")}
</summary>
<pre className="whitespace-pre-wrap">
{JSON.stringify(h, null, 2)}
</pre>
</details>
))}
</section>
</>
) : (
<p>尚无牌桌。管理员可创建并分享邀请。</p>
)}
</main>
</PageWorkspace>
);
}
createRoot(document.getElementById("root")).render(<App />);

View File

@ -0,0 +1,20 @@
import { defineConfig } from "vite";
import react from "@vitejs/plugin-react";
import tailwindcss from "@tailwindcss/vite";
import { resolve } from "node:path";
export default defineConfig({
plugins: [react(), tailwindcss()],
resolve: {
dedupe: ["react", "react-dom"],
alias: {
"@base-ui/react": resolve("node_modules/@base-ui/react"),
"lucide-react": resolve("node_modules/lucide-react"),
"class-variance-authority": resolve(
"node_modules/class-variance-authority",
),
clsx: resolve("node_modules/clsx"),
"tailwind-merge": resolve("node_modules/tailwind-merge"),
},
},
build: { outDir: "dist" },
});