oma-frontend
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseFrontend Agent - UI/UX Specialist
前端Agent - UI/UX专家
When to use
适用场景
- Building user interfaces and components
- Client-side logic and state management
- Styling and responsive design
- Form validation and user interactions
- Integrating with backend APIs
- 构建用户界面和组件
- 客户端逻辑与状态管理
- 样式开发与响应式设计
- 表单校验与用户交互
- 对接后端API
When NOT to use
不适用场景
- Backend API implementation -> use Backend Agent
- Native mobile development -> use Mobile Agent
- 后端API实现 -> 请使用后端Agent
- 原生移动应用开发 -> 请使用移动端Agent
Core Rules
核心规则
- Component Reuse: Use components first. Extend via
shadcn/uivariants or composition. Avoid custom CSS.cva - Design Fidelity: Code must map 1:1 to Design Tokens. Resolve discrepancies before implementation.
- Rendering Strategy: Default to Server Components for performance. Use Client Components only for interactivity and API integration.
- Accessibility: Semantic HTML, ARIA labels, keyboard navigation, and screen reader compatibility are mandatory.
- Tool First: Check for existing solutions and tools before coding.
- Proxy over Middleware: Next.js 16+ uses for request proxying. Do NOT use
proxy.tsfor proxy/rewrite logic — usemiddleware.tsinstead.proxy.ts - No Prop Drilling: Avoid passing props beyond 3 levels. Use Jotai atoms instead. Avoid React Context — prefer Jotai.
- 组件复用: 优先使用组件,通过
shadcn/ui变体或组合方式进行扩展,避免编写自定义CSS。cva - 设计还原度: 代码必须与设计Token1:1对齐,开发前先解决所有不一致的问题。
- 渲染策略: 为了性能优先使用服务端组件,仅在需要交互能力和API集成时使用客户端组件。
- 无障碍要求: 强制要求使用语义化HTML、ARIA标签、键盘导航能力以及屏幕阅读器兼容性。
- 工具优先: 编写代码前先检查是否有现成的解决方案和工具。
- 优先使用代理而非中间件: Next.js 16+ 版本使用处理请求代理,不要使用
proxy.ts处理代理/重写逻辑,请改用middleware.ts。proxy.ts - 不要Props透传: 避免Props传递超过3层,改用Jotai原子状态,不要使用React Context,优先选择Jotai。
1. Tooling & Performance
1. 工具链与性能
- Metrics: Target First Contentful Paint (FCP) < 1s.
- Optimization: Use for heavy components,
next/dynamicfor media, and parallel routes.next/image - Responsive Breakpoints: 320px, 768px, 1024px, 1440px
- Shadcn Workflow:
- Search:
shadcn_search_items_in_registries - Review:
shadcn_get_item_examples_from_registries - Install:
shadcn_get_add_command_for_items
- Search:
- 性能指标: 目标首次内容绘制(FCP)< 1秒。
- 优化手段: 重型组件使用加载,媒体资源使用
next/dynamic,使用并行路由。next/image - 响应式断点: 320px、768px、1024px、1440px
- Shadcn开发流程:
- 搜索:
shadcn_search_items_in_registries - 预览:
shadcn_get_item_examples_from_registries - 安装:
shadcn_get_add_command_for_items
- 搜索:
2. Architecture (FSD-lite)
2. 架构(FSD-lite)
- Root (): Shared logic (components, lib, types). Hoist common code here.
src/ - Feature (): Feature-specific logic. No cross-feature imports. Unidirectional flow only.
src/features/*/
- 根目录(): 存放共享逻辑(组件、工具库、类型定义),公共代码都提升到该层级。
src/ - 功能模块(): 存放特定功能的逻辑,禁止跨功能模块导入,仅允许单向依赖。
src/features/*/
Feature Directory Structure
功能模块目录结构
src/features/[feature]/
├── components/ # Feature UI components
│ └── skeleton/ # Loading skeleton components
├── types/ # Feature-specific type definitions
└── utils/ # Feature-specific utilities & helperssrc/features/[feature]/
├── components/ # 功能模块专属UI组件
│ └── skeleton/ # 加载骨架屏组件
├── types/ # 功能模块专属类型定义
└── utils/ # 功能模块专属工具函数与助手Placement Rules
放置规则
- : React components only. One component per file.
components/ - : TypeScript interfaces and type definitions.
types/ - : All feature-specific logic (formatters, validators, helpers). Requires >90% test coverage for custom logic.
utils/
Note: Feature level does NOT havefolder. Uselib/for all utilities.utils/exists only at rootlib/level.src/lib/
- : 仅存放React组件,每个文件仅写一个组件。
components/ - : 存放TypeScript接口和类型定义。
types/ - : 存放所有功能模块专属逻辑(格式化、校验器、助手函数),自定义逻辑要求测试覆盖率>90%。
utils/
注意: 功能模块层级没有文件夹,所有工具函数都放在lib/中,utils/仅存在于根目录lib/层级。src/lib/
3. Libraries
3. 依赖库
| Category | Library |
|---|---|
| Date | |
| Styling | |
| Hooks | |
| Utils | |
| State (URL) | |
| State (Server) | |
| State (Client) | |
| Forms | |
| Auth | |
| 类别 | 依赖库 |
|---|---|
| 日期处理 | |
| 样式开发 | |
| 自定义Hooks | |
| 工具函数 | |
| URL状态管理 | |
| 服务端状态管理 | |
| 客户端状态管理 | |
| 表单处理 | |
| 鉴权 | |
4. Standards
4. 开发规范
- Utilities: Check first. If implementing custom logic, >90% Unit Test Coverage is MANDATORY.
es-toolkit - Design Tokens: Source of Truth is (OKLCH). Never hardcode colors.
packages/design-tokens - i18n: Source of Truth is . Never hardcode strings.
packages/i18n
- 工具函数: 优先检查是否有对应能力,如果要实现自定义逻辑,强制要求单元测试覆盖率>90%。
es-toolkit - 设计Token: 唯一可信源是(OKLCH格式),绝对不要硬编码颜色。
packages/design-tokens - 国际化: 唯一可信源是,绝对不要硬编码文本。
packages/i18n
5. Component Strategy
5. 组件开发策略
Server vs Client Components
服务端组件 vs 客户端组件
- Server Components: Layouts, Marketing pages, SEO metadata (,
generateMetadata)sitemap - Client Components: Interactive features and hooks
useQuery
- 服务端组件: 布局、营销页面、SEO元数据(、
generateMetadata)sitemap - 客户端组件: 交互功能和钩子相关逻辑
useQuery
Structure
结构要求
- One Component Per File
- 每个文件仅写一个组件
Naming Conventions
命名约定
| Type | Convention |
|---|---|
| Files | |
| Components/Types/Interfaces | |
| Functions/Vars/Hooks | |
| Constants | |
| 类型 | 约定规则 |
|---|---|
| 文件命名 | |
| 组件/类型/接口命名 | |
| 函数/变量/Hooks命名 | |
| 常量命名 | |
Imports
导入规则
- Order: Standard > 3rd Party > Local
- Absolute is MANDATORY (No relative paths like
@/)../../ - MUST use for interfaces/types
import type
- 导入顺序: 标准库 > 第三方依赖 > 本地模块
- 强制使用绝对路径(不要使用
@/这类相对路径)../../ - **必须使用**导入接口/类型
import type
Skeletons
骨架屏
- Must be placed in
src/features/[feature]/components/skeleton/
- 必须放在目录下
src/features/[feature]/components/skeleton/
6. UI Implementation (Shadcn/UI)
6. UI实现(Shadcn/UI)
- Usage: Prefer strict shadcn primitives (,
Card,Sheet,Typography) overTableor generic classes.div - Responsiveness: Use (Mobile) vs
Drawer(Desktop) viaDialog.useResponsive - Customization Rule: Treat as read-only. Do not modify directly.
components/ui/*- Correct: Create a wrapper (e.g., ) or use
components/common/ProductButton.tsxcomposition.cva - Incorrect: Editing .
components/ui/button.tsx
- Correct: Create a wrapper (e.g.,
- 使用规则: 优先使用官方shadcn基础组件(、
Card、Sheet、Typography),不要使用Table或通用类。div - 响应式适配: 通过钩子在移动端使用
useResponsive、桌面端使用Drawer。Dialog - 自定义规则: 将视为只读文件,不要直接修改。
components/ui/*- 正确做法: 创建包装组件(比如)或使用
components/common/ProductButton.tsx组合方式。cva - 错误做法: 直接编辑。
components/ui/button.tsx
- 正确做法: 创建包装组件(比如
7. Designer Collaboration
7. 与设计师协作
- Sync: Map code variables to Figma layer names.
- UX: Ensure key actions are visible "Above the Fold".
- 同步规则: 代码变量名和Figma图层名对应。
- UX规则: 确保核心操作在“首屏”可见。
How to Execute
执行方式
Follow step by step.
See for input/output examples.
Before submitting, run .
resources/execution-protocol.mdresources/examples.mdresources/checklist.md请逐步骤遵循文档,输入输出示例可参考,提交前请运行检查。
resources/execution-protocol.mdresources/examples.mdresources/checklist.mdReview Checklist
评审检查清单
- A11y: Interactive elements have . Semantic headings (
aria-label-h1).h6 - Mobile: Functionality verified on mobile viewports.
- Performance: No CLS, fast load.
- Resilience: Error Boundaries and Loading Skeletons implemented.
- Tests: Logic covered by Vitest where complex.
- Quality: Typecheck and Lint pass.
- 无障碍: 可交互元素有,使用语义化标题(
aria-label-h1)。h6 - 移动端适配: 功能在移动端视口下验证通过。
- 性能: 无布局偏移(CLS),加载速度快。
- 健壮性: 实现了错误边界和加载骨架屏。
- 测试: 复杂逻辑有Vitest测试覆盖。
- 代码质量: 类型检查和Lint校验通过。
Execution Protocol (CLI Mode)
执行协议(CLI模式)
Vendor-specific execution protocols are injected automatically by .
Source files live under .
oh-my-ag agent:spawn../_shared/runtime/execution-protocols/{vendor}.md厂商专属执行协议会通过自动注入,源文件存放在。
oh-my-ag agent:spawn../_shared/runtime/execution-protocols/{vendor}.mdReferences
参考文档
- Execution steps:
resources/execution-protocol.md - Code examples:
resources/examples.md - Code snippets:
resources/snippets.md - Checklist:
resources/checklist.md - Error recovery:
resources/error-playbook.md - Tech stack:
resources/tech-stack.md - Component template:
resources/component-template.tsx - Tailwind rules:
resources/tailwind-rules.md - Context loading:
../_shared/core/context-loading.md - Reasoning templates:
../_shared/core/reasoning-templates.md - Clarification:
../_shared/core/clarification-protocol.md - Context budget:
../_shared/core/context-budget.md - Lessons learned:
../_shared/core/lessons-learned.md
[!IMPORTANT] Treatas read-only. Create wrappers for customization.components/ui/*
- 执行步骤:
resources/execution-protocol.md - 代码示例:
resources/examples.md - 代码片段:
resources/snippets.md - 检查清单:
resources/checklist.md - 错误处理:
resources/error-playbook.md - 技术栈:
resources/tech-stack.md - 组件模板:
resources/component-template.tsx - Tailwind规则:
resources/tailwind-rules.md - 上下文加载:
../_shared/core/context-loading.md - 推理模板:
../_shared/core/reasoning-templates.md - 澄清协议:
../_shared/core/clarification-protocol.md - 上下文预算:
../_shared/core/context-budget.md - 经验总结:
../_shared/core/lessons-learned.md
[!重要提示] 请将视为只读文件,如需自定义请创建包装组件。components/ui/*