Community程式設計與開發github.com

增量式實作

以薄型、可驗證的增量方式交付變更。當實作任何涉及多個檔案的變更,或從計畫中接手下一個任務時使用。

增量式實作 是什麼?

此技能「增量式實作」教導開發者以垂直薄切片的方式建構功能,而非一次完成整個功能。每個增量都應包含實作、測試、驗證和提交的完整循環,並讓系統始終保持在可運作且可測試的狀態。其核心優勢在於降低大型功能的開發風險,透過早期發現並隔離錯誤,讓除錯與回滾變得簡單。此技能支援任何需要逐步交付的場景,尤其適合多檔案變更、新功能開發或程式碼重構。它提供了多種切片策略(垂直切片、契約優先切片、風險優先切片)和明確的實作規則(如保持簡單、範圍紀律、單一職責),並包含一個完整的增量檢查清單,以確保品質。技能也說明了如何與 AI 代理協作,透過指定每次增量的範圍來實現精準的增量開發。

相容平台~Claude Code~Codex CLI~Cursor
npx skills add https://github.com/alfathafp/portofolio-web-design/tree/HEAD/.agents/skills/incremental-implementation

Installed? Explore more 程式設計與開發 skills: steipete/bluebubbles, steipete/eightctl, steipete/blucli · View all 6 →

在你喜歡的 AI 中提問

開啟一個已預先載入此 Agent Skill 的新對話。

說明文件

增量式實作 是做什麼的?

概述

以垂直薄切片的方式構建——實作一個片段,測試它,驗證它,然後再擴展。避免一次完成整個功能的實作。每個增量應使系統保持在可運作、可測試的狀態。這是讓大型功能易於管理的執行紀律。

使用時機

  • 實作任何多檔案變更
  • 從任務分解中構建新功能
  • 重構現有程式碼
  • 任何時候你忍不住想在測試前寫超過約 100 行程式碼

何時不使用: 單檔案、單函數的變更,且範圍已足夠小。

增量循環

┌──────────────────────────────────────┐
│                                      │
│   實作 ──→ 測試 ──→ 驗證 ──┐  │
│       ▲                           │  │
│       └───── 提交 ◄─────────────┘  │
│              │                       │
│              ▼                       │
│         下一個切片                  │
│                                      │
└──────────────────────────────────────┘

對於每個切片:

  1. 實作 最小完整的單一功能片段
  2. 測試 — 執行測試套件(如果沒有測試則撰寫一個)
  3. 驗證 — 確認切片如預期運作(測試通過、建置成功、手動檢查)
  4. 提交 -- 使用描述性訊息儲存進度(關於原子提交的指導,請參閱 git-workflow-and-versioning)
  5. 移至下一個切片 — 持續前進,不要重新開始

切片策略

垂直切片(首選)

構建一個完整的垂直路徑:

切片 1:建立任務(資料庫 + API + 基本 UI)
    → 測試通過,使用者可以透過 UI 建立任務

切片 2:列出任務(查詢 + API + UI)
    → 測試通過,使用者可以查看任務

切片 3:編輯任務(更新 + API + UI)
    → 測試通過,使用者可以修改任務

切片 4:刪除任務(刪除 + API + UI + 確認)
    → 測試通過,完整的 CRUD 完成

每個切片提供可運作的端到端功能。

契約優先切片

當後端和前端需要並行開發時:

切片 0:定義 API 契約(型別、介面、OpenAPI 規範)
切片 1a:根據契約實作後端 + API 測試
切片 1b:根據符合契約的模擬資料實作前端
切片 2:整合並進行端到端測試

風險優先切片

先處理風險最高或不確定的部分:

切片 1:證明 WebSocket 連線能運作(風險最高)
切片 2:在已驗證的連線上構建即時任務更新
切片 3:加入離線支援和重新連線

如果切片 1 失敗,你會在投入切片 2 和 3 之前就發現問題。

實作規則

規則 0:簡潔優先

在寫任何程式碼之前,先問:「最簡單可行的做法是什麼?」

寫完程式碼後,根據以下檢查點進行審查:

  • 這可以用更少的行數完成嗎?
  • 這些抽象層值得其複雜性嗎?
  • 一位資深工程師看到這個會不會說「你為什麼不直接...」?
  • 我是在為假設的未來需求而構建,還是為了當前的任務?
簡潔檢查:
✗ 為了一個通知建立帶中介軟體管線的通用 EventBus
✓ 簡單的函數呼叫

✗ 為兩個相似元件使用抽象工廠模式
✓ 兩個直接的元件加上共用工具函數

✗ 為三個表單使用配置驅動的表單生成器
✓ 三個表單元件

三行相似的程式碼勝過一個過早的抽象。先實作樸素、顯而易見正確的版本。只有在透過測試證明正確性之後,才進行最佳化。

規則 0.5:範圍紀律

只觸及任務所需的內容。

請勿:

  • 「清理」與你變更相鄰的程式碼
  • 重構你未在修改的檔案中的匯入
  • 移除你未完全理解的註解
  • 新增規格中沒有的功能,只因為它們「看起來有用」
  • 在你只讀取的檔案中現代化語法

如果你注意到任務範圍外有值得改進的地方,記錄下來——不要修復它:

注意到但未觸及:
- src/utils/format.ts 有一個未使用的匯入(與此任務無關)
- auth 中介軟體可以使用更好的錯誤訊息(另開任務)
→ 需要我為這些建立任務嗎?

規則 1:一次只做一件事

每個增量只改變一件邏輯上的事。不要混淆關注點:

糟糕: 一個提交同時新增新元件、重構現有元件並更新建置配置。

良好: 三個獨立的提交——每個變更一個。

規則 2:保持可編譯

每個增量之後,專案必須能夠建置,且現有測試必須通過。不要在切片之間讓程式碼庫處於損毀狀態。

規則 3:為未完成的功能使用功能標誌

如果某個功能尚未準備好給使用者,但你需要合併增量:

// 進行中功能的標誌
const ENABLE_TASK_SHARING = process.env.FEATURE_TASK_SHARING === 'true';

if (ENABLE_TASK_SHARING) {
  // 新的分享 UI
}

這讓你可以將小增量合併到主分支,而不會暴露未完成的功能。

規則 4:安全預設值

新程式碼應預設為安全、保守的行為:

// 安全:預設禁用,選擇加入
export function createTask(data: TaskInput, options?: { notify?: boolean }) {
  const shouldNotify = options?.notify ?? false;
  // ...
}

規則 5:便於回滾

每個增量應可獨立回滾:

  • 新增的變更(新檔案、新函數)易於回滾
  • 對現有程式碼的修改應最小且集中
  • 資料庫遷移應有對應的回滾遷移
  • 避免在一個提交中刪除某個內容,然後在同一個提交中替換它——將它們分開

與代理協作

當指導代理進行增量實作時:

「我們來實作計畫中的任務 3。

先只做資料庫綱要變更和 API 端點。
先不要碰 UI——我們在下一個增量中再做。

實作完成後,執行儲存庫的測試和建置命令來驗證沒有任何東西損毀。」

對於每個增量,要明確說明範圍內和範圍外的內容。

增量檢查清單

在每個增量之後,使用儲存庫自己的命令進行驗證(請參閱 test-driven-development 技能的 Discover the Stack First 章節):

  • 變更只做一件事,並完整完成它
  • 所有現有測試仍然通過(儲存庫的測試命令:npm test、./gradlew test、pytest、...)
  • 建置成功(儲存庫的建置命令)
  • 型別檢查通過(如果技術棧有的話:npx tsc --noEmit、mypy、...)
  • Linting 檢查通過(儲存庫的 lint 命令)
  • 新功能如預期運作
  • 變更已提交,並附上描述性訊息

注意: 在可能受影響的變更之後,執行每個驗證命令。在成功執行後,除非程式碼已改變,否則不要重複相同的命令——對未改變的程式碼重複執行不會增加資訊。

常見的理由

理由現實
「我會在最後一起測試」錯誤會疊加。切片 1 中的錯誤會使切片 2-5 都出錯。測試每個切片。
「一次做完比較快」直到某些東西壞掉而你無法找出 500 行變更中的哪一行導致問題時,它感覺上比較快。
「這些變更太小了,不值得分開提交」小提交是免費的。大提交會隱藏錯誤並使回滾變得痛苦。
「我之後再補上功能標誌」如果功能不完整,就不該讓使用者看到。現在就加上標誌。
「這個重構很小,可以包含進來」將重構與功能混在一起會讓兩者都更難審查和除錯。將它們分開。
「讓我再跑一次建置命令確認一下」成功執行後,除非程式碼已改變,否則重複相同的命令不會增加任何資訊。在後續編輯之後再執行,而不是為了安心。

警示訊號

  • 寫了超過 100 行程式碼但還沒有執行測試
  • 一個增量中包含多個不相關的變更
  • 「讓我順便加這個吧」的範圍擴張
  • 為了加快速度而跳過測試/驗證步驟
  • 切片之間的建置或測試中斷
  • 未提交的大型變更持續累積
  • 在第三個使用案例要求之前就建立抽象層
  • 觸及任務範圍外的檔案,「反正我都來了」
  • 為一次性操作建立新的工具檔案
  • 連續兩次執行相同的建置/測試命令,但中間沒有任何程式碼變更

驗證

完成任務的所有增量後:

  • 每個增量都已個別測試並提交
  • 完整的測試套件通過
  • 建置乾淨
  • 功能按規格端到端運作
  • 沒有未提交的變更遺留

參見

每次增量的驗證是局部檢查。在宣告任務完成之前,將專案層級的「完成的定義」作為最終關卡,這是每個增量無論任務為何都必須通過的常設標準。請參閱 ../../references/definition-of-done.md。

Individual skills in this repo

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

alfathafp/portofolio-web-design

You MUST use this before any creative work - creating features, building components, adding functionality, modifying behavior, or planning anything new, in software or out of it (a talk, a business, a renovation).

alfathafp/portofolio-web-design

Tests in real browsers via Chrome DevTools MCP. Use when building or debugging anything that runs in a browser. Use when you need to inspect the DOM, capture console errors, analyze network requests, profile performance, or verify visual output with real runtime data. Requires the chrome-devtools MCP server to be configured.

alfathafp/portofolio-web-design

Automates CI/CD pipeline setup. Use when setting up or modifying build and deployment pipelines. Use when you need to automate quality gates, configure test runners in CI, or establish deployment strategies.

alfathafp/portofolio-web-design

Conducts multi-axis code review. Use before merging any change. Use when reviewing code written by yourself, another agent, or a human. Use when you need to assess code quality across multiple dimensions before it enters the main branch. Use when asked to review a diff or a pull request, even when the diff is pasted inline.

alfathafp/portofolio-web-design

Simplifies code for clarity. Use when refactoring code for clarity without changing behavior. Use when code works but is harder to read, maintain, or extend than it should be. Use when reviewing code that has accumulated unnecessary complexity.

alfathafp/portofolio-web-design

Establishes a project's quality bar as a written contract and stops agents quietly lowering it. Interviews the user on which dimensions matter, supplies sane default thresholds when they have no number in mind, records everything in CONSTRAINTS.md, and watches the diff for a weakened bar — new @ts-ignore or eslint-disable suppressions, skipped or deleted tests, assertions stripped out, unimplemented stubs, thresholds edited down. Use when no quality bar is written down, when the user says "set up constraints" or "define our standards", when the user wants dimensions they care about — accessibility, web performance, coverage — set up as enforced constraints, when an agent keeps silencing checks or skipping tests to get to green, when you need a coverage or performance threshold and don't know what number to pick, or when an agent writes more code than anyone will read.

alfathafp/portofolio-web-design

Optimizes agent context setup. Use when starting a new session, when agent output quality degrades, when switching between tasks, or when you need to configure rules files and context for a project.

alfathafp/portofolio-web-design

Guides systematic root-cause debugging. Use when tests fail, builds break, something that worked yesterday broke, behavior doesn't match expectations, or you encounter any unexpected error. Use when you need to figure out what broke and why — a systematic approach to finding and fixing the root cause rather than guessing.

alfathafp/portofolio-web-design

Deploy applications and websites to Vercel. Use when the user requests deployment actions like "deploy my app", "deploy and give me the link", "push this live", or "create a preview deployment".

alfathafp/portofolio-web-design

Manages deprecation and migration. Use when removing old systems, APIs, or features. Use when migrating users from one implementation to another. Use when migrating a database schema in production, such as renaming or dropping a column without downtime (expand/contract). Use when deciding whether to maintain or sunset existing code.

alfathafp/portofolio-web-design

Use when a superpowers session went wrong and your human partner wants to know why — repeated work, ignored plans, stumbles, poor results, a skill that didn't fire, "it took too long", "why is it so expensive", "what is it doing" — or wants to build a bug report for the superpowers maintainers, for the current session or a past one identified by id or path, on any harness.

alfathafp/portofolio-web-design

Use when facing 2+ independent tasks that can be worked on without shared state or sequential dependencies

alfathafp/portofolio-web-design

Records decisions and documentation. Use when you need to document an architecture decision (ADR) or the reasoning behind a design choice, when changing public APIs, shipping features, or when you need to record context that future engineers and agents will need to understand the codebase.

alfathafp/portofolio-web-design

Subjects every non-trivial decision to a fresh-context adversarial review before it stands. Use when you want every assumption cross-examined before proceeding, when stress-testing a plan for hidden failure modes, when correctness matters more than speed, when working in unfamiliar code, when stakes are high (production auth, security-sensitive logic, a high-stakes migration, irreversible operations), or any time a confident output would be cheaper to verify now than to debug later.

alfathafp/portofolio-web-design

Use when executing an implementation plan in the current session as the implementer yourself — your human partner chose inline execution, or no subagent tool is available

alfathafp/portofolio-web-design

Use when implementation is complete, all tests pass, and you need to decide how to integrate the work

alfathafp/portofolio-web-design

Builds production-quality, accessible, responsive user-facing UIs. Use when building or modifying interfaces and pages, creating components, implementing layouts, meeting WCAG accessibility requirements, managing state, or when the output needs to look and feel production-quality rather than AI-generated.

alfathafp/portofolio-web-design

Structures git workflow practices. Use when making any code change. Use when committing, branching, resolving conflicts, splitting uncommitted work in a messy working tree into clean atomic commits, opening or reviewing a pull request (PR), pushing to a remote, or when you need to organize work across multiple parallel streams. Use when cutting a release, choosing a semantic version bump, tagging, or writing a changelog.

alfathafp/portofolio-web-design

Refines raw ideas into sharp, actionable concepts through structured divergent and convergent thinking. Use when an idea is still vague, when you need to stress-test assumptions before committing to a plan, or when you want to expand options before converging on one. Triggers on "ideate", "refine this idea", or "stress-test my plan".

alfathafp/portofolio-web-design

Guides stable API and interface design. Use when designing APIs, module boundaries, or any public interface. Use when creating REST or GraphQL endpoints, defining type contracts between modules, or establishing boundaries between frontend and backend.

相關技能