From 8c1da28a2f4b8fc5500c794301594bb45e38e183 Mon Sep 17 00:00:00 2001 From: d0zingcat Date: Thu, 15 Jan 2026 20:57:32 +0800 Subject: [PATCH] docs: add mandatory lint check convention for AI Signed-off-by: d0zingcat --- CHANGELOG.md | 1 + apps/server/src/db/migrate-tokens.ts | 4 ++-- apps/server/src/db/migrate.ts | 2 +- apps/server/src/webhook.ts | 8 ++++---- docs/copilot-context.md | 2 +- 5 files changed, 9 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e194f08..5eaf74a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ ### 变更 - **用户 Token**:将用户的 `personalToken` 从 32 位 UUID 缩短为 8 位十六进制字符串,提升易用性。 - **数据库迁移**:完善了数据库迁移流程,在 `db:migrate:deploy` 中集成了存量用户 Token 的自动缩短逻辑,确保线上环境数据的一致性。 +- **AI 规范**:更新了 `copilot-context.md`,明确要求 AI 在每次修改代码后必须进行代码风格和 Lint 检查。 ## [1.2.5] - 2026-01-15 diff --git a/apps/server/src/db/migrate-tokens.ts b/apps/server/src/db/migrate-tokens.ts index 0919bfb..ea22c21 100644 --- a/apps/server/src/db/migrate-tokens.ts +++ b/apps/server/src/db/migrate-tokens.ts @@ -2,8 +2,8 @@ import { db } from "./index"; import { migrateUserTokens } from "./migrate"; async function main() { - await migrateUserTokens(db); - process.exit(0); + await migrateUserTokens(db); + process.exit(0); } main(); diff --git a/apps/server/src/db/migrate.ts b/apps/server/src/db/migrate.ts index 7dfbaa9..e2281e2 100644 --- a/apps/server/src/db/migrate.ts +++ b/apps/server/src/db/migrate.ts @@ -9,7 +9,7 @@ const connectionString = process.env.DATABASE_URL || "postgres://postgres:password@localhost:5432/alert_message_center"; -export async function migrateUserTokens(db: any) { +export async function migrateUserTokens(db: ReturnType) { console.log("⏳ Checking for user tokens that need shortening..."); try { const allUsers = await db.select().from(users); diff --git a/apps/server/src/webhook.ts b/apps/server/src/webhook.ts index c3bcb1c..dfc3eb9 100644 --- a/apps/server/src/webhook.ts +++ b/apps/server/src/webhook.ts @@ -4,7 +4,6 @@ import { db } from "./db"; import { alertLogs, alertTasks, topics, users } from "./db/schema"; import { feishuClient } from "./feishu"; import { logger } from "./lib/logger"; -import { uuid } from "zod/v4"; type FeishuReceiveIdType = "open_id" | "user_id" | "email" | "chat_id"; @@ -144,21 +143,22 @@ webhook.post("/:token/topic/:slug", async (c) => { } else { // 2. Pass-through strategy: Use rest of body as content // Exclude keys that are definitely not part of content - // biome-ignore lint/performance/noDelete: usage is limited const { msg_type, token, ...rest } = body; content = rest; // 3. Infer msgType if missing if (!msgType) { if (body.post) msgType = "post"; + else if (body.file_key && body.image_key) + msgType = "media"; // Media has both else if (body.image_key) msgType = "image"; - else if (body.file_key && body.image_key) msgType = "media"; // Media has both else if (body.file_key) msgType = "file"; else if (body.audio_key) msgType = "audio"; else if (body.sticker_key) msgType = "sticker"; else if (body.chat_id) msgType = "share_chat"; else if (body.user_id) msgType = "share_user"; - else if (body.header || body.elements) msgType = "interactive"; // Unwrapped card + else if (body.header || body.elements) + msgType = "interactive"; // Unwrapped card else { // Fallback to text msgType = "text"; diff --git a/docs/copilot-context.md b/docs/copilot-context.md index 0e8c65c..a163008 100644 --- a/docs/copilot-context.md +++ b/docs/copilot-context.md @@ -198,7 +198,7 @@ The database schema is defined in `apps/server/src/db/schema.ts`. - Framework: [Biome](https://biomejs.dev/). - **Rules**: Strict configuration for `a11y`, `suspicious`, `style`, and `correctness`. - **Tailwind**: `noUnknownAtRules` is configured to ignore Tailwind directives (`@tailwind`, `@apply`, etc.). - - **Enforcement**: CI/CD runs `biome check` to ensure compliance. Avoid Use of `as any` is strictly prohibited except for specialized cases like `import.meta as any` (for Vite env) or very complex JSON spread operations. In those rare cases, use `// biome-ignore` with a clear explanation. + - **Enforcement**: CI/CD runs `biome check` to ensure compliance. **AI assistants MUST run `bun x biome check --write .` (or equivalent) in the respective app directory after every code modification to verify and fix lint/formatting issues before finalizing.** Avoid Use of `as any` is strictly prohibited except for specialized cases like `import.meta as any` (for Vite env) or very complex JSON spread operations. In those rare cases, use `// biome-ignore` with a clear explanation. - **Vite Env Access**: When accessing Vite environment variables via `import.meta.env` (or casting `import.meta as any`), **always use optional chaining** (e.g., `meta.env?.VITE_...`). This prevents crashes if the environment is not initialized or if the code runs in a non-browser context during pre-rendering/testing. - **Frontend Resilience**: - Always check `res.ok` before attempting to parse or use API responses.