ARTICLE · INTELLIGENCE

战地情报 · 详情页

来自尧图项目组的一线实战观察与深度解析

agents-generator - decision-matrix

agents-generator - decision-matrix

决策矩阵——项目检测与规则选择

检测顺序

按此顺序运行检测。每个步骤读取文件并设置后续步骤使用的标志。

1. 包管理器

检查锁文件:bun.lock→ bun,pnpm-lock.yaml→ pnpm,package-lock.json→ npm,yarn.lock→ yarn。

2. 项目类型

根package.json中的workspaces→ 单一代码库。否则 → 单一应用。

3. 框架

Dep foundFrameworkRouter detection
nextNext.jsapp/haspage.tsxorlayout.tsx→ App Router;pages/has.tsx→ Pages Router; both → hybrid (treat as App Router primary)
@nestjs/coreNestJSN/A
viteViteCheckreactfor React,vuefor Vue,sveltefor Svelte
@angular/coreAngularN/A
expressExpressN/A
fastifyFastifyN/A
remix/@remix-run/*RemixN/A
astroAstroN/A

4. 单仓库工具(如果是单仓库)

File foundTool
turbo.jsonTurborepo
nx.jsonNx
lerna.jsonLerna
pnpm-workspace.yamlonlypnpm workspaces (no orchestrator)

5. 语言

tsconfig.json存在 → TypeScript。检查compilerOptions.strict: true→ 严格模式。

6. CSS 方法

SignalApproach
tailwindcssin depsTailwind CSS
components.jsonexistsshadcn/ui (implies Tailwind)
styled-componentsin depsstyled-components
@emotion/*in depsEmotion
.module.cssor.module.scssfiles foundCSS Modules
sassornode-sassin depsSass/SCSS
None of the abovePlain CSS / CSS imports

7. 测试

Dep foundRunnerExtra
vitestVitestCheckvitest.config.*for env (node/jsdom/happy-dom)
jestJestCheckjest.config.*for env
playwrightor@playwright/testPlaywrightE2E tests present
cypressCypressE2E tests present
None—Skip testing rules

8. 验证

Dep foundLibrary
zodZod
yupYup
class-validatorclass-validator
valibotValibot
NonePlain TypeScript (type guards, manual validation)

9. ORM / 数据库

Dep foundORMDetect provider
prismaPrismaReadprisma/schema.prisma→datasource db { provider = "..." }
drizzle-ormDrizzleCheckdrizzle.config.*fordialect
knexKnexCheckknexfile.*for client
typeormTypeORMCheck config fortype
mongooseMongoDB/MongooseN/A

提供程序影响ID类型约定(PostgreSQL使用UUID,SQLite/MySQL使用自增,MongoDB使用ObjectId)。

10. 状态管理

Dep foundLibrary
zustandZustand
@reduxjs/toolkitRedux Toolkit
jotaiJotai
valtioValtio
recoilRecoil
mobxMobX
xstateXState
@tanstack/react-queryReact Query (server state)
swrSWR (server state)
NoneuseState / useReducer only

服务器状态库(React Query、SWR)需要与客户端状态(Zustand、Redux)不同的规则。

11. API 客户端模式

SignalPattern
@trpc/*in depstRPC
graphql+@apollo/clientGraphQL (Apollo)
graphql+relay-runtimeGraphQL (Relay)
@tanstack/react-query+fetchREST with React Query
swr+fetchREST with SWR
axiosin depsREST with Axios
Server action files ("use server") foundServer Actions
app/api/withroute.tsfilesNext.js API Routes
src/with NestJS controllersNestJS REST
None of the abovefetch() directly

12. 表单库

Dep foundLibrary
react-hook-formreact-hook-form
formikFormik
@tanstack/react-formTanStack Form
@hookform/resolversreact-hook-form + Zod/Yup resolver
NoneControlled/uncontrolled inputs manually

13. 认证库

Dep foundLibraryExtra detection
next-authNextAuth v5 (Auth.js)Check forauth.ts,middleware.tsroute protection
next-authv4NextAuth v4Check for[...nextauth].ts
@clerk/nextjsClerkCheck formiddleware.ts
lucia/lucia-authLuciaCheck forauth.ts
@supabase/supabase-js+@supabase/ssrSupabase AuthCheck for middleware
firebase+firebase/authFirebase AuthCheck forfirebase.tsconfig
@auth0/*Auth0Check forauth0.ts
NoneNo auth or custom—

14. 国际化库

Dep foundLibraryExtra detection
next-intlnext-intlChecki18n.ts,messages/, middleware config
react-i18next+i18nextreact-i18nextChecki18n.ts, locale JSON files
next-i18nextnext-i18nextChecknext-i18next.config.js
lingui/*LinguiChecklingui.config.*
NoneNo i18nChecklang=in<html>for language hint

15. 后端模式

SignalPattern
Files containing"use server"Server Actions
app/api/withroute.tsNext.js API Routes
NestJS controllersNestJS REST
Express/Fastify route filesREST API
tRPC routerstRPC API
GraphQL resolversGraphQL API

16. 代码检查与质量

File/Dep foundTool
eslintin depsESLint
eslint.config.*ESLint flat config
.eslintrc.*ESLint legacy config
prettierin depsPrettier
.prettierrc*Prettier configured
react-doctorin depsreact-doctor
doctor.config.*react-doctor configured
biome.jsonBiome
.oxlintrc.*oxlint

规则文件选择

将检测到的标志映射到规则文件以生成:

Rule FileRequired When
architecture.mdAlways
frontend-patterns.mdHas React/Next.js/Vite/Angular/Vue/Svelte frontend
backend-patterns.mdHas NestJS backend
server-actions.mdUses server actions OR has API routes OR has NestJS/Express/Fastify backend
styling.mdHas Tailwind, CSS Modules, or styled-components (not plain CSS)
forms.mdHas react-hook-form, formik, or TanStack Form
database.mdHas Prisma, Drizzle, Knex, TypeORM, or Mongoose
i18n.mdHas next-intl, react-i18next, or similar
testing.mdHas test runner (vitest/jest/playwright/cypress) in devDeps
git-workflow.mdAlways
sdd-workflow.mdAlways

AGENTS.md 部分选择

根据检测生成的 AGENTS.md 中包含的部分:

SectionInclude When
Monorepo Structureworkspacesin package.json
Monorepo Tool CommandsTurborepo/Nx/Lerna detected
Next.js Router ConventionNext.js detected → App Router vs Pages Router rules
Zod Validation Conventionzodoryuporvalibotin deps
Plain TS Validation ConventionNo validation library, but TypeScript strict
Prisma Conventionprismain deps
Drizzle Conventiondrizzle-ormin deps
Server Actions Convention"use server"files detected
tRPC ConventiontRPC detected
GraphQL ConventionGraphQL detected
Tailwind Conventiontailwindcssin deps
shadcn/ui Conventioncomponents.jsonexists
CSS Modules Convention.module.cssfiles found
Styled Components Conventionstyled-componentsin deps
State Management SectionZustand/Redux/Jotai/MobX/XState in deps
Server State SectionReact Query/SWR in deps
Form Library Sectionreact-hook-form/formik/TanStack Form in deps
i18n Sectioni18n library detected
Auth SectionAuth library detected
react-doctor Conventiondoctor.config.*orreact-doctorin deps
UI Language ConventionChecklang=attribute or i18n config

命令生成

从package.json的scripts生成命令表。直接映射scripts键:

{"scripts":{"dev":"...","build":"...","lint":"...","test":"..."}}

变为:

ComandoQué hace
{pm} devServidor de desarrollo
{pm} run buildBuild de producción
{pm} run lintLinting
{pm} run testTests (watch)

为以下内容添加额外行:test:run(单次运行)、test:coverage、doctor、format、typecheck。

其中{pm}= 对于 bun(不带run的脚本)为bun,pnpm 为pnpm,npm 为npm run,yarn 为yarn。

Monorepo 命令生成

如果使用 Turborepo 的 monorepo:生成turbo run {cmd}变体。
如果使用 pnpm 的 monorepo:生成pnpm --filter {pkg} {cmd}示例。
如果使用 Nx 的单仓库:生成nx {cmd} {pkg}变体。

验证周期

从检测到的工具组装:

{typecheck} → {lint} → {test} → {doctor}
  • {typecheck}:如果是 TypeScript,则使用tsc --noEmit,如果是 bun,则使用bunx tsc --noEmit,如果没有 TS 则跳过。
  • {lint}:{pm} run lint或检测到的 lint 命令。
  • {test}:{pm} run test:run或{pm} run test(取单次运行的那个)。
  • {doctor}:{pm} doctor或{pm}x react-doctor@latest如果检测到 react-doctor。如果没有检测到则跳过。

单仓库重建说明

如果是带共享包的单一代码库:添加关于在循环之前重建包的说明:

Si se modificaron packages compartidos ({shared_pkg_list}), ejecutar su rebuild primero: {rebuild_commands}

特定框架的约定

Next.js 应用路由器

  • 默认使用服务器组件。只有在使用钩子时才使用"use client"。
  • 服务器操作在lib/actions.ts或src/actions/。
  • error.tsx、loading.tsx、not-found.tsx按段落。
  • generateMetadata()用于 SEO。
  • next/image用于图片,next/font用于字体。
  • 路径别名@/*→./*或./src/*。

Next.js 页面路由器

  • getServerSideProps、getStaticProps、getStaticPaths。
  • pages/api/用于 API 路由。
  • pages/_app.tsx,pages/_document.tsx。
  • 没有服务器组件。所有都是客户端或 API。

NestJS

  • 模块像目录:src/{feature}/{feature}.module.ts。
  • 带装饰器的 DTO。使用class-validator或ZodValidationPipe进行验证。
  • 守卫用于身份验证:@UseGuards(AuthGuard)。
  • PrismaService作为全局提供者。

边缘情况

SituationAction
No test runnerSkip testing.md, skip test from verification cycle
No lint toolSkip lint from verification cycle
No TypeScriptSkiptsc --noEmit, skip no-any rule, use JSDoc conventions instead
No config files at allMinimal defaults, note that project needs setup
Multiple frameworksPick primary based on root package.json, note secondary
Both App Router and Pages RouterTreat as App Router primary, note Pages Router legacy routes
No package.json scriptsGenerate commands from direct tool invocations (npx next dev)
Bun withoutbun runscriptsUsebunxprefix for npx equivalents
Monorepo without workspacesTreat eachapps/*orpackages/*as independent
CSS: multiple approachesPick primary (Tailwind wins over CSS Modules over plain CSS)
Auth: multiple librariesPick primary, note secondary (e.g., NextAuth for web, Clerk for admin)
i18n with Pages RouterDifferent routing rules than App Router i18n
Database with multiple providersDocument each, note which is primary
RELATED READING

延伸阅读

更多一线实战笔记与深度复盘,助您持续精进