## MCP Tools: code-review-graph **IMPORTANT: This project has a knowledge graph. ALWAYS use the code-review-graph MCP tools BEFORE using Grep/Glob/Read to explore the codebase.** The graph is faster, cheaper (fewer tokens), and gives you structural context (callers, dependents, test coverage) that file scanning cannot. ### When to use graph tools FIRST - **Exploring code**: `semantic_search_nodes` or `query_graph` instead of Grep - **Understanding impact**: `get_impact_radius` instead of manually tracing imports - **Code review**: `detect_changes` + `get_review_context` instead of reading entire files - **Finding relationships**: `query_graph` with callers_of/callees_of/imports_of/tests_for - **Architecture questions**: `get_architecture_overview` + `list_communities` Fall back to Grep/Glob/Read **only** when the graph doesn't cover what you need. ### Key Tools | Tool | Use when | | ------ | ---------- | | `detect_changes` | Reviewing code changes — gives risk-scored analysis | | `get_review_context` | Need source snippets for review — token-efficient | | `get_impact_radius` | Understanding blast radius of a change | | `get_affected_flows` | Finding which execution paths are impacted | | `query_graph` | Tracing callers, callees, imports, tests, dependencies | | `semantic_search_nodes` | Finding functions/classes by name or keyword | | `get_architecture_overview` | Understanding high-level codebase structure | | `refactor_tool` | Planning renames, finding dead code | ### Workflow 1. The graph auto-updates on file changes (via hooks). 2. Use `detect_changes` for code review. 3. Use `get_affected_flows` to understand impact. 4. Use `query_graph` pattern="tests_for" to check coverage. --- ## 数据库操作规范 ### PostgreSQL 序列同步规则(强制) **问题背景**:项目使用 `BIGSERIAL` / `autoIncrement` 自增主键。当通过 SQL 手动 `INSERT` 指定 `id` 值时,PostgreSQL 序列不会自动跟进,导致后续 GORM 插入报 `duplicate key value violates unique constraint`。 **触发场景**: - 测试数据脚本(如 `create_gallery_test_users.go`)硬编码 ID - 数据迁移脚本手动插入记录 - DBeaver / psql 手动补数据 **规范要求**: 1. **任何手动指定 ID 的 INSERT 语句,末尾必须同步重置序列**: ```sql -- 错误示例(会导致序列不同步) INSERT INTO assets (id, name, ...) VALUES (1000, 'xxx', ...); -- 正确示例 INSERT INTO assets (id, name, ...) VALUES (1000, 'xxx', ...); SELECT setval('assets_id_seq', (SELECT MAX(id) FROM assets)); ``` 2. **脚本文件规范**:所有输出 SQL 的 Go 脚本(如 `backend/scripts/*.go`),必须在生成的 SQL 末尾包含序列重置语句: ```go fmt.Printf(`SELECT setval('%s_id_seq', (SELECT MAX(id) FROM %s));\n`, tableName, tableName) ``` 3. **新表创建时**:预留足够的序列起始值给测试数据: ```sql CREATE SEQUENCE assets_id_seq START WITH 10000; ``` 4. **定期检查**:环境部署后执行以下 SQL 确认序列健康: ```sql SELECT schemaname, sequencename, last_value, (SELECT MAX(id) FROM assets) AS table_max_id, last_value >= (SELECT MAX(id) FROM assets) AS is_healthy FROM pg_sequences WHERE sequencename = 'assets_id_seq'; ``` **受影响表**(使用 autoIncrement 主键): - `assets` - `asset_registry` - `users` - `stars` - `activity_assets` - `collection_assets` - `materials` - `exhibitions` - `galleries` - 以及其他所有 `id BIGSERIAL PRIMARY KEY` 的表 **违规后果**:生产环境报 `duplicate key` 导致用户铸造/创建失败,需紧急修复序列。 --- ## 前端开发规范(uniapp + vue3 · app 端) ### 技术栈基线 - **框架**:UniApp 3.x + **Vue 3 组合式 API**(`vueVersion: "3"`,`@vue/compiler-sfc ^3.5`),不要再写 Vue 2 Options API 或混用 `this` - **状态管理**:Vuex 4(`store/index.js` + `store/modules/*`),跨页面状态走 Vuex,组件临时状态用 `ref` / `reactive` - **复用逻辑**:放进 `composables/useXxx.js`(已有 `useHolographicPreview` / `useDashboardData` / `useLenticularStudioTilt` 等),**禁止**把可复用的逻辑写在单文件组件里 - **目标平台**:以 **app-plus(Android + iOS)为主**,H5 / 微信小程序等其他端仅在显式 `#ifdef` 支持时才能用 - **原生能力**:`plus.*`(陀螺仪、角标、Intent 跳转等)、UniPush、设备指纹、Socket 全都走 `utils/` 下专用封装,**不要**在组件里直接 `plus.*` ### 关键约定 1. **条件编译是硬约束**——涉及原生 API / 原生插件 / 平台差异代码必须包在 `// #ifdef APP-PLUS … // #endif`(或 `MP-WEIXIN` / `H5` 等): ```js // 正确 // #ifdef APP-PLUS plus.runtime.setBadgeNumber(0) // #endif // 错误(plus 在非 app 端是 undefined,会直接报错) plus.runtime.setBadgeNumber(0) ``` **禁止**用 `if (typeof plus !== 'undefined')` 之类兜底代替条件编译。 2. **API 调用统一封装**——所有后端接口走 `utils/api.js`(设备注册、WebSocket token 上报等),组件层只调封装函数,**禁止**在 `.vue` 里直接 `uni.request`。 3. **路由与页面注册**——新页面**先在 [frontend/pages.json](frontend/pages.json) 注册再写 `.vue` 文件**;Tab 页面用 `uni.switchTab`,普通跳转用 `navigateTo`,**禁止**用 `redirectTo` 替代 `navigateBack` 制造假"返回"。 4. **权限申请必须给出口**——通知 / 相机 / 相册 / 定位等敏感权限,授权失败时必须给"去设置"按钮并调用系统设置页(参照 `App.vue#setPermissions` 的 Android Intent / iOS `app-settings:` 范式),**禁止**静默失败。 5. **性能基线**——长列表使用现有 [components/VirtualList.vue](frontend/components/VirtualList.vue),图片用 [components/LazyImage.vue](frontend/components/LazyImage.vue);自定义字体已知坑:部分 Android WebView 对部分 `.ttf` 会报 OTS / cmap 解析失败(如 `JDLTYuanTiJian.ttf`),新增字体前先在小内存 Android 机上验证。 6. **资源与产物隔离**——`unpackage/dist/*` 是编译产物,**禁止**手动修改;图标准备物放在 `unpackage/res/icons/`,源码改动放 `static/`。 ### 禁止的反模式 - ❌ 在 Vue 3 项目里混用 `export default { data() { return {} } }` Options API - ❌ 在非 `APP-PLUS` 分支直接调 `plus.*` / 原生插件 API - ❌ 在组件里直接 `uni.request` / `uni.connectSocket`,绕过 `utils/api.js` - ❌ 跨页面状态用 props 层层下传 / `getApp().globalData` 散落——必须走 Vuex - ❌ 新增页面不写 `pages.json` 就提交 - ❌ 权限被拒后只 `console.warn` 不引导用户去开启 - ❌ 手动编辑 `unpackage/dist/` 下的任何文件 ### 完成自检(提交前过一遍) - [ ] 新组件用 `