Communitygithub.com

lguidolin/先设计后编码

在开始新功能、修复非琐碎缺陷或即将编写实现代码之前——任何代码都不应存在时使用。需要此技能的症状:“这个简单,直接写代码就行”、在方案获批前就打开编辑器、或者想法尚未转化为规范和计划。

先设计后编码 是什么?

此技能强制实施“先设计,后编码”的工作流,将任务划分为五个有序阶段:头脑风暴、规格说明、计划、执行和记录。任何实现代码都必须先有明确的设计并获批准,杜绝“边写边设计”的依赖心理。该技能通过一系列不可跳过的阶段来减少重写和隐性假设带来的成本,适合非琐碎改动,同时为真正可逆的修正(如拼写错误、日志行、配置值)保留了捷径。它适用于Claude Code、Cursor、Codex等AI Agent平台,以Markdown格式文档呈现,作为工程团队中人类或AI协作者的决策执行指南。

兼容平台~Claude Code~Codex CLI~Cursor
npx skills add https://github.com/lguidolin/agent-skills/tree/main/skills/designing-before-building

在你喜欢的 AI 中提问

打开一个已预加载此 Agent Skill 的新对话。

文档

先设计后编码 是做什么的?

概述

工作流按顺序依次推进五个阶段:头脑风暴 → 规格说明 → 计划 → 执行 → 记录。 在设计和批准完成之前,不进行任何实现。最简单的任务中,未经检验的假设往往代价最高。

违反本规则的文字即违反其精神。“边写边设计”并非真正的设计。

五个阶段

  1. 头脑风暴。 探索意图、约束和成功标准。一次只问一个问题。提出2-3种方案,附带权衡分析和推荐意见。收敛到一个设计并获得明确批准。此阶段不写代码。
  2. 规格说明。 将批准的设计写入带日期的文档。规格说明是构建内容的合同。
  3. 计划。 在接触代码之前,将规格说明分解为有序、可审查的实现计划。
  4. 执行。 按照计划实现,设置审查里程碑。
  5. 记录。 将构建的内容及原因浓缩为决策记录(参见 recording-decisions)。

分解大型工作。 如果请求涉及多个独立子系统,请先分解再细化细节。每个子项目运行自己的周期,按依赖顺序构建。

何时不使用

真正琐碎、可逆的修改(拼写错误、日志行、配置值)可以直接跳到执行阶段。判断标准:在此处猜错,代价是否超过设计步骤? 如果是,则先设计。

常见借口

借口真相
“这个太简单,不需要设计”简单任务隐藏着假设。几句话的设计很便宜,重写则不便宜。
“我会边写边设计”设计尚未确定时编写的代码,就是需要重写的代码。设计是独立的行动。
“用户告诉我要构建什么,那就是设计”请求说的是做什么,而不是怎么做。怎么做才是设计。
“先探索代码库就能找到方法”探索可以为设计提供信息,但不能取代对方案的批准。
“我们很急”着急正是跳过设计会产生返工工作的时候。

危险信号——停止

  • 在获得批准的设计之前就打开编辑器
  • “让我快速原型一下”(没有规格说明的原型就是未经审查的范围扩展)
  • 在没有计划的情况下开始多文件修改
  • 将用户的一行请求当作完整的规格说明

这些都意味着:停止,设计,获得批准,然后再构建。

完整理由:工程宪章的第一条,见 engineering-constitution/references/engineering-constitution.md。

Individual skills in this repo

This repo contains 18 individual skills — each has its own dedicated page.

lguidolin/change-hygiene-and-code-craft

Use when writing or refactoring code, structuring a commit or PR, or deciding whether to abstract duplication. Symptoms — mixing reorg with logic changes, a PR doing several things at once, a file growing large, the second copy of similar code, or unsure whether to DRY something up.

lguidolin/cloud-delivery-aks

Use when deploying to Kubernetes or Azure Kubernetes Service (AKS), configuring cloud secrets, setting up progressive rollout/canary, per-PR ephemeral environments, or k8s health probes. Keywords — Kubernetes, AKS, Key Vault, Argo Rollouts, Flagger, canary, blue-green, liveness, readiness, PodDisruptionBudget, HPA, rollback, GHCR.

lguidolin/commit-history-rewrite

Use when an existing repository has messy commit history that needs to conform to conventional commits before adopting release-please, or when intermediate WIP/fixup/merge commits need to be cleaned up.

lguidolin/conventional-commits-and-releases

Use when committing, writing a commit message, opening a PR that will be squash-merged, or configuring automated versioning/changelogs. Keywords — conventional commits, release-please, semver, feat/fix/chore, breaking change, changelog.

lguidolin/defense-in-depth-security

Use when handling untrusted input, secrets, authentication/authorization, or dependencies — or threat-modeling a new surface. Keywords — STRIDE, threat model, least privilege, secrets management, supply chain, dependency scanning, input validation, audit log, defense in depth.

lguidolin/engineering-constitution

Use when starting work in a project that follows the engineering constitution, orienting to its rules, or deciding which engineering practice applies to a task — spec writing, commits, testing, security, deploys, database, or UI work.

lguidolin/graphql-contract-testing

Use when writing a GraphQL query/mutation that the UI and a test will share, or building route/schema contract or smoke tests. Symptoms — copying a query into a test, a test asserting on query text, schema change that didn't break the UI build, or RLS/permission drift. Keywords — graphql-codegen, typed document, contract test, route smoke test.

lguidolin/init-repo-CI

Use when setting up a new repository with conventional commits, release-please, and CI automation, or when retrofitting an existing repository that lacks automated versioning and PR validation workflows.

lguidolin/interface-craft-and-accessibility

Use when building or styling UI — components, layouts, forms, design tokens — or making accessibility decisions. Keywords — a11y, WCAG, keyboard navigation, focus state, contrast, design system, minimalist UI, component reuse, ARIA, semantic HTML.

lguidolin/merge-gates-and-automation

Use when setting up or changing CI, pre-push hooks, or a task runner, or deciding what must pass before merge. Symptoms — tempted to put authoritative checks only in a local hook, skip CI, bypass with --no-verify, or unsure what gates a merge vs. runs locally.

lguidolin/observability-and-slos

Use when adding logging, metrics, tracing, health checks, SLOs, or alerting — or when building a service surface that needs to be operable and debuggable. Keywords — structured logs, OpenTelemetry, correlation id, RED metrics, liveness, readiness, SLI, SLO, error budget, alerting.

lguidolin/performance-and-scale

Use when working on hot paths, list endpoints, pagination, data-access in loops, or public interfaces/schemas. Symptoms — unbounded queries, N+1 access, no latency budget, optimizing without measuring, or changing an interface many consumers depend on. Keywords — pagination, N+1, Hyrum's Law, performance budget, bundle size.

lguidolin/postgres-postgraphile-rls-and-sql

Use when writing PostgreSQL, PostGraphile config, Row-Level Security policies, SQL schema files, or working on the Browser→App→PostGraphile→Postgres data path. Keywords — RLS, SECURITY DEFINER, search_path, pgSettings, grants, roles, GraphQL depth limit, query cost, statement_timeout, SQL file organization.

lguidolin/recording-decisions

Use when a design or architecture decision has been made and needs to be captured — writing a decision record or ADR, updating a decision index, noting a deferred idea, or superseding a past decision. Keywords — ADR, decision record, rationale, rejected alternatives, dependency index.

lguidolin/resilience-and-deploy-safety

Use when planning a deploy, designing a rollback, or responding to an incident or writing a postmortem. Keywords — deploy safety, rollback, immutable artifact, progressive delivery, canary, blast radius, incident response, blameless postmortem, error budget.

lguidolin/ship-it

Use when the user wants to ship work — push, PR, archive decision records, merge, and clean up. Handles the full lifecycle from committing final changes through post-merge cleanup including converting specs/plans to compact decision records.

lguidolin/tests-as-a-control

Use when writing or modifying tests, when a test breaks during a refactor, or when testing permission/role rules. Symptoms — tempted to edit a test to make it pass, testing only the happy path, a deny-test that started passing, flaky tests, or unsure what to assert.

lguidolin/zero-downtime-migrations

Use when changing a database schema where data must survive the change — adding/removing/renaming columns, constraints, indexes, or backfilling. Symptoms — a destructive migration bundled with a code deploy, a NOT NULL column with a backfill, a table-locking UPDATE, or a rename. Keywords — expand/contract, parallel change, backfill, NOT VALID, CREATE INDEX CONCURRENTLY, graphile-migrate.

相关技能