worktree-workflow
Original:🇺🇸 English
Translated
current release-driven profileでWorktrunkをWSL/Linux workspace lifecycle Practiceとして使い、Rust/Cargo worktreeのbuild-output isolation・cache reuse・cleanupを含め、同等以上のguaranteeを持つalternativeへのrefinementも判断する時に使用する。
2installs
Sourcerebuildup/project-init
Added on
NPX Install
npx skill4agent add rebuildup/project-init worktree-workflowTags
Translated version includes tags in frontmatterSKILL.md Content
View Translation Comparison →Worktree Workflow
Layer: Practice
Current release-driven profileではWorktrunkをGit worktreeの標準操作frontendとして使用する。WSL2/LinuxまたはLinux hostでWorktrunkが利用可能なら、日常のworktree作成・切替・一覧・review checkout・cleanupは原則 経由で行う。
wtWorktrunk自体はConstitutionではない。採用理由はworkspace lifecycle / recoverability / process-port ergonomicsであり、native agent workspace等が同等以上のguaranteeを提供する場合はADR-0017のrefinement contractに従って置換できる。
単にagentがnative に慣れていることはdeviation evidenceにならない。native WindowsをこのSkillの必須targetにはしない。
git worktreeこのSkillは主にauthoring workspace lifecycleを扱う。ADR-0020のverification-only executorへworktree作成を機械的に要求しない。Windows native等でproject/tooling constraintによりworktreeが使えない検証は / のverification contractへrouteする。
sandbox-runtimequality-gateCurrent practice guarantees
- Worktrunkはworkspace lifecycle toolであり、execution isolation boundaryではない。
- branch/ref/GitHub Issue/PRがcanonical stateであり、worktree pathやWorktrunk local stateをSoTにしない。
- ticket branchはIssue番号のみ、release branchはを維持する。
release-<major>-<minor>-<patch> - 等でGitHub PR lifecycle / protected main / explicit release authorization boundaryを迂回しない。ticket PRのautonomous landingもGitHub delivery contract経由で行う。
wt merge main - project-shared Worktrunk hookはへcommitする。
.config/wt.toml - worktree path等のmachine preferenceはuser configであり、project truthにしない。
- WSLでは高頻度build/watch用worktreeをLinux filesystemへ置き、を標準にしない。
/mnt/c
Prerequisites
最初に で利用可否を確認する。未導入ならrepositoryのreproducible toolchainに含められるかを確認し、安全にprovision可能なら導入する。導入不能・非対応・権限不足の場合だけnative へfallbackし、恒常的な制約ならproject documentationへ理由を残す。
wt --versiongit worktreeCargoで導入する例:
bash
cargo install worktrunk
wt config shell installshell integrationはでcurrent shell directoryを切り替えるために必要。
wt switch導入後:
bash
wt --version
wt config showで利用可能性とconfig locationを確認する。
Standard operations
現在のrelease branchへ移動:
bash
wt switch release-0-2-0Issue #123用ticket branch/worktreeを作成:
bash
wt switch --create 123 --base=release-0-2-0wt switch --create <name>--basemain--base- current HEADから派生:
wt switch --create <name> --base=@ - 指定release branchから派生:
wt switch --create <name> --base=release-x-y-z - stacked ticketでimmediate predecessor branchから派生:
wt switch --create <dependent-issue> --base=<predecessor-issue>
default branchからの派生はtarget release trunkへ直接stackできないticketを作るため、 policy違反になる。作成元はcurrent expected baseでなければならない。stacked ticketではimmediate predecessor snapshot/branchとの関係を / policyに従って決める。
github-deliverygithub-deliveryparallel-orchestrationworktree一覧:
bash
wt list
wt list --fullPR review用checkout:
bash
wt switch pr:123PR checkoutはreview workspaceを分離するための操作であり、review対象SHAとvalidation evidenceは別途pinする。
branchが不要になった後のcleanup:
bash
wt remove <branch>削除前にPR / release landing state、未commit変更、必要artifactを確認する。
Project configuration
repository-specific hookが必要なら:
bash
wt config create --projectでを作成し、実際のproject stackへ合わせて編集・commitする。
.config/wt.tomluniversalなdev commandを決め打ちしない。initializerはpackage scripts、framework docs/config、existing startup commandを調査して、port override方法を特定する。
Worktrunk専用のdev server例(Orca/plain gitでは展開されない):
toml
# .config/wt.toml
[post-start]
server = "wt step tether -- <project-specific command using {{ branch | hash_port }}>"
[list]
url = "http://localhost:{{ branch | hash_port }}"例のplaceholderをそのままcommitしてはいけない。Vite / Next.js / backend CLI / env-based server等、実際のcommand semanticsへ変換する。
Frontend independence
worktreeを作るfrontendはWorktrunk以外(Orca、plain git等)も使われる。frontendごとにsetupが違うと、同じbranchでも作り方によって状態がずれる。そのため、作成・削除時の処理はfrontendに書かず、repository-controlledな入口(例: / )に置く。frontendはその入口を呼ぶだけにする。
mise run worktree:setupmise run worktree:teardowntoml
# .config/wt.toml
[pre-start]
setup = "mise run worktree:setup"
[pre-remove]
teardown = "mise run worktree:teardown"- portなどworktreeごとの値は、frontendのtemplate(等)ではなく入口の中でbranch名から決める。
hash_port - 入口は何度実行しても同じ状態になるようにする。どのfrontendから、何回呼ばれても壊れないためである。
- はliteralなpathだけで書く。globはOrcaが無視する。
.worktreeinclude - 全frontendで使える入口がなければ、plain gitで作ったworktreeで手動実行できる形にする。
参照実装はproject-initの 、、、 にある。projectへ写してから、project固有のsetupを入口に足す。Orcaを併用する手順は Skillを参照する。
scripts/worktree/mise.toml.config/wt.tomlorca.yamlorca-frontendRust / Cargo build output and cache
Rust/Cargo projectでは、肥大化をworktree lifecycle上の明示的なresource concernとして扱う。ただし容量削減のためにcorrectness-sensitiveなmutable build outputを共有してはいけない。詳細なdecisionはADR-0024に従う。
target/Default boundary
concurrentにbuildされ得るworktree間では次を共有しない。
- /
target-dirCARGO_TARGET_DIR - Cargo
build.build-dir - incremental compilation state
- へのsymlinkや同一external build directory
target/
Cargoのtarget directory lockingはparallel buildを直列化し得るうえ、divergent Git worktreeが同じbuild directoryを共有した場合のfingerprint/artifact correctness issueがcurrent Cargoで報告されている。したがって「全worktreeを1個のtargetへ向ける」を標準optimizationにしない。
Cargo 1.91+のをexternal locationへ移す場合も、workspace pathごとに一意なdirectoryを使い、そのdirectoryのcleanup ownershipを定義する。異なるmutable worktreeへ同じbuild directoryを割り当てない。
build.build-dir共有候補は次に限定する。
- Cargo registry / git dependency download cache
- read-only toolchain cache
- bounded compiler cache such as
sccache
sccachebuild.rustc-wrapperRUSTC_WRAPPERSCCACHE_BASEDIRSbasedirsbasedirs--remap-path-prefixSCCACHE_DIRWorktree bootstrap
Rust をsymlinkしたり、単一directoryとして共有してはいけない。一方、Worktrunkのがfilesystemのreflinkを使える場合は、を必須とし、repository-controlled で承認済みseed pathだけをallowlistした場合に限り、各worktreeに独立pathを保ったcopy-on-write seedとして利用してよい。Rust target seedではを基本allowlistとし、、credential、token、socket、DB、その他mutable runtime stateを含めない。
target/wt step copy-ignored--require-include.worktreeincludetarget/.envWorktrunkはAPFS / btrfs / XFS / ReFS等ではreflinkを使用できる。reflink対応が実測で確認できたhostでは、compatibleなbase worktreeからをseedすることでinitial disk増加を抑えつつcold startを短縮できる。
target/ext4 / NTFS等ではfull copyになるため巨大なをコピーしない。Worktrunkのsummaryでreflink利用を確認できないhostではproject config等で:
target/toml
[step.copy-ignored]
exclude = ["target/"]を標準候補とする。はなしで実行せず、はrepository-controlled allowlistとしてreviewする。を含めるのもreflink capabilityを確認したhost/projectだけにする。
wt step copy-ignored--require-include.worktreeincludetarget/CoW seedはmutable-directory sharingではないが、seed artifact自体をvalidation evidenceにしない。新worktreeでは通常どおりCargoのfingerprint/rebuildとrequired validationを実行する。
Incremental compilation
incremental compilationは一律に無効化しない。
- long-lived interactive checkout: Cargo dev defaultのincremental buildを標準候補とする
- short-lived / disposable agent worktree: reuse期間が短くdisk amplificationが大きい場合、を優先候補とする
CARGO_INCREMENTAL=0 - project-wide はclean build / representative rebuild / disk footprintを比較してから採用する
[profile.dev] incremental = false
sccacheはincrementally compiled Rust crateをcacheできない。short-lived agent worktreeでcross-worktree sccache reuseを狙う場合はを明示することを標準候補とする。long-lived interactive checkoutではedit/rebuild latencyとの比較で決め、「incrementalを保持すること」自体を目的化しない。
CARGO_INCREMENTAL=0Reclamation
cargo cleanbash
cargo clean --dry-run -v
cargo clean --doc
cargo clean --release
cargo clean --profile <name>
cargo clean --target <triple>
cargo clean -p <package>full はcache corruption、toolchain/profile regime change、active worktreeの強いdisk pressure、externalized per-worktree build directoryのretirement等、rebuild costよりreclamation benefitが大きい場合に限定する。
cargo clean通常のworktree-local はworktree directoryと一緒に削除されるため、直前にfull cleanを二重実行しない。external build directoryを採用したprojectだけは、worktree removal時にそのworktree固有directoryを安全にreclaimするhook/taskを用意する。
target/wt removeCargo global cache auto-GCはregistry/git等のglobal cache用であり、current Cargoのtarget build artifact lifecycleの代替として扱わない。
Reduce what gets built
target footprintが継続的に問題になるprojectでは、cleanupだけでなくartifact production自体を調べる。
- で実際に有効なfeatureとenable元を調べる
cargo tree -e features - でduplicate dependency versionを調べる
cargo tree -d - で高cost compile unitを調べる
cargo build --timings - virtual workspaceを含めappropriate Cargo resolverを確認する
- unused default featuresがproject evidenceで確認できたdirect dependencyだけ+ explicit featuresを検討する
default-features = false - project MSRVがstring debug levelをsupportし、通常開発でfull debugger variable informationを必要としないなら、Cargo公式build-performance guidanceの次のshapeを優先候補として計測する
toml
[profile.dev]
debug = "line-tables-only"
[profile.dev.package."*"]
debug = false
[profile.debugging]
inherits = "dev"
debug = true通常devではworkspace memberをbacktraceに必要なline infoへ抑え、dependency debug infoを生成しない。full debugger sessionはへopt-inする。
--profile debuggingdependency default featureやlibrary feature surfaceはpublic behaviorへ影響し得るため、disk optimizationだけを理由に一括変更しない。
recursive cleaner等のthird-party toolはhost convenienceとして使ってよいが、project correctnessの必須依存にしない。unmaintained toolをcurrent defaultへ固定しない。
Port allocation
Worktrunk専用の はbranch名からportを決める。Orca/plain gitと併用する場合は使わず、共通setup入口でportを決める。
{{ branch | hash_port }}ただしhash-based allocationは絶対的なuniqueness guaranteeではない。dev server / runtimeはbind failureを明示的に検出し、必要ならproject-specificなport reservationまたはcollision-resolutionを追加する。既に別processが占有しているportを「自分のbranch用」と仮定して継続してはいけない。
適用境界:
- hostへ直接bindするprocess: dev commandのportへ適用
- container/sandbox: host-published portへ適用し、container内部portは通常固定でよい
- preview URL: 同じport templateから構築できる
- DB等の別service: 別namespaceを使う。Worktrunk専用なら 、複数frontendなら共通入口で決める
('db-' ~ branch) | hash_port
portが一意でもprocess/database/filesystem/credential isolationが成立したとは扱わない。
Process lifecycle
long-running dev server/watch processをWorktrunk hookから起動する場合は、適切なら:
bash
wt step tether -- <command>を使用する。
tethered processはworktree lifecycleへ結び付け、worktree removal後のorphan processやstale port ownershipを減らす。
これはprocess cleanup mechanismであり、sandbox security boundaryではない。
Mutable services and state
同一hostへ複数worktreeをmaterializeする場合、次を共有しない設計にする:
- writable DB/schema
- Redis namespace / queue
- container name
- Unix socket
- app-local mutable state
- generated runtime state
- credentials with broader authority than the worker requires
Worktrunkの / 等はdeterministic identifierとして利用できるが、実際のservice isolationは policyに従う。
sanitize_dbhash_portsandbox-runtimeDelivery boundary
Worktrunk commandはGitHub deliveryのergonomic frontendに限定する。
許可される典型操作:
text
wt switch release-x-y-z
-> wt switch --create <issue-number> --base=release-x-y-z
-> implementation / commit / publish
-> immediate PR creation/state
-> review / validation
-> ticket-class: autonomous GitHub landing / release-class: explicitly authorized GitHub landing
-> wt remove <issue-number>wt mergeFallback and recovery
Authoring
Worktrunkが利用できないmutable authoring workerではnative へ縮退してよい。ただしbranch naming、mutable ownership、runtime state safety、PR state lifecycle等のapplicable semanticsは維持する。
git worktreeworktree自体を作れないauthoring environmentでは、同じshared checkoutへ複数workerを並行配置しない。isolated clone / sandbox / serialized ownership等、同等以上のmutable ownership guaranteeを選ぶ。
Verification-only
verification-only executionはworktree fallback chainの対象ではない。immutable candidate artifactをcleanにmaterializeできれば、package / installed build / clean checkout / disposable clone / serialized singleton checkout等を利用できる。
singleton checkoutを使う場合はdirty stateを暗黙に上書きせず、exclusive ownershipとbefore/after state auditを行う。validation中にsource authoringへ移行した場合はmutable worker policyへpromotionする。
fresh environmentではGit refs、Issue/PR metadata、committed 、project docsからworkflowを再構成できなければならない。user-level Worktrunk configだけに必要情報を残さない。
.config/wt.tomlRefinement / deviation
Worktrunkから外れる場合は、少なくとも次を確認する。
- canonical task/source identityがlocal pathに依存しない
- concurrent workspaceのmutable-state safetyを悪化させない
- current expected baseからmaterializeできる
- review/recoveryがtool-local hidden stateだけに依存しない
- dev process / port / mutable service lifecycleについて必要なguaranteeを維持する
同等以上ならalternativeを許容する。Worktrunk command shapeそのものをorganizational correctnessとして扱わない。
Remove / re-evaluate
- agent/runtimeがnativeに同等以上のworkspace lifecycleを提供する
- Worktrunk固有hookがproject stackと不整合になる
- host worktreeを使わないruntime modelへ移行する
- comparative evalでWorktrunk-specific instructionの追加価値が消える