Metadata-Version: 2.4
Name: triplane
Version: 0.2.0
Summary: Three-plane isolated Python runtime framework for persistent-connection apps (Gateway / StateEngine / WebBackend)
Author: Jack Lu
License-Expression: MIT
Project-URL: Homepage, https://github.com/JackLuguibin/triplane
Project-URL: Repository, https://github.com/JackLuguibin/triplane
Project-URL: Issues, https://github.com/JackLuguibin/triplane/issues
Keywords: asyncio,fastapi,websockets,state-machine,gateway,triplane
Classifier: Development Status :: 3 - Alpha
Classifier: Framework :: AsyncIO
Classifier: Intended Audience :: Developers
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.13
Classifier: Typing :: Typed
Requires-Python: >=3.13
Description-Content-Type: text/markdown
License-File: LICENSE
Provides-Extra: gateway
Requires-Dist: websockets<16,>=15.0; extra == "gateway"
Requires-Dist: cryptography>=44.0; extra == "gateway"
Requires-Dist: fastapi>=0.128.0; extra == "gateway"
Requires-Dist: uvicorn[standard]>=0.39.0; extra == "gateway"
Provides-Extra: engine
Requires-Dist: websockets<16,>=15.0; extra == "engine"
Requires-Dist: fastapi>=0.128.0; extra == "engine"
Requires-Dist: uvicorn[standard]>=0.39.0; extra == "engine"
Provides-Extra: web
Requires-Dist: fastapi>=0.128.0; extra == "web"
Requires-Dist: uvicorn[standard]>=0.39.0; extra == "web"
Requires-Dist: httpx>=0.28.0; extra == "web"
Requires-Dist: websockets<16,>=15.0; extra == "web"
Provides-Extra: all
Requires-Dist: triplane[engine,gateway,web]; extra == "all"
Provides-Extra: dev
Requires-Dist: ruff<1,>=0.14; extra == "dev"
Dynamic: license-file

# triplane

> 面向长连接、有状态业务自动化与实时 Web 控制台的**纯 Python 三平面隔离运行时框架**（无 Redis / NATS / gRPC / PostgreSQL 依赖）。

## 核心设计理念

1. **三平面彻底隔离**
   - **Plane 1 · `SessionGateway`**：多渠道鉴权、长连接保活心跳、有界 `PacketRingBuffer` 与上行幂等去重；账号在线态唯一真相源，长期常驻不重启。
   - **Plane 2 · `StateEngine`**：原生极简共用无状态状态机（`StrEnum + dataclass + TRANSITIONS`）、按账号串行队列、`heapq + gen` 统一业务定时器、`engine.sqlite3`（WAL）、5 步无感热更新。
   - **Plane 3 · `WebBackend`**：无状态 HTTP API、只读视图缓存、事件日志热环与 `Last-Event-ID` SSE 断线续传。
2. **统一启动入口 + 延迟工厂加载**
   - 业务项目仅维护一份声明字符串路径的 `TriplaneApp` 配置（延迟导入，启动单个平面时绝不加载其他平面的代码）。
   - 本机一键拉起三进程（内置轻量 Supervisor）与容器单平面独立启动共用同一个 `triplane` CLI。

## 安装（Installation）

```bash
# 完整安装（包含 gateway / engine / web 三个平面运行时依赖）
pip install "triplane[all]"
# 或使用 uv
uv add "triplane[all]"

# 容器场景按平面精简安装
pip install "triplane[gateway]"
pip install "triplane[engine]"
pip install "triplane[web]"
```

## 快速开始（CLI）

```bash
# 脚手架生成最小三平面项目
triplane init mygame --dir .

# 本机一键拉起三平面（顺序健康探活 gateway -> engine -> web）
triplane up myapp.app:app --data-dir .private

# 运行内置零依赖本地 Demo（登录 / 状态机 / 不确定故障注入 / 热重启 / SSE 续传）
PYTHONPATH=src:. triplane up examples.demo_game.app:app --data-dir .private

# 容器 / 独立进程按平面启动
triplane run gateway myapp.app:app --port 18761
triplane run engine  myapp.app:app --port 18762
triplane run web     myapp.app:app --port 8765

# 本机开发态单平面热更新（例如仅重启 engine，保持 gateway 长连接不断）
triplane reload engine --data-dir .private

# 查看运行状态 & 初始化/重置 Web 管理员账号
triplane status --data-dir .private
triplane admin init --data-dir .private --username admin
triplane admin init --data-dir .private --username admin --reset-password
```

## 核心运行时保障

- **崩溃隔离与可信重同步**：`PlaneSupervisor` 隔离单平面故障并保持 Gateway 长连接不断；跨 Gateway 硬重启通过进程级 `stream_epoch` 与认证全量基线实现确定性重同步（`resync_account`）。
- **外发对账与结果不明收敛**：`SEND_RAW_ACK` 按 `(account_id, request_id, conn_gen)` 严格归属；结果不明不盲目重发，并支持进程内 `deferred_queue` 与可选时效边界持久化 Outbox（`enable_persistent_outbox=True`、`outbox_ttl_seconds`）。
- **多租户工作区与能力发现**：`WebApp` 内置基于 `web.sqlite3`（WAL）的用户/工作区隔离、邀请码与限流登录控制；Engine 暴露 `/internal/v1/metrics`、能力与渠道发现及离线确定性回放引擎 `triplane.testing.replay`。

## 文档与基准

- 架构设计：[docs/architecture.md](https://github.com/JackLuguibin/triplane/blob/main/docs/architecture.md)
- 演进路线图：[docs/framework-roadmap.md](https://github.com/JackLuguibin/triplane/blob/main/docs/framework-roadmap.md)
- 容量与性能基线：[docs/benchmark-report.md](https://github.com/JackLuguibin/triplane/blob/main/docs/benchmark-report.md)
- 实施清单：[docs/TODO.md](https://github.com/JackLuguibin/triplane/blob/main/docs/TODO.md)
