Communitygithub.com

alfathafp/portofolio-web-design

當開始需要隔離於當前工作區的新功能開發,或在執行實作計畫之前使用,透過原生工具或 git worktree 回退機制確保存在隔離的工作區。

portofolio-web-design 是什麼?

這個技能「Using Git Worktrees」提供了一個標準化流程,用於為開發工作建立隔離的工作區,避免污染當前的分支或工作環境。它首先檢查開發者是否已經處於隔離環境中,並能正確區分 git submodule 與真正的 linked worktree。如果尚未隔離,技能會優先使用平台內建的原生隔離工具(例如 `EnterWorktree` 指令),僅在沒有這類工具時才回退到手動執行 `git worktree add`。此外,它包含完整的專案設定與基準測試驗證步驟,確保工作區整潔可運作。此技能適用於任何使用 Git 進行版本控制的開發環境,尤其是 Claude Code、Cursor 或 Codex 等 AI 代理工具,能有效防止開發過程中的意外衝突與狀態混亂。

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

在你喜歡的 AI 中提問

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

說明文件

使用 Git Worktrees

概覽

確保工作在隔離的工作區中進行。優先使用平台的原生 worktree 工具。僅在沒有原生工具可用時,才回退到手動的 git worktree。

核心原則: 先偵測現有的隔離狀態。然後使用原生工具。最後才回退到 git。切勿與現有環境對抗。

開始時宣告: 「我正在使用 using-git-worktrees 技能來建立一個隔離的工作區。」

步驟 0:偵測現有隔離

在建立任何東西之前,先檢查你是否已處於隔離的工作區中。

GIT_DIR=$(cd "$(git rev-parse --git-dir)" 2>/dev/null && pwd -P)
GIT_COMMON=$(cd "$(git rev-parse --git-common-dir)" 2>/dev/null && pwd -P)
BRANCH=$(git branch --show-current)

子模組防護: GIT_DIR != GIT_COMMON 在 git 子模組內部也會成立。在得出「已經在 worktree 中」的結論之前,先確認你不在子模組中:

# 如果這回傳路徑,表示你在子模組中,而不是 worktree —— 視為正常 repo
這樣處理
git rev-parse --show-superproject-working-tree 2>/dev/null

如果 GIT_DIR != GIT_COMMON(且不在子模組中): 你已經在一個連結的 worktree 中。跳至步驟 2(專案設定)。不要建立另一個 worktree。

回報分支狀態:

  • 在分支上:「已在隔離工作區 <路徑>,分支為 <名稱>。」
  • 分離 HEAD:「已在隔離工作區 <路徑>(分離 HEAD,外部管理)。需要在完成時建立分支。」

如果 GIT_DIR == GIT_COMMON(或在子模組中): 你在正常的 repo 簽出中。

使用者是否已經在你的指示中表明他們的 worktree 偏好?如果沒有,在建立 worktree 之前先徵求同意:

「您希望我建立一個隔離的 worktree 嗎?它可以保護您目前的分支不受變更影響。」

尊重任何已經明確宣告的偏好,無需再次詢問。如果使用者拒絕同意,就在原位工作並跳至步驟 2。

步驟 1:建立隔離工作區

你有兩種機制。請依此順序嘗試。

1a. 原生 Worktree 工具(優先)

使用者已經要求一個隔離的工作區(步驟 0 同意)。你是否已經有建立 worktree 的方法?可能是名稱像是 EnterWorktree、WorktreeCreate、/worktree 指令,或 --worktree 旗標的工具。如果有,就直接使用並跳至步驟 2。

原生工具會自動處理目錄放置、分支建立和清理工作。在有原生工具的情況下使用 git worktree add 會建立你的環境無法看見或管理的幽靈狀態。

只有在沒有任何原生 worktree 工具可用時,才繼續進行步驟 1b。

1b. Git Worktree 回退

僅在步驟 1a 不適用時使用——你沒有可用的原生 worktree 工具。使用 git 手動建立 worktree。

目錄選擇

遵循此優先順序。明確的使用者偏好永遠優先於觀察到的檔案系統狀態。

  1. 檢查你的指示中是否有宣告的 worktree 目錄偏好。 如果使用者已經指定了一個,直接使用它,無需詢問。

  2. 檢查專案本機中是否存在 worktree 目錄:

    ls -d .worktrees 2>/dev/null     # 首選(隱藏)
    ls -d worktrees 2>/dev/null      # 替代
    

    如果找到,就使用它。如果兩者都存在,.worktrees 優先。

  3. 如果沒有其他指導可用,預設使用專案根目錄下的 .worktrees/。

安全性驗證(僅限專案本機目錄)

在建立 worktree 之前,必須確認目錄已被忽略:

git check-ignore -q .worktrees 2>/dev/null || git check-ignore -q worktrees 2>/dev/null

如果未忽略: 加入 .gitignore,提交變更,然後繼續。

為什麼重要: 防止意外將 worktree 的內容提交到倉庫中。

建立 Worktree

# 根據選擇的位置決定路徑
path="$LOCATION/$BRANCH_NAME"

git worktree add "$path" -b "$BRANCH_NAME"
cd "$path"

沙箱回退: 如果 git worktree add 因權限錯誤(沙箱拒絕)而失敗,告知使用者沙箱阻擋了 worktree 建立,你將改為在當前目錄中工作。然後在原地執行設定和基準測試。

步驟 2:專案設定

自動偵測並執行適當的設定:

# Node.js
if [ -f package.json ]; then npm install; fi

# Rust
if [ -f Cargo.toml ]; then cargo build; fi

# Python
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
if [ -f pyproject.toml ]; then poetry install; fi

# Go
if [ -f go.mod ]; then go mod download; fi

步驟 3:驗證乾淨的基準

執行測試以確保工作區從一個乾淨的狀態開始:

# 使用專案適用的指令
npm test / cargo test / pytest / go test ./...

如果測試失敗: 回報失敗,詢問是否繼續或調查。

如果測試通過: 回報就緒。

回報

Worktree ready at <完整路徑>
Tests passing (<N> 個測試,0 個失敗)
Ready to implement <功能名稱>

快速參考

情況行動
已在連結的 worktree 中跳過建立(步驟 0)
在子模組中視為正常 repo(步驟 0 防護)
有原生 worktree 工具可用使用它(步驟 1a)
無原生工具Git worktree 回退(步驟 1b)
.worktrees/ 存在使用它(驗證已忽略)
worktrees/ 存在使用它(驗證已忽略)
兩者都存在使用 .worktrees/
兩者都不存在檢查指示檔案,然後預設 .worktrees/
目錄未被忽略加入 .gitignore + 提交
建立時權限錯誤沙箱回退,在原位工作
基準測試失敗回報失敗 + 詢問
無 package.json/Cargo.toml跳過依賴安裝

常見的合理化藉口

藉口現實
「我顯然不在 worktree 中——無需檢查」執行步驟 0。由環境建立的隔離和子模組都會欺騙肉眼;偵測指令能解決問題。
「git worktree add 比尋找原生工具更快」原生工具(例如 EnterWorktree)掌管放置、分支和清理。繞過它是最常見的錯誤——它會建立你的環境無法看見或管理的幽靈狀態。
「worktree 目錄肯定已經被忽略了」執行 git check-ignore。一個未被忽略的 worktree 目錄會將整個樹提交到倉庫中。
「任何目錄名稱都可以」明確的指示優於現有的專案本機目錄,而現有目錄又優於 .worktrees/ 預設。
「工作區是全新的——基準測試可以等」一個骯髒的基準會讓之後的每次失敗都變得模稜兩可。現在就執行測試;在失敗情況下繼續與否,是你的合作夥伴的決定。

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.

相關技能