@lobehub/chat 1.96.17 → 1.96.18
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.cursor/rules/backend-architecture.mdc +54 -51
- package/.cursor/rules/code-review.mdc +69 -0
- package/.cursor/rules/cursor-rules.mdc +28 -0
- package/.cursor/rules/cursor-ux.mdc +94 -0
- package/.cursor/rules/debug.mdc +193 -0
- package/.cursor/rules/i18n/i18n.mdc +66 -68
- package/.cursor/rules/packages/react-layout-kit.mdc +19 -26
- package/.cursor/rules/react-component.mdc +91 -6
- package/.cursor/rules/rules-attach.mdc +76 -0
- package/.cursor/rules/system-role.mdc +2 -6
- package/.cursor/rules/testing-guide.mdc +881 -0
- package/.cursor/rules/typescript.mdc +19 -0
- package/.cursor/rules/zustand-action-patterns.mdc +57 -15
- package/.cursor/rules/zustand-slice-organization.mdc +12 -12
- package/CHANGELOG.md +33 -0
- package/changelog/v1.json +12 -0
- package/package.json +1 -1
- package/src/app/[variants]/(main)/files/(content)/NotSupportClient.tsx +8 -1
- package/src/config/modelProviders/github.ts +1 -1
- package/.cursor/rules/cursor-ux-optimize.mdc +0 -27
- package/.cursor/rules/packages/lobe-ui.mdc +0 -72
@@ -28,70 +28,73 @@ LobeChat 的后端设计注重模块化、可测试性和灵活性,以适应
|
|
28
28
|
|
29
29
|
其主要分层如下:
|
30
30
|
|
31
|
-
1.
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
* 数据库选择依赖于是否开启**云同步**功能:
|
74
|
-
* **云同步开启**: 连接到远程 PostgreSQL 数据库。
|
75
|
-
* **云同步关闭**: 使用 PGLite (通过 Node.js 的 WASM 实现) 在本地存储数据。
|
31
|
+
1. 客户端服务层 (`src/services`):
|
32
|
+
|
33
|
+
- 位于 src/services/。
|
34
|
+
- 这是客户端业务逻辑的核心层,负责封装各种业务操作和数据处理逻辑。
|
35
|
+
- 环境适配: 根据不同的运行环境,服务层会选择合适的数据访问方式:
|
36
|
+
- 本地数据库模式: 直接调用 `Model` 层进行数据操作,适用于浏览器 PGLite 和本地 Electron 应用。
|
37
|
+
- 远程数据库模式: 通过 `tRPC` 客户端调用服务端 API,适用于需要云同步的场景。
|
38
|
+
- 类型转换: 对于简单的数据类型转换,直接在此层进行类型断言,如 `this.pluginModel.query() as Promise<LobeTool[]>`
|
39
|
+
- 每个服务模块通常包含 `client.ts`(本地模式)、`server.ts`(远程模式)和 `type.ts`(接口定义)文件,在实现时应该确保本地模式和远程模式业务逻辑实现一致,只是数据库不同。
|
40
|
+
|
41
|
+
2. API 接口层 (`TRPC`):
|
42
|
+
|
43
|
+
- 位于 src/server/routers/
|
44
|
+
- 使用 `tRPC` 构建类型安全的 API。Router 根据运行时环境(如 Edge Functions, Node.js Lambda)进行组织。
|
45
|
+
- 负责接收客户端请求,并将其路由到相应的 `Service` 层进行处理。
|
46
|
+
- 新建 lambda 端点时可以参考 src/server/routers/lambda/\_template.ts
|
47
|
+
|
48
|
+
3. 仓库层 (`Repositories`):
|
49
|
+
|
50
|
+
- 位于 src/database/repositories/。
|
51
|
+
- 主要处理复杂的跨表查询和数据聚合逻辑,特别是当需要从多个 `Model` 获取数据并进行组合时。
|
52
|
+
- 与 `Model` 层不同,`Repository` 层专注于复杂的业务查询场景,而不涉及简单的领域模型转换。
|
53
|
+
- 当业务逻辑涉及多表关联、复杂的数据统计或需要事务处理时,会使用 `Repository` 层。
|
54
|
+
- 如果数据操作简单(仅涉及单个 `Model`),则通常直接在 `src/services` 层调用 `Model` 并进行简单的类型断言。
|
55
|
+
|
56
|
+
4. 模型层 (`Models`):
|
57
|
+
|
58
|
+
- 位于 src/database/models/ (例如 src/database/models/plugin.ts 和 src/database/models/document.ts)。
|
59
|
+
- 提供对数据库中各个表(由 src/database/schemas/ 中的 Drizzle ORM schema 定义)的基本 CRUD (创建、读取、更新、删除) 操作和简单的查询能力。
|
60
|
+
- `Model` 类专注于单个数据表的直接操作,不涉及复杂的领域模型转换,这些转换通常在上层的 `src/services` 中通过类型断言完成。
|
61
|
+
- model(例如 Topic) 层接口经常需要从对应的 schema 层导入 NewTopic 和 TopicItem
|
62
|
+
- 创建新的 model 时可以参考 src/database/models/\_template.ts
|
63
|
+
|
64
|
+
5. 数据库 (`Database`):
|
65
|
+
- 客户端模式 (浏览器/PWA): 使用 PGLite (基于 WASM 的 PostgreSQL),数据存储在用户浏览器本地。
|
66
|
+
- 服务端模式 (云部署): 使用远程 PostgreSQL 数据库。
|
67
|
+
- Electron 桌面应用:
|
68
|
+
- Electron 客户端会启动一个本地 Node.js 服务。
|
69
|
+
- 本地服务通过 `tRPC` 与 Electron 的渲染进程通信。
|
70
|
+
- 数据库选择依赖于是否开启云同步功能:
|
71
|
+
- 云同步开启: 连接到远程 PostgreSQL 数据库。
|
72
|
+
- 云同步关闭: 使用 PGLite (通过 Node.js 的 WASM 实现) 在本地存储数据。
|
76
73
|
|
77
74
|
## 数据流向说明
|
78
75
|
|
79
76
|
### 浏览器/PWA 模式
|
77
|
+
|
80
78
|
```
|
81
|
-
UI (React) → Zustand
|
79
|
+
UI (React) → Zustand action -> Client Service → Model Layer → PGLite (本地数据库)
|
82
80
|
```
|
83
81
|
|
84
82
|
### 服务端模式
|
83
|
+
|
85
84
|
```
|
86
|
-
UI (React) → Zustand
|
85
|
+
UI (React) → Zustand action → Client Service -> TRPC Client → TRPC Routers → Repositories/Models → Remote PostgreSQL
|
87
86
|
```
|
88
87
|
|
89
88
|
### Electron 桌面应用模式
|
89
|
+
|
90
90
|
```
|
91
|
-
UI (Electron Renderer) → Zustand
|
91
|
+
UI (Electron Renderer) → Zustand action → Client Service -> TRPC Client → 本地 Node.js 服务 → TRPC Routers → Repositories/Models → PGLite/Remote PostgreSQL (取决于云同步设置)
|
92
92
|
```
|
93
93
|
|
94
|
+
## 服务层 (Server Services)
|
94
95
|
|
95
|
-
|
96
|
-
|
97
|
-
|
96
|
+
- 位于 src/server/services/。
|
97
|
+
- 核心职责是封装独立的、可复用的业务逻辑单元。这些服务应易于测试。
|
98
|
+
- 平台差异抽象: 一个关键特性是通过其内部的 `impls` 子目录(例如 src/server/services/file/impls 包含 s3.ts 和 local.ts)来抹平不同运行环境带来的差异(例如云端使用 S3 存储,桌面版使用本地文件系统)。这使得上层(如 `tRPC` routers)无需关心底层具体实现。
|
99
|
+
- 目标是使 `tRPC` router 层的逻辑尽可能纯粹,专注于请求处理和业务流程编排。
|
100
|
+
- 服务可能会调用 `Repository` 层或直接调用 `Model` 层进行数据持久化和检索,也可能调用其他服务。
|
@@ -0,0 +1,69 @@
|
|
1
|
+
---
|
2
|
+
description: How to code review
|
3
|
+
globs:
|
4
|
+
alwaysApply: false
|
5
|
+
---
|
6
|
+
# Role Description
|
7
|
+
|
8
|
+
- You are a senior full-stack engineer skilled in performance optimization, security, and design systems.
|
9
|
+
- You excel at reviewing code and providing constructive feedback.
|
10
|
+
- Your task is to review submitted Git diffs **in Chinese** and return a structured review report.
|
11
|
+
- Review style: concise, direct, focused on what matters most, with actionable suggestions.
|
12
|
+
|
13
|
+
## Before the Review
|
14
|
+
|
15
|
+
Gather the modified code and context. Please strictly follow the process below:
|
16
|
+
|
17
|
+
1. Use `read_file` to read [package.json](mdc:package.json)
|
18
|
+
2. Use terminal to run command `git diff HEAD | cat` to obtain the diff and list the changed files. If you recieived empty result, run the same command once more.
|
19
|
+
3. Use `read_file` to open each changed file.
|
20
|
+
4. Use `read_file` to read [rules-attach.mdc](mdc:.cursor/rules/rules-attach.mdc). Even if you think it's unnecessary, you must read it.
|
21
|
+
5. combine changed files, step3 and `agent_requestable_workspace_rules`, list the rules which need to read
|
22
|
+
6. Use `read_file` to read the rules list in step 5
|
23
|
+
|
24
|
+
## Review
|
25
|
+
|
26
|
+
### Code Style
|
27
|
+
|
28
|
+
- Ensure JSDoc comments accurately reflect the implementation; update them when needed.
|
29
|
+
- Look for opportunities to simplify or modernize code with the latest JavaScript/TypeScript features.
|
30
|
+
- Prefer `async`/`await` over callbacks or chained `.then` promises.
|
31
|
+
- Use consistent, descriptive naming—avoid obscure abbreviations.
|
32
|
+
- Replace magic numbers or strings with well-named constants.
|
33
|
+
- Use semantically meaningful variable, function, and class names.
|
34
|
+
- Ignore purely formatting issues and other autofixable lint problems.
|
35
|
+
|
36
|
+
### Code Optimization
|
37
|
+
|
38
|
+
- Prefer `for…of` loops to index-based `for` loops when feasible.
|
39
|
+
- Decide whether callbacks should be **debounced** or **throttled**.
|
40
|
+
- Use components from `@lobehub/ui`, Ant Design, or the existing design system instead of raw HTML tags (e.g., `Button` vs. `button`).
|
41
|
+
- reuse npm packages already installed (e.g., `lodash/omit`) rather than reinventing the wheel.
|
42
|
+
- Design for dark mode and mobile responsiveness:
|
43
|
+
- Use the `antd-style` token system instead of hard-coded colors.
|
44
|
+
- Select the proper component variants.
|
45
|
+
- Performance considerations:
|
46
|
+
- Where safe, convert sequential async flows to concurrent ones with `Promise.all`, `Promise.race`, etc.
|
47
|
+
- Query only the required columns from a database rather than selecting entire rows.
|
48
|
+
|
49
|
+
### Obvious Bugs
|
50
|
+
|
51
|
+
- Do not silently swallow errors in `catch` blocks; at minimum, log them.
|
52
|
+
- Revert temporary code used only for testing (e.g., debug logs, temporary configs).
|
53
|
+
- Remove empty handlers (e.g., an empty `onClick`).
|
54
|
+
- Confirm the UI degrades gracefully for unauthenticated users.
|
55
|
+
|
56
|
+
## After the Review: output
|
57
|
+
|
58
|
+
1. Summary
|
59
|
+
- Start with a brief explanation of what the change set does.
|
60
|
+
- Summarize the changes for each modified file (or logical group).
|
61
|
+
2. Comments Issues
|
62
|
+
- List the most critical issues first.
|
63
|
+
- Use an ordered list, which will be convenient for me to reference later.
|
64
|
+
- For each issue:
|
65
|
+
- Mark severity tag (`❌ Must fix`, `⚠️ Should fix`, `💅 Nitpick`)
|
66
|
+
- Provode file path to the relevant file.
|
67
|
+
- Provide recommended fix
|
68
|
+
- End with a **git commit** command, instruct the author to run it.
|
69
|
+
- We use gitmoji to label commit messages, format: [emoji] <type>(<scope>): <subject>
|
@@ -0,0 +1,28 @@
|
|
1
|
+
---
|
2
|
+
description: cursor rules writing and optimization guide
|
3
|
+
globs:
|
4
|
+
alwaysApply: false
|
5
|
+
---
|
6
|
+
当你编写或修改 Cursor Rule 时,请遵循以下准则:
|
7
|
+
|
8
|
+
- 当你知道 rule 的文件名时,使用 `read_file` 而不是 `fetch_rules` 去读取它们,它们都在项目根目录的 `.cursor/rules/` 文件夹下
|
9
|
+
|
10
|
+
- 代码示例
|
11
|
+
- 示例应尽量精简,仅保留演示核心
|
12
|
+
- 删除与示例无关的导入/导出语句,但保留必要的导入
|
13
|
+
- 同一文件存在多个示例时,若前文已演示模块导入,后续示例可省略重复导入
|
14
|
+
- 无需书写 `export`
|
15
|
+
- 可省略与演示无关或重复的 props、配置对象属性、try/catch、CSS 等代码
|
16
|
+
- 删除无关注释,保留有助理解的注释
|
17
|
+
|
18
|
+
- 格式
|
19
|
+
- 修改前请先确认原始文档语言,并保持一致
|
20
|
+
- 无序列表统一使用 `-`
|
21
|
+
- 列表末尾的句号是多余的
|
22
|
+
- 非必要不使用加粗、行内代码等样式,Rule 主要供 LLM 阅读
|
23
|
+
- 避免中英文逐句对照。若括号内容为示例而非翻译,可保留
|
24
|
+
|
25
|
+
- Review
|
26
|
+
- 修正 Markdown 语法问题
|
27
|
+
- 纠正错别字
|
28
|
+
- 指出示例与说明不一致之处
|
@@ -0,0 +1,94 @@
|
|
1
|
+
---
|
2
|
+
description:
|
3
|
+
globs:
|
4
|
+
alwaysApply: true
|
5
|
+
---
|
6
|
+
# Guide to Optimize Output(Response) Rendering
|
7
|
+
|
8
|
+
## File Path and Code Symbol Rendering
|
9
|
+
|
10
|
+
- When rendering file paths, use backtick wrapping instead of markdown links so they can be parsed as clickable links in Cursor IDE.
|
11
|
+
|
12
|
+
- Good: `src/components/Button.tsx`
|
13
|
+
- Bad: [src/components/Button.tsx](mdc:src/components/Button.tsx)
|
14
|
+
|
15
|
+
- When rendering functions, variables, or other code symbols, use backtick wrapping so they can be parsed as navigable links in Cursor IDE
|
16
|
+
- Good: The `useState` hook in `MyComponent`
|
17
|
+
- Bad: The useState hook in MyComponent
|
18
|
+
|
19
|
+
## Markdown Render
|
20
|
+
|
21
|
+
- don't use br tag to wrap in table cell
|
22
|
+
|
23
|
+
## Terminal Command Output
|
24
|
+
|
25
|
+
- If terminal commands don't produce output, it's likely due to paging issues. Try piping the command to `cat` to ensure full output is displayed.
|
26
|
+
- Good: `git show commit_hash -- file.txt | cat`
|
27
|
+
- Good: `git log --oneline | cat`
|
28
|
+
- Reason: Some git commands use pagers by default, which may prevent output from being captured properly
|
29
|
+
|
30
|
+
## Mermaid Diagram Generation: Strict Syntax Validation Checklist
|
31
|
+
|
32
|
+
Before producing any Mermaid diagram, you **must** compare your final code line-by-line against every rule in the following checklist to ensure 100% compliance. **This is a hard requirement and takes precedence over other stylistic suggestions.** Please follow these action steps:
|
33
|
+
|
34
|
+
1. Plan the Mermaid diagram logic in your mind.
|
35
|
+
2. Write the Mermaid code.
|
36
|
+
3. **Carefully review your code line-by-line against the entire checklist below.**
|
37
|
+
4. Fix any aspect of your code that doesn't comply.
|
38
|
+
5. Use the `validateMermaid` tool to check your code for syntax errors. Only proceed if validation passes.
|
39
|
+
6. Output the final, compliant, and copy-ready Mermaid code block.
|
40
|
+
7. Immediately after the Mermaid code block, output:
|
41
|
+
I have checked that the Mermaid syntax fully complies with the validation checklist.
|
42
|
+
|
43
|
+
---
|
44
|
+
|
45
|
+
### Checklist Details
|
46
|
+
|
47
|
+
#### Rule 1: Edge Labels – Must Be Plain Text Only
|
48
|
+
> **Essence:** Anything inside `|...|` must contain pure, unformatted text. Absolutely NO Markdown, list markers, or parentheses/brackets allowed—these often cause rendering failures.
|
49
|
+
|
50
|
+
- **✅ Do:** `A -->|Process plain text data| B`
|
51
|
+
- **❌ Don't:** `A -->|1. Ordered list item| B` (No numbered lists)
|
52
|
+
- **❌ Don't:** `CC --"1. fetch('/api/...')"--> API` (No square brackets)
|
53
|
+
- **❌ Don't:** `A -->|- Unordered list item| B` (No hyphen lists)
|
54
|
+
- **❌ Don't:** `A -->|Transform (important)| B` (No parentheses)
|
55
|
+
- **❌ Don't:** `A -->|Transform [important]| B` (No square brackets)
|
56
|
+
|
57
|
+
#### Rule 2: Node Definition – Handle Special Characters with Care
|
58
|
+
> **Essence:** When node text or subgraph titles contain special characters like `()` or `[]`, wrap the text in quotes to avoid conflicts with Mermaid shape syntax.
|
59
|
+
|
60
|
+
- **When your node text includes parentheses (e.g., 'React (JSX)'):**
|
61
|
+
- **✅ Do:** `I_REACT["<b>React component (JSX)</b>"]` (Quotes wrap all text)
|
62
|
+
- **❌ Don't:** `I_REACT(<b>React component (JSX)</b>)` (Wrong, Mermaid parses this as a shape)
|
63
|
+
- **❌ Don't:** `subgraph Plugin Features (Plugins)` (Wrong, subgraph titles with parentheses must also be wrapped in quotes)
|
64
|
+
|
65
|
+
#### Rule 3: Double Quotes in Text – Must Be Escaped
|
66
|
+
> **Essence:** Use `"` for double quotes **inside node text**.
|
67
|
+
|
68
|
+
- **✅ Do:** `A[This node contains "quotes"]`
|
69
|
+
- **❌ Don't:** `A[This node contains "quotes"]`
|
70
|
+
|
71
|
+
#### Rule 4: All Formatting Must Use HTML Tags (NOT Markdown!)
|
72
|
+
> **Essence:** For newlines, bold, and other text formatting in nodes, use HTML tags only. Markdown is not supported.
|
73
|
+
|
74
|
+
- **✅ Do (robust):** `A["<b>Bold</b> and <code>code</code><br>This is a new line"]`
|
75
|
+
- **❌ Don't (not rendered):** `C["# This is a heading"]`
|
76
|
+
- **❌ Don't (not rendered):** ``C["`const` means constant"]``
|
77
|
+
- **⚠️ Warning (unreliable):** `B["Markdown **bold** might sometimes work but DON'T rely on it"]`
|
78
|
+
|
79
|
+
#### Rule 5: No HTML Tags for Participants and Message Labels (Sequence Diagrams)
|
80
|
+
> **Important Addition:**
|
81
|
+
> In Mermaid sequence diagrams, you MUST NOT use any HTML tags (such as `<b>`, `<code>`, etc.) in:
|
82
|
+
> - `participant` display names (`as` part)
|
83
|
+
> - Message labels (the text after `:` in diagram flows)
|
84
|
+
>
|
85
|
+
> These tags are generally not rendered—they may appear as-is or cause compatibility issues.
|
86
|
+
|
87
|
+
- **✅ Do:** `participant A as Client`
|
88
|
+
- **❌ Don't:** `participant A as <b>Client</b>`
|
89
|
+
- **✅ Do:** `A->>B: 1. Establish connection`
|
90
|
+
- **❌ Don't:** `A->>B: 1. <code>Establish connection</code>`
|
91
|
+
|
92
|
+
---
|
93
|
+
|
94
|
+
**Validate each Mermaid code block by running it through the `validateMermaid` tool before delivering your output!**
|
@@ -0,0 +1,193 @@
|
|
1
|
+
---
|
2
|
+
description: Debug 调试指南
|
3
|
+
globs:
|
4
|
+
alwaysApply: false
|
5
|
+
---
|
6
|
+
# Debug 调试指南
|
7
|
+
|
8
|
+
## 💡 调试流程概览
|
9
|
+
|
10
|
+
当遇到问题时,请按照以下优先级进行处理:
|
11
|
+
|
12
|
+
1. **快速判断** - 对于熟悉的错误,直接提供解决方案
|
13
|
+
2. **信息收集** - 使用工具搜索相关代码和配置
|
14
|
+
3. **网络搜索** - 查找现有解决方案
|
15
|
+
4. **定位调试** - 添加日志进行问题定位
|
16
|
+
5. **临时方案** - 如果找不到根本解决方案,提供临时解决方案
|
17
|
+
6. **解决实施** - 提供可维护的最终解决方案
|
18
|
+
|
19
|
+
## 🔍 错误信息分析
|
20
|
+
|
21
|
+
### 错误来源识别
|
22
|
+
|
23
|
+
错误信息可能来自:
|
24
|
+
|
25
|
+
- **Terminal 输出** - 构建、运行时错误
|
26
|
+
- **浏览器控制台** - 前端 JavaScript 错误
|
27
|
+
- **开发工具** - ESLint、TypeScript、测试框架等
|
28
|
+
- **服务器日志** - API、数据库连接等后端错误
|
29
|
+
- **截图或文本** - 用户直接提供的错误信息
|
30
|
+
|
31
|
+
## 🛠️ 信息收集工具
|
32
|
+
|
33
|
+
### 代码搜索工具
|
34
|
+
|
35
|
+
使用以下工具收集相关信息,并根据场景选择最合适的工具:
|
36
|
+
|
37
|
+
- **`codebase_search` (语义搜索)**
|
38
|
+
- **何时使用**: 当你不确定具体的代码实现,想要寻找相关概念、功能或逻辑时。
|
39
|
+
- **示例**: `查询"文件上传"功能的实现`
|
40
|
+
- **`grep_search` (精确/正则搜索)**
|
41
|
+
- **何时使用**: 当你知道要查找的确切字符串、函数名、变量名或一个特定的模式时。
|
42
|
+
- **示例**: `查找所有使用了 'useState' 的地方`
|
43
|
+
- **`file_search` (文件搜索)**
|
44
|
+
- **何时使用**: 当你知道文件名的一部分,需要快速定位文件时。
|
45
|
+
- **示例**: `查找 'Button.tsx' 组件`
|
46
|
+
- **`read_file` (内容读取)**
|
47
|
+
- **何时使用**: 在定位到具体文件后,用于查看其完整内容和上下文。
|
48
|
+
- **`web_search` (网络搜索)**
|
49
|
+
- **何时使用**: 当错误信息可能与第三方库、API 或常见问题相关时,用于获取外部信息。
|
50
|
+
|
51
|
+
### 环境与依赖检查
|
52
|
+
|
53
|
+
- **检查 `package.json`**: 查看 `scripts` 了解项目如何运行、构建和测试。查看 `dependencies` 和 `devDependencies` 确认库版本,版本冲突有时是问题的根源。
|
54
|
+
- **运行测试**: 使用 `ni vitest` 运行单元测试和集成测试,这可以快速定位功能回归或组件错误。
|
55
|
+
|
56
|
+
### 项目特定搜索目标
|
57
|
+
|
58
|
+
针对 lobe-chat 项目,重点关注:
|
59
|
+
|
60
|
+
- **配置文件**: [package.json](mdc:package.json), [next.config.mjs](mdc:next.config.mjs)
|
61
|
+
- **核心功能**: `src/features/` 下的相关模块
|
62
|
+
- **状态管理**: `src/store/` 下的 Zustand stores
|
63
|
+
- **数据库**: `src/database/` 和 `src/migrations/`
|
64
|
+
- **类型定义**: `src/types/` 下的类型文件
|
65
|
+
- **服务层**: `src/services/` 下的 API 服务
|
66
|
+
- **启动流程**: [apps/desktop/src/main/core/App.ts](mdc:apps/desktop/src/main/core/App.ts) - 了解应用启动流程
|
67
|
+
|
68
|
+
## 🌐 网络搜索策略
|
69
|
+
|
70
|
+
### 搜索顺序优先级
|
71
|
+
|
72
|
+
1. **和问题相关的项目的 github issue**
|
73
|
+
|
74
|
+
2. **技术社区**
|
75
|
+
- Stack Overflow
|
76
|
+
- GitHub Discussions
|
77
|
+
- Reddit
|
78
|
+
|
79
|
+
3. **官方文档**
|
80
|
+
- 使用 `mcp_context7_resolve-library-id` 和 `mcp_context7_get-library-docs` 工具
|
81
|
+
- 查阅官方文档网站
|
82
|
+
|
83
|
+
### 搜索关键词策略
|
84
|
+
|
85
|
+
- **错误信息**: 完整的错误消息
|
86
|
+
- **技术栈**: "Next.js 15" + "error message"
|
87
|
+
- **上下文**: 添加功能相关的关键词
|
88
|
+
|
89
|
+
## 🔧 问题定位与结构化思考
|
90
|
+
|
91
|
+
如果问题比较复杂,我们要按照先定位问题,再解决问题的大方向进行。
|
92
|
+
|
93
|
+
### 结构化思考工具
|
94
|
+
|
95
|
+
对于复杂或多步骤的调试任务,使用 `mcp_sequential-thinking_sequentialthinking` 工具来结构化思考过程。这有助于:
|
96
|
+
|
97
|
+
- **分解问题**: 将大问题拆解成可管理的小步骤。
|
98
|
+
- **清晰追踪**: 记录每一步的发现和决策,避免遗漏。
|
99
|
+
- **自我修正**: 在过程中评估和调整调试路径。
|
100
|
+
|
101
|
+
### 日志调试
|
102
|
+
|
103
|
+
在问题产生的路径上添加日志,可以简单使用 `console.log` 或者参考 [debug-usage.mdc](mdc:.cursor/rules/debug-usage.mdc) 使用 `debug` 模块。添加完日志后,请求我运行相关的代码并提供关键输出和错误信息。
|
104
|
+
|
105
|
+
### 引导式交互调试
|
106
|
+
|
107
|
+
虽然我无法直接操作浏览器开发者工具,但我可以引导你进行交互式调试:
|
108
|
+
|
109
|
+
1. **设置断点**: 我会告诉你可以在哪些关键代码行设置断点。
|
110
|
+
2. **检查变量**: 我会请你在断点处检查特定变量的值或 `props`/`state`。
|
111
|
+
3. **分析调用栈**: 我会请你提供调用栈信息,以帮助理解代码执行流程。
|
112
|
+
|
113
|
+
## 💡 临时解决方案策略
|
114
|
+
|
115
|
+
当无法找到根本解决方案时,提供临时解决方案:
|
116
|
+
|
117
|
+
### 临时方案准则
|
118
|
+
|
119
|
+
- **快速修复** - 优先让功能可用
|
120
|
+
- **最小修改** - 减少对现有代码的影响
|
121
|
+
- **清晰标记** - 明确标注这是临时方案
|
122
|
+
- **后续计划** - 说明后续如何找到更好的解决方案
|
123
|
+
|
124
|
+
### 临时方案模板
|
125
|
+
|
126
|
+
```markdown
|
127
|
+
## 临时解决方案 ⚠️
|
128
|
+
|
129
|
+
**问题**: [简要描述问题]
|
130
|
+
|
131
|
+
**临时修复**:
|
132
|
+
[具体的临时修复步骤]
|
133
|
+
|
134
|
+
**风险说明**:
|
135
|
+
|
136
|
+
- [可能的副作用或限制]
|
137
|
+
- [需要注意的事项]
|
138
|
+
|
139
|
+
**后续计划**:
|
140
|
+
|
141
|
+
- [ ] 深入调研根本原因
|
142
|
+
- [ ] 寻找更优雅的解决方案
|
143
|
+
- [ ] 监控是否有其他影响
|
144
|
+
```
|
145
|
+
|
146
|
+
## ✅ 解决方案准则
|
147
|
+
|
148
|
+
### 方案质量标准
|
149
|
+
|
150
|
+
提供的解决方案应该:
|
151
|
+
|
152
|
+
- **✅ 低侵入性** - 最小化对现有代码的修改
|
153
|
+
- **✅ 可维护性** - 易于理解和后续维护
|
154
|
+
- **✅ 类型安全** - 符合 TypeScript 规范
|
155
|
+
- **✅ 最佳实践** - 遵循项目的编码规范
|
156
|
+
- **✅ 测试友好** - 便于编写和运行测试
|
157
|
+
- **❌ 避免长期 Hack** - 临时方案可以 hack,但要明确标注
|
158
|
+
|
159
|
+
### 解决方案模板
|
160
|
+
|
161
|
+
```markdown
|
162
|
+
## 问题原因
|
163
|
+
|
164
|
+
[简要说明问题产生的根本原因]
|
165
|
+
|
166
|
+
## 解决方案
|
167
|
+
|
168
|
+
[详细的解决步骤]
|
169
|
+
|
170
|
+
## 代码修改
|
171
|
+
|
172
|
+
[具体的代码变更]
|
173
|
+
|
174
|
+
## 验证方法
|
175
|
+
|
176
|
+
[如何验证问题已解决]
|
177
|
+
|
178
|
+
## 预防措施
|
179
|
+
|
180
|
+
[如何避免类似问题再次发生]
|
181
|
+
```
|
182
|
+
|
183
|
+
## 🔄 迭代调试流程
|
184
|
+
|
185
|
+
如果初次解决方案无效:
|
186
|
+
|
187
|
+
1. **重新收集信息** - 基于新的错误信息搜索
|
188
|
+
2. **深入代码分析** - 查看更多相关代码文件
|
189
|
+
3. **运行相关测试** - 编写或运行一个失败的测试来稳定复现问题。
|
190
|
+
4. **扩大搜索范围** - 搜索更广泛的相关问题
|
191
|
+
5. **请求更多日志** - 添加更详细的调试信息
|
192
|
+
6. **提供临时方案** - 如果根本解决方案复杂,先提供临时修复
|
193
|
+
7. **分解问题** - 将复杂问题拆解为更小的子问题
|