Agent Skills
› trycompai/comp
› audit-hooks
audit-hooks
GitHub审计并修复代码中的 Hook 和 API 使用模式,消除过时的 server actions、raw fetch 等反模式。强制替换为 SWR 和自定义 Hook,确保数据获取与缓存失效合规,并通过类型检查验证修复结果。
Trigger Scenarios
需要审计前端 Hook 和 API 调用规范时
发现使用了 useAction、raw fetch 或 useEffect 进行数据获取时
需要批量重构客户端组件以符合 SWR 最佳实践时
Install
npx skills add trycompai/comp --skill audit-hooks -g -y
SKILL.md
Frontmatter
{
"name": "audit-hooks",
"description": "Audit & fix hooks and API usage patterns — eliminate server actions, raw fetch, and stale patterns"
}
Audit the specified files for hook and API usage compliance. Fix every issue found immediately.
Forbidden Patterns (fix immediately)
useActionfromnext-safe-action→ replace with SWR hook or custom mutation hook- Server actions mutating via
@db→ delete and use API hook instead - Direct
@dbin client components → replace withapiClientvia hook - Direct
@dbin Next.js pages for mutations → replace withserverApi - Raw
fetch()withoutcredentials: 'include'→ useapiClient window.location.reload()after mutations → use SWRmutate()router.refresh()after mutations → use SWRmutate()useEffect+apiClient.getfor data fetching → replace withuseSWR- Callback props for data refresh (
onXxxAdded,onSuccess) → remove, rely on SWR cache sharing
Required Patterns
- Client data fetching:
useSWRwithapiClientor custom hook - Client mutations: custom hooks wrapping
apiClientwithmutate()for cache invalidation - Server components:
serverApifromapps/app/src/lib/api-server.ts - SWR:
fallbackDatafor SSR data,revalidateOnMount: !initialData - API response: lists =
response.data.data, single =response.data mutate()safety: guard againstundefinedin optimistic update functionsArray.isArray()checks: when consuming SWR data that could be stale
Process
- Read files specified in
$ARGUMENTS - Find forbidden patterns and fix them
- Ensure all data fetching uses SWR hooks
- Run typecheck to verify:
bunx turbo run typecheck --filter=@trycompai/app
Version History
- 0ccfcc2 Current 2026-09-27 10:22


