Agent Skillsshinpr/claude-code-workflows › frontend-ai-guide

frontend-ai-guide

GitHub

提供React/TypeScript前端开发的技术决策标准、反模式检测及质量门禁。用于审查组件、Hooks、浏览器行为及实现完整性,强调价值优先与低生命周期成本,识别代码与设计层面的不良实践。

dev-workflows-frontend/skills/frontend-ai-guide/SKILL.md shinpr/claude-code-workflows

触发场景

审查React或TypeScript组件实现 检查Hooks编写规范 评估前端代码质量与反模式 审核浏览器兼容性或行为逻辑

安装

npx skills add shinpr/claude-code-workflows --skill frontend-ai-guide -g -y
更多选项

非标准路径

npx skills add https://github.com/shinpr/claude-code-workflows/tree/main/dev-workflows-frontend/skills/frontend-ai-guide -g -y

不安装直接使用

npx skills use shinpr/claude-code-workflows@frontend-ai-guide

指定 Agent (Claude Code)

npx skills add shinpr/claude-code-workflows --skill frontend-ai-guide -a claude-code -g -y

安装 repo 全部 skill

npx skills add shinpr/claude-code-workflows --all -g -y

预览 repo 内 skill

npx skills add shinpr/claude-code-workflows --list

SKILL.md

Frontmatter
{
    "name": "frontend-ai-guide",
    "description": "Applies React\/TypeScript-specific technical decision criteria, anti-pattern detection, debugging, and frontend quality gates. Use when reviewing components, hooks, browser behavior, or frontend implementation completeness."
}

AI Developer Guide - Technical Decision Criteria and Anti-pattern Collection (Frontend)

Value-First Engineering

Explore broadly, then converge on the lowest-lifecycle-cost solution that delivers the required user value while keeping the UI correct and maintainable.

  • Resolve verified problems within confirmed scope or dependencies required for the outcome; report other findings with evidence for a scope decision.
  • Introduce state, props, variants, abstractions, or speculative edge-case handling when a current outcome, verified constraint, or evidence-backed material risk requires them.

Technical Anti-patterns (Red Flag Patterns)

Pause the affected decision and review the design when detecting the following patterns:

Code Quality Anti-patterns

  1. Writing similar code 3 or more times - Violates Rule of Three
  2. Multiple responsibilities mixed in a single component - Violates Single Responsibility Principle (SRP)
  3. Defining same content in multiple components - Violates DRY principle
  4. Making changes without checking dependencies - Potential for unexpected impacts
  5. Disabling code with comments - Should use version control
  6. Error suppression - Hiding problems creates technical debt
  7. Excessive use of type assertions (as) - Abandoning type safety
  8. Prop drilling through 3+ levels - Mandatory ownership review. Use composition, Context, or the project's state layer when intermediate components only forward the value; retain explicit props only when they keep ownership clearer and avoid broader shared state
  9. Components at 300+ lines - Mandatory decomposition review. Split by default when rendering, state/data ownership, or reusable/testable behavior forms an independent responsibility; retain only when the component is cohesive and splitting would add avoidable prop/state synchronization

Design Anti-patterns

  • "Make it work for now" thinking - Accumulation of technical debt
  • Patchwork implementation - Unplanned additions to existing components
  • Optimistic implementation of uncertain technology - Designing unknown elements assuming "it'll probably work"
  • Symptomatic fixes - Surface-level fixes that don't solve root causes
  • Unplanned large-scale changes - Lack of incremental approach

Fallback Design Principles

Core Principle: Fail-Fast

Design philosophy that prioritizes improving primary code reliability over fallback implementations.

Criteria for Fallback Implementation

  • Fallback rule: Implement a fallback when an accepted requirement, boundary contract, project policy, or Design Doc defines the degraded outcome and recovery owner
  • Layer Responsibilities:
    • Rendering failure in a child component subtree, including a hook that throws during render: Use the project's Error Boundary
    • Event handlers, ordinary async callbacks, SSR, and hook/API operations outside rendering: Handle them at the owning event, hook, API, or server boundary using its error contract

Detection of Excessive Fallbacks

  • Require design review when writing the 3rd catch statement in the same feature; retain it only for a distinct failure mode with a documented recovery owner and visible UI outcome
  • Require design review when the same failure is caught at multiple component/hook/API layers without one recovery owner, or when nested handlers obscure the visible UI state
  • Identify the accepted recovery contract before implementing a fallback
  • Make fallback activation observable through one existing UI, log, or metric channel at the boundary that owns diagnosis or recovery; add a new channel only when an operational requirement or project policy requires it

Rule of Three - Criteria for Code Duplication

How to handle duplicate code based on Martin Fowler's "Refactoring":

Duplication Count Action Reason
1st time Inline implementation Cannot predict future changes
2nd time Consider future consolidation Pattern beginning to emerge
3rd time Implement commonalization Pattern established

Criteria for Commonalization

Cases for Commonalization

  • Business logic duplication
  • Complex processing algorithms
  • Component patterns (form fields, cards, etc.)
  • Custom hooks
  • Validation rules

Cases to Avoid Commonalization

  • Accidental matches (coincidentally same code)
  • Possibility of evolving in different directions
  • Significant readability decrease from commonalization
  • Simple helpers in test code

Implementation Example

// 1st-2nd occurrence: keep separate, no commonalization yet
function UserEmailInput() { /* ... */ }
function ContactEmailInput() { /* ... */ }

// Commonalize on 3rd occurrence
function EmailInput({ context }: { context: 'user' | 'contact' | 'admin' }) { /* ... */ }

Common Failure Patterns and Avoidance Methods

Pattern 1: Error Fix Chain

Symptom: Fixing one error causes new errors Cause: Surface-level fixes without understanding root cause Avoidance: Identify root cause with 5 Whys before fixing

Pattern 2: Abandoning Type Safety

Symptom: Excessive use of any type or as Cause: Impulse to avoid type errors Avoidance: Handle safely with unknown type and type guards

Pattern 3: Implementation Without Sufficient Testing

Symptom: Many bugs after implementation Cause: Ignoring Red-Green-Refactor process Avoidance: Start new or changed behavior and reproducible bug fixes with a failing test. For behavior-preserving refactors, confirm existing or characterization tests pass before and after the change

Pattern 4: Ignoring Technical Uncertainty

Symptom: Frequent unexpected errors when introducing new technology Cause: Assuming "it should work according to official documentation" without prior investigation Avoidance:

  • Record certainty evaluation at the beginning of task files
    Certainty: low (Reason: new experimental feature with limited production examples)
    Exploratory implementation: true
    Fallback: use established patterns
    
  • For low certainty cases, create minimal verification code first

Pattern 5: Insufficient Existing Code Investigation

Symptom: Duplicate implementations, architecture inconsistency, integration failures Cause: Insufficient understanding of existing code before implementation Avoidance Methods:

  • Before implementation, always search for similar functionality (using domain, responsibility, component patterns as keywords)
  • Similar functionality found → Verify that its props, lifecycle, design-system role, and repository usage are representative; reuse or extend it when compatible, otherwise record why it is not a valid model
  • Similar functionality is technical debt → Repair it when it blocks the current outcome, was caused by the current change, or lies in confirmed scope; otherwise report it separately. Create an ADR when the repair requires an architectural decision
  • No similar functionality exists → Implement new functionality following existing design philosophy
  • Record all decisions and rationale in "Existing Codebase Analysis" section of Design Doc

Quality Check Workflow

Read package.json scripts and run them with the project's package manager (packageManager field). Map the project's actual script names to the phases below — do not assume fixed names.

Phases (run in order)

  1. Lint/format — the project's formatter + linter (e.g., Biome, or ESLint + Prettier)
  2. Type check — type check without emit
  3. Build — production build
  4. Test — unit/integration tests
  5. Coverage — coverage run when the task added or changed behavior

Troubleshooting

  • Port already in use — stop the stale dev/preview/test process holding the port
  • Stale cache — re-run with the project's fresh/clean-cache option
  • Dependency errors — clean reinstall dependencies

Situations Requiring Technical Decisions

Timing of Abstraction

  • Extract patterns after writing concrete implementation 3 times
  • Be conscious of YAGNI, implement only currently needed features
  • Prioritize current simplicity over future extensibility

Performance vs Readability

  • Prioritize readability unless the project's performance budget or a React DevTools Profiler comparison identifies a meaningful bottleneck in the affected interaction
  • Measure before optimizing with React DevTools Profiler
  • Document reason with comments when optimizing

Granularity of Component/Type Definitions

  • Overly detailed components/types reduce maintainability
  • Design components that appropriately express UI patterns
  • Use composition over inheritance

Implementation Completeness Assurance

Risk-Scaled Procedure for Impact Analysis

Completion Criteria: Complete all 3 stages. Concise search/inspection notes are sufficient for an isolated component change with no shared contract, routing, state-ownership, or build/config impact; use the structured report for cross-component or high-risk changes.

1. Discovery

Grep -n "ComponentName\|hookName" -o content
Grep -n "importedFunction" -o content
Grep -n "propsType\|StateType" -o content

2. Understanding

Read the discovered files needed to establish:

  • Caller's purpose and context
  • Component hierarchy
  • Data flow: Props → State → Event handlers → Callbacks

3. Identification

For cross-component or high-risk changes, produce a structured impact report:

## Impact Analysis
### Direct Impact: ComponentA, ComponentB (with reasons)
### Indirect Impact: FeatureX, PageY (with integration paths)
### Processing Flow: Props → Render → Events → Callbacks

Proceed when the user-requested or task-defined scope, consumers, state flow, and required checks are identified.

Unused Code Deletion Rule

When the requested change makes a component, hook, utility, document, or configuration entry obsolete, delete it after checking its consumers and generated/operational use. Preserve and report uncertain or out-of-scope cleanup; do not implement unrelated dormant code merely because it was discovered.

Existing Code Deletion Decision Flow

Required by the requested change? No → Preserve unless the change proves it obsolete
                               Yes → Working and compatible? Yes → Fix/extend
                                                             No → Repair or replace with migration/rollback evidence

版本历史

  • d439b50 当前 2026-07-31 02:50

    新增“价值优先工程”章节,明确以最低生命周期成本交付用户价值的指导原则;重构共享技能指南,细化设计收敛逻辑。

  • 56ab6c1 2026-07-19 22:41

    优化提示词执行引导,使技能指导更贴合具体项目上下文;细化反模式描述(如Prop drilling和大型组件),增强容错设计原则的完整性。

  • 66e3b29 2026-07-05 11:57

同 Skill 集合

dev-skills/skills/ai-development-guide/SKILL.md
dev-skills/skills/coding-principles/SKILL.md
dev-skills/skills/documentation-criteria/SKILL.md
dev-skills/skills/external-resource-context/SKILL.md
dev-skills/skills/frontend-ai-guide/SKILL.md
dev-skills/skills/implementation-approach/SKILL.md
dev-skills/skills/integration-e2e-testing/SKILL.md
dev-skills/skills/llm-friendly-context/SKILL.md
dev-skills/skills/test-implement/SKILL.md
dev-skills/skills/testing-principles/SKILL.md
dev-skills/skills/typescript-rules/SKILL.md
dev-workflows-frontend/skills/ai-development-guide/SKILL.md
dev-workflows-frontend/skills/coding-principles/SKILL.md
dev-workflows-frontend/skills/documentation-criteria/SKILL.md
dev-workflows-frontend/skills/external-resource-context/SKILL.md
dev-workflows-frontend/skills/implementation-approach/SKILL.md
dev-workflows-frontend/skills/integration-e2e-testing/SKILL.md
dev-workflows-frontend/skills/llm-friendly-context/SKILL.md
dev-workflows-frontend/skills/recipe-diagnose/SKILL.md
dev-workflows-frontend/skills/recipe-front-adjust/SKILL.md
dev-workflows-frontend/skills/recipe-front-build/SKILL.md
dev-workflows-frontend/skills/recipe-front-design/SKILL.md
dev-workflows-frontend/skills/recipe-front-plan/SKILL.md
dev-workflows-frontend/skills/recipe-front-review/SKILL.md
dev-workflows-frontend/skills/recipe-task/SKILL.md
dev-workflows-frontend/skills/recipe-update-doc/SKILL.md
dev-workflows-frontend/skills/subagents-orchestration-guide/SKILL.md
dev-workflows-frontend/skills/task-analyzer/SKILL.md
dev-workflows-frontend/skills/test-implement/SKILL.md
dev-workflows-frontend/skills/testing-principles/SKILL.md
dev-workflows-frontend/skills/typescript-rules/SKILL.md
dev-workflows-fullstack/skills/ai-development-guide/SKILL.md
dev-workflows-fullstack/skills/coding-principles/SKILL.md
dev-workflows-fullstack/skills/documentation-criteria/SKILL.md
dev-workflows-fullstack/skills/external-resource-context/SKILL.md
dev-workflows-fullstack/skills/frontend-ai-guide/SKILL.md
dev-workflows-fullstack/skills/implementation-approach/SKILL.md
dev-workflows-fullstack/skills/integration-e2e-testing/SKILL.md
dev-workflows-fullstack/skills/llm-friendly-context/SKILL.md
dev-workflows-fullstack/skills/recipe-add-integration-tests/SKILL.md
dev-workflows-fullstack/skills/recipe-build/SKILL.md
dev-workflows-fullstack/skills/recipe-design/SKILL.md
dev-workflows-fullstack/skills/recipe-diagnose/SKILL.md
dev-workflows-fullstack/skills/recipe-front-adjust/SKILL.md
dev-workflows-fullstack/skills/recipe-front-build/SKILL.md
dev-workflows-fullstack/skills/recipe-front-design/SKILL.md
dev-workflows-fullstack/skills/recipe-front-plan/SKILL.md
dev-workflows-fullstack/skills/recipe-front-review/SKILL.md
dev-workflows-fullstack/skills/recipe-fullstack-build/SKILL.md

元信息

文件数
0
版本
d439b50
Hash
83832364
收录时间
2026-07-05 11:57

首页 - Wiki
Copyright © 2011-2026 iteam. Current version is 2.155.2. UTC+08:00, 2026-08-01 01:41
浙ICP备14020137号-1 $访客地图$