@michaelxwb/code-flow 0.8.1 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +73 -152
- package/bin/code-flow.js +12 -0
- package/docs/README.md +19 -0
- package/docs/USAGE.md +156 -1417
- package/docs/v1-design.md +1858 -0
- package/docs/v1-implementation.md +186 -0
- package/lib/adapters.js +126 -0
- package/lib/cli.js +258 -0
- package/lib/config.js +85 -0
- package/lib/doctor.js +283 -0
- package/lib/frontmatter.js +42 -0
- package/lib/fs.js +141 -0
- package/lib/glob.js +23 -0
- package/lib/hook.js +99 -0
- package/lib/init.js +132 -0
- package/lib/learn.js +170 -0
- package/lib/locks.js +52 -0
- package/lib/markdown.js +13 -0
- package/lib/process.js +116 -0
- package/lib/render.js +115 -0
- package/lib/repo.js +48 -0
- package/lib/runs.js +155 -0
- package/lib/session.js +40 -0
- package/lib/spec.js +80 -0
- package/lib/task.js +258 -0
- package/lib/taskdoc.js +308 -0
- package/lib/toml.js +140 -0
- package/lib/verify.js +168 -0
- package/lib/worktree.js +930 -0
- package/package.json +18 -21
- package/templates/adapters/opencode.mjs +65 -0
- package/templates/config.json +39 -0
- package/templates/instructions.md +13 -0
- package/templates/launcher/bridge.cjs +295 -0
- package/templates/launcher/hook.cmd +15 -0
- package/templates/launcher/hook.ps1 +10 -0
- package/templates/launcher/hook.sh +20 -0
- package/templates/skills/cf-check.md +19 -0
- package/templates/skills/cf-init.md +16 -0
- package/templates/skills/cf-spec.md +20 -0
- package/templates/skills/cf-task-align.md +19 -0
- package/templates/skills/cf-task-archive.md +20 -0
- package/templates/skills/cf-task-plan.md +31 -0
- package/templates/skills/cf-task-prd.md +14 -0
- package/templates/skills/cf-task-start.md +41 -0
- package/{src/core/code-flow/specs/shared/design → templates/workflow}/design-frontend.md +12 -12
- package/{src/core/code-flow/specs/shared/design → templates/workflow}/design-full.md +17 -19
- package/{src/core/code-flow/specs/shared/design → templates/workflow}/design-lite.md +12 -12
- package/{src/core/code-flow/specs/shared/prd-template.md → templates/workflow/prd.md} +1 -1
- package/templates/workflow/project-guidelines.md +48 -0
- package/templates/workflow/scenarios.md +67 -0
- package/templates/workflow/task.md +56 -0
- package/docs/acceptance-contract.md +0 -217
- package/docs/ci/acceptance-evidence.md +0 -77
- package/docs/migrations/runtime-0.7.0.md +0 -41
- package/docs/migrations/runtime-0.8.0.md +0 -154
- package/docs/migrations/runtime-0.9.0.md +0 -40
- package/docs/migrations/spec-workflow-0.6.0.md +0 -42
- package/docs/spec-injection-hardening.md +0 -54
- package/docs/spec-injection-performance.json +0 -73
- package/docs/spec-optimization.md +0 -12
- package/src/adapters/claude/CLAUDE.md +0 -45
- package/src/adapters/claude/commands/cf-init.md +0 -262
- package/src/adapters/claude/commands/cf-learn.md +0 -291
- package/src/adapters/claude/commands/cf-spec.md +0 -87
- package/src/adapters/claude/commands/cf-stats.md +0 -96
- package/src/adapters/claude/commands/cf-sync.md +0 -39
- package/src/adapters/claude/commands/cf-task/align.md +0 -331
- package/src/adapters/claude/commands/cf-task/archive.md +0 -155
- package/src/adapters/claude/commands/cf-task/block.md +0 -49
- package/src/adapters/claude/commands/cf-task/graph.md +0 -92
- package/src/adapters/claude/commands/cf-task/note.md +0 -248
- package/src/adapters/claude/commands/cf-task/plan.md +0 -477
- package/src/adapters/claude/commands/cf-task/prd.md +0 -173
- package/src/adapters/claude/commands/cf-task/start.md +0 -317
- package/src/adapters/claude/commands/cf-task/status.md +0 -71
- package/src/adapters/claude/commands/cf-task/verify-e2e.md +0 -148
- package/src/adapters/claude/commands/cf-validate.md +0 -100
- package/src/adapters/claude/settings.local.json +0 -50
- package/src/adapters/codex/AGENTS.md +0 -45
- package/src/adapters/codex/config.toml +0 -3
- package/src/adapters/codex/hooks.json +0 -54
- package/src/adapters/codex/skills/cf-init/SKILL.md +0 -273
- package/src/adapters/codex/skills/cf-learn/SKILL.md +0 -296
- package/src/adapters/codex/skills/cf-spec/SKILL.md +0 -88
- package/src/adapters/codex/skills/cf-stats/SKILL.md +0 -97
- package/src/adapters/codex/skills/cf-sync/SKILL.md +0 -45
- package/src/adapters/codex/skills/cf-task-align/SKILL.md +0 -332
- package/src/adapters/codex/skills/cf-task-archive/SKILL.md +0 -156
- package/src/adapters/codex/skills/cf-task-block/SKILL.md +0 -50
- package/src/adapters/codex/skills/cf-task-graph/SKILL.md +0 -93
- package/src/adapters/codex/skills/cf-task-note/SKILL.md +0 -245
- package/src/adapters/codex/skills/cf-task-plan/SKILL.md +0 -478
- package/src/adapters/codex/skills/cf-task-prd/SKILL.md +0 -174
- package/src/adapters/codex/skills/cf-task-start/SKILL.md +0 -318
- package/src/adapters/codex/skills/cf-task-status/SKILL.md +0 -72
- package/src/adapters/codex/skills/cf-task-verify-e2e/SKILL.md +0 -145
- package/src/adapters/codex/skills/cf-validate/SKILL.md +0 -102
- package/src/adapters/commands.json +0 -115
- package/src/adapters/costrict/CLAUDE.md +0 -45
- package/src/adapters/costrict/commands/cf-init.md +0 -262
- package/src/adapters/costrict/commands/cf-learn.md +0 -291
- package/src/adapters/costrict/commands/cf-spec.md +0 -87
- package/src/adapters/costrict/commands/cf-stats.md +0 -96
- package/src/adapters/costrict/commands/cf-sync.md +0 -39
- package/src/adapters/costrict/commands/cf-task/align.md +0 -331
- package/src/adapters/costrict/commands/cf-task/archive.md +0 -155
- package/src/adapters/costrict/commands/cf-task/block.md +0 -49
- package/src/adapters/costrict/commands/cf-task/graph.md +0 -92
- package/src/adapters/costrict/commands/cf-task/note.md +0 -248
- package/src/adapters/costrict/commands/cf-task/plan.md +0 -477
- package/src/adapters/costrict/commands/cf-task/prd.md +0 -173
- package/src/adapters/costrict/commands/cf-task/start.md +0 -317
- package/src/adapters/costrict/commands/cf-task/status.md +0 -71
- package/src/adapters/costrict/commands/cf-task/verify-e2e.md +0 -148
- package/src/adapters/costrict/commands/cf-validate.md +0 -100
- package/src/adapters/costrict/settings.local.json +0 -50
- package/src/adapters/install-plan.json +0 -100
- package/src/adapters/opencode/AGENTS.md +0 -45
- package/src/adapters/opencode/commands/cf-init.md +0 -281
- package/src/adapters/opencode/commands/cf-learn.md +0 -295
- package/src/adapters/opencode/commands/cf-spec.md +0 -91
- package/src/adapters/opencode/commands/cf-stats.md +0 -100
- package/src/adapters/opencode/commands/cf-sync.md +0 -44
- package/src/adapters/opencode/commands/cf-task/align.md +0 -331
- package/src/adapters/opencode/commands/cf-task/archive.md +0 -160
- package/src/adapters/opencode/commands/cf-task/block.md +0 -54
- package/src/adapters/opencode/commands/cf-task/graph.md +0 -97
- package/src/adapters/opencode/commands/cf-task/note.md +0 -253
- package/src/adapters/opencode/commands/cf-task/plan.md +0 -477
- package/src/adapters/opencode/commands/cf-task/prd.md +0 -178
- package/src/adapters/opencode/commands/cf-task/start.md +0 -317
- package/src/adapters/opencode/commands/cf-task/status.md +0 -76
- package/src/adapters/opencode/commands/cf-task/verify-e2e.md +0 -148
- package/src/adapters/opencode/commands/cf-validate.md +0 -105
- package/src/adapters/opencode/opencode.json +0 -3
- package/src/adapters/opencode/plugins/code-flow/index.js +0 -162
- package/src/adapters/opencode/plugins/code-flow/package.json +0 -6
- package/src/adapters/platform-bindings.json +0 -370
- package/src/cli.js +0 -1076
- package/src/core/code-flow/config.yml +0 -161
- package/src/core/code-flow/runtime-commands.json +0 -259
- package/src/core/code-flow/scripts/cf_acceptance_manifest.py +0 -10
- package/src/core/code-flow/scripts/cf_acceptance_runner.py +0 -10
- package/src/core/code-flow/scripts/cf_audit.py +0 -10
- package/src/core/code-flow/scripts/cf_codex_hook.py +0 -10
- package/src/core/code-flow/scripts/cf_design_lint.py +0 -10
- package/src/core/code-flow/scripts/cf_evidence_import.py +0 -10
- package/src/core/code-flow/scripts/cf_feedback.py +0 -10
- package/src/core/code-flow/scripts/cf_opencode_event.py +0 -10
- package/src/core/code-flow/scripts/cf_post_hook.py +0 -11
- package/src/core/code-flow/scripts/cf_pre_tool_hook.py +0 -11
- package/src/core/code-flow/scripts/cf_scenarios.py +0 -10
- package/src/core/code-flow/scripts/cf_spec_context.py +0 -10
- package/src/core/code-flow/scripts/cf_spec_gate.py +0 -10
- package/src/core/code-flow/scripts/cf_spec_session.py +0 -10
- package/src/core/code-flow/scripts/cf_stats.py +0 -10
- package/src/core/code-flow/scripts/cf_stop_hook.py +0 -11
- package/src/core/code-flow/scripts/cf_sync.py +0 -10
- package/src/core/code-flow/scripts/cf_task_index.py +0 -10
- package/src/core/code-flow/scripts/cf_task_parallel.py +0 -10
- package/src/core/code-flow/scripts/cf_task_workflow.py +0 -10
- package/src/core/code-flow/scripts/cf_user_prompt_hook.py +0 -11
- package/src/core/code-flow/scripts/cf_validation.py +0 -10
- package/src/core/code-flow/scripts/codeflow/__init__.py +0 -0
- package/src/core/code-flow/scripts/codeflow/acceptance/__init__.py +0 -0
- package/src/core/code-flow/scripts/codeflow/acceptance/cf_acceptance_evidence.py +0 -347
- package/src/core/code-flow/scripts/codeflow/acceptance/cf_acceptance_manifest_core.py +0 -660
- package/src/core/code-flow/scripts/codeflow/acceptance/cf_acceptance_plan.py +0 -202
- package/src/core/code-flow/scripts/codeflow/acceptance/cf_acceptance_registration.py +0 -60
- package/src/core/code-flow/scripts/codeflow/acceptance/cf_acceptance_risk.py +0 -73
- package/src/core/code-flow/scripts/codeflow/acceptance/cf_acceptance_schema.py +0 -282
- package/src/core/code-flow/scripts/codeflow/acceptance/cf_acceptance_selection.py +0 -266
- package/src/core/code-flow/scripts/codeflow/acceptance/cf_check_inputs.py +0 -172
- package/src/core/code-flow/scripts/codeflow/acceptance/cf_check_registration.py +0 -326
- package/src/core/code-flow/scripts/codeflow/acceptance/cf_checks.py +0 -333
- package/src/core/code-flow/scripts/codeflow/acceptance/cf_plan_quality.py +0 -197
- package/src/core/code-flow/scripts/codeflow/acceptance/cf_scenario_quality.py +0 -174
- package/src/core/code-flow/scripts/codeflow/acceptance/cf_scenario_source.py +0 -300
- package/src/core/code-flow/scripts/codeflow/acceptance/cf_traceability.py +0 -502
- package/src/core/code-flow/scripts/codeflow/cli/__init__.py +0 -0
- package/src/core/code-flow/scripts/codeflow/cli/cf_acceptance_manifest.py +0 -347
- package/src/core/code-flow/scripts/codeflow/cli/cf_acceptance_runner.py +0 -1490
- package/src/core/code-flow/scripts/codeflow/cli/cf_audit.py +0 -533
- package/src/core/code-flow/scripts/codeflow/cli/cf_design_lint.py +0 -172
- package/src/core/code-flow/scripts/codeflow/cli/cf_evidence_import.py +0 -607
- package/src/core/code-flow/scripts/codeflow/cli/cf_feedback.py +0 -53
- package/src/core/code-flow/scripts/codeflow/cli/cf_scenarios.py +0 -58
- package/src/core/code-flow/scripts/codeflow/cli/cf_spec_context.py +0 -1175
- package/src/core/code-flow/scripts/codeflow/cli/cf_spec_gate.py +0 -60
- package/src/core/code-flow/scripts/codeflow/cli/cf_spec_session.py +0 -46
- package/src/core/code-flow/scripts/codeflow/cli/cf_stats.py +0 -540
- package/src/core/code-flow/scripts/codeflow/cli/cf_sync.py +0 -144
- package/src/core/code-flow/scripts/codeflow/cli/cf_task_index.py +0 -177
- package/src/core/code-flow/scripts/codeflow/cli/cf_task_parallel.py +0 -1142
- package/src/core/code-flow/scripts/codeflow/cli/cf_task_workflow.py +0 -742
- package/src/core/code-flow/scripts/codeflow/cli/cf_validation.py +0 -31
- package/src/core/code-flow/scripts/codeflow/core/__init__.py +0 -0
- package/src/core/code-flow/scripts/codeflow/core/cf_context_cache.py +0 -67
- package/src/core/code-flow/scripts/codeflow/core/cf_core.py +0 -609
- package/src/core/code-flow/scripts/codeflow/core/cf_exec_base.py +0 -325
- package/src/core/code-flow/scripts/codeflow/core/cf_fs.py +0 -57
- package/src/core/code-flow/scripts/codeflow/core/cf_git.py +0 -92
- package/src/core/code-flow/scripts/codeflow/core/cf_log.py +0 -160
- package/src/core/code-flow/scripts/codeflow/core/cf_markdown.py +0 -77
- package/src/core/code-flow/scripts/codeflow/core/cf_native_paths.py +0 -26
- package/src/core/code-flow/scripts/codeflow/core/cf_patch.py +0 -33
- package/src/core/code-flow/scripts/codeflow/core/cf_runtime_install.py +0 -32
- package/src/core/code-flow/scripts/codeflow/core/cf_session_state.py +0 -37
- package/src/core/code-flow/scripts/codeflow/core/cf_stop_guard.py +0 -53
- package/src/core/code-flow/scripts/codeflow/core/cf_task_state.py +0 -9
- package/src/core/code-flow/scripts/codeflow/core/cf_validators.py +0 -408
- package/src/core/code-flow/scripts/codeflow/core/cf_worktree_env.py +0 -253
- package/src/core/code-flow/scripts/codeflow/evidence/__init__.py +0 -0
- package/src/core/code-flow/scripts/codeflow/evidence/cf_evidence_store.py +0 -527
- package/src/core/code-flow/scripts/codeflow/hooks/__init__.py +0 -0
- package/src/core/code-flow/scripts/codeflow/hooks/cf_codex_hook.py +0 -95
- package/src/core/code-flow/scripts/codeflow/hooks/cf_opencode_event.py +0 -98
- package/src/core/code-flow/scripts/codeflow/hooks/cf_post_hook.py +0 -30
- package/src/core/code-flow/scripts/codeflow/hooks/cf_pre_tool_hook.py +0 -41
- package/src/core/code-flow/scripts/codeflow/hooks/cf_stop_hook.py +0 -292
- package/src/core/code-flow/scripts/codeflow/hooks/cf_user_prompt_hook.py +0 -161
- package/src/core/code-flow/scripts/codeflow/spec/__init__.py +0 -0
- package/src/core/code-flow/scripts/codeflow/spec/cf_active_task.py +0 -412
- package/src/core/code-flow/scripts/codeflow/spec/cf_context_refresh.py +0 -301
- package/src/core/code-flow/scripts/codeflow/spec/cf_edit_service.py +0 -149
- package/src/core/code-flow/scripts/codeflow/spec/cf_injection.py +0 -111
- package/src/core/code-flow/scripts/codeflow/spec/cf_rule_readiness.py +0 -114
- package/src/core/code-flow/scripts/codeflow/spec/cf_scan.py +0 -367
- package/src/core/code-flow/scripts/codeflow/spec/cf_spec_budget.py +0 -55
- package/src/core/code-flow/scripts/codeflow/spec/cf_spec_context_model.py +0 -477
- package/src/core/code-flow/scripts/codeflow/spec/cf_spec_impact.py +0 -119
- package/src/core/code-flow/scripts/codeflow/spec/cf_spec_metadata.py +0 -387
- package/src/core/code-flow/scripts/codeflow/spec/cf_spec_migrate.py +0 -529
- package/src/core/code-flow/scripts/codeflow/spec/cf_spec_optimize.py +0 -193
- package/src/core/code-flow/scripts/codeflow/spec/cf_spec_optimize_apply.py +0 -187
- package/src/core/code-flow/scripts/codeflow/spec/cf_spec_resolver.py +0 -369
- package/src/core/code-flow/scripts/codeflow/spec/cf_spec_router.py +0 -304
- package/src/core/code-flow/scripts/codeflow/spec/cf_spec_verify.py +0 -687
- package/src/core/code-flow/scripts/codeflow/spec/cf_stage_gate.py +0 -330
- package/src/core/code-flow/scripts/codeflow/spec/cf_task_projection.py +0 -83
- package/src/core/code-flow/scripts/codeflow/spec/cf_workflow_service.py +0 -755
- package/src/core/code-flow/scripts/codeflow/spec/cf_workflow_transaction.py +0 -110
- package/src/core/code-flow/scripts/codeflow/task/__init__.py +0 -0
- package/src/core/code-flow/scripts/codeflow/task/cf_requirement_verification.py +0 -867
- package/src/core/code-flow/scripts/codeflow/task/cf_task_doc.py +0 -178
- package/src/core/code-flow/scripts/codeflow/task/cf_task_merge.py +0 -635
- package/src/core/code-flow/scripts/codeflow/task/cf_task_plan.py +0 -251
- package/src/core/code-flow/scripts/codeflow/task/cf_task_runtime.py +0 -570
- package/src/core/code-flow/scripts/codeflow/task/cf_validation_service.py +0 -73
- package/src/core/code-flow/scripts/runtime-resources.json +0 -29
- package/src/core/code-flow/specs/backend/_map.md +0 -56
- package/src/core/code-flow/specs/backend/code-quality-performance.md +0 -59
- package/src/core/code-flow/specs/backend/database.md +0 -51
- package/src/core/code-flow/specs/backend/directory-structure.md +0 -54
- package/src/core/code-flow/specs/backend/logging.md +0 -50
- package/src/core/code-flow/specs/backend/platform-rules.md +0 -55
- package/src/core/code-flow/specs/frontend/_map.md +0 -52
- package/src/core/code-flow/specs/frontend/component-specs.md +0 -68
- package/src/core/code-flow/specs/frontend/directory-structure.md +0 -53
- package/src/core/code-flow/specs/frontend/quality-standards.md +0 -58
- package/src/core/code-flow/specs/shared/_map.md +0 -57
- package/src/core/code-flow/specs/shared/scenarios-template.md +0 -55
- package/src/core/code-flow/tasks/.gitkeep +0 -0
- package/src/core/code-flow/validation.yml +0 -59
- package/src/migrate/runtime.js +0 -213
- package/src/migrate/spec-workflow.js +0 -253
- package/src/runtime.js +0 -219
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
# Backend Retrieval Map
|
|
2
|
-
|
|
3
|
-
> AI 导航地图:定位后端代码结构和关键模块。可由 `/cf-learn --map` 重生成,建议按真实项目手动校准。
|
|
4
|
-
|
|
5
|
-
## Purpose
|
|
6
|
-
|
|
7
|
-
后端服务,负责 API 暴露、业务逻辑与数据持久化。默认假设为分层架构(API → Service → Model)。
|
|
8
|
-
|
|
9
|
-
## Architecture
|
|
10
|
-
|
|
11
|
-
- Framework: 任意 Web 框架(FastAPI / Express / Spring / Gin 等)
|
|
12
|
-
- ORM/Driver: 与数据库匹配的官方/主流驱动
|
|
13
|
-
- Database: 关系型为主(PostgreSQL / MySQL),可叠加缓存(Redis)
|
|
14
|
-
- Auth: Token-based(JWT / OAuth2 / Session)
|
|
15
|
-
- Async: 必要时引入消息队列或后台任务(Celery / Bull / BullMQ)
|
|
16
|
-
|
|
17
|
-
## Key Files
|
|
18
|
-
|
|
19
|
-
| File | Purpose |
|
|
20
|
-
|------|---------|
|
|
21
|
-
| `src/main.*` | 应用入口,初始化框架、路由、中间件 |
|
|
22
|
-
| `src/api/router.*` | 路由注册,统一前缀与版本 |
|
|
23
|
-
| `src/services/` | 业务逻辑实现,禁止跨层调用 ORM |
|
|
24
|
-
| `src/models/` | 数据模型定义(ORM / Schema) |
|
|
25
|
-
| `src/crud/`(或 `repositories/`) | 数据访问层,业务只依赖此抽象 |
|
|
26
|
-
| `src/config/` | 配置加载,环境变量优先 |
|
|
27
|
-
|
|
28
|
-
## Module Map
|
|
29
|
-
|
|
30
|
-
```
|
|
31
|
-
src/
|
|
32
|
-
├── api/ # 接口层:路由 + 请求/响应 schema 校验
|
|
33
|
-
├── services/ # 业务逻辑层:纯函数为主,便于测试
|
|
34
|
-
├── models/ # 数据模型(ORM 或 ODM)
|
|
35
|
-
├── crud/ # 数据访问层(repositories),业务只调 CRUD 不碰 ORM
|
|
36
|
-
├── migrations/ # DB 迁移脚本(可回滚或幂等)
|
|
37
|
-
├── errors/ # 错误码→message 常量,按业务模块拆分
|
|
38
|
-
├── schemas/ # DTO / 请求响应类型
|
|
39
|
-
├── middleware/ # 认证、日志、限流、CORS
|
|
40
|
-
├── utils/ # 工具函数,无业务依赖
|
|
41
|
-
└── config/ # 配置与环境变量
|
|
42
|
-
```
|
|
43
|
-
|
|
44
|
-
## Data Flow
|
|
45
|
-
|
|
46
|
-
```
|
|
47
|
-
Request → Middleware(auth/log) → Router → Handler(API)
|
|
48
|
-
→ Service(业务) → Model(DB/Cache) → Response
|
|
49
|
-
```
|
|
50
|
-
|
|
51
|
-
## Navigation Guide
|
|
52
|
-
|
|
53
|
-
- 新增 API → `api/` 加路由 + `schemas/` 定义请求响应 + `services/` 实现业务
|
|
54
|
-
- 新增表 → `models/` 定义模型 + `migrations/` 加迁移脚本
|
|
55
|
-
- 错误处理 → 抛业务异常类,由中间件统一转 HTTP 响应
|
|
56
|
-
- 配置项 → `config/` 集中管理,禁止散落 `os.environ`/`process.env`
|
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
id: backend-code-quality-performance
|
|
3
|
-
description: 写后端代码时适用:错误处理、测试、超时重试、缓存等质量与性能约束
|
|
4
|
-
stages: [design, plan, code, review]
|
|
5
|
-
enforcement: required
|
|
6
|
-
verifiers:
|
|
7
|
-
- rule: RULE-backend-quality-001
|
|
8
|
-
type: manual
|
|
9
|
-
config:
|
|
10
|
-
checklist: Confirm all Guidance and Avoid items for this Spec.
|
|
11
|
-
owner: project-owner
|
|
12
|
-
---
|
|
13
|
-
|
|
14
|
-
# Backend Code Quality & Performance
|
|
15
|
-
|
|
16
|
-
## Examples
|
|
17
|
-
|
|
18
|
-
> ✅/❌ 对照示例对 AI 的引导远强于规则条文——新写规范优先用这个格式(cf-learn 候选会自动生成草稿)。
|
|
19
|
-
|
|
20
|
-
✅ 显式错误处理
|
|
21
|
-
|
|
22
|
-
```python
|
|
23
|
-
try:
|
|
24
|
-
result = service.call()
|
|
25
|
-
except ServiceError as exc:
|
|
26
|
-
logger.warning("call failed: %s", exc)
|
|
27
|
-
raise
|
|
28
|
-
```
|
|
29
|
-
|
|
30
|
-
❌ 静默吞异常
|
|
31
|
-
|
|
32
|
-
```python
|
|
33
|
-
try:
|
|
34
|
-
result = service.call()
|
|
35
|
-
except Exception:
|
|
36
|
-
pass
|
|
37
|
-
```
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
## Rules
|
|
41
|
-
- [RULE-backend-quality-001] The implementation must satisfy every applicable item in Guidance and avoid every item in Avoid.
|
|
42
|
-
|
|
43
|
-
## Guidance
|
|
44
|
-
- 所有公开函数 / 方法必须有类型注解(type hints / 类型签名)
|
|
45
|
-
- 异常必须显式处理或显式上抛,禁止 `except Exception: pass` / `catch (e) {}` 静默吞掉
|
|
46
|
-
- 外部依赖调用(HTTP / RPC / DB)必须设置超时,关键调用补重试 + 指数退避
|
|
47
|
-
- 单元测试覆盖核心业务路径:happy path + 边界 + 错误分支,每个需求 ≥ 1 个用例
|
|
48
|
-
|
|
49
|
-
## Patterns
|
|
50
|
-
- 缓存可计算结果以减少重复 IO,明确缓存 key、TTL 与失效策略
|
|
51
|
-
- 重 IO 用异步或批处理,CPU 密集任务下沉到 worker / 队列
|
|
52
|
-
- 资源(连接、文件、锁)使用 `with` / `using` / `defer` 确保释放
|
|
53
|
-
- 性能敏感路径加监控指标(QPS / P95 延迟 / 错误率)
|
|
54
|
-
|
|
55
|
-
## Avoid
|
|
56
|
-
- 禁止在请求链路中吞掉异常导致客户端拿到错误结果却无日志
|
|
57
|
-
- 禁止无超时的外部调用(容易导致线程 / 协程泄漏)
|
|
58
|
-
- 禁止用循环模拟批量操作(DB 批量 / 网络批量必须用原生批量 API)
|
|
59
|
-
- 禁止把缓存失败当致命错误,缓存层必须可降级为直接查询
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
id: backend-database
|
|
3
|
-
description: 涉及数据库/ORM/迁移/查询时适用:schema 与数据访问约束
|
|
4
|
-
stages: [design, plan, code, review]
|
|
5
|
-
enforcement: required
|
|
6
|
-
verifiers:
|
|
7
|
-
- rule: RULE-backend-database-001
|
|
8
|
-
type: manual
|
|
9
|
-
config:
|
|
10
|
-
checklist: Confirm all Guidance and Avoid items for this Spec.
|
|
11
|
-
owner: project-owner
|
|
12
|
-
---
|
|
13
|
-
|
|
14
|
-
# Backend Database
|
|
15
|
-
|
|
16
|
-
## Examples
|
|
17
|
-
|
|
18
|
-
✅ 参数化查询,明确列出字段
|
|
19
|
-
|
|
20
|
-
```python
|
|
21
|
-
cur.execute("SELECT id, name FROM users WHERE email = %s", (email,))
|
|
22
|
-
```
|
|
23
|
-
|
|
24
|
-
❌ 字符串拼接用户输入(SQL 注入)+ `SELECT *`
|
|
25
|
-
|
|
26
|
-
```python
|
|
27
|
-
cur.execute(f"SELECT * FROM users WHERE email = '{email}'")
|
|
28
|
-
```
|
|
29
|
-
|
|
30
|
-
## Rules
|
|
31
|
-
- [RULE-backend-database-001] The implementation must satisfy every applicable item in Guidance and avoid every item in Avoid.
|
|
32
|
-
|
|
33
|
-
## Guidance
|
|
34
|
-
- 所有 SQL 必须参数化,禁止字符串拼接 / 模板插值用户输入
|
|
35
|
-
- 迁移脚本必须可回滚,或写成幂等脚本(`IF NOT EXISTS` / `ON CONFLICT`)
|
|
36
|
-
- 事务边界明确:跨表写入必须在同一事务内,禁止"半提交"状态
|
|
37
|
-
- 涉及索引/锁的 schema 变更必须评估线上影响,大表慎用 `ALTER TABLE` 阻塞操作
|
|
38
|
-
- 每个 model 必须有对应 CRUD 抽象层(`crud/<model>.py` 或 `repositories/<Model>Repo`),业务代码只调 CRUD,禁止在 service / handler 直接写 ORM 查询或裸 SQL
|
|
39
|
-
|
|
40
|
-
## Patterns
|
|
41
|
-
- 读写分离场景显式标注读库/写库,强一致读走主库
|
|
42
|
-
- N+1 查询用预加载(`joinedload` / `include` / `Preload`)解决
|
|
43
|
-
- 大批量写入分批 + commit,避免单事务过大
|
|
44
|
-
- 缓存与数据库一致性:先写库再失效缓存(`cache-aside`)
|
|
45
|
-
- CRUD 基类统一实现 `get / list / create / update / delete / bulk_*`,子类只扩展模型特有查询
|
|
46
|
-
|
|
47
|
-
## Avoid
|
|
48
|
-
- 禁止在事务内发起外部 HTTP / RPC 调用,超时会导致连接池耗尽
|
|
49
|
-
- 禁止在循环中执行单条 `INSERT` / `UPDATE`,必须批量化
|
|
50
|
-
- 禁止在 ORM 之外手写 SQL 时绕过参数绑定
|
|
51
|
-
- 禁止用 `SELECT *` 上线,明确列出字段控制传输与索引
|
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
id: backend-directory-structure
|
|
3
|
-
description: 新建/移动后端文件时适用:目录结构与模块组织约束
|
|
4
|
-
stages: [design, plan, code, review]
|
|
5
|
-
enforcement: required
|
|
6
|
-
verifiers:
|
|
7
|
-
- rule: RULE-backend-directory-001
|
|
8
|
-
type: manual
|
|
9
|
-
config:
|
|
10
|
-
checklist: Confirm all Guidance and Avoid items for this Spec.
|
|
11
|
-
owner: project-owner
|
|
12
|
-
---
|
|
13
|
-
|
|
14
|
-
# Backend Directory Structure
|
|
15
|
-
|
|
16
|
-
## Examples
|
|
17
|
-
|
|
18
|
-
✅ 魔法值集中到 `constants/`,命名引用
|
|
19
|
-
|
|
20
|
-
```python
|
|
21
|
-
# constants/order.py
|
|
22
|
-
ORDER_PAID = 1
|
|
23
|
-
# service:if order.status == ORDER_PAID: ...
|
|
24
|
-
```
|
|
25
|
-
|
|
26
|
-
❌ 业务代码散落硬编码字面量
|
|
27
|
-
|
|
28
|
-
```python
|
|
29
|
-
if order.status == 1 and role == "admin": # 魔法数字 / 魔法字符串
|
|
30
|
-
...
|
|
31
|
-
```
|
|
32
|
-
|
|
33
|
-
## Rules
|
|
34
|
-
- [RULE-backend-directory-001] The implementation must satisfy every applicable item in Guidance and avoid every item in Avoid.
|
|
35
|
-
|
|
36
|
-
## Guidance
|
|
37
|
-
- 接口层放 `api/`,业务逻辑放 `services/`,数据模型放 `models/`,禁止跨层倒置依赖
|
|
38
|
-
- 入口文件(`main.*`)只做框架装配,不写业务代码
|
|
39
|
-
- 配置统一放 `config/`,禁止在业务代码中直接读 `os.environ` / `process.env`
|
|
40
|
-
- 常量集中放 `constants/`,按业务模块拆分(`constants/order.py`、`constants/user.py`),禁止在业务代码中散落硬编码字面量(魔法数字 / 字符串 / 状态码)
|
|
41
|
-
- 数据访问层独立放 `crud/` 或 `repositories/`,业务层依赖 CRUD 抽象,不直接依赖 ORM
|
|
42
|
-
- 新增一级目录必须同步更新导航地图与 `__init__` / `index` 索引
|
|
43
|
-
|
|
44
|
-
## Patterns
|
|
45
|
-
- 模块按业务域拆分(如 `services/order/`、`services/user/`),目录深度建议 ≤ 3 层
|
|
46
|
-
- 公共工具放 `utils/`,无业务依赖;与业务相关的 helper 放对应 service 子目录
|
|
47
|
-
- 常量命名用 UPPER_SNAKE_CASE,枚举优先使用语言原生 `Enum`
|
|
48
|
-
- 测试目录与源码同构(`tests/services/order/test_*`)
|
|
49
|
-
|
|
50
|
-
## Avoid
|
|
51
|
-
- 禁止在根目录堆放脚本与临时代码,临时脚本放 `scripts/` 并命名清晰
|
|
52
|
-
- 禁止在 `models/` 里写业务逻辑,模型仅定义结构与简单关联
|
|
53
|
-
- 禁止把常量直接写在业务代码里(如 `if status == 1` / `role == "admin"`),必须引用 `constants/` 中的命名常量
|
|
54
|
-
- 禁止单文件超过 500 行或单函数超过 50 行
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
id: backend-logging
|
|
3
|
-
description: 涉及日志/调试/监控时适用:日志级别、格式、追踪约束
|
|
4
|
-
stages: [design, plan, code, review]
|
|
5
|
-
enforcement: required
|
|
6
|
-
verifiers:
|
|
7
|
-
- rule: RULE-backend-logging-001
|
|
8
|
-
type: manual
|
|
9
|
-
config:
|
|
10
|
-
checklist: Confirm all Guidance and Avoid items for this Spec.
|
|
11
|
-
owner: project-owner
|
|
12
|
-
---
|
|
13
|
-
|
|
14
|
-
# Backend Logging
|
|
15
|
-
|
|
16
|
-
## Examples
|
|
17
|
-
|
|
18
|
-
✅ 结构化字段 + 脱敏 + 保留堆栈
|
|
19
|
-
|
|
20
|
-
```python
|
|
21
|
-
logger.info("login", extra={"user_id": uid, "request_id": rid})
|
|
22
|
-
logger.error("pay failed", exc_info=True)
|
|
23
|
-
```
|
|
24
|
-
|
|
25
|
-
❌ 明文 token + `print` 吞掉堆栈
|
|
26
|
-
|
|
27
|
-
```python
|
|
28
|
-
print(f"login token={token}") # 泄露敏感字段 + 非日志框架
|
|
29
|
-
logger.error("failed") # 丢失原始错误与上下文
|
|
30
|
-
```
|
|
31
|
-
|
|
32
|
-
## Rules
|
|
33
|
-
- [RULE-backend-logging-001] The implementation must satisfy every applicable item in Guidance and avoid every item in Avoid.
|
|
34
|
-
|
|
35
|
-
## Guidance
|
|
36
|
-
- 关键路径(请求入口、外部调用、DB 写入、异常分支)必须输出结构化日志
|
|
37
|
-
- 日志中禁止出现明文密码、token、身份证号等敏感字段,需在记录前脱敏
|
|
38
|
-
- 每条请求日志必须包含 `request_id`,串联整个调用链
|
|
39
|
-
- 日志级别遵循:`DEBUG`(开发)/ `INFO`(业务事件)/ `WARN`(可恢复异常)/ `ERROR`(需告警)
|
|
40
|
-
|
|
41
|
-
## Patterns
|
|
42
|
-
- 统一字段命名:`request_id`、`user_id`、`route`、`status`、`latency_ms`、`error`
|
|
43
|
-
- 异常日志必须带堆栈(`exc_info=True` 或等价机制)
|
|
44
|
-
- 高频路径用采样日志,避免 IO 阻塞主流程
|
|
45
|
-
- 日志输出到 stdout/stderr,由部署环境采集,禁止业务代码写文件
|
|
46
|
-
|
|
47
|
-
## Avoid
|
|
48
|
-
- 禁止在循环或热路径中无脱敏地打印请求体
|
|
49
|
-
- 禁止用 `print` / `console.log` 替代日志框架
|
|
50
|
-
- 禁止吞掉异常仅打 `logger.error("failed")`,必须保留原始错误与上下文
|
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
id: backend-platform-rules
|
|
3
|
-
description: 涉及 API 设计/部署/配置/版本兼容时适用:平台规则
|
|
4
|
-
stages: [design, plan, code, review]
|
|
5
|
-
enforcement: required
|
|
6
|
-
verifiers:
|
|
7
|
-
- rule: RULE-backend-platform-001
|
|
8
|
-
type: manual
|
|
9
|
-
config:
|
|
10
|
-
checklist: Confirm all Guidance and Avoid items for this Spec.
|
|
11
|
-
owner: project-owner
|
|
12
|
-
---
|
|
13
|
-
|
|
14
|
-
# Backend Platform Rules
|
|
15
|
-
|
|
16
|
-
## Examples
|
|
17
|
-
|
|
18
|
-
✅ 走统一封装 + 错误码常量
|
|
19
|
-
|
|
20
|
-
```python
|
|
21
|
-
return success(data)
|
|
22
|
-
raise BizError(ORDER_NOT_FOUND) # 错误码定义在 errors/order.py
|
|
23
|
-
```
|
|
24
|
-
|
|
25
|
-
❌ handler 手拼响应结构 + 硬编码 message
|
|
26
|
-
|
|
27
|
-
```python
|
|
28
|
-
return {"code": 1, "message": "order not found", "data": None}
|
|
29
|
-
```
|
|
30
|
-
|
|
31
|
-
## Rules
|
|
32
|
-
- [RULE-backend-platform-001] The implementation must satisfy every applicable item in Guidance and avoid every item in Avoid.
|
|
33
|
-
|
|
34
|
-
## Guidance
|
|
35
|
-
- API 变更必须保持向后兼容;破坏性变更走新版本路径(`/v2/...`)并保留旧版本至少一个发布周期
|
|
36
|
-
- 配置项分环境管理(dev / staging / prod),敏感值走密钥管理服务,禁止入库
|
|
37
|
-
- 新增外部依赖必须更新部署文档与 `requirements` / `package.json` 锁文件
|
|
38
|
-
- 灰度 / 实验性功能必须由 feature flag 控制,默认关闭
|
|
39
|
-
- API 响应必须走统一封装:`success(data)` / `fail(code, message?)`,handler 禁止手写 `{code, message, data}` 字面量
|
|
40
|
-
- 错误码 → message 映射定义为常量,按业务模块拆分(`errors/order.py`、`errors/user.py`),错误码全局唯一,禁止重复
|
|
41
|
-
|
|
42
|
-
## Patterns
|
|
43
|
-
- API 响应统一结构:`{ code, message, data }`(`code=0` 表示成功),全项目一致
|
|
44
|
-
- 错误码命名空间:模块前缀 + 顺序号(如订单错误码 `10xxx`、用户 `20xxx`),便于定位归属
|
|
45
|
-
- 异常 → 错误码:自定义业务异常类携带 `code`,由中间件统一转 `fail(code)` 响应
|
|
46
|
-
- 配置加载优先级:环境变量 > 配置文件 > 默认值
|
|
47
|
-
- 健康检查端点(`/healthz`、`/readyz`)必须独立于业务认证
|
|
48
|
-
- 部署前跑 smoke test,覆盖核心路径
|
|
49
|
-
|
|
50
|
-
## Avoid
|
|
51
|
-
- 禁止在生产环境开启 `DEBUG` / 详细堆栈输出
|
|
52
|
-
- 禁止把 secret 写进代码库或 dev 配置文件
|
|
53
|
-
- 禁止破坏性 API 变更不通知调用方直接发布
|
|
54
|
-
- 禁止 feature flag 长期遗留,上线稳定后必须清理
|
|
55
|
-
- 禁止在 handler 里直接拼响应结构或硬编码错误 message,必须引用 `errors/` 常量并走 `success / fail` 封装
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
# Frontend Retrieval Map
|
|
2
|
-
|
|
3
|
-
> AI 导航地图:定位前端代码结构和关键模块。可由 `/cf-learn --map` 重生成,建议按真实项目手动校准。
|
|
4
|
-
|
|
5
|
-
## Purpose
|
|
6
|
-
|
|
7
|
-
前端单页 / 多页应用,负责用户交互、页面渲染与 API 调用。默认假设为基于组件的 SPA。
|
|
8
|
-
|
|
9
|
-
## Architecture
|
|
10
|
-
|
|
11
|
-
- Framework: 任意主流框架(React / Vue / Svelte / Solid 等)
|
|
12
|
-
- Language: TypeScript(推荐)或 JavaScript + JSDoc
|
|
13
|
-
- State: 局部状态优先,跨组件共享走集中式(Redux / Zustand / Pinia)
|
|
14
|
-
- Routing: 框架官方路由(React Router / Vue Router / 文件路由)
|
|
15
|
-
- Styling: 原子化(Tailwind)或模块化(CSS Modules / styled-components)
|
|
16
|
-
- Build: Vite / Webpack / Next.js 等
|
|
17
|
-
|
|
18
|
-
## Key Files
|
|
19
|
-
|
|
20
|
-
| File | Purpose |
|
|
21
|
-
|------|---------|
|
|
22
|
-
| `src/main.*` | 应用入口,挂载 Root |
|
|
23
|
-
| `src/App.*` | 根组件,注册路由与全局 Provider |
|
|
24
|
-
| `src/router.*` | 路由定义 |
|
|
25
|
-
| `src/services/` | API 调用封装 |
|
|
26
|
-
|
|
27
|
-
## Module Map
|
|
28
|
-
|
|
29
|
-
```
|
|
30
|
-
src/
|
|
31
|
-
├── components/ # 通用 UI 组件,无业务依赖
|
|
32
|
-
├── pages/ # 页面级组件(路由叶子)
|
|
33
|
-
├── hooks/ # 业务复用逻辑(React)/ composables(Vue)
|
|
34
|
-
├── stores/ # 状态管理
|
|
35
|
-
├── services/ # API 调用层
|
|
36
|
-
├── utils/ # 纯函数工具
|
|
37
|
-
├── types/ # 类型定义
|
|
38
|
-
└── styles/ # 全局样式 / 主题
|
|
39
|
-
```
|
|
40
|
-
|
|
41
|
-
## Data Flow
|
|
42
|
-
|
|
43
|
-
```
|
|
44
|
-
User Action → Event Handler → Service(API) → Store/State → Re-render
|
|
45
|
-
```
|
|
46
|
-
|
|
47
|
-
## Navigation Guide
|
|
48
|
-
|
|
49
|
-
- 新增页面 → `pages/` 添加组件 + 路由配置
|
|
50
|
-
- 新增组件 → `components/` 按业务域分子目录,复用优先
|
|
51
|
-
- API 调用 → 统一走 `services/`,不在组件内裸 fetch
|
|
52
|
-
- 状态管理 → 跨组件状态走 `stores/`,组件通过 hook / composable 消费
|
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
id: frontend-component-specs
|
|
3
|
-
description: 写/改组件时适用:props、hooks、渲染、UI 样式约束
|
|
4
|
-
stages: [design, plan, code, review]
|
|
5
|
-
enforcement: required
|
|
6
|
-
verifiers:
|
|
7
|
-
- rule: RULE-frontend-component-001
|
|
8
|
-
type: manual
|
|
9
|
-
config:
|
|
10
|
-
checklist: Confirm all Guidance and Avoid items for this Spec.
|
|
11
|
-
owner: project-owner
|
|
12
|
-
---
|
|
13
|
-
|
|
14
|
-
# Component Specs
|
|
15
|
-
|
|
16
|
-
## Examples
|
|
17
|
-
|
|
18
|
-
✅ 稳定唯一 key + 改值经回调上抛
|
|
19
|
-
|
|
20
|
-
```tsx
|
|
21
|
-
{items.map((it) => <Row key={it.id} item={it} onChange={onChange} />)}
|
|
22
|
-
```
|
|
23
|
-
|
|
24
|
-
❌ 用数组 index 作 key + 组件内直接改 props
|
|
25
|
-
|
|
26
|
-
```tsx
|
|
27
|
-
{items.map((it, i) => { it.value = next; return <Row key={i} item={it} />; })}
|
|
28
|
-
```
|
|
29
|
-
|
|
30
|
-
✅ 容器/展示分离 + 样式走 token,展示组件不碰数据获取
|
|
31
|
-
|
|
32
|
-
```tsx
|
|
33
|
-
// 展示组件:纯 props 驱动,样式用 class/token,无请求
|
|
34
|
-
const OrderRow = ({ order, onSelect }: Props) =>
|
|
35
|
-
<div className={styles.row} onClick={() => onSelect(order.id)}>{order.title}</div>;
|
|
36
|
-
```
|
|
37
|
-
|
|
38
|
-
❌ 展示组件内自取数据 + 内联魔法样式
|
|
39
|
-
|
|
40
|
-
```tsx
|
|
41
|
-
const OrderRow = ({ id }) => {
|
|
42
|
-
const [o, setO] = useState(); useEffect(() => { fetch(`/orders/${id}`)... }, []);
|
|
43
|
-
return <div style={{ margin: 13, color: '#3a7' }}>{o?.title}</div>;
|
|
44
|
-
};
|
|
45
|
-
```
|
|
46
|
-
|
|
47
|
-
## Rules
|
|
48
|
-
- [RULE-frontend-component-001] The implementation must satisfy every applicable item in Guidance and avoid every item in Avoid.
|
|
49
|
-
|
|
50
|
-
## Guidance
|
|
51
|
-
- Props 必须类型化(TS interface / PropTypes / defineProps),可选项给默认值
|
|
52
|
-
- 组件文件名与导出组件名一致,使用 PascalCase
|
|
53
|
-
- 单组件文件 ≤ 300 行,超出拆成子组件或提取 hook
|
|
54
|
-
- 组件内禁止直接修改 props,需改值通过事件 / 回调上抛
|
|
55
|
-
- **样式与逻辑/数据分离**:样式走 CSS Modules / 原子类 / 设计 token,不与数据获取或业务逻辑混在同一处;展示组件不发起请求
|
|
56
|
-
|
|
57
|
-
## Patterns
|
|
58
|
-
- 拆分容器组件(数据获取 / 状态)与展示组件(纯 UI),便于测试和复用
|
|
59
|
-
- 复用逻辑提取为 hook(`useXxx`)/ composable,禁止跨组件复制粘贴
|
|
60
|
-
- 列表渲染必须给 `key`,且 `key` 稳定唯一,避免使用数组索引
|
|
61
|
-
- 受控表单优先;非受控仅用于不需要回读值的场景
|
|
62
|
-
- 样式遵循设计系统:间距用 4 的倍数,强调色 ≤ 2 种
|
|
63
|
-
|
|
64
|
-
## Avoid
|
|
65
|
-
- 禁止在组件内直接修改 props 或 store 内部状态
|
|
66
|
-
- 禁止把大量逻辑塞进 JSX 表达式,复杂条件提取变量或子组件
|
|
67
|
-
- 禁止用 `index` 作为列表 `key`(顺序变更会触发错误复用)
|
|
68
|
-
- 禁止省略 `alt` / `aria-*` 等可访问性属性
|
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
id: frontend-directory-structure
|
|
3
|
-
description: 新建/移动前端文件时适用:目录结构、路由/页面/组件存放约束
|
|
4
|
-
stages: [design, plan, code, review]
|
|
5
|
-
enforcement: required
|
|
6
|
-
verifiers:
|
|
7
|
-
- rule: RULE-frontend-directory-001
|
|
8
|
-
type: manual
|
|
9
|
-
config:
|
|
10
|
-
checklist: Confirm all Guidance and Avoid items for this Spec.
|
|
11
|
-
owner: project-owner
|
|
12
|
-
---
|
|
13
|
-
|
|
14
|
-
# Frontend Directory Structure
|
|
15
|
-
|
|
16
|
-
## Examples
|
|
17
|
-
|
|
18
|
-
✅ 三层分离:service 发请求 → hook/composable 管状态 → 组件纯展示
|
|
19
|
-
|
|
20
|
-
```ts
|
|
21
|
-
// services/order.ts — 只管 HTTP,不含状态
|
|
22
|
-
export const fetchOrder = (id: string) => http.get(`/orders/${id}`);
|
|
23
|
-
// hooks/useOrder.ts — 管 loading/error/data,复用逻辑收口于此
|
|
24
|
-
export const useOrder = (id: string) => { /* 调 fetchOrder,返回 { data, loading, error } */ };
|
|
25
|
-
// components/OrderCard.tsx — 纯展示,消费 hook
|
|
26
|
-
const { data, loading, error } = useOrder(id);
|
|
27
|
-
```
|
|
28
|
-
|
|
29
|
-
❌ 组件内裸 `fetch`,请求/状态/样式糊在一处
|
|
30
|
-
|
|
31
|
-
```tsx
|
|
32
|
-
const order = await fetch(`/orders/${id}`).then((r) => r.json());
|
|
33
|
-
```
|
|
34
|
-
|
|
35
|
-
## Rules
|
|
36
|
-
- [RULE-frontend-directory-001] The implementation must satisfy every applicable item in Guidance and avoid every item in Avoid.
|
|
37
|
-
|
|
38
|
-
## Guidance
|
|
39
|
-
- 通用组件放 `src/components/`,页面级组件放 `src/pages/`,业务复用逻辑放 `src/hooks/`(或 `composables/`)
|
|
40
|
-
- **接口调用独立成层**:API 调用必须在 `src/services/` 封装;组件 / hook / composable 经 service 消费,**禁止组件或视图层内裸 `fetch` / `axios`**
|
|
41
|
-
- 类型定义放 `src/types/`(共享)或与组件同目录(局部),禁止散落
|
|
42
|
-
- 新增一级目录必须更新路由 / 入口索引与导航地图
|
|
43
|
-
|
|
44
|
-
## Patterns
|
|
45
|
-
- 组件目录按业务域分子目录(`components/order/`、`components/user/`)
|
|
46
|
-
- 页面与路由一一对应,路由配置集中在 `router.*`
|
|
47
|
-
- 资源文件(图片 / 字体)放 `src/assets/`,构建工具处理 hash 与压缩
|
|
48
|
-
- 测试文件与源码同目录(`Foo.test.tsx`)或镜像放 `tests/`
|
|
49
|
-
|
|
50
|
-
## Avoid
|
|
51
|
-
- 禁止在 `src/` 下随意新增未登记的一级目录
|
|
52
|
-
- 禁止页面与组件互相循环引用
|
|
53
|
-
- 禁止把仅本组件用的 hook / 类型上提到全局目录
|
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
id: frontend-quality-standards
|
|
3
|
-
description: 写前端代码时适用:类型、lint、错误处理、测试、状态管理质量约束
|
|
4
|
-
stages: [design, plan, code, review]
|
|
5
|
-
enforcement: required
|
|
6
|
-
verifiers:
|
|
7
|
-
- rule: RULE-frontend-quality-001
|
|
8
|
-
type: manual
|
|
9
|
-
config:
|
|
10
|
-
checklist: Confirm all Guidance and Avoid items for this Spec.
|
|
11
|
-
owner: project-owner
|
|
12
|
-
---
|
|
13
|
-
|
|
14
|
-
# Frontend Quality Standards
|
|
15
|
-
|
|
16
|
-
## Examples
|
|
17
|
-
|
|
18
|
-
✅ `unknown` 收敛 + 异步三态
|
|
19
|
-
|
|
20
|
-
```ts
|
|
21
|
-
setState("loading");
|
|
22
|
-
try {
|
|
23
|
-
const raw: unknown = await api.fetch();
|
|
24
|
-
setState("success", parse(raw));
|
|
25
|
-
} catch (e) {
|
|
26
|
-
setState("error", toMessage(e));
|
|
27
|
-
}
|
|
28
|
-
```
|
|
29
|
-
|
|
30
|
-
❌ `any` + `@ts-ignore` + 只处理成功路径
|
|
31
|
-
|
|
32
|
-
```ts
|
|
33
|
-
// @ts-ignore
|
|
34
|
-
const data: any = await api.fetch();
|
|
35
|
-
render(data);
|
|
36
|
-
```
|
|
37
|
-
|
|
38
|
-
## Rules
|
|
39
|
-
- [RULE-frontend-quality-001] The implementation must satisfy every applicable item in Guidance and avoid every item in Avoid.
|
|
40
|
-
|
|
41
|
-
## Guidance
|
|
42
|
-
- TypeScript 项目禁止使用 `any`,未知类型用 `unknown` 并显式收敛
|
|
43
|
-
- 组件统一使用函数组件(React)/ 组合式 API(Vue 3),禁止类组件新增
|
|
44
|
-
- 关键交互(提交 / 删除 / 支付)必须有错误提示与 loading 状态
|
|
45
|
-
- 异步操作必须处理 loading / success / error 三态,禁止只处理成功路径
|
|
46
|
-
- 提交前必须通过 lint 与 type check,禁止 `eslint-disable` / `@ts-ignore` 滥用
|
|
47
|
-
|
|
48
|
-
## Patterns
|
|
49
|
-
- 跨组件状态用集中式状态管理,避免 prop drilling 超过 2 层
|
|
50
|
-
- 表单校验在提交前完成,错误信息定位到具体字段
|
|
51
|
-
- 网络请求统一处理 401 / 403 / 5xx,避免每个调用方重复
|
|
52
|
-
- 关键路径补端到端测试或组件交互测试
|
|
53
|
-
|
|
54
|
-
## Avoid
|
|
55
|
-
- 禁止在 render / setup 中发起未受控的副作用(用 `useEffect` / `onMounted`)
|
|
56
|
-
- 禁止把后端错误直接抛给用户(如 SQL / stack trace)
|
|
57
|
-
- 禁止用 `// @ts-ignore` 绕过类型错误,必须修复或改为 `@ts-expect-error` 加注释
|
|
58
|
-
- 禁止在组件中直接修改 store 内部状态,必须走 action / mutation
|
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
# Shared Specs Navigation Map
|
|
2
|
-
|
|
3
|
-
> 跨项目的共享模板和规范
|
|
4
|
-
|
|
5
|
-
## Purpose
|
|
6
|
-
|
|
7
|
-
共享模板供 `cf-task:align` 和 `cf-task:prd` 命令使用,为文档生成提供规范约束。
|
|
8
|
-
|
|
9
|
-
## Templates
|
|
10
|
-
|
|
11
|
-
### PRD Templates
|
|
12
|
-
|
|
13
|
-
| 文件 | 用途 | 适用场景 |
|
|
14
|
-
|------|------|---------|
|
|
15
|
-
| `prd-template.md` | 产品需求文档 | 需求早期阶段,在设计之前 |
|
|
16
|
-
|
|
17
|
-
### Design Templates
|
|
18
|
-
|
|
19
|
-
| 文件 | 用途 | 适用场景 |
|
|
20
|
-
|------|------|---------|
|
|
21
|
-
| `design/design-lite.md` | 轻量设计简报 | 功能开发/CLI/Bug修复/小型重构 |
|
|
22
|
-
| `design/design-full.md` | 完整设计文档 | 跨系统集成/性能优化/架构演进/中大型功能 |
|
|
23
|
-
|
|
24
|
-
> 两档模板均覆盖:接口设计(API/CLI/函数三形态)、性能与容量设计、可执行验收(场景即 TC)。design-full 额外含方案选型 ADR 决策记录与 §6 需求追溯矩阵。
|
|
25
|
-
|
|
26
|
-
## Workflow
|
|
27
|
-
|
|
28
|
-
```
|
|
29
|
-
需求 → cf-task:prd → PRD (.prd.md)
|
|
30
|
-
↓ (align 读取 .prd.md 派生)
|
|
31
|
-
→ cf-task:align → 设计 (.design.md)
|
|
32
|
-
↓ (plan 读取 .design.md 拆解)
|
|
33
|
-
→ cf-task:plan → 任务
|
|
34
|
-
```
|
|
35
|
-
|
|
36
|
-
## Selection Guide
|
|
37
|
-
|
|
38
|
-
```
|
|
39
|
-
需求阶段(还未明确用户与场景):
|
|
40
|
-
→ cf-task:prd 生成 PRD
|
|
41
|
-
|
|
42
|
-
设计阶段(已有 PRD 或已明确做什么):
|
|
43
|
-
→ cf-task:align 生成设计简报
|
|
44
|
-
- 输入 .prd.md → 派生模式(继承目标/用户/功能/范围)
|
|
45
|
-
- 输入文本 → 新建模式(从零对话)
|
|
46
|
-
|
|
47
|
-
复杂度判断:
|
|
48
|
-
简单功能/脚本/Bugfix → design-lite.md
|
|
49
|
-
复杂系统/跨模块/性能优化 → design-full.md
|
|
50
|
-
```
|
|
51
|
-
|
|
52
|
-
## Usage
|
|
53
|
-
|
|
54
|
-
1. `cf-task:prd` 命令引用 `prd-template.md` 生成 PRD
|
|
55
|
-
2. `cf-task:align` 命令引用 `design/design-lite.md` 或 `design/design-full.md` 生成设计文档
|
|
56
|
-
3. PRD 的 US/FEAT ID 被 design 的功能清单"来源"列引用,形成追溯链
|
|
57
|
-
4. 性能敏感需求:align 在出技术方案时即按最优性能设计,落点 design-lite §3.4 / design-full §3.5,并在 §6 矩阵闭合 US→FEAT→API→TC
|
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
id: scenarios-template
|
|
3
|
-
description: Scenario-first acceptance source template (not auto-injected)
|
|
4
|
-
stages: [design]
|
|
5
|
-
enforcement: advisory
|
|
6
|
-
---
|
|
7
|
-
|
|
8
|
-
# {需求名} 验收场景
|
|
9
|
-
|
|
10
|
-
> 本文件是验收场景的唯一源。design 文档只写实现逻辑并引用场景 ID;任务文件只登记 owner 与执行命令。
|
|
11
|
-
>
|
|
12
|
-
> 以下是可通过场景质量检查的订单示例,使用时替换为本需求的真实行为与路径。将 YAML 放到 `<需求>.scenarios.md` 的 frontmatter 或作为整个 YAML 文件保存;不要把模板自身的 Spec 元数据当成场景源。`checks` 在 plan 生成真实 check ID 后绑定,空列表不能通过需要测试登记的 verify-plan。
|
|
13
|
-
|
|
14
|
-
```yaml
|
|
15
|
-
schema: 1
|
|
16
|
-
requirement: 订单创建
|
|
17
|
-
scenarios:
|
|
18
|
-
- id: S-01
|
|
19
|
-
title: 登录用户通过浏览器创建订单
|
|
20
|
-
priority: P0 # P0 / P1 / P2;E2E 只允许 P0/P1 关键旅程
|
|
21
|
-
level: e2e # unit / component / contract / integration / system / capacity / e2e / manual
|
|
22
|
-
exec: deferred # auto / deferred / manual / aspirational
|
|
23
|
-
env: browser # none / local / local-api / browser / external / staging / capacity / ci / production
|
|
24
|
-
components: [browser, frontend, api, db]
|
|
25
|
-
boundary: 真实浏览器 → 订单 API → 数据库
|
|
26
|
-
preconditions: [用户已登录,购物车含一件库存充足的商品]
|
|
27
|
-
steps: [在浏览器点击提交订单]
|
|
28
|
-
expected: [订单列表新增一条状态为 created 的订单]
|
|
29
|
-
expected_refs: [{expected: 1, steps: [1]}] # 从 1 开始,逐个 expected 引用步骤或已声明断言 ID
|
|
30
|
-
why_e2e: 真实浏览器登录态与订单持久化跨前后端,需要联合验证
|
|
31
|
-
trigger_paths: [src/frontend/*, src/orders/*]
|
|
32
|
-
smoke: true # check 与收集到的测试都必须登记 smoke marker
|
|
33
|
-
defer_reason: 在需求终验阶段运行真实浏览器链路
|
|
34
|
-
owner: TASK-001
|
|
35
|
-
target_phase: review # plan / code / review / ci / release
|
|
36
|
-
features: [FEAT-01]
|
|
37
|
-
design_refs: [API-01] # 对应设计必须定义 FEAT-01 / API-01
|
|
38
|
-
rules: []
|
|
39
|
-
checks: [] # plan 阶段绑定;一个场景可多个 check
|
|
40
|
-
```
|
|
41
|
-
|
|
42
|
-
> **测试层级决策**:UI 交互/布局/字段顺序 → `component`;DTO/OpenAPI/错误码 →
|
|
43
|
-
> `contract`;鉴权/事务/模块边界/进程内 API → `integration`;API/CLI/后台全链路 →
|
|
44
|
-
> `system`;容量 → `capacity` 或 capacity 标签;只有真实浏览器 +
|
|
45
|
-
> 真实后端 + 真实 DB/鉴权的关键旅程才用 `E2E`。E2E 不是“用户可见结果”的默认层。
|
|
46
|
-
|
|
47
|
-
> CAS 409 示例:contract 检查冲突响应,component 检查表单保留,integration 用真实存储验证并发写入;分别登记 check,按 expected 映射必要成员。低层覆盖完整时可以不新增 E2E;仅为剩余跨边界接线风险选择 E2E,说明独特故障、已有低层覆盖及剩余风险,由设计评审判断理由。
|
|
48
|
-
>
|
|
49
|
-
> ✅ CAS 用 contract + component + 真实存储 integration;聚合补零用数据 contract + component;关系绑定用真实存储 integration。Cookie 身份隔离与 SSE 断线恢复仍可保留针对性的浏览器 E2E,验证低层无法证明的跨边界接线。
|
|
50
|
-
>
|
|
51
|
-
> ❌ 因用户看得到结果就为每个表单、聚合或关系操作新增一条 E2E;也不要只改旧 E2E 的层级后继承历史通过证据。
|
|
52
|
-
>
|
|
53
|
-
> **质量门禁**:E2E 必须声明浏览器 env/组件、匹配的 boundary、why_e2e、步骤和具体预期;非 smoke 必须有 trigger_paths。每个 expected 必须引用存在的步骤或断言,deferred 必须有原因、owner 与 target_phase。
|
|
54
|
-
>
|
|
55
|
-
> `scenarios parse --quality` 检查语义,`design lint` 检查设计 ID 闭环,`acceptance manifest --verify-plan` 还检查 Spec Gate 与真实测试登记/收集。start 按当前 TASK 的 E2E 与全局 smoke 生成 e2e_plan,不额外扩大本任务验收范围。收集通过不能替代真实执行证据;配置示例见工具文档 `docs/acceptance-contract.md`。
|