universal-dev-standards 4.2.0 → 5.0.0-beta.10
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 +3 -3
- package/bin/uds.js +165 -5
- package/bundled/core/acceptance-test-driven-development.md +19 -721
- package/bundled/core/accessibility-standards.md +862 -0
- package/bundled/core/ai-agreement-standards.md +95 -0
- package/bundled/core/ai-friendly-architecture.md +2 -0
- package/bundled/core/ai-instruction-standards.md +2 -0
- package/bundled/core/anti-hallucination.md +90 -637
- package/bundled/core/behavior-driven-development.md +20 -735
- package/bundled/core/changelog-standards.md +4 -0
- package/bundled/core/checkin-standards.md +21 -4
- package/bundled/core/code-review-checklist.md +3 -0
- package/bundled/core/commit-message-guide.md +14 -3
- package/bundled/core/deployment-standards.md +296 -0
- package/bundled/core/developer-memory.md +568 -0
- package/bundled/core/documentation-structure.md +114 -18
- package/bundled/core/documentation-writing-standards.md +272 -2
- package/bundled/core/error-code-standards.md +3 -0
- package/bundled/core/forward-derivation-standards.md +134 -8
- package/bundled/core/git-workflow.md +72 -686
- package/bundled/core/guides/anti-hallucination-guide.md +517 -0
- package/bundled/core/guides/git-workflow-guide.md +954 -0
- package/bundled/core/guides/performance-guide.md +508 -0
- package/bundled/core/guides/refactoring-guide.md +608 -0
- package/bundled/core/guides/security-guide.md +485 -0
- package/bundled/core/logging-standards.md +337 -2
- package/bundled/core/performance-standards.md +231 -0
- package/bundled/core/project-context-memory.md +180 -0
- package/bundled/core/project-structure.md +315 -2
- package/bundled/core/refactoring-standards.md +81 -761
- package/bundled/core/requirement-engineering.md +39 -0
- package/bundled/core/reverse-engineering-standards.md +6 -4
- package/bundled/core/security-standards.md +244 -0
- package/bundled/core/spec-driven-development.md +20 -319
- package/bundled/core/test-completeness-dimensions.md +213 -11
- package/bundled/core/test-driven-development.md +22 -978
- package/bundled/core/testing-standards.md +222 -2903
- package/bundled/core/versioning.md +16 -55
- package/bundled/core/virtual-organization-standards.md +85 -0
- package/bundled/locales/README.md +4 -4
- package/bundled/locales/zh-CN/CHANGELOG.md +18 -18
- package/bundled/locales/zh-CN/CLAUDE.md +3 -3
- package/bundled/locales/zh-CN/MAINTENANCE.md +7 -7
- package/bundled/locales/zh-CN/README.md +2 -2
- package/bundled/locales/zh-CN/STANDARDS-MAPPING.md +1 -1
- package/bundled/locales/zh-CN/adoption/ADOPTION-GUIDE.md +3 -3
- package/bundled/locales/zh-CN/adoption/DAILY-WORKFLOW-GUIDE.md +66 -7
- package/bundled/locales/zh-CN/adoption/STATIC-DYNAMIC-GUIDE.md +22 -22
- package/bundled/locales/zh-CN/adoption/checklists/enterprise.md +5 -5
- package/bundled/locales/zh-CN/adoption/checklists/minimal.md +4 -4
- package/bundled/locales/zh-CN/adoption/checklists/recommended.md +5 -5
- package/bundled/locales/zh-CN/ai/MAINTENANCE.md +13 -13
- package/bundled/locales/zh-CN/core/ai-instruction-standards.md +1 -1
- package/bundled/locales/zh-CN/core/anti-hallucination.md +39 -3
- package/bundled/locales/zh-CN/core/checkin-standards.md +18 -5
- package/bundled/locales/zh-CN/core/commit-message-guide.md +1 -1
- package/bundled/locales/zh-CN/core/developer-memory.md +576 -0
- package/bundled/locales/zh-CN/core/documentation-structure.md +43 -5
- package/bundled/locales/zh-CN/core/documentation-writing-standards.md +146 -5
- package/bundled/locales/zh-CN/core/git-workflow.md +179 -4
- package/bundled/locales/zh-CN/core/logging-standards.md +177 -4
- package/bundled/locales/zh-CN/core/project-structure.md +117 -5
- package/bundled/locales/zh-CN/core/refactoring-standards.md +3 -3
- package/bundled/locales/zh-CN/core/reverse-engineering-standards.md +6 -6
- package/bundled/locales/zh-CN/core/spec-driven-development.md +516 -14
- package/bundled/locales/zh-CN/core/test-completeness-dimensions.md +155 -24
- package/bundled/locales/zh-CN/core/test-driven-development.md +71 -20
- package/bundled/locales/zh-CN/core/testing-standards.md +4 -4
- package/bundled/locales/zh-CN/core/versioning.md +1 -1
- package/bundled/locales/zh-CN/docs/AI-AGENT-ROADMAP.md +90 -51
- package/bundled/locales/zh-CN/docs/CHEATSHEET.md +184 -0
- package/bundled/locales/zh-CN/docs/CLI-FLOW.md +239 -0
- package/bundled/locales/zh-CN/docs/FEATURE-REFERENCE.md +320 -0
- package/bundled/locales/zh-CN/docs/OPERATION-WORKFLOW.md +43 -43
- package/bundled/locales/zh-CN/docs/STANDARDS-REFERENCE.md +440 -0
- package/bundled/locales/zh-CN/docs/USAGE-MODES-COMPARISON.md +1 -1
- package/bundled/locales/zh-CN/docs/WINDOWS-GUIDE.md +1 -1
- package/bundled/locales/zh-CN/integrations/codex/README.md +3 -3
- package/bundled/locales/zh-CN/integrations/gemini-cli/README.md +3 -3
- package/bundled/locales/zh-CN/integrations/github-copilot/README.md +5 -5
- package/bundled/locales/zh-CN/integrations/github-copilot/copilot-instructions.md +9 -9
- package/bundled/locales/zh-CN/integrations/github-copilot/skills-mapping.md +18 -6
- package/bundled/locales/zh-CN/integrations/google-antigravity/README.md +2 -2
- package/bundled/locales/zh-CN/integrations/opencode/README.md +3 -3
- package/bundled/locales/zh-CN/integrations/opencode/skills-mapping.md +22 -10
- package/bundled/locales/zh-CN/integrations/openspec/README.md +1 -1
- package/bundled/locales/zh-CN/integrations/spec-kit/AGENTS.md +3 -3
- package/bundled/locales/zh-CN/integrations/spec-kit/README.md +1 -1
- package/bundled/locales/zh-CN/options/commit-message/bilingual.md +1 -1
- package/bundled/locales/zh-CN/options/commit-message/english.md +1 -1
- package/bundled/locales/zh-CN/options/commit-message/traditional-chinese.md +1 -1
- package/bundled/locales/zh-CN/options/git-workflow/gitflow.md +1 -1
- package/bundled/locales/zh-CN/options/git-workflow/github-flow.md +1 -1
- package/bundled/locales/zh-CN/options/git-workflow/merge-commit.md +1 -1
- package/bundled/locales/zh-CN/options/git-workflow/rebase-ff.md +1 -1
- package/bundled/locales/zh-CN/options/git-workflow/squash-merge.md +1 -1
- package/bundled/locales/zh-CN/options/git-workflow/trunk-based.md +1 -1
- package/bundled/locales/zh-CN/options/project-structure/dotnet.md +1 -1
- package/bundled/locales/zh-CN/options/project-structure/go.md +1 -1
- package/bundled/locales/zh-CN/options/project-structure/java.md +1 -1
- package/bundled/locales/zh-CN/options/project-structure/nodejs.md +1 -1
- package/bundled/locales/zh-CN/options/project-structure/python.md +1 -1
- package/bundled/locales/zh-CN/options/testing/e2e-testing.md +1 -1
- package/bundled/locales/zh-CN/options/testing/integration-testing.md +1 -1
- package/bundled/locales/zh-CN/options/testing/system-testing.md +1 -1
- package/bundled/locales/zh-CN/options/testing/unit-testing.md +1 -1
- package/bundled/locales/zh-CN/skills/{claude-code/CONTRIBUTING.template.md → CONTRIBUTING.template.md} +2 -2
- package/bundled/locales/zh-CN/skills/README.md +131 -81
- package/bundled/locales/zh-CN/skills/agents/README.md +281 -0
- package/bundled/locales/zh-CN/skills/{claude-code/ai-collaboration-standards → ai-collaboration-standards}/SKILL.md +10 -10
- package/bundled/locales/zh-CN/skills/{claude-code/ai-collaboration-standards → ai-collaboration-standards}/anti-hallucination.md +8 -8
- package/bundled/locales/zh-CN/skills/{claude-code/ai-collaboration-standards → ai-collaboration-standards}/certainty-labels.md +8 -8
- package/bundled/locales/zh-CN/skills/ai-friendly-architecture/SKILL.md +221 -0
- package/bundled/locales/zh-CN/skills/ai-instruction-standards/SKILL.md +214 -0
- package/bundled/locales/zh-CN/skills/atdd-assistant/SKILL.md +71 -0
- package/bundled/locales/zh-CN/skills/atdd-assistant/acceptance-criteria-guide.md +428 -0
- package/bundled/locales/zh-CN/skills/atdd-assistant/atdd-workflow.md +484 -0
- package/bundled/locales/zh-CN/skills/atdd-assistant/guide.md +368 -0
- package/bundled/locales/zh-CN/skills/bdd-assistant/SKILL.md +68 -0
- package/bundled/locales/zh-CN/skills/bdd-assistant/bdd-workflow.md +406 -0
- package/bundled/locales/zh-CN/skills/bdd-assistant/gherkin-guide.md +454 -0
- package/bundled/locales/zh-CN/skills/bdd-assistant/guide.md +324 -0
- package/bundled/locales/zh-CN/skills/changelog-guide/SKILL.md +64 -0
- package/bundled/locales/zh-CN/skills/{claude-code/changelog-guide/SKILL.md → changelog-guide/guide.md} +6 -7
- package/bundled/locales/zh-CN/skills/checkin-assistant/SKILL.md +56 -0
- package/bundled/locales/zh-CN/skills/{claude-code/checkin-assistant/SKILL.md → checkin-assistant/guide.md} +6 -7
- package/bundled/locales/zh-CN/skills/code-review-assistant/SKILL.md +56 -0
- package/bundled/locales/zh-CN/skills/{claude-code/code-review-assistant → code-review-assistant}/checkin-checklist.md +4 -4
- package/bundled/locales/zh-CN/skills/{claude-code/code-review-assistant/SKILL.md → code-review-assistant/guide.md} +5 -6
- package/bundled/locales/zh-CN/skills/{claude-code/code-review-assistant → code-review-assistant}/review-checklist.md +4 -4
- package/bundled/locales/zh-CN/skills/{claude-code/commands → commands}/bdd.md +2 -2
- package/bundled/locales/zh-CN/skills/{claude-code/commands → commands}/methodology.md +3 -3
- package/bundled/locales/zh-CN/skills/{claude-code/commands → commands}/refactor.md +3 -3
- package/bundled/locales/zh-CN/skills/commit-standards/SKILL.md +61 -0
- package/bundled/locales/zh-CN/skills/{claude-code/commit-standards → commit-standards}/conventional-commits.md +4 -4
- package/bundled/locales/zh-CN/skills/{claude-code/commit-standards/SKILL.md → commit-standards/guide.md} +5 -6
- package/bundled/locales/zh-CN/skills/{claude-code/commit-standards → commit-standards}/language-options.md +3 -3
- package/bundled/locales/zh-CN/skills/docs-generator/SKILL.md +59 -0
- package/bundled/locales/zh-CN/skills/docs-generator/guide.md +262 -0
- package/bundled/locales/zh-CN/skills/{claude-code/documentation-guide → documentation-guide}/SKILL.md +7 -8
- package/bundled/locales/zh-CN/skills/{claude-code/documentation-guide → documentation-guide}/documentation-structure.md +4 -4
- package/bundled/locales/zh-CN/skills/{claude-code/documentation-guide → documentation-guide}/readme-template.md +3 -3
- package/bundled/locales/zh-CN/skills/{claude-code/error-code-guide → error-code-guide}/SKILL.md +6 -6
- package/bundled/locales/zh-CN/skills/forward-derivation/SKILL.md +62 -0
- package/bundled/locales/zh-CN/skills/forward-derivation/guide.md +130 -0
- package/bundled/locales/zh-CN/skills/{claude-code/git-workflow-guide → git-workflow-guide}/SKILL.md +6 -6
- package/bundled/locales/zh-CN/skills/{claude-code/git-workflow-guide → git-workflow-guide}/branch-naming.md +3 -3
- package/bundled/locales/zh-CN/skills/{claude-code/git-workflow-guide → git-workflow-guide}/git-workflow.md +4 -4
- package/bundled/locales/zh-CN/skills/{claude-code/logging-guide → logging-guide}/SKILL.md +6 -6
- package/bundled/locales/zh-CN/skills/methodology-system/SKILL.md +78 -0
- package/bundled/locales/zh-CN/skills/{claude-code/methodology-system → methodology-system}/create-methodology.md +2 -2
- package/bundled/locales/zh-CN/skills/{claude-code/methodology-system/SKILL.md → methodology-system/guide.md} +2 -2
- package/bundled/locales/zh-CN/skills/{claude-code/methodology-system → methodology-system}/runtime.md +3 -3
- package/bundled/locales/zh-CN/skills/project-discovery/SKILL.md +66 -0
- package/bundled/locales/zh-CN/skills/project-discovery/guide.md +371 -0
- package/bundled/locales/zh-CN/skills/{claude-code/project-structure-guide → project-structure-guide}/SKILL.md +4 -4
- package/bundled/locales/zh-CN/skills/{claude-code/project-structure-guide → project-structure-guide}/language-patterns.md +1 -1
- package/bundled/locales/zh-CN/skills/refactoring-assistant/SKILL.md +67 -0
- package/bundled/locales/zh-CN/skills/{claude-code/refactoring-assistant/SKILL.md → refactoring-assistant/guide.md} +7 -8
- package/bundled/locales/zh-CN/skills/release-standards/SKILL.md +64 -0
- package/bundled/locales/zh-CN/skills/{claude-code/release-standards → release-standards}/changelog-format.md +3 -3
- package/bundled/locales/zh-CN/skills/{claude-code/release-standards/SKILL.md → release-standards/guide.md} +5 -6
- package/bundled/locales/zh-CN/skills/{claude-code/release-standards → release-standards}/release-workflow.md +7 -7
- package/bundled/locales/zh-CN/skills/{claude-code/release-standards → release-standards}/semantic-versioning.md +3 -3
- package/bundled/locales/zh-CN/skills/requirement-assistant/SKILL.md +67 -0
- package/bundled/locales/zh-CN/skills/{claude-code/requirement-assistant/SKILL.md → requirement-assistant/guide.md} +4 -5
- package/bundled/locales/zh-CN/skills/{claude-code/requirement-assistant → requirement-assistant}/requirement-checklist.md +3 -3
- package/bundled/locales/zh-CN/skills/{claude-code/requirement-assistant → requirement-assistant}/requirement-writing.md +3 -3
- package/bundled/locales/zh-CN/skills/reverse-engineer/SKILL.md +67 -0
- package/bundled/locales/zh-CN/skills/{claude-code/reverse-engineer → reverse-engineer}/bdd-extraction.md +2 -2
- package/bundled/locales/zh-CN/skills/{claude-code/reverse-engineer/SKILL.md → reverse-engineer/guide.md} +17 -18
- package/bundled/locales/zh-CN/skills/{claude-code/reverse-engineer → reverse-engineer}/tdd-analysis.md +2 -2
- package/bundled/locales/zh-CN/skills/{claude-code/reverse-engineer → reverse-engineer}/workflow.md +3 -3
- package/bundled/locales/zh-CN/skills/spec-driven-dev/SKILL.md +75 -0
- package/bundled/locales/zh-CN/skills/{claude-code/spec-driven-dev/SKILL.md → spec-driven-dev/guide.md} +10 -11
- package/bundled/locales/zh-CN/skills/tdd-assistant/SKILL.md +66 -0
- package/bundled/locales/zh-CN/skills/{claude-code/tdd-assistant/SKILL.md → tdd-assistant/guide.md} +12 -16
- package/bundled/locales/zh-CN/skills/{claude-code/tdd-assistant → tdd-assistant}/language-examples.md +3 -3
- package/bundled/locales/zh-CN/skills/{claude-code/tdd-assistant → tdd-assistant}/tdd-workflow.md +3 -3
- package/bundled/locales/zh-CN/skills/test-coverage-assistant/SKILL.md +65 -0
- package/bundled/locales/zh-CN/skills/test-coverage-assistant/guide.md +284 -0
- package/bundled/locales/zh-CN/skills/{claude-code/testing-guide → testing-guide}/SKILL.md +8 -8
- package/bundled/locales/zh-CN/skills/{claude-code/testing-guide → testing-guide}/testing-pyramid.md +4 -4
- package/bundled/locales/zh-CN/skills/{cline → tools/cline}/README.md +1 -1
- package/bundled/locales/zh-CN/skills/{copilot → tools/copilot}/README.md +1 -1
- package/bundled/locales/zh-CN/skills/{copilot → tools/copilot}/copilot-instructions.md +1 -1
- package/bundled/locales/zh-CN/skills/{cursor → tools/cursor}/README.md +1 -1
- package/bundled/locales/zh-CN/skills/{windsurf → tools/windsurf}/README.md +1 -1
- package/bundled/locales/zh-TW/CHANGELOG.md +16 -16
- package/bundled/locales/zh-TW/CLAUDE.md +3 -3
- package/bundled/locales/zh-TW/MAINTENANCE.md +7 -7
- package/bundled/locales/zh-TW/README.md +13 -7
- package/bundled/locales/zh-TW/STANDARDS-MAPPING.md +1 -1
- package/bundled/locales/zh-TW/adoption/ADOPTION-GUIDE.md +4 -4
- package/bundled/locales/zh-TW/adoption/DAILY-WORKFLOW-GUIDE.md +66 -7
- package/bundled/locales/zh-TW/adoption/STATIC-DYNAMIC-GUIDE.md +22 -22
- package/bundled/locales/zh-TW/adoption/checklists/enterprise.md +5 -5
- package/bundled/locales/zh-TW/adoption/checklists/minimal.md +4 -4
- package/bundled/locales/zh-TW/adoption/checklists/recommended.md +5 -5
- package/bundled/locales/zh-TW/ai/MAINTENANCE.md +13 -13
- package/bundled/locales/zh-TW/ai/standards/anti-hallucination.ai.yaml +3 -2
- package/bundled/locales/zh-TW/ai/standards/git-workflow.ai.yaml +4 -3
- package/bundled/locales/zh-TW/ai/standards/spec-driven-development.ai.yaml +3 -3
- package/bundled/locales/zh-TW/ai/standards/testing.ai.yaml +1 -0
- package/bundled/locales/zh-TW/core/ai-instruction-standards.md +1 -1
- package/bundled/locales/zh-TW/core/anti-hallucination.md +38 -701
- package/bundled/locales/zh-TW/core/changelog-standards.md +1 -1
- package/bundled/locales/zh-TW/core/checkin-standards.md +18 -5
- package/bundled/locales/zh-TW/core/code-review-checklist.md +1 -1
- package/bundled/locales/zh-TW/core/commit-message-guide.md +1 -1
- package/bundled/locales/zh-TW/core/developer-memory.md +576 -0
- package/bundled/locales/zh-TW/core/documentation-structure.md +115 -22
- package/bundled/locales/zh-TW/core/documentation-writing-standards.md +126 -5
- package/bundled/locales/zh-TW/core/forward-derivation-standards.md +2 -2
- package/bundled/locales/zh-TW/core/git-workflow.md +38 -812
- package/bundled/locales/zh-TW/core/guides/anti-hallucination-guide.md +779 -0
- package/bundled/locales/zh-TW/core/guides/git-workflow-guide.md +1016 -0
- package/bundled/locales/zh-TW/core/guides/refactoring-guide.md +864 -0
- package/bundled/locales/zh-TW/core/guides/testing-guide.md +2280 -0
- package/bundled/locales/zh-TW/core/logging-standards.md +159 -4
- package/bundled/locales/zh-TW/core/project-structure.md +102 -9
- package/bundled/locales/zh-TW/core/refactoring-standards.md +37 -823
- package/bundled/locales/zh-TW/core/reverse-engineering-standards.md +6 -6
- package/bundled/locales/zh-TW/core/spec-driven-development.md +17 -268
- package/bundled/locales/zh-TW/core/test-completeness-dimensions.md +128 -14
- package/bundled/locales/zh-TW/core/test-driven-development.md +20 -983
- package/bundled/locales/zh-TW/core/testing-standards.md +120 -2105
- package/bundled/locales/zh-TW/core/versioning.md +13 -55
- package/bundled/locales/zh-TW/docs/AI-AGENT-ROADMAP.md +90 -51
- package/bundled/locales/zh-TW/docs/CHEATSHEET.md +184 -0
- package/bundled/locales/zh-TW/docs/CLI-FLOW.md +239 -0
- package/bundled/locales/zh-TW/docs/FEATURE-REFERENCE.md +320 -0
- package/bundled/locales/zh-TW/docs/MIGRATION-V5.md +71 -0
- package/bundled/locales/zh-TW/docs/OPERATION-WORKFLOW.md +42 -42
- package/bundled/locales/zh-TW/docs/STANDARDS-REFERENCE.md +440 -0
- package/bundled/locales/zh-TW/docs/USAGE-MODES-COMPARISON.md +1 -1
- package/bundled/locales/zh-TW/docs/WINDOWS-GUIDE.md +1 -1
- package/bundled/locales/zh-TW/integrations/claude-code/README.md +44 -0
- package/bundled/locales/zh-TW/integrations/github-copilot/copilot-instructions.md +3 -3
- package/bundled/locales/zh-TW/integrations/github-copilot/skills-mapping.md +18 -6
- package/bundled/locales/zh-TW/integrations/opencode/skills-mapping.md +22 -10
- package/bundled/locales/zh-TW/methodologies/guides/sdd-guide.md +338 -0
- package/bundled/locales/zh-TW/methodologies/guides/tdd-guide.md +1055 -0
- package/bundled/locales/zh-TW/options/commit-message/bilingual.md +1 -1
- package/bundled/locales/zh-TW/options/commit-message/english.md +1 -1
- package/bundled/locales/zh-TW/options/commit-message/traditional-chinese.md +1 -1
- package/bundled/locales/zh-TW/options/git-workflow/gitflow.md +1 -1
- package/bundled/locales/zh-TW/options/git-workflow/github-flow.md +1 -1
- package/bundled/locales/zh-TW/options/git-workflow/merge-commit.md +1 -1
- package/bundled/locales/zh-TW/options/git-workflow/rebase-ff.md +1 -1
- package/bundled/locales/zh-TW/options/git-workflow/squash-merge.md +1 -1
- package/bundled/locales/zh-TW/options/git-workflow/trunk-based.md +1 -1
- package/bundled/locales/zh-TW/options/project-structure/dotnet.md +1 -1
- package/bundled/locales/zh-TW/options/project-structure/go.md +1 -1
- package/bundled/locales/zh-TW/options/project-structure/java.md +1 -1
- package/bundled/locales/zh-TW/options/project-structure/nodejs.md +1 -1
- package/bundled/locales/zh-TW/options/project-structure/python.md +1 -1
- package/bundled/locales/zh-TW/options/testing/e2e-testing.md +1 -1
- package/bundled/locales/zh-TW/options/testing/integration-testing.md +1 -1
- package/bundled/locales/zh-TW/options/testing/system-testing.md +1 -1
- package/bundled/locales/zh-TW/options/testing/unit-testing.md +1 -1
- package/bundled/locales/zh-TW/skills/{claude-code/CONTRIBUTING.template.md → CONTRIBUTING.template.md} +2 -2
- package/bundled/locales/zh-TW/skills/README.md +131 -79
- package/bundled/locales/zh-TW/skills/agents/README.md +281 -0
- package/bundled/locales/zh-TW/skills/{claude-code/ai-collaboration-standards → ai-collaboration-standards}/SKILL.md +7 -7
- package/bundled/locales/zh-TW/skills/{claude-code/ai-collaboration-standards → ai-collaboration-standards}/anti-hallucination.md +8 -8
- package/bundled/locales/zh-TW/skills/{claude-code/ai-collaboration-standards → ai-collaboration-standards}/certainty-labels.md +8 -8
- package/bundled/locales/zh-TW/skills/ai-friendly-architecture/SKILL.md +221 -0
- package/bundled/locales/zh-TW/skills/ai-instruction-standards/SKILL.md +214 -0
- package/bundled/locales/zh-TW/skills/atdd-assistant/SKILL.md +71 -0
- package/bundled/locales/zh-TW/skills/atdd-assistant/acceptance-criteria-guide.md +428 -0
- package/bundled/locales/zh-TW/skills/atdd-assistant/atdd-workflow.md +484 -0
- package/bundled/locales/zh-TW/skills/atdd-assistant/guide.md +368 -0
- package/bundled/locales/zh-TW/skills/bdd-assistant/SKILL.md +68 -0
- package/bundled/locales/zh-TW/skills/bdd-assistant/bdd-workflow.md +406 -0
- package/bundled/locales/zh-TW/skills/bdd-assistant/gherkin-guide.md +454 -0
- package/bundled/locales/zh-TW/skills/bdd-assistant/guide.md +324 -0
- package/bundled/locales/zh-TW/skills/changelog-guide/SKILL.md +64 -0
- package/bundled/locales/zh-TW/skills/{claude-code/changelog-guide/SKILL.md → changelog-guide/guide.md} +6 -7
- package/bundled/locales/zh-TW/skills/checkin-assistant/SKILL.md +56 -0
- package/bundled/locales/zh-TW/skills/{claude-code/checkin-assistant/SKILL.md → checkin-assistant/guide.md} +6 -7
- package/bundled/locales/zh-TW/skills/code-review-assistant/SKILL.md +56 -0
- package/bundled/locales/zh-TW/skills/{claude-code/code-review-assistant → code-review-assistant}/checkin-checklist.md +4 -4
- package/bundled/locales/zh-TW/skills/{claude-code/code-review-assistant/SKILL.md → code-review-assistant/guide.md} +2 -3
- package/bundled/locales/zh-TW/skills/{claude-code/code-review-assistant → code-review-assistant}/review-checklist.md +4 -4
- package/bundled/locales/zh-TW/skills/{claude-code/commands → commands}/bdd.md +2 -2
- package/bundled/locales/zh-TW/skills/{claude-code/commands → commands}/methodology.md +3 -3
- package/bundled/locales/zh-TW/skills/{claude-code/commands → commands}/refactor.md +3 -3
- package/bundled/locales/zh-TW/skills/commit-standards/SKILL.md +61 -0
- package/bundled/locales/zh-TW/skills/{claude-code/commit-standards → commit-standards}/conventional-commits.md +4 -4
- package/bundled/locales/zh-TW/skills/{claude-code/commit-standards/SKILL.md → commit-standards/guide.md} +5 -6
- package/bundled/locales/zh-TW/skills/{claude-code/commit-standards → commit-standards}/language-options.md +3 -3
- package/bundled/locales/zh-TW/skills/docs-generator/SKILL.md +59 -0
- package/bundled/locales/zh-TW/skills/docs-generator/guide.md +262 -0
- package/bundled/locales/zh-TW/skills/{claude-code/documentation-guide → documentation-guide}/SKILL.md +7 -8
- package/bundled/locales/zh-TW/skills/{claude-code/documentation-guide → documentation-guide}/documentation-structure.md +4 -4
- package/bundled/locales/zh-TW/skills/{claude-code/documentation-guide → documentation-guide}/readme-template.md +3 -3
- package/bundled/locales/zh-TW/skills/{claude-code/error-code-guide → error-code-guide}/SKILL.md +6 -6
- package/bundled/locales/zh-TW/skills/forward-derivation/SKILL.md +62 -0
- package/bundled/locales/zh-TW/skills/{claude-code/forward-derivation/SKILL.md → forward-derivation/guide.md} +24 -19
- package/bundled/locales/zh-TW/skills/{claude-code/git-workflow-guide → git-workflow-guide}/SKILL.md +3 -3
- package/bundled/locales/zh-TW/skills/{claude-code/git-workflow-guide → git-workflow-guide}/branch-naming.md +3 -3
- package/bundled/locales/zh-TW/skills/{claude-code/git-workflow-guide → git-workflow-guide}/git-workflow.md +4 -4
- package/bundled/locales/zh-TW/skills/{claude-code/logging-guide → logging-guide}/SKILL.md +6 -6
- package/bundled/locales/zh-TW/skills/methodology-system/SKILL.md +78 -0
- package/bundled/locales/zh-TW/skills/{claude-code/methodology-system → methodology-system}/create-methodology.md +2 -2
- package/bundled/locales/zh-TW/skills/{claude-code/methodology-system/SKILL.md → methodology-system/guide.md} +2 -2
- package/bundled/locales/zh-TW/skills/{claude-code/methodology-system → methodology-system}/runtime.md +3 -3
- package/bundled/locales/zh-TW/skills/project-discovery/SKILL.md +66 -0
- package/bundled/locales/zh-TW/skills/project-discovery/guide.md +371 -0
- package/bundled/locales/zh-TW/skills/project-discovery/workflow.md +574 -0
- package/bundled/locales/zh-TW/skills/{claude-code/project-structure-guide → project-structure-guide}/SKILL.md +4 -4
- package/bundled/locales/zh-TW/skills/{claude-code/project-structure-guide → project-structure-guide}/language-patterns.md +1 -1
- package/bundled/locales/zh-TW/skills/refactoring-assistant/SKILL.md +67 -0
- package/bundled/locales/zh-TW/skills/{claude-code/refactoring-assistant/SKILL.md → refactoring-assistant/guide.md} +7 -8
- package/bundled/locales/zh-TW/skills/release-standards/SKILL.md +64 -0
- package/bundled/locales/zh-TW/skills/{claude-code/release-standards → release-standards}/changelog-format.md +3 -3
- package/bundled/locales/zh-TW/skills/{claude-code/release-standards/SKILL.md → release-standards/guide.md} +2 -3
- package/bundled/locales/zh-TW/skills/{claude-code/release-standards → release-standards}/release-workflow.md +60 -28
- package/bundled/locales/zh-TW/skills/{claude-code/release-standards → release-standards}/semantic-versioning.md +3 -3
- package/bundled/locales/zh-TW/skills/requirement-assistant/SKILL.md +67 -0
- package/bundled/locales/zh-TW/skills/{claude-code/requirement-assistant/SKILL.md → requirement-assistant/guide.md} +2 -3
- package/bundled/locales/zh-TW/skills/{claude-code/requirement-assistant → requirement-assistant}/requirement-checklist.md +3 -3
- package/bundled/locales/zh-TW/skills/{claude-code/requirement-assistant → requirement-assistant}/requirement-writing.md +3 -3
- package/bundled/locales/zh-TW/skills/reverse-engineer/SKILL.md +67 -0
- package/bundled/locales/zh-TW/skills/{claude-code/reverse-engineer → reverse-engineer}/bdd-extraction.md +2 -2
- package/bundled/locales/zh-TW/skills/{claude-code/reverse-engineer/SKILL.md → reverse-engineer/guide.md} +17 -18
- package/bundled/locales/zh-TW/skills/{claude-code/reverse-engineer → reverse-engineer}/tdd-analysis.md +2 -2
- package/bundled/locales/zh-TW/skills/{claude-code/reverse-engineer → reverse-engineer}/workflow.md +3 -3
- package/bundled/locales/zh-TW/skills/spec-driven-dev/SKILL.md +75 -0
- package/bundled/locales/zh-TW/skills/{claude-code/spec-driven-dev/SKILL.md → spec-driven-dev/guide.md} +9 -10
- package/bundled/locales/zh-TW/skills/tdd-assistant/SKILL.md +66 -0
- package/bundled/locales/zh-TW/skills/{claude-code/tdd-assistant/SKILL.md → tdd-assistant/guide.md} +9 -10
- package/bundled/locales/zh-TW/skills/{claude-code/tdd-assistant → tdd-assistant}/language-examples.md +3 -3
- package/bundled/locales/zh-TW/skills/{claude-code/tdd-assistant → tdd-assistant}/tdd-workflow.md +3 -3
- package/bundled/locales/zh-TW/skills/test-coverage-assistant/SKILL.md +65 -0
- package/bundled/locales/zh-TW/skills/{claude-code/test-coverage-assistant/SKILL.md → test-coverage-assistant/guide.md} +27 -24
- package/bundled/locales/zh-TW/skills/{claude-code/testing-guide → testing-guide}/SKILL.md +6 -6
- package/bundled/locales/zh-TW/skills/{claude-code/testing-guide → testing-guide}/testing-pyramid.md +4 -4
- package/bundled/locales/zh-TW/skills/{cline → tools/cline}/README.md +1 -1
- package/bundled/locales/zh-TW/skills/{copilot → tools/copilot}/README.md +1 -1
- package/bundled/locales/zh-TW/skills/{copilot → tools/copilot}/copilot-instructions.md +1 -1
- package/bundled/locales/zh-TW/skills/{cursor → tools/cursor}/README.md +1 -1
- package/bundled/locales/zh-TW/skills/{windsurf → tools/windsurf}/README.md +1 -1
- package/bundled/skills/INTEGRATION-GUIDE.md +210 -0
- package/bundled/skills/README.md +95 -0
- package/bundled/skills/_shared/README.md +60 -0
- package/bundled/skills/{claude-code/agents → agents}/README.md +2 -2
- package/bundled/skills/{claude-code/agents → agents}/code-architect.md +1 -1
- package/bundled/skills/{claude-code/agents → agents}/doc-writer.md +1 -1
- package/bundled/skills/{claude-code/agents → agents}/reviewer.md +1 -1
- package/bundled/skills/{claude-code/agents → agents}/spec-analyst.md +1 -1
- package/bundled/skills/{claude-code/agents → agents}/test-specialist.md +1 -1
- package/bundled/skills/{claude-code/ai-collaboration-standards → ai-collaboration-standards}/SKILL.md +28 -5
- package/bundled/skills/{claude-code/ai-collaboration-standards → ai-collaboration-standards}/anti-hallucination.md +24 -5
- package/bundled/skills/{claude-code/ai-collaboration-standards → ai-collaboration-standards}/certainty-labels.md +31 -6
- package/bundled/skills/ai-friendly-architecture/SKILL.md +216 -0
- package/bundled/skills/ai-instruction-standards/SKILL.md +209 -0
- package/bundled/skills/atdd-assistant/SKILL.md +74 -0
- package/bundled/skills/{claude-code/atdd-assistant → atdd-assistant}/acceptance-criteria-guide.md +1 -1
- package/bundled/skills/{claude-code/atdd-assistant → atdd-assistant}/atdd-workflow.md +1 -1
- package/bundled/skills/{claude-code/atdd-assistant/SKILL.md → atdd-assistant/guide.md} +11 -11
- package/bundled/skills/bdd-assistant/SKILL.md +70 -0
- package/bundled/skills/{claude-code/bdd-assistant → bdd-assistant}/bdd-workflow.md +1 -1
- package/bundled/skills/{claude-code/bdd-assistant → bdd-assistant}/gherkin-guide.md +1 -1
- package/bundled/skills/{claude-code/bdd-assistant/SKILL.md → bdd-assistant/guide.md} +11 -11
- package/bundled/skills/changelog-guide/SKILL.md +66 -0
- package/bundled/skills/{claude-code/changelog-guide/SKILL.md → changelog-guide/guide.md} +8 -6
- package/bundled/skills/checkin-assistant/SKILL.md +52 -0
- package/bundled/skills/{claude-code/checkin-assistant/SKILL.md → checkin-assistant/guide.md} +6 -6
- package/bundled/skills/code-review-assistant/SKILL.md +53 -0
- package/bundled/skills/{claude-code/code-review-assistant → code-review-assistant}/checkin-checklist.md +3 -3
- package/bundled/skills/{claude-code/code-review-assistant/SKILL.md → code-review-assistant/guide.md} +7 -5
- package/bundled/skills/{claude-code/code-review-assistant → code-review-assistant}/review-checklist.md +3 -3
- package/bundled/skills/commands/COMMAND-FAMILY-OVERVIEW.md +290 -0
- package/bundled/skills/{claude-code/commands → commands}/README.md +13 -3
- package/bundled/skills/{claude-code/commands → commands}/atdd.md +3 -3
- package/bundled/skills/{claude-code/commands → commands}/bdd.md +2 -2
- package/bundled/skills/commands/changelog.md +58 -0
- package/bundled/skills/{claude-code/commands → commands}/check.md +1 -1
- package/bundled/skills/commands/checkin.md +53 -0
- package/bundled/skills/{claude-code/commands → commands}/commit.md +3 -3
- package/bundled/skills/{claude-code/commands → commands}/config.md +1 -1
- package/bundled/skills/{claude-code/commands → commands}/coverage.md +5 -4
- package/bundled/skills/commands/derive-all.md +53 -0
- package/bundled/skills/commands/derive-atdd.md +49 -0
- package/bundled/skills/commands/derive-bdd.md +47 -0
- package/bundled/skills/commands/derive-tdd.md +48 -0
- package/bundled/skills/commands/derive.md +72 -0
- package/bundled/skills/commands/discover.md +80 -0
- package/bundled/skills/commands/docgen.md +61 -0
- package/bundled/skills/commands/docs.md +59 -0
- package/bundled/skills/commands/guide.md +44 -0
- package/bundled/skills/{claude-code/commands → commands}/init.md +2 -2
- package/bundled/skills/{claude-code/commands → commands}/methodology.md +32 -16
- package/bundled/skills/{claude-code/commands → commands}/refactor.md +2 -2
- package/bundled/skills/commands/release.md +56 -0
- package/bundled/skills/{claude-code/commands → commands}/requirement.md +3 -3
- package/bundled/skills/commands/reverse-bdd.md +47 -0
- package/bundled/skills/commands/reverse-sdd.md +51 -0
- package/bundled/skills/commands/reverse-tdd.md +51 -0
- package/bundled/skills/commands/reverse.md +63 -0
- package/bundled/skills/{claude-code/commands → commands}/review.md +3 -3
- package/bundled/skills/commands/sdd.md +135 -0
- package/bundled/skills/{claude-code/commands → commands}/tdd.md +3 -3
- package/bundled/skills/{claude-code/commands → commands}/update.md +2 -2
- package/bundled/skills/commit-standards/SKILL.md +60 -0
- package/bundled/skills/{claude-code/commit-standards → commit-standards}/conventional-commits.md +3 -3
- package/bundled/skills/{claude-code/commit-standards/SKILL.md → commit-standards/guide.md} +17 -5
- package/bundled/skills/{claude-code/commit-standards → commit-standards}/language-options.md +2 -2
- package/bundled/skills/docs-generator/SKILL.md +69 -0
- package/bundled/skills/docs-generator/guide.md +258 -0
- package/bundled/skills/{claude-code/documentation-guide → documentation-guide}/SKILL.md +7 -7
- package/bundled/skills/{claude-code/documentation-guide → documentation-guide}/documentation-structure.md +3 -3
- package/bundled/skills/{claude-code/documentation-guide → documentation-guide}/readme-template.md +2 -2
- package/bundled/skills/{claude-code/error-code-guide → error-code-guide}/SKILL.md +7 -5
- package/bundled/skills/forward-derivation/SKILL.md +61 -0
- package/bundled/skills/{claude-code/forward-derivation/SKILL.md → forward-derivation/guide.md} +44 -29
- package/bundled/skills/{claude-code/git-workflow-guide → git-workflow-guide}/SKILL.md +7 -5
- package/bundled/skills/{claude-code/git-workflow-guide → git-workflow-guide}/branch-naming.md +2 -2
- package/bundled/skills/{claude-code/git-workflow-guide → git-workflow-guide}/git-workflow.md +3 -3
- package/bundled/skills/{claude-code/logging-guide → logging-guide}/SKILL.md +7 -5
- package/bundled/skills/methodology-system/SKILL.md +75 -0
- package/bundled/skills/{claude-code/methodology-system → methodology-system}/create-methodology.md +1 -1
- package/bundled/skills/{claude-code/methodology-system/SKILL.md → methodology-system/guide.md} +51 -16
- package/bundled/skills/methodology-system/integrated-flow.md +454 -0
- package/bundled/skills/{claude-code/methodology-system → methodology-system}/runtime.md +2 -2
- package/bundled/skills/project-discovery/SKILL.md +63 -0
- package/bundled/skills/project-discovery/guide.md +367 -0
- package/bundled/skills/project-discovery/workflow.md +566 -0
- package/bundled/skills/{claude-code/project-structure-guide → project-structure-guide}/SKILL.md +14 -4
- package/bundled/skills/refactoring-assistant/SKILL.md +78 -0
- package/bundled/skills/{claude-code/refactoring-assistant/SKILL.md → refactoring-assistant/guide.md} +7 -7
- package/bundled/skills/release-standards/SKILL.md +61 -0
- package/bundled/skills/{claude-code/release-standards → release-standards}/changelog-format.md +2 -2
- package/bundled/skills/{claude-code/release-standards/SKILL.md → release-standards/guide.md} +7 -5
- package/bundled/skills/{claude-code/release-standards → release-standards}/release-workflow.md +59 -24
- package/bundled/skills/{claude-code/release-standards → release-standards}/semantic-versioning.md +2 -2
- package/bundled/skills/requirement-assistant/SKILL.md +66 -0
- package/bundled/skills/{claude-code/requirement-assistant/SKILL.md → requirement-assistant/guide.md} +14 -6
- package/bundled/skills/{claude-code/requirement-assistant → requirement-assistant}/requirement-checklist.md +2 -2
- package/bundled/skills/{claude-code/requirement-assistant → requirement-assistant}/requirement-writing.md +2 -2
- package/bundled/skills/reverse-engineer/SKILL.md +64 -0
- package/bundled/skills/{claude-code/reverse-engineer → reverse-engineer}/bdd-extraction.md +1 -1
- package/bundled/skills/{claude-code/reverse-engineer/SKILL.md → reverse-engineer/guide.md} +21 -18
- package/bundled/skills/{claude-code/reverse-engineer → reverse-engineer}/tdd-analysis.md +1 -1
- package/bundled/skills/{claude-code/reverse-engineer → reverse-engineer}/workflow.md +2 -2
- package/bundled/skills/spec-driven-dev/SKILL.md +80 -0
- package/bundled/skills/{claude-code/spec-driven-dev/SKILL.md → spec-driven-dev/guide.md} +50 -8
- package/bundled/skills/tdd-assistant/SKILL.md +65 -0
- package/bundled/skills/{claude-code/tdd-assistant/SKILL.md → tdd-assistant/guide.md} +10 -10
- package/bundled/skills/{claude-code/tdd-assistant → tdd-assistant}/language-examples.md +3 -3
- package/bundled/skills/{claude-code/tdd-assistant → tdd-assistant}/tdd-workflow.md +2 -2
- package/bundled/skills/test-coverage-assistant/SKILL.md +63 -0
- package/bundled/skills/{claude-code/test-coverage-assistant/SKILL.md → test-coverage-assistant/guide.md} +39 -24
- package/bundled/skills/{claude-code/testing-guide → testing-guide}/SKILL.md +12 -7
- package/bundled/skills/{claude-code/testing-guide → testing-guide}/testing-pyramid.md +3 -3
- package/bundled/skills/testing-guide/testing-theory.md +2291 -0
- package/bundled/skills/tools/cline/.clinerules +79 -0
- package/bundled/skills/tools/cline/README.md +50 -0
- package/bundled/skills/tools/copilot/README.md +99 -0
- package/bundled/skills/tools/copilot/copilot-instructions.md +71 -0
- package/bundled/skills/tools/cursor/.cursorrules +101 -0
- package/bundled/skills/tools/cursor/README.md +50 -0
- package/bundled/skills/tools/windsurf/.windsurfrules +76 -0
- package/bundled/skills/tools/windsurf/README.md +51 -0
- package/bundled/skills/{claude-code/workflows → workflows}/README.md +1 -1
- package/bundled/skills/workflows/release.workflow.yaml +893 -0
- package/package.json +4 -1
- package/src/commands/check.js +195 -130
- package/src/commands/config.js +1262 -0
- package/src/commands/configure.js +3 -950
- package/src/commands/fix.js +53 -0
- package/src/commands/hitl.js +19 -0
- package/src/commands/init.js +320 -1030
- package/src/commands/list.js +1 -1
- package/src/commands/simulate.js +61 -0
- package/src/commands/spec.js +288 -0
- package/src/commands/start.js +373 -0
- package/src/commands/sweep.js +142 -0
- package/src/commands/update.js +136 -19
- package/src/commands/workflow.js +265 -1
- package/src/config/ai-agent-paths.js +89 -29
- package/src/core/constants.js +7 -1
- package/src/core/manifest.js +1 -0
- package/src/flows/init-flow.js +243 -0
- package/src/hitl/checkpoint.js +80 -0
- package/src/hitl/classifier.js +54 -0
- package/src/hitl/manager.js +88 -0
- package/src/i18n/messages.js +907 -99
- package/src/index.js +1 -0
- package/src/installers/integration-installer.js +237 -0
- package/src/installers/manifest-installer.js +131 -0
- package/src/installers/skills-installer.js +286 -0
- package/src/installers/standards-installer.js +193 -0
- package/src/missions/MissionManager.js +501 -0
- package/src/prompts/init.js +228 -130
- package/src/prompts/integrations.js +13 -1
- package/src/schemas/standard.schema.json +117 -0
- package/src/utils/agents-installer.js +2 -2
- package/src/utils/config-loader.js +47 -0
- package/src/utils/config-manager.js +108 -0
- package/src/utils/config-merger.js +47 -0
- package/src/utils/github.js +22 -18
- package/src/utils/inquirer-patch.js +98 -0
- package/src/utils/integration-generator.js +392 -58
- package/src/utils/reference-sync.js +69 -19
- package/src/utils/skills-installer.js +6 -3
- package/src/utils/standard-fixer.js +141 -0
- package/src/utils/standard-validator.js +329 -0
- package/src/utils/workflow-executor.js +886 -0
- package/src/utils/workflow-state.js +404 -0
- package/src/utils/workflows-installer.js +2 -2
- package/src/vibe/auto-sweep.js +349 -0
- package/src/vibe/micro-spec.js +428 -0
- package/standards-registry.json +278 -102
- package/bundled/locales/zh-CN/skills/claude-code/README.md +0 -174
- package/bundled/locales/zh-CN/skills/claude-code/test-coverage-assistant/SKILL.md +0 -282
- package/bundled/locales/zh-TW/skills/claude-code/README.md +0 -174
- package/bundled/skills/claude-code/README.md +0 -215
- package/bundled/skills/claude-code/commands/changelog.md +0 -57
- package/bundled/skills/claude-code/commands/derive-all.md +0 -214
- package/bundled/skills/claude-code/commands/derive-atdd.md +0 -177
- package/bundled/skills/claude-code/commands/derive-bdd.md +0 -158
- package/bundled/skills/claude-code/commands/derive-tdd.md +0 -259
- package/bundled/skills/claude-code/commands/docs.md +0 -75
- package/bundled/skills/claude-code/commands/release.md +0 -50
- package/bundled/skills/claude-code/commands/reverse-bdd.md +0 -264
- package/bundled/skills/claude-code/commands/reverse-spec.md +0 -185
- package/bundled/skills/claude-code/commands/reverse-tdd.md +0 -351
- package/bundled/skills/claude-code/commands/spec.md +0 -69
- package/bundled/skills/claude-code/methodology-system/integrated-flow.md +0 -322
- /package/bundled/skills/{claude-code/CONTRIBUTING.template.md → CONTRIBUTING.template.md} +0 -0
- /package/bundled/skills/{claude-code/ai → ai}/standards/checkin.ai.yaml +0 -0
- /package/bundled/skills/{claude-code/ai → ai}/standards/commit.ai.yaml +0 -0
- /package/bundled/skills/{claude-code/ai → ai}/standards/refactoring.ai.yaml +0 -0
- /package/bundled/skills/{claude-code/ai → ai}/standards/testing.ai.yaml +0 -0
- /package/bundled/skills/{claude-code/project-structure-guide → project-structure-guide}/language-patterns.md +0 -0
- /package/bundled/skills/{claude-code/workflows → workflows}/code-review.workflow.yaml +0 -0
- /package/bundled/skills/{claude-code/workflows → workflows}/feature-dev.workflow.yaml +0 -0
- /package/bundled/skills/{claude-code/workflows → workflows}/integrated-flow.workflow.yaml +0 -0
- /package/bundled/skills/{claude-code/workflows → workflows}/large-codebase-analysis.workflow.yaml +0 -0
|
@@ -0,0 +1,864 @@
|
|
|
1
|
+
---
|
|
2
|
+
source: ../../core/refactoring-standards.md
|
|
3
|
+
source_version: 2.0.0
|
|
4
|
+
translation_version: 2.0.0
|
|
5
|
+
last_synced: 2026-01-21
|
|
6
|
+
status: current
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
# 重構標準
|
|
10
|
+
|
|
11
|
+
> **語言**: [English](../../../../core/refactoring-standards.md) | 繁體中文
|
|
12
|
+
|
|
13
|
+
**版本**: 2.0.0
|
|
14
|
+
**最後更新**: 2026-01-21
|
|
15
|
+
**適用範圍**: 所有進行程式碼改善的軟體專案
|
|
16
|
+
|
|
17
|
+
---
|
|
18
|
+
|
|
19
|
+
## 目的
|
|
20
|
+
|
|
21
|
+
本標準定義程式碼重構的完整指引,涵蓋從日常 TDD 重構循環到大型遺留系統現代化的所有場景。確保重構工作安全、可衡量,並與業務目標一致。
|
|
22
|
+
|
|
23
|
+
**主要優點**:
|
|
24
|
+
- 系統化的程式碼品質改善方法
|
|
25
|
+
- 降低重構過程中引入錯誤的風險
|
|
26
|
+
- 清晰的重構 vs 重寫決策框架
|
|
27
|
+
- 可衡量的成果與投資報酬率追蹤
|
|
28
|
+
|
|
29
|
+
---
|
|
30
|
+
|
|
31
|
+
## 目錄
|
|
32
|
+
|
|
33
|
+
1. [重構 vs 重寫決策矩陣](#重構-vs-重寫決策矩陣)
|
|
34
|
+
2. [戰術性重構策略](#戰術性重構策略)
|
|
35
|
+
- [預備性重構](#預備性重構)
|
|
36
|
+
- [童子軍規則](#童子軍規則)
|
|
37
|
+
- [紅-綠-重構](#紅-綠-重構)
|
|
38
|
+
3. [戰略性重構策略](#戰略性重構策略)
|
|
39
|
+
- [絞殺榕模式](#絞殺榕模式)
|
|
40
|
+
- [防腐層](#防腐層)
|
|
41
|
+
- [抽象分支](#抽象分支)
|
|
42
|
+
- [平行變更](#平行變更expand-migrate-contract)
|
|
43
|
+
4. [遺留程式碼安全策略](#遺留程式碼安全策略)
|
|
44
|
+
- [特徵測試](#特徵測試)
|
|
45
|
+
- [探針式重構](#探針式重構)
|
|
46
|
+
- [尋找接縫](#尋找接縫)
|
|
47
|
+
- [Sprout 與 Wrap 技術](#sprout-與-wrap-技術)
|
|
48
|
+
5. [資料庫重構](#資料庫重構)
|
|
49
|
+
6. [安全重構工作流程](#安全重構工作流程)
|
|
50
|
+
7. [重構度量指標](#重構度量指標)
|
|
51
|
+
8. [團隊協作](#團隊協作)
|
|
52
|
+
9. [技術債管理](#技術債管理)
|
|
53
|
+
10. [決策矩陣摘要](#決策矩陣摘要)
|
|
54
|
+
11. [相關標準](#相關標準)
|
|
55
|
+
12. [參考資料](#參考資料)
|
|
56
|
+
13. [版本歷程](#版本歷程)
|
|
57
|
+
|
|
58
|
+
---
|
|
59
|
+
|
|
60
|
+
## 重構 vs 重寫決策矩陣
|
|
61
|
+
|
|
62
|
+
在開始任何大型重構工作之前,評估重構或重寫哪個更合適。
|
|
63
|
+
|
|
64
|
+
### 決策流程圖
|
|
65
|
+
|
|
66
|
+
```
|
|
67
|
+
┌─────────────────────────────────────────────────────────────────┐
|
|
68
|
+
│ 重構 vs 重寫決策樹 │
|
|
69
|
+
├─────────────────────────────────────────────────────────────────┤
|
|
70
|
+
│ │
|
|
71
|
+
│ 程式碼目前在生產環境運行嗎? │
|
|
72
|
+
│ ├─ 否 → 考慮重寫(風險較低) │
|
|
73
|
+
│ └─ 是 ↓ │
|
|
74
|
+
│ │
|
|
75
|
+
│ 你了解程式碼在做什麼嗎? │
|
|
76
|
+
│ ├─ 否 → 先寫特徵測試,再決定 │
|
|
77
|
+
│ └─ 是 ↓ │
|
|
78
|
+
│ │
|
|
79
|
+
│ 測試覆蓋率足夠嗎(>60%)? │
|
|
80
|
+
│ ├─ 否 → 先補測試,再決定 │
|
|
81
|
+
│ └─ 是 ↓ │
|
|
82
|
+
│ │
|
|
83
|
+
│ 核心架構可以保留嗎? │
|
|
84
|
+
│ ├─ 否 → Strangler Fig(漸進替換) │
|
|
85
|
+
│ └─ 是 → 漸進式重構 ✓ │
|
|
86
|
+
│ │
|
|
87
|
+
└─────────────────────────────────────────────────────────────────┘
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
### 比較矩陣
|
|
91
|
+
|
|
92
|
+
| 因素 | 傾向重構 | 傾向重寫 |
|
|
93
|
+
|------|---------|---------|
|
|
94
|
+
| **程式碼規模** | 大型、複雜 | 小型、獨立 |
|
|
95
|
+
| **測試覆蓋率** | 良好(>60%)| 差或沒有 |
|
|
96
|
+
| **業務連續性** | 關鍵 | 可容忍停機 |
|
|
97
|
+
| **團隊知識** | 團隊理解程式碼 | 無組織知識 |
|
|
98
|
+
| **核心架構** | 健全,只是混亂 | 根本性缺陷 |
|
|
99
|
+
| **時間壓力** | 緊迫期限 | 彈性時間 |
|
|
100
|
+
| **風險容忍度** | 低 | 較高 |
|
|
101
|
+
|
|
102
|
+
### 警告:第二系統效應
|
|
103
|
+
|
|
104
|
+
> 「第二個系統是一個人設計過最危險的系統。」— Fred Brooks
|
|
105
|
+
|
|
106
|
+
重寫時,團隊常常過度工程化。避免:
|
|
107
|
+
- 新增原本沒有的功能
|
|
108
|
+
- 「為了未來彈性」過度抽象
|
|
109
|
+
- 忽視現有系統的教訓
|
|
110
|
+
|
|
111
|
+
---
|
|
112
|
+
|
|
113
|
+
## 戰術性重構策略
|
|
114
|
+
|
|
115
|
+
戰術性策略用於日常開發工作。運作時間為分鐘到小時級別,需要最小的協調。
|
|
116
|
+
|
|
117
|
+
### 預備性重構
|
|
118
|
+
|
|
119
|
+
**定義**:在新增功能之前,先調整既有結構,使其易於接納新功能。
|
|
120
|
+
|
|
121
|
+
> 「先把改變變容易(這可能很難),然後再做那個容易的改變。」— Kent Beck
|
|
122
|
+
|
|
123
|
+
**適用情境**:
|
|
124
|
+
- 現有架構難以直接插入新功能
|
|
125
|
+
- 程式碼結構需要調整以支援新需求
|
|
126
|
+
- 降低即將到來的變更的阻力
|
|
127
|
+
|
|
128
|
+
**工作流程**:
|
|
129
|
+
|
|
130
|
+
```
|
|
131
|
+
1. 識別你想要做的改變
|
|
132
|
+
2. 識別是什麼讓這個改變變困難
|
|
133
|
+
3. 重構以讓改變變容易
|
|
134
|
+
4. 做那個(現在已經變容易的)改變
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
**範例**:
|
|
138
|
+
- 改變前:為一個緊耦合的服務加入快取很複雜
|
|
139
|
+
- 預備性重構:抽取介面、注入依賴
|
|
140
|
+
- 改變後:加入快取變得簡單直接
|
|
141
|
+
|
|
142
|
+
**關鍵原則**:
|
|
143
|
+
- 預備性重構是與功能分開的提交
|
|
144
|
+
- 每一步都維持測試通過
|
|
145
|
+
- 不要在同一個提交中混合重構與功能開發
|
|
146
|
+
|
|
147
|
+
### 童子軍規則
|
|
148
|
+
|
|
149
|
+
**定義**:離開時讓程式碼比你來的時候更乾淨。這是一種「機會主義重構」— 不刻意安排重構衝刺,而是在修復 Bug 或新增功能時,順手清理所接觸到的程式碼。
|
|
150
|
+
|
|
151
|
+
> 「離開營地時,讓它比你來的時候更乾淨。」— Robert C. Martin
|
|
152
|
+
|
|
153
|
+
**適用情境**:
|
|
154
|
+
- 任何維護作業
|
|
155
|
+
- Bug 修復
|
|
156
|
+
- 功能新增
|
|
157
|
+
- 對抗軟體熵(Software Entropy)
|
|
158
|
+
|
|
159
|
+
**指導原則**:
|
|
160
|
+
- 只做小改進(分鐘,不是小時)
|
|
161
|
+
- 不可改變行為
|
|
162
|
+
- 不可破壞現有測試
|
|
163
|
+
- 改動範圍保持在你的任務內
|
|
164
|
+
|
|
165
|
+
**童子軍改進的範例**:
|
|
166
|
+
- 重新命名一個令人困惑的變數
|
|
167
|
+
- 將幾行程式碼提取為命名良好的方法
|
|
168
|
+
- 移除你注意到的死程式碼
|
|
169
|
+
- 加入澄清註解
|
|
170
|
+
- 修復一個小的程式碼風格問題
|
|
171
|
+
|
|
172
|
+
**應避免的反模式**:
|
|
173
|
+
- 把 Bug 修復變成大規模重構專案
|
|
174
|
+
- 重構不相關的程式碼
|
|
175
|
+
- 在沒有測試覆蓋的情況下修改
|
|
176
|
+
- 範圍蔓延超出原始任務
|
|
177
|
+
|
|
178
|
+
### 紅-綠-重構
|
|
179
|
+
|
|
180
|
+
測試驅動開發(TDD)循環的一部分。完整細節請見[測試驅動開發](../test-driven-development.md)。
|
|
181
|
+
|
|
182
|
+
**特點**:
|
|
183
|
+
- 時長:每循環 5-15 分鐘
|
|
184
|
+
- 範圍:單一方法或類別
|
|
185
|
+
- 測試:重構後必須保持綠色
|
|
186
|
+
|
|
187
|
+
**循環**:
|
|
188
|
+
|
|
189
|
+
```
|
|
190
|
+
┌─────────────────────────────────────────┐
|
|
191
|
+
│ │
|
|
192
|
+
│ ┌─────┐ ┌─────┐ ┌─────────┐ │
|
|
193
|
+
│ │ 紅燈│ ──► │綠燈 │ ──► │ 重構 │ │
|
|
194
|
+
│ └─────┘ └─────┘ └─────────┘ │
|
|
195
|
+
│ ▲ │ │
|
|
196
|
+
│ └──────────────────────────┘ │
|
|
197
|
+
│ │
|
|
198
|
+
└─────────────────────────────────────────┘
|
|
199
|
+
```
|
|
200
|
+
|
|
201
|
+
**常用重構技術**:
|
|
202
|
+
- 提取方法(Extract Method)
|
|
203
|
+
- 重新命名(Rename)
|
|
204
|
+
- 內聯變數(Inline Variable)
|
|
205
|
+
- 以常數取代魔術數字(Replace Magic Number with Constant)
|
|
206
|
+
- 移除重複(Remove Duplication)
|
|
207
|
+
|
|
208
|
+
---
|
|
209
|
+
|
|
210
|
+
## 戰略性重構策略
|
|
211
|
+
|
|
212
|
+
戰略性策略用於重大架構變更。運作時間為週到月級別,需要團隊協調。
|
|
213
|
+
|
|
214
|
+
### 絞殺榕模式
|
|
215
|
+
|
|
216
|
+
**定義**:透過逐步將功能路由到新系統,漸進替換遺留系統。
|
|
217
|
+
|
|
218
|
+
**來源**:命名自絞殺榕樹,它們環繞宿主樹生長,最終取代它。
|
|
219
|
+
|
|
220
|
+
**適用情境**:
|
|
221
|
+
- 漸進替換遺留系統
|
|
222
|
+
- 無法承受大爆炸式重寫
|
|
223
|
+
- 需要在遷移期間維持服務
|
|
224
|
+
|
|
225
|
+
**架構**:
|
|
226
|
+
|
|
227
|
+
```
|
|
228
|
+
┌─────────────────────────────────────────────────────────────────┐
|
|
229
|
+
│ 絞殺榕模式 (Strangler Fig) │
|
|
230
|
+
├─────────────────────────────────────────────────────────────────┤
|
|
231
|
+
│ │
|
|
232
|
+
│ 階段 1: 攔截(INTERCEPT) │
|
|
233
|
+
│ ┌─────────┐ ┌─────────┐ ┌─────────────┐ │
|
|
234
|
+
│ │ 請求 │────▶│ 門面 │────▶│ 舊系統(100%)│ │
|
|
235
|
+
│ └─────────┘ └─────────┘ └─────────────┘ │
|
|
236
|
+
│ │
|
|
237
|
+
│ 階段 2: 遷移(MIGRATE) │
|
|
238
|
+
│ ┌─────────┐ ┌─────────┐ ┌─────────────┐ │
|
|
239
|
+
│ │ 請求 │────▶│ 門面 │──┬─▶│ 新系統(功能A)│ │
|
|
240
|
+
│ └─────────┘ └─────────┘ │ └─────────────┘ │
|
|
241
|
+
│ └─▶│ 舊系統(其餘) │ │
|
|
242
|
+
│ └─────────────┘ │
|
|
243
|
+
│ │
|
|
244
|
+
│ 階段 3: 完成(COMPLETE) │
|
|
245
|
+
│ ┌─────────┐ ┌─────────────┐ │
|
|
246
|
+
│ │ 請求 │────▶│ 新系統(100%)│ [舊系統已下線] │
|
|
247
|
+
│ └─────────┘ └─────────────┘ │
|
|
248
|
+
│ │
|
|
249
|
+
└─────────────────────────────────────────────────────────────────┘
|
|
250
|
+
```
|
|
251
|
+
|
|
252
|
+
**檢查清單**:
|
|
253
|
+
- [ ] 識別攔截點(API 閘道、門面、代理)
|
|
254
|
+
- [ ] 建立事件捕獲層
|
|
255
|
+
- [ ] 在新系統中實作第一個功能
|
|
256
|
+
- [ ] 漸進式路由流量
|
|
257
|
+
- [ ] 監控並比較結果
|
|
258
|
+
- [ ] 下線舊元件
|
|
259
|
+
|
|
260
|
+
### 防腐層
|
|
261
|
+
|
|
262
|
+
**定義**:在遺留系統與新系統之間建立的翻譯層,防止遺留系統混亂的領域模型「污染」新系統的整潔架構。
|
|
263
|
+
|
|
264
|
+
**來源**:Eric Evans,《領域驅動設計》(2003)
|
|
265
|
+
|
|
266
|
+
**適用情境**:
|
|
267
|
+
- 新舊系統必須並存且頻繁互動
|
|
268
|
+
- 遺留系統有複雜/混亂的領域模型
|
|
269
|
+
- 保護新系統的限界上下文(Bounded Context)
|
|
270
|
+
|
|
271
|
+
**架構**:
|
|
272
|
+
|
|
273
|
+
```
|
|
274
|
+
┌────────────────────────────────────────────────────────────┐
|
|
275
|
+
│ 防腐層 (ACL) │
|
|
276
|
+
├────────────────────────────────────────────────────────────┤
|
|
277
|
+
│ │
|
|
278
|
+
│ ┌─────────────┐ ┌─────────────┐ ┌─────────────┐ │
|
|
279
|
+
│ │ 新系統 │────▶│ ACL │────▶│ 遺留系統 │ │
|
|
280
|
+
│ │ (整潔 API) │ │ │ │(混亂模型) │ │
|
|
281
|
+
│ └─────────────┘ │ ┌─────────┐ │ └─────────────┘ │
|
|
282
|
+
│ │ │ Adapter │ │ │
|
|
283
|
+
│ │ │ Facade │ │ │
|
|
284
|
+
│ │ │Translator││ │
|
|
285
|
+
│ │ └─────────┘ │ │
|
|
286
|
+
│ └─────────────┘ │
|
|
287
|
+
│ │
|
|
288
|
+
└────────────────────────────────────────────────────────────┘
|
|
289
|
+
```
|
|
290
|
+
|
|
291
|
+
**組件**:
|
|
292
|
+
|
|
293
|
+
| 組件 | 用途 |
|
|
294
|
+
|------|------|
|
|
295
|
+
| **Facade(門面)** | 簡化複雜的遺留介面 |
|
|
296
|
+
| **Adapter(轉接器)** | 將遺留資料格式轉換為新領域模型 |
|
|
297
|
+
| **Translator(翻譯器)** | 將遺留術語映射到通用語言 |
|
|
298
|
+
|
|
299
|
+
**實作檢查清單**:
|
|
300
|
+
- [ ] 定義 ACL 的清晰介面
|
|
301
|
+
- [ ] 映射遺留實體到新領域模型
|
|
302
|
+
- [ ] 處理資料格式轉換
|
|
303
|
+
- [ ] 實作錯誤翻譯
|
|
304
|
+
- [ ] 加入日誌以便除錯
|
|
305
|
+
- [ ] 徹底測試 ACL 隔離性
|
|
306
|
+
|
|
307
|
+
**與絞殺榕的比較**:
|
|
308
|
+
|
|
309
|
+
| 面向 | 絞殺榕 | 防腐層 |
|
|
310
|
+
|------|--------|--------|
|
|
311
|
+
| **目標** | 取代遺留系統 | 與遺留系統共存 |
|
|
312
|
+
| **方向** | 遷移離開遺留 | 整合遺留 |
|
|
313
|
+
| **最終狀態** | 遺留系統下線 | 兩個系統繼續運作 |
|
|
314
|
+
|
|
315
|
+
### 抽象分支
|
|
316
|
+
|
|
317
|
+
**定義**:透過引入抽象層,在不使用長期分支的情況下重構共享程式碼。
|
|
318
|
+
|
|
319
|
+
**適用情境**:
|
|
320
|
+
- 在不用長期分支的情況下重構共享程式碼
|
|
321
|
+
- 需要主幹開發
|
|
322
|
+
- 變更風險太高,無法單一提交
|
|
323
|
+
|
|
324
|
+
**步驟**:
|
|
325
|
+
|
|
326
|
+
```
|
|
327
|
+
步驟 1:引入抽象
|
|
328
|
+
客戶端 → 抽象(介面)→ 舊實作
|
|
329
|
+
|
|
330
|
+
步驟 2:新增新實作
|
|
331
|
+
客戶端 → 抽象 → 舊實作
|
|
332
|
+
└─→ 新實作(功能開關控制)
|
|
333
|
+
|
|
334
|
+
步驟 3:切換並移除
|
|
335
|
+
客戶端 → 新實作
|
|
336
|
+
[舊實作已移除]
|
|
337
|
+
```
|
|
338
|
+
|
|
339
|
+
**關鍵原則**:
|
|
340
|
+
- 所有變更在主幹(trunk)上(沒有長期分支)
|
|
341
|
+
- 功能開關控制哪個實作是活躍的
|
|
342
|
+
- 兩個實作可以在過渡期共存
|
|
343
|
+
|
|
344
|
+
### 平行變更(Expand-Migrate-Contract)
|
|
345
|
+
|
|
346
|
+
**定義**:透過三階段方法變更被多個客戶端使用的介面。
|
|
347
|
+
|
|
348
|
+
**適用情境**:
|
|
349
|
+
- 變更多個客戶端使用的介面
|
|
350
|
+
- 資料庫 Schema 遷移
|
|
351
|
+
- 需要零停機遷移
|
|
352
|
+
|
|
353
|
+
**階段**:
|
|
354
|
+
|
|
355
|
+
```
|
|
356
|
+
階段 1: 擴展(EXPAND)
|
|
357
|
+
├─ 在舊的旁邊新增新欄位/方法
|
|
358
|
+
├─ 新程式碼使用新介面
|
|
359
|
+
└─ 舊程式碼仍然運作
|
|
360
|
+
|
|
361
|
+
階段 2: 遷移(MIGRATE)
|
|
362
|
+
├─ 更新所有客戶端使用新介面
|
|
363
|
+
├─ 驗證所有客戶端已遷移
|
|
364
|
+
└─ 資料遷移(如需要)
|
|
365
|
+
|
|
366
|
+
階段 3: 收縮(CONTRACT)
|
|
367
|
+
├─ 移除舊欄位/方法
|
|
368
|
+
├─ 清理遷移程式碼
|
|
369
|
+
└─ 更新文件
|
|
370
|
+
```
|
|
371
|
+
|
|
372
|
+
---
|
|
373
|
+
|
|
374
|
+
## 遺留程式碼安全策略
|
|
375
|
+
|
|
376
|
+
基於 Michael Feathers 的《Working Effectively with Legacy Code》。
|
|
377
|
+
|
|
378
|
+
### 遺留程式碼困境
|
|
379
|
+
|
|
380
|
+
**定義**:遺留程式碼 = 沒有測試的程式碼(無關年齡)
|
|
381
|
+
|
|
382
|
+
**困境**:
|
|
383
|
+
- 要安全地修改程式碼,我們需要測試
|
|
384
|
+
- 要加測試,我們常常需要修改程式碼
|
|
385
|
+
- 沒有測試就修改程式碼是有風險的
|
|
386
|
+
|
|
387
|
+
**解決方案**:使用安全技術在修改前加入測試。
|
|
388
|
+
|
|
389
|
+
### 特徵測試
|
|
390
|
+
|
|
391
|
+
**定義**:捕獲現有行為(不是驗證正確性)的測試。
|
|
392
|
+
|
|
393
|
+
**目的**:在重構遺留程式碼前建立安全網。
|
|
394
|
+
|
|
395
|
+
**流程**:
|
|
396
|
+
|
|
397
|
+
```
|
|
398
|
+
1. 呼叫你想了解的程式碼
|
|
399
|
+
2. 寫一個你預期會失敗的斷言
|
|
400
|
+
3. 執行測試看實際發生什麼
|
|
401
|
+
4. 更新斷言以符合實際行為
|
|
402
|
+
5. 重複直到覆蓋你需要修改的行為
|
|
403
|
+
```
|
|
404
|
+
|
|
405
|
+
**範例**:
|
|
406
|
+
|
|
407
|
+
```javascript
|
|
408
|
+
// 步驟 1:初始(預期會失敗)
|
|
409
|
+
test('calculateDiscount 回傳... 某個值', () => {
|
|
410
|
+
const result = calculateDiscount(100, 'GOLD');
|
|
411
|
+
expect(result).toBe(0); // 猜測 - 可能會失敗
|
|
412
|
+
});
|
|
413
|
+
|
|
414
|
+
// 步驟 2:執行後,更新為實際值
|
|
415
|
+
test('calculateDiscount 對 GOLD 客戶回傳 15', () => {
|
|
416
|
+
const result = calculateDiscount(100, 'GOLD');
|
|
417
|
+
expect(result).toBe(15); // 實際行為
|
|
418
|
+
});
|
|
419
|
+
```
|
|
420
|
+
|
|
421
|
+
**關鍵原則**:特徵測試記錄程式碼*做什麼*,而非*應該做什麼*。
|
|
422
|
+
|
|
423
|
+
### 探針式重構
|
|
424
|
+
|
|
425
|
+
**定義**:為了理解程式碼而重構,不保留任何變更。
|
|
426
|
+
|
|
427
|
+
**目的**:透過實際動手修改來探索和理解無文件程式碼。
|
|
428
|
+
|
|
429
|
+
**工作流程**:
|
|
430
|
+
|
|
431
|
+
```
|
|
432
|
+
1. 建立探針分支(或使用 git stash)
|
|
433
|
+
2. 大膽重構以理解程式碼
|
|
434
|
+
3. 記錄學到的內容
|
|
435
|
+
4. 捨棄所有變更(git reset --hard)
|
|
436
|
+
5. 將學習成果應用於撰寫特徵測試
|
|
437
|
+
```
|
|
438
|
+
|
|
439
|
+
**適用情境**:
|
|
440
|
+
- 程式碼太複雜,無法透過閱讀理解
|
|
441
|
+
- 沒有文件存在
|
|
442
|
+
- 需要快速建立心智模型
|
|
443
|
+
|
|
444
|
+
**關鍵原則**:目標是理解,不是整潔的程式碼。完成後捨棄一切。
|
|
445
|
+
|
|
446
|
+
### 尋找接縫
|
|
447
|
+
|
|
448
|
+
**定義**:接縫是可以在不編輯程式碼的情況下改變行為的地方。
|
|
449
|
+
|
|
450
|
+
| 接縫類型 | 運作方式 | 範例 |
|
|
451
|
+
|---------|---------|------|
|
|
452
|
+
| **物件接縫** | 透過多型覆寫 | 透過介面注入測試替身 |
|
|
453
|
+
| **預處理接縫** | 編譯時替換 | 條件編譯、巨集 |
|
|
454
|
+
| **連結接縫** | 連結時替換 | 依賴注入、模組替換 |
|
|
455
|
+
|
|
456
|
+
**目的**:在不修改遺留程式碼的情況下注入測試替身。
|
|
457
|
+
|
|
458
|
+
### Sprout 與 Wrap 技術
|
|
459
|
+
|
|
460
|
+
| 技術 | 使用時機 | 做法 |
|
|
461
|
+
|-----|---------|-----|
|
|
462
|
+
| **Sprout Method** | 在現有方法中加入新邏輯 | 建立新方法,從舊方法呼叫 |
|
|
463
|
+
| **Sprout Class** | 新邏輯需要獨立演進 | 建立新類別,從舊程式碼參照 |
|
|
464
|
+
| **Wrap Method** | 需要在前後加入行為 | 重命名原方法,建立包裝器 |
|
|
465
|
+
| **Wrap Class** | 裝飾現有類別 | 裝飾者模式 |
|
|
466
|
+
|
|
467
|
+
**原則**:新程式碼使用 TDD;遺留程式碼在測試前保持不動。
|
|
468
|
+
|
|
469
|
+
### 程式碼考古
|
|
470
|
+
|
|
471
|
+
理解無文件程式碼的技術:
|
|
472
|
+
|
|
473
|
+
```
|
|
474
|
+
1. 探針式重構(見上方)
|
|
475
|
+
├─ 重構以理解,不是保留
|
|
476
|
+
├─ 使用 git stash 或分支
|
|
477
|
+
└─ 完成後捨棄(git reset --hard)
|
|
478
|
+
|
|
479
|
+
2. 追蹤變數流動
|
|
480
|
+
├─ 從輸入追蹤到輸出
|
|
481
|
+
├─ 標記關鍵轉換點
|
|
482
|
+
└─ 邊發現邊記錄
|
|
483
|
+
|
|
484
|
+
3. 執行時觀察
|
|
485
|
+
├─ 加入暫時性日誌
|
|
486
|
+
├─ 使用除錯器逐步執行
|
|
487
|
+
└─ 建立心智模型
|
|
488
|
+
|
|
489
|
+
4. Git 考古
|
|
490
|
+
├─ git log -p <file>(查看所有變更)
|
|
491
|
+
├─ git blame(找到原作者)
|
|
492
|
+
└─ 搜尋提交訊息找脈絡
|
|
493
|
+
```
|
|
494
|
+
|
|
495
|
+
---
|
|
496
|
+
|
|
497
|
+
## 資料庫重構
|
|
498
|
+
|
|
499
|
+
### Schema 變更的 Expand-Contract 模式
|
|
500
|
+
|
|
501
|
+
```
|
|
502
|
+
┌─────────────────────────────────────────────────────────────────┐
|
|
503
|
+
│ 資料庫重構(Expand-Contract) │
|
|
504
|
+
├─────────────────────────────────────────────────────────────────┤
|
|
505
|
+
│ │
|
|
506
|
+
│ 階段 1: 擴展(新增新的,保留舊的) │
|
|
507
|
+
│ ├─ 新增新欄位/表 │
|
|
508
|
+
│ ├─ 應用程式同時寫入新舊 │
|
|
509
|
+
│ └─ 此時可安全回滾 │
|
|
510
|
+
│ │
|
|
511
|
+
│ 階段 2: 遷移(搬移資料) │
|
|
512
|
+
│ ├─ 從舊複製資料到新 │
|
|
513
|
+
│ ├─ 驗證資料一致性 │
|
|
514
|
+
│ └─ 應用程式開始從新讀取 │
|
|
515
|
+
│ │
|
|
516
|
+
│ 階段 3: 收縮(移除舊的) │
|
|
517
|
+
│ ├─ 確認舊欄位/表不再被讀取 │
|
|
518
|
+
│ ├─ 移除舊欄位/表 │
|
|
519
|
+
│ └─ 清理雙寫程式碼 │
|
|
520
|
+
│ │
|
|
521
|
+
└─────────────────────────────────────────────────────────────────┘
|
|
522
|
+
```
|
|
523
|
+
|
|
524
|
+
### 常見 Schema 重構場景
|
|
525
|
+
|
|
526
|
+
| 場景 | 策略 | 風險等級 |
|
|
527
|
+
|-----|------|---------|
|
|
528
|
+
| **重命名欄位** | 新增新的 → 遷移 → 刪除舊的 | 中 |
|
|
529
|
+
| **拆分表格** | 新表 + 外鍵 → 遷移 → 調整應用程式 | 高 |
|
|
530
|
+
| **合併表格** | 新表 → 合併資料 → 切換應用程式 | 高 |
|
|
531
|
+
| **變更資料型別** | 新欄位 → 轉換 → 切換應用程式 | 中 |
|
|
532
|
+
| **新增 NOT NULL** | 填入預設值 → 新增約束 | 低 |
|
|
533
|
+
|
|
534
|
+
### 資料庫遷移安全檢查清單
|
|
535
|
+
|
|
536
|
+
```
|
|
537
|
+
遷移前:
|
|
538
|
+
□ 完整備份已完成
|
|
539
|
+
□ 遷移腳本已在測試環境驗證
|
|
540
|
+
□ 回滾腳本已準備
|
|
541
|
+
□ 遷移時間已估算(考慮資料量)
|
|
542
|
+
□ 維護視窗已通知
|
|
543
|
+
|
|
544
|
+
遷移中:
|
|
545
|
+
□ 監控資料庫效能
|
|
546
|
+
□ 增量驗證資料完整性
|
|
547
|
+
□ 應用程式健康檢查通過
|
|
548
|
+
|
|
549
|
+
遷移後:
|
|
550
|
+
□ 資料一致性驗證
|
|
551
|
+
□ 應用程式功能驗證
|
|
552
|
+
□ 效能基線比較
|
|
553
|
+
□ 備份保留一段時間以供回滾
|
|
554
|
+
```
|
|
555
|
+
|
|
556
|
+
### 零停機遷移技術
|
|
557
|
+
|
|
558
|
+
| 技術 | 說明 | 使用場景 |
|
|
559
|
+
|-----|------|---------|
|
|
560
|
+
| **Online Schema Change** | pt-osc, gh-ost | MySQL 大表變更 |
|
|
561
|
+
| **Blue-Green Database** | 雙資料庫切換 | 高可用需求 |
|
|
562
|
+
| **Shadow Write** | 同時寫入兩個資料庫並比較 | 驗證遷移正確性 |
|
|
563
|
+
| **Feature Flag** | 控制讀取來源 | 漸進式切換 |
|
|
564
|
+
|
|
565
|
+
---
|
|
566
|
+
|
|
567
|
+
## 安全重構工作流程
|
|
568
|
+
|
|
569
|
+
### 重構前
|
|
570
|
+
|
|
571
|
+
```
|
|
572
|
+
□ 定義成功標準(可衡量的)
|
|
573
|
+
□ 確保足夠的測試覆蓋率(建議 >80%)
|
|
574
|
+
□ 提交/暫存當前工作(乾淨的工作目錄)
|
|
575
|
+
□ 建立功能分支(或在主幹上使用功能開關)
|
|
576
|
+
□ 與團隊溝通以避免衝突
|
|
577
|
+
```
|
|
578
|
+
|
|
579
|
+
### 重構中
|
|
580
|
+
|
|
581
|
+
```
|
|
582
|
+
□ 一次只做一個小變更
|
|
583
|
+
□ 每次變更後執行測試
|
|
584
|
+
□ 如果測試失敗,立即復原
|
|
585
|
+
□ 頻繁提交(每次測試通過都是一個存檔點)
|
|
586
|
+
□ 重構時絕不加入新功能
|
|
587
|
+
```
|
|
588
|
+
|
|
589
|
+
### 重構後
|
|
590
|
+
|
|
591
|
+
```
|
|
592
|
+
□ 所有測試通過(與之前相同)
|
|
593
|
+
□ 程式碼可衡量地更好(複雜度、重複等)
|
|
594
|
+
□ 如需要則更新文件
|
|
595
|
+
□ 團隊審查完成
|
|
596
|
+
□ 沒有新增功能
|
|
597
|
+
```
|
|
598
|
+
|
|
599
|
+
---
|
|
600
|
+
|
|
601
|
+
## 重構度量指標
|
|
602
|
+
|
|
603
|
+
### 程式碼品質指標
|
|
604
|
+
|
|
605
|
+
| 指標 | 測量方式 | 目標 |
|
|
606
|
+
|-----|---------|-----|
|
|
607
|
+
| **循環複雜度** | 靜態分析工具 | 每函式 < 10 |
|
|
608
|
+
| **認知複雜度** | SonarQube 等 | 越低越好 |
|
|
609
|
+
| **耦合度** | 模組間依賴數 | 降低 |
|
|
610
|
+
| **內聚性** | LCOM 指標 | 提高 |
|
|
611
|
+
| **程式碼重複** | 重複程式碼百分比 | < 3% |
|
|
612
|
+
| **程式碼行數** | 僅供參考 | 較少 ≠ 一定更好 |
|
|
613
|
+
|
|
614
|
+
### 測試品質指標
|
|
615
|
+
|
|
616
|
+
| 指標 | 目標 | 備註 |
|
|
617
|
+
|-----|-----|------|
|
|
618
|
+
| **測試覆蓋率** | ≥ 80% | 重構期間不要降低 |
|
|
619
|
+
| **測試速度** | 更快 | 重構應改善可測試性 |
|
|
620
|
+
| **不穩定測試數** | 降低 | 穩定性改善 |
|
|
621
|
+
|
|
622
|
+
### 運維指標(DORA 指標)
|
|
623
|
+
|
|
624
|
+
| 指標 | 測量方式 | 預期改善 |
|
|
625
|
+
|-----|---------|---------|
|
|
626
|
+
| **部署頻率** | CI/CD 記錄 | 提高(可維護性改善)|
|
|
627
|
+
| **變更失敗率** | 回滾次數 | 降低 |
|
|
628
|
+
| **平均恢復時間** | 事故記錄 | 縮短 |
|
|
629
|
+
| **前置時間** | 從提交到部署 | 縮短 |
|
|
630
|
+
|
|
631
|
+
### 團隊效率指標
|
|
632
|
+
|
|
633
|
+
| 指標 | 測量方式 | 備註 |
|
|
634
|
+
|-----|---------|------|
|
|
635
|
+
| **新人上手時間** | 新員工熟悉時間 | 縮短 = 更好的可讀性 |
|
|
636
|
+
| **PR 審查時間** | Git 記錄 | 縮短 = 更好的可理解性 |
|
|
637
|
+
| **Bug 修復時間** | Issue 追蹤 | 縮短 = 更好的可維護性 |
|
|
638
|
+
|
|
639
|
+
### 重構 ROI 框架
|
|
640
|
+
|
|
641
|
+
```
|
|
642
|
+
成本:
|
|
643
|
+
├─ 開發時間 × 時薪
|
|
644
|
+
├─ 測試時間
|
|
645
|
+
├─ 部署風險成本
|
|
646
|
+
└─ 機會成本(未建置的功能)
|
|
647
|
+
|
|
648
|
+
收益:
|
|
649
|
+
├─ 減少的維護時間 × 未來年數
|
|
650
|
+
├─ 減少的 Bug × 修復成本
|
|
651
|
+
├─ 更快的功能開發
|
|
652
|
+
└─ 更低的人員流動成本
|
|
653
|
+
```
|
|
654
|
+
|
|
655
|
+
---
|
|
656
|
+
|
|
657
|
+
## 團隊協作
|
|
658
|
+
|
|
659
|
+
### 重構專案啟動
|
|
660
|
+
|
|
661
|
+
```
|
|
662
|
+
啟動會議議程:
|
|
663
|
+
1. 範圍定義
|
|
664
|
+
├─ 哪些模組/檔案在範圍內
|
|
665
|
+
└─ 明確排除什麼
|
|
666
|
+
|
|
667
|
+
2. 成功標準對齊
|
|
668
|
+
├─ 量化目標(複雜度降低 X%)
|
|
669
|
+
└─ 功能目標(行為不變)
|
|
670
|
+
|
|
671
|
+
3. 工作分配
|
|
672
|
+
├─ 按模組(垂直切分)
|
|
673
|
+
└─ 按層級(水平切分)
|
|
674
|
+
|
|
675
|
+
4. 風險評估
|
|
676
|
+
├─ 最高風險區域
|
|
677
|
+
└─ 回滾策略
|
|
678
|
+
```
|
|
679
|
+
|
|
680
|
+
### 分工策略
|
|
681
|
+
|
|
682
|
+
| 策略 | 使用時機 | 注意事項 |
|
|
683
|
+
|-----|---------|---------|
|
|
684
|
+
| **垂直切分** | 獨立模組 | 確保介面不變 |
|
|
685
|
+
| **水平切分** | 跨模組重構(如命名規範)| 需嚴格同步 |
|
|
686
|
+
| **Strangler 分工** | 大型系統替換 | 一人一個 Strangler 切片 |
|
|
687
|
+
| **Mob Programming** | 核心/高風險區域 | 全團隊一起,降低風險 |
|
|
688
|
+
|
|
689
|
+
### 溝通機制
|
|
690
|
+
|
|
691
|
+
```
|
|
692
|
+
日常溝通:
|
|
693
|
+
├─ 站立會議同步重構進度
|
|
694
|
+
├─ 共享的重構看板(Kanban)
|
|
695
|
+
└─ 專用頻道(#refactoring-xxx)
|
|
696
|
+
|
|
697
|
+
PR 規範:
|
|
698
|
+
├─ 標題加 [Refactor] 前綴
|
|
699
|
+
├─ 說明改了什麼以及為什麼
|
|
700
|
+
├─ 包含前後複雜度比較
|
|
701
|
+
└─ 遺留程式碼需要特徵測試
|
|
702
|
+
|
|
703
|
+
衝突處理:
|
|
704
|
+
├─ 小範圍:立即解決
|
|
705
|
+
├─ 中範圍:每日同步會議
|
|
706
|
+
└─ 大範圍:考慮 Branch by Abstraction
|
|
707
|
+
```
|
|
708
|
+
|
|
709
|
+
### PR 大小指引
|
|
710
|
+
|
|
711
|
+
| 大小 | 變更行數 | 審查時間 |
|
|
712
|
+
|-----|---------|---------|
|
|
713
|
+
| 小 | < 200 | < 30 分鐘 |
|
|
714
|
+
| 中 | 200-500 | < 1 小時 |
|
|
715
|
+
| 大 | > 500 | **應該拆分** |
|
|
716
|
+
|
|
717
|
+
**原則**:多個小 PR > 一個大 PR
|
|
718
|
+
|
|
719
|
+
---
|
|
720
|
+
|
|
721
|
+
## 技術債管理
|
|
722
|
+
|
|
723
|
+
### 技術債象限
|
|
724
|
+
|
|
725
|
+
基於 Martin Fowler 的技術債象限:
|
|
726
|
+
|
|
727
|
+
```
|
|
728
|
+
刻意的
|
|
729
|
+
│
|
|
730
|
+
┌────────────────┼────────────────┐
|
|
731
|
+
│ │ │
|
|
732
|
+
│ 審慎的 │ 魯莽的 │
|
|
733
|
+
│ 「我們知道 │ 「我們沒時間 │
|
|
734
|
+
│ 這是債務」 │ 做設計」 │
|
|
735
|
+
│ │ │
|
|
736
|
+
審慎的 ├────────────────┼────────────────┤ 魯莽的
|
|
737
|
+
│ │ │
|
|
738
|
+
│ 審慎的 │ 魯莽的 │
|
|
739
|
+
│ 「現在我們 │ 「什麼是 │
|
|
740
|
+
│ 知道該怎麼 │ 分層?」 │
|
|
741
|
+
│ 做了」 │ │
|
|
742
|
+
│ │ │
|
|
743
|
+
└────────────────┼────────────────┘
|
|
744
|
+
│
|
|
745
|
+
無意的
|
|
746
|
+
```
|
|
747
|
+
|
|
748
|
+
### 債務優先順序
|
|
749
|
+
|
|
750
|
+
| 優先級 | 標準 | 行動 |
|
|
751
|
+
|-------|------|-----|
|
|
752
|
+
| **高** | 阻擋開發、導致頻繁 Bug | 立即處理 |
|
|
753
|
+
| **中** | 拖慢開發、增加複雜度 | 排入下個 Sprint |
|
|
754
|
+
| **低** | 小煩惱、影響隔離 | 隨機處理 |
|
|
755
|
+
|
|
756
|
+
### 追蹤技術債
|
|
757
|
+
|
|
758
|
+
```
|
|
759
|
+
每個債務項目記錄:
|
|
760
|
+
├─ 描述:問題是什麼?
|
|
761
|
+
├─ 影響:如何影響開發?
|
|
762
|
+
├─ 估計工作量:修復需要多久?
|
|
763
|
+
├─ 忽視的風險:不處理會怎樣?
|
|
764
|
+
└─ 相關程式碼:受影響的檔案/模組連結
|
|
765
|
+
```
|
|
766
|
+
|
|
767
|
+
---
|
|
768
|
+
|
|
769
|
+
## 決策矩陣摘要
|
|
770
|
+
|
|
771
|
+
選擇適當重構策略的快速參考:
|
|
772
|
+
|
|
773
|
+
| 策略 | 規模 | 風險 | 關鍵用途 |
|
|
774
|
+
|------|------|------|----------|
|
|
775
|
+
| **預備性重構** | 小 | 低 | 降低功能開發阻力 |
|
|
776
|
+
| **童子軍規則** | 極小 | 低 | 持續償還技術債 |
|
|
777
|
+
| **紅-綠-重構** | 小 | 低 | TDD 開發循環 |
|
|
778
|
+
| **絞殺榕模式** | 大 | 中 | 系統汰換、架構遷移 |
|
|
779
|
+
| **防腐層** | 中 | 低 | 新舊系統共存 |
|
|
780
|
+
| **抽象分支** | 大 | 中 | 主幹上的長期重構 |
|
|
781
|
+
| **平行變更** | 中 | 低 | 介面/Schema 遷移 |
|
|
782
|
+
| **特徵測試** | — | — | **所有遺留重構的前置條件** |
|
|
783
|
+
| **探針式重構** | 小 | 低 | 理解黑盒程式碼 |
|
|
784
|
+
|
|
785
|
+
### 策略選擇指南
|
|
786
|
+
|
|
787
|
+
```
|
|
788
|
+
你的情境是什麼?
|
|
789
|
+
|
|
790
|
+
功能開發被混亂程式碼阻擋?
|
|
791
|
+
└─► 預備性重構
|
|
792
|
+
|
|
793
|
+
在 Bug 修復中接觸程式碼?
|
|
794
|
+
└─► 童子軍規則
|
|
795
|
+
|
|
796
|
+
用 TDD 寫新程式碼?
|
|
797
|
+
└─► 紅-綠-重構
|
|
798
|
+
|
|
799
|
+
取代整個遺留系統?
|
|
800
|
+
└─► 絞殺榕模式
|
|
801
|
+
|
|
802
|
+
需要整合遺留而不被污染?
|
|
803
|
+
└─► 防腐層
|
|
804
|
+
|
|
805
|
+
在主幹上重構共享程式碼?
|
|
806
|
+
└─► 抽象分支
|
|
807
|
+
|
|
808
|
+
變更被廣泛使用的介面?
|
|
809
|
+
└─► 平行變更(Expand-Migrate-Contract)
|
|
810
|
+
|
|
811
|
+
處理未測試的遺留程式碼?
|
|
812
|
+
└─► 先用特徵測試 + 探針式重構
|
|
813
|
+
```
|
|
814
|
+
|
|
815
|
+
---
|
|
816
|
+
|
|
817
|
+
## 相關標準
|
|
818
|
+
|
|
819
|
+
- [測試驅動開發](../test-driven-development.md) - TDD 循環包含重構階段
|
|
820
|
+
- [程式碼審查清單](../code-review-checklist.md) - 重構 PR 審查指引
|
|
821
|
+
- [提交訊息指南](../commit-message-guide.md) - `refactor` 提交類型
|
|
822
|
+
- [程式碼簽入標準](../checkin-standards.md) - 提交前要求
|
|
823
|
+
|
|
824
|
+
---
|
|
825
|
+
|
|
826
|
+
## 參考資料
|
|
827
|
+
|
|
828
|
+
### 書籍
|
|
829
|
+
|
|
830
|
+
- Martin Fowler -《重構:改善既有程式的設計》第二版(2018)
|
|
831
|
+
- Michael Feathers -《Working Effectively with Legacy Code》(2004)
|
|
832
|
+
- Joshua Kerievsky -《Refactoring to Patterns》(2004)
|
|
833
|
+
- Kent Beck -《Implementation Patterns》(2007)
|
|
834
|
+
- Robert C. Martin -《Clean Code》(2008)
|
|
835
|
+
- Eric Evans -《Domain-Driven Design》(2003)
|
|
836
|
+
|
|
837
|
+
### 文章
|
|
838
|
+
|
|
839
|
+
- Martin Fowler - [Strangler Fig Application](https://martinfowler.com/bliki/StranglerFigApplication.html)
|
|
840
|
+
- Martin Fowler - [Branch by Abstraction](https://martinfowler.com/bliki/BranchByAbstraction.html)
|
|
841
|
+
- Martin Fowler - [Preparatory Refactoring](https://martinfowler.com/articles/preparatory-refactoring-example.html)
|
|
842
|
+
- Pete Hodgson - [Feature Toggles](https://martinfowler.com/articles/feature-toggles.html)
|
|
843
|
+
- Martin Fowler - [Technical Debt Quadrant](https://martinfowler.com/bliki/TechnicalDebtQuadrant.html)
|
|
844
|
+
|
|
845
|
+
### 工具
|
|
846
|
+
|
|
847
|
+
- [Refactoring Guru](https://refactoring.guru/) - 重構技術目錄
|
|
848
|
+
- [SonarQube](https://www.sonarqube.org/) - 程式碼品質與複雜度分析
|
|
849
|
+
- [ApprovalTests](https://approvaltests.com/) - Golden Master 測試
|
|
850
|
+
|
|
851
|
+
---
|
|
852
|
+
|
|
853
|
+
## 版本歷程
|
|
854
|
+
|
|
855
|
+
| 版本 | 日期 | 變更 |
|
|
856
|
+
|-----|------|------|
|
|
857
|
+
| 2.0.0 | 2026-01-21 | 重大重構:新增戰術性策略(預備性重構、童子軍規則)、防腐層、決策矩陣摘要。重組為戰術性/戰略性/安全防護三層分類。 |
|
|
858
|
+
| 1.0.0 | 2026-01-12 | 初始重構標準定義 |
|
|
859
|
+
|
|
860
|
+
---
|
|
861
|
+
|
|
862
|
+
## 授權
|
|
863
|
+
|
|
864
|
+
本標準以 [CC BY 4.0](https://creativecommons.org/licenses/by/4.0/) 授權釋出。
|