From fafe02bdbdff88c4ec6140f83e14aa3732a78de2 Mon Sep 17 00:00:00 2001 From: imbytecat Date: Sat, 25 Apr 2026 17:06:22 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20=E4=B8=BB=E5=8A=A8=E5=AE=A1?= =?UTF-8?q?=E8=AE=A1=E4=BF=AE=E5=A4=8D=E5=A4=9A=E5=A4=84=E5=8F=AF=E8=A7=82?= =?UTF-8?q?=E6=B5=8B=E6=80=A7=E3=80=81=E4=BE=9D=E8=B5=96=E3=80=81=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=E8=B4=A8=E9=87=8F=E7=BC=BA=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 通过并行 explore + librarian + 自查发现并修复: 代码缺陷 - shutdown.ts: db.$client.end().finally(...) 静默吞错——关闭失败会 谎报 "DB pool closed" 后照常 exit 0。改用 await + try/catch 分别记录成功/失败,setTimeout 也换成 Bun.sleep。 - interceptors.ts: 两条 instanceof ORPCError && instanceof ValidationError 重复检查,改用 early return + 单 if 分支区分 code。 - types.ts: 移除从未被引用的 RouterInputs 死代码(仅 RouterOutputs 被 TodoItem 用到)。 Bun 原生 API(删/换 Node 兼容层) - fields.ts: uuid v7 → Bun.randomUUIDv7(),删除 uuid 依赖 - migrate.ts: node:crypto.createHash → Bun.CryptoHasher.hash, 少一个 Promise.all 项 + 一个 import - shutdown.ts: setTimeout → Bun.sleep(顺带) Biome 2.4 规则补强 - domains.types: "all"——开启类型感知规则集(noFloatingPromises / noMisusedPromises / useAwaitThenable / noUnnecessaryConditions 等 Promise/异步陷阱) - domains.drizzle: "recommended"、domains.react: "recommended" - 显式开启 suspicious.noImportCycles(2.4 已 promote) 文档 - AGENTS.md 在 Stack & runtime 段加 "Prefer Bun-native APIs" 原则,列出 UUIDv7/SHA-256/sleep/Bun.file 的优先路径 - AGENTS.md 在 Code style (Biome) 段记录本次启用的 lint domain 与 noImportCycles 规则 验证:fix / typecheck / test 3/3 / build 568ms / compile 117M / docker compose 全套(migrate JSON 日志 ✓、UUIDv7 写入 ✓、SIGTERM shutdown 正确序列化 ✓) --- AGENTS.md | 2 ++ biome.json | 6 ++++++ bun.lock | 3 --- package.json | 1 - src/cli/migrate.ts | 5 ++--- src/server/api/interceptors.ts | 6 ++++-- src/server/api/types.ts | 3 +-- src/server/db/fields.ts | 3 +-- src/server/plugins/shutdown.ts | 20 +++++++++++--------- 9 files changed, 27 insertions(+), 22 deletions(-) diff --git a/AGENTS.md b/AGENTS.md index 5d061a4..c0193cc 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -5,6 +5,7 @@ Compact, repo-specific notes for AI agents. Generic language/framework knowledge ## Stack & runtime - **Bun-only** (`mise.toml` pins `bun = 1.3.13`). Never invoke `npm`/`npx`/`node`/`yarn`/`pnpm`. Use `bun run