Communitygithub.com

lguidolin/変更衛生とコードクラフト

コードの記述やリファクタリング、コミットやPRの構成、重複を抽象化すべきかの判断時に使用します。兆候としては、再編成とロジック変更の混在、複数のことを同時に行うPR、ファイルの肥大化、類似コードの2つ目のコピー、DRY化の判断に迷う場合などがあります。

変更衛生とコードクラフト とは?

このスキルは、変更の衛生(Change Hygiene)とコードクラフト(Code Craft)という2つのテーマに基づき、ソフトウェア開発における変更の構成とコード記述のベストプラクティスを提供します。構造的変更と振る舞いの変更を分離し、それぞれを独立して検証可能なステップとして扱うことで、レビューのしやすさと変更の信頼性を高めます。また、暗黙的でなく明示的であること、意図を説明する命名、コメントは意図のみを記述すること、ユニットは単一責任で小さく保つこと、DRYは意味の重複にのみ適用する(見た目の類似ではない)などを推奨します。さらに、DRYと早期抽象化のトレードオフ、DRYとDAMP(テストコードの明確さ)のバランスについても指針を示します。このスキルはClaude Code、Cursor、Codexなど、AIエージェントがコードを作成・修正するあらゆるプラットフォームで活用できます。ドキュメントはマークダウン形式で、具体的なルールと回避すべきアンチパターン(赤旗)を定義しており、エンジニアリング憲章の関連記事を参照として挙げています。

対応~Claude Code~Codex CLI~Cursor
npx skills add https://github.com/lguidolin/agent-skills/tree/main/skills/change-hygiene-and-code-craft

お気に入りのAIに質問する

このエージェントスキルを事前に読み込んだ状態で新しいチャットを開きます。

ドキュメント

変更衛生とコードクラフト は何をしますか?

概要

変更の形とコードの記述方法について。2つのテーマ: 構造的変更と振る舞いの変更を分離すること、そして動作する最もシンプルな方法で意図を明確に表現すること。

変更衛生

  • 構造的変更は振る舞いの変更より先に、独立して検証する。 再編成(ファイル分割、リネーム、コメント追加)は、振る舞いの変更(新しい制約、ロジックの変更)とは別の、独立してチェック可能なステップとする。両方を1つの不可分な変更に混ぜてはならない。レビュアーは安全な再構成と実際のロジック変更を区別できない。
  • 変更は1つの関心事につき1つ。 変更は単一の、説明可能な目的を持つ。
  • 作業中のコードを改善する(問題がタスクに影響する場合、キャンプサイトをよりきれいにする)が、無関係なリファクタリングは行わない。目標に集中する。

コードクラフト

  • 暗黙的より明示的。 名前があるべき場所にワイルドカードなし、暗黙のキャストなし、空文字列やマジックセンチネルなし。意図を明確に述べる。
  • 説明的な名前。 関数・変数はその動作を説明する。言語やエコシステムのイディオムに従う。
  • コメントは意図を、仕組みは書かない。 非自明な場合になぜを説明する。自明なコードへのコメントは省略する。
  • 小さく、単一目的のユニット。 どのユニットも、内部を読まなくても、何をするか、どう使うか、何に依存するかを説明できるべき。大きなファイルは通常、やりすぎである。
  • 本番コードでは判断をもってDRYに。 重複はシグナルであり、自動的なエラーではない。2つ目のほぼ同一の出現が、抽象化するか、その理由を記録するかの意図的な判断を引き起こす。共有された意味を抽象化し、偶然の形は抽象化しない。見た目は似ていても異なる理由で変更されるものは分離する。
  • エコシステムの標準に従う。 有能な実践者が期待するイディオムとよくサポートされたライブラリを使用する。プラットフォームが解決したものを再発明しない。

名前付きの緊張関係

  • DRY vs. 早期抽象化: 本番コードは、意図の実証された繰り返しに基づいて抽象化する。予期される繰り返しではない。判断に迷ったら、3回目の出現を待つ(YAGNIがタイブレークを支配する)。
  • DRY vs. DAMP: 本番コードはDRYに。テストコードはDAMPに(重複排除よりも明確さ、 tests-as-a-control 参照)。テストにDRYを適用するのは違反である。

よくある正当化

言い訳現実
「リネームと機能追加を1つのコミットでやります」構造と振る舞いが1つの差分にあるとレビュー不可能。分離せよ。
「コピーが2つあるから、今すぐDRYにしなければ」2回目の出現 = 判断せよ。同じ形 ≠ 同じ意味。偶然の重複は分離すべき。
「ついでだから、この別モジュールもリファクタリングしよう」無関係なリファクタリングはスコープとリスクを拡大する。メモしておき、今はやらない。
「賢いワンライナーのほうがエレガントだ」明示的は賢いより勝る。次の読み手のために最適化せよ。

赤旗 — 中止

  • コードの移動と振る舞いの変更を同時に行う差分
  • 目的を説明するのに「そして」という単語が必要なPR
  • 類似性の最初の出現で、または予期される(実際ではない)繰り返しに基づいて抽象化すること
  • 頭の中に収まらなくなったファイル

完全な理論的根拠: 憲法の第5条および第6条。engineering-constitution/references/engineering-constitution.md にバンドルされています。

Individual skills in this repo

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

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/designing-before-building

Use when starting a feature, fixing a non-trivial bug, or about to write implementation code — before any code exists. Symptoms you need this: "this is simple, I'll just code it", reaching for the editor before a design is approved, or an idea that hasn't been turned into a spec and plan.

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.

関連スキル