|
1 | | -# AGENTS.md - PCL.Proto Development Guide |
| 1 | +# PCL.Proto 开发指南 |
2 | 2 |
|
3 | | -This document provides essential information for AI agents working on the PCL.Proto project. |
4 | | - |
5 | | -## Project Overview |
6 | | - |
7 | | -PCL.Proto is a Minecraft launcher prototype built with: |
8 | | - |
9 | | -- **Frontend**: Vue 3 + TypeScript + Vite + Pinia + Vue Router |
10 | | -- **Backend**: Rust + Tauri 2 |
11 | | -- **UI Framework**: Custom components |
12 | | -- **Package Manager**: pnpm |
13 | | - |
14 | | -## Build & Development Commands |
15 | | - |
16 | | -### Development |
17 | | - |
18 | | -```bash |
19 | | -# Start development server (frontend + Tauri) |
20 | | -pnpm run dev |
21 | | - |
22 | | -# Frontend-only development |
23 | | -pnpm run ui:dev |
24 | | -``` |
25 | | - |
26 | | -### Building |
27 | | - |
28 | | -```bash |
29 | | -# Full build (frontend + Tauri) |
30 | | -pnpm run build |
31 | | - |
32 | | -# Frontend-only build |
33 | | -pnpm run ui:build |
34 | | - |
35 | | -# Type checking |
36 | | -pnpm run type-check |
37 | | -``` |
38 | | - |
39 | | -### Testing |
40 | | - |
41 | | -**Note**: No test framework is currently configured in this project. Primary validation is through: |
42 | | - |
43 | | -- Type checking: `pnpm run type-check` |
44 | | -- Manual testing: `pnpm run dev` |
45 | | -- Rust tests can be run with: `cargo test` in `src-tauri/` directory |
46 | | - |
47 | | -### Tauri Commands |
| 3 | +## 项目技术栈 |
| 4 | +- **前端**:Vue 3 + TypeScript + Vite + Pinia + Vue Router |
| 5 | +- **后端**:Rust + Tauri 2 |
| 6 | +- **UI**:自定义组件 |
| 7 | +- **包管理**:pnpm |
48 | 8 |
|
| 9 | +## 核心开发命令 |
49 | 10 | ```bash |
50 | | -# Run any Tauri command |
51 | | -pnpm run tauri [command] |
52 | | - |
53 | | -# Generate icons |
54 | | -pnpm run tauri icon |
| 11 | +# 开发 |
| 12 | +pnpm run dev # 全栈开发 |
| 13 | +pnpm run ui:dev # 仅前端 |
| 14 | + |
| 15 | +# 构建 |
| 16 | +pnpm run build # 全栈构建 |
| 17 | +pnpm run ui:build # 仅前端构建 |
| 18 | +pnpm run type-check # 类型检查 |
| 19 | + |
| 20 | +# 测试 |
| 21 | +pnpm run type-check # 主要验证方式 |
| 22 | +cargo test # Rust测试(在src-tauri目录下) |
55 | 23 | ``` |
56 | 24 |
|
57 | | -### Deployment |
58 | | - |
59 | | -```bash |
60 | | -# Deploy to GitHub Pages |
61 | | -pnpm run deploy |
62 | | -``` |
63 | | - |
64 | | -## Code Style Guidelines |
65 | | - |
66 | | -### TypeScript/JavaScript |
67 | | - |
68 | | -**Imports:** |
69 | | - |
70 | | -- Use ES modules (`import/export`) |
71 | | -- Group imports: external libraries first, then internal modules |
72 | | -- Use `@/` alias for internal imports (configured in Vite) |
73 | | -- Example from `src/main.ts:12-20`: |
74 | | - ```typescript |
75 | | - import { createApp } from 'vue' |
76 | | - import { createPinia } from 'pinia' |
77 | | - import router from '@/router/index' |
78 | | - ``` |
79 | | - |
80 | | -**Naming Conventions:** |
81 | | - |
82 | | -- **Variables/Functions**: camelCase (`getAccount`, `username`) |
83 | | -- **Types/Interfaces**: PascalCase (`AccountInner`, `IVersionShow`) |
84 | | -- **Constants**: UPPER_SNAKE_CASE for true constants |
85 | | -- **Store names**: kebab-case (`account-info`) |
86 | | -- **Component files**: PascalCase (`Modal.vue`, `PButton.vue`) |
87 | | - |
88 | | -**Formatting:** |
89 | | - |
90 | | -- **Semicolons**: No semicolons (Prettier config) |
91 | | -- **Quotes**: Single quotes |
92 | | -- **Line length**: 100 characters (Prettier config) |
93 | | -- **Trailing commas**: Not used in examples |
94 | | -- **Indentation**: 2 spaces (no tabs) |
95 | | - |
96 | | -**Prettier Configuration:** |
97 | | - |
98 | | -```json |
99 | | -{ |
100 | | - "semi": false, |
101 | | - "singleQuote": true, |
102 | | - "printWidth": 100 |
103 | | -} |
104 | | -``` |
105 | | - |
106 | | -**Error Handling:** |
107 | | - |
108 | | -- Use try/catch for async operations |
109 | | -- Log errors with `console.error` |
110 | | -- Example from `src/stores/account.ts:31`: |
111 | | - ```typescript |
112 | | - } catch (error) { |
113 | | - console.error('Failed to initialize account:', error) |
114 | | - } |
115 | | - ``` |
116 | | - |
117 | | -**TypeScript:** |
118 | | - |
119 | | -- Use strict typing |
120 | | -- Define interfaces for complex data structures |
121 | | -- Use `ref` for reactive state in composables |
122 | | -- Prefer composition API with `<script setup>` |
123 | | - |
124 | | -### Vue Components |
125 | | - |
126 | | -**Component Structure:** |
127 | | - |
128 | | -```vue |
129 | | -<script setup lang="ts"> |
130 | | -// Imports first |
131 | | -import { useModal } from '@/composables/useModal' |
132 | | -import PButton from './widget/PButton.vue' |
133 | | -
|
134 | | -// Type definitions |
135 | | -import type { ModalButtonOption } from '@/types/modal' |
136 | | -
|
137 | | -// Logic |
138 | | -const { isOpen, options, close, inputValue } = useModal() |
139 | | -</script> |
140 | | -
|
141 | | -<template lang="pug"> |
142 | | -// Pug template syntax |
143 | | -</template> |
144 | | -
|
145 | | -<style scoped> |
146 | | -// Scoped styles |
147 | | -</style> |
148 | | -``` |
149 | | - |
150 | | -**Template Language:** |
151 | | - |
152 | | -- Use **Pug** for templates (`lang="pug"`) |
153 | | -- Use kebab-case for template attributes and events |
154 | | -- Use Vue directives (`v-if`, `v-for`, `v-model`) |
155 | | - |
156 | | -**State Management:** |
157 | | - |
158 | | -- Use **Pinia** stores for global state |
159 | | -- Use `ref` and `computed` for component state |
160 | | -- Store naming: `useStoreName()` pattern |
161 | | - |
162 | | -### Rust (Backend) |
163 | | - |
164 | | -**File Structure:** |
165 | | - |
166 | | -- Backend code in `src-tauri/src/` |
167 | | -- Core logic in `src-tauri/src/core/` |
168 | | -- Utilities in `src-tauri/src/util/` |
169 | | - |
170 | | -**Naming:** |
171 | | - |
172 | | -- **Modules**: snake_case (`api_client`, `game_launcher`) |
173 | | -- **Structs/Enums**: PascalCase (`GameInstance`, `GameJava`) |
174 | | -- **Functions**: snake_case (`from_version_folder`) |
175 | | -- **Variables**: snake_case (`version_folder`, `json_files`) |
176 | | - |
177 | | -**Error Handling:** |
178 | | - |
179 | | -- Use `thiserror` crate for custom error types |
180 | | -- Use `Result<T, E>` for fallible operations |
181 | | -- Use `?` operator for error propagation |
182 | | - |
183 | | -**Imports:** |
184 | | - |
185 | | -- Group standard library imports first |
186 | | -- Then external crate imports |
187 | | -- Then internal module imports |
188 | | -- Example from `src-tauri/src/core/game.rs:1-6`: |
189 | | - |
190 | | - ```rust |
191 | | - use std::{fs, path::PathBuf, sync::Arc}; |
192 | | - |
193 | | - use crate::core::{ |
194 | | - api_client::game::VersionDetails, java::JavaRuntime, launcher::GameLaunchError, |
195 | | - mcmod::PluginType, repository::GameRepository, |
196 | | - }; |
197 | | - ``` |
198 | | - |
199 | | -## Project Structure |
200 | | - |
| 25 | +## 代码风格要点 |
| 26 | + |
| 27 | +### TypeScript/Vue |
| 28 | +- **导入**:使用 `@/` 别名,外部库在前 |
| 29 | +- **命名**: |
| 30 | + - 变量/函数:camelCase |
| 31 | + - 类型/接口:PascalCase |
| 32 | + - 组件文件:PascalCase(如 `Modal.vue`) |
| 33 | + - Store命名:kebab-case(如 `account-info`) |
| 34 | +- **格式化**:无分号、单引号、100字符行宽 |
| 35 | +- **错误处理**:async操作必须用 try/catch |
| 36 | +- **组件**:使用 `<script setup>` + Pug模板 + 组合式API |
| 37 | + |
| 38 | +### Rust |
| 39 | +- **命名**:模块/函数/变量用 snake_case,结构体/枚举用 PascalCase |
| 40 | +- **错误**:使用 `thiserror` + `Result<T, E>` + `?` 传播 |
| 41 | +- **导入**:标准库 → 外部crate → 内部模块 |
| 42 | + |
| 43 | +## 项目结构 |
201 | 44 | ``` |
202 | 45 | src/ |
203 | | -├── api/ # API clients and data fetching |
204 | | -├── assets/ # Static assets (fonts, icons, images) |
205 | | -├── components/ # Vue components |
206 | | -│ ├── icons/ # Icon components |
207 | | -│ └── widget/ # Reusable UI widgets |
208 | | -├── composables/ # Vue composables |
209 | | -├── layout/ # Layout components |
210 | | -├── locales/ # Internationalization |
211 | | -├── router/ # Vue Router configuration |
212 | | -├── stores/ # Pinia stores |
213 | | -├── types/ # TypeScript type definitions |
214 | | -├── util/ # Utility functions |
215 | | -└── views/ # Page components |
| 46 | +├── components/ # Vue组件 |
| 47 | +├── composables/ # 组合式函数 |
| 48 | +├── stores/ # Pinia仓库 |
| 49 | +├── types/ # TS类型定义 |
| 50 | +└── views/ # 页面 |
216 | 51 |
|
217 | 52 | src-tauri/ |
218 | | -├── src/ |
219 | | -│ ├── core/ # Core Rust logic |
220 | | -│ └── util/ # Rust utilities |
221 | | -└── Cargo.toml # Rust dependencies |
| 53 | +└── src/ |
| 54 | + ├── core/ # Rust核心逻辑 |
| 55 | + └── util/ # 工具函数 |
222 | 56 | ``` |
223 | 57 |
|
224 | | -## Testing Notes |
225 | | - |
226 | | -- No test framework detected in package.json |
227 | | -- Type checking serves as primary validation: `pnpm run type-check` |
228 | | -- Manual testing through development server: `pnpm run dev` |
229 | | -- Rust tests can be run with: `cargo test` in `src-tauri/` directory |
230 | | - |
231 | | -## Git & Workflow |
232 | | - |
233 | | -**Submodules:** |
234 | | - |
235 | | -- Project uses git submodules (locales directory) |
236 | | -- Initialize with: `git submodule update --init --recursive` |
237 | | - |
238 | | -**Commit Messages:** |
239 | | - |
240 | | -- Follow conventional commits style |
241 | | -- Use present tense ("Add feature" not "Added feature") |
242 | | -- Reference issues when applicable |
243 | | - |
244 | | -## Important Notes for Agents |
245 | | - |
246 | | -1. **Always run type checking** after making changes: `pnpm run type-check` |
247 | | -2. **Format code** before committing: `pnpm run format` |
248 | | -3. **Check for submodule updates** when cloning |
249 | | -4. **Tauri requires platform-specific toolchains** (MSVC for Windows, Xcode for macOS) |
250 | | -5. **Use pnpm** not npm or yarn for package management |
251 | | -6. **Component naming**: Use PascalCase for Vue component files |
252 | | -7. **Store pattern**: Use `useStoreName()` pattern for Pinia stores |
253 | | -8. **Error handling**: Always handle async errors with try/catch |
254 | | -9. **Type safety**: Define interfaces for all complex data structures |
255 | | -10. **Internationalization**: Support both English (en-US) and Chinese (zh-CN) locales |
256 | | - |
257 | | -## Performance Considerations |
258 | | - |
259 | | -- Use `ref` for reactive primitives, `reactive` for objects |
260 | | -- Implement proper cleanup in composables |
261 | | -- Use `v-memo` for expensive template computations when needed |
262 | | -- Consider lazy loading for large components |
263 | | - |
264 | | -## Security Notes |
265 | | - |
266 | | -- Never commit secrets or API keys |
267 | | -- Validate all user input in Rust backend |
268 | | -- Use Tauri's secure IPC for frontend-backend communication |
269 | | -- Follow Rust's memory safety guarantees for backend code |
| 58 | +## 关键提醒 |
| 59 | +1. 始终在修改后运行 `pnpm run type-check` |
| 60 | +2. 提交前格式化代码:`pnpm run format` |
| 61 | +3. 使用 `pnpm`,勿用 npm/yarn |
| 62 | +4. Vue组件文件使用 **PascalCase** |
| 63 | +5. Pinia仓库使用 `useStoreName()` 模式 |
| 64 | +6. 支持中英文国际化(en-US / zh-CN) |
| 65 | +7. 子模块初始化:`git submodule update --init --recursive` |
| 66 | +8. 后端验证用户输入,利用Tauri安全IPC |
0 commit comments