|
| 1 | +$ErrorActionPreference = "Stop" |
| 2 | +Set-StrictMode -Version Latest |
| 3 | + |
| 4 | +$expectedRepo = "E:\FlowMemory\flowmemory-main" |
| 5 | +$flowMemoryRoot = "E:\FlowMemory" |
| 6 | + |
| 7 | +function Resolve-CanonicalPath { |
| 8 | + param( |
| 9 | + [Parameter(Mandatory = $true)] |
| 10 | + [string] $Path |
| 11 | + ) |
| 12 | + |
| 13 | + return (Resolve-Path -LiteralPath $Path).Path.TrimEnd("\") |
| 14 | +} |
| 15 | + |
| 16 | +function Test-GitRef { |
| 17 | + param( |
| 18 | + [Parameter(Mandatory = $true)] |
| 19 | + [string] $Ref |
| 20 | + ) |
| 21 | + |
| 22 | + & git show-ref --verify --quiet $Ref *> $null |
| 23 | + return $LASTEXITCODE -eq 0 |
| 24 | +} |
| 25 | + |
| 26 | +function Add-AgentWorktree { |
| 27 | + param( |
| 28 | + [Parameter(Mandatory = $true)] |
| 29 | + [string] $Path, |
| 30 | + |
| 31 | + [Parameter(Mandatory = $true)] |
| 32 | + [string] $Branch |
| 33 | + ) |
| 34 | + |
| 35 | + if (Test-Path -LiteralPath $Path) { |
| 36 | + Write-Host "Exists, skipping: $Path" |
| 37 | + return |
| 38 | + } |
| 39 | + |
| 40 | + Write-Host "Creating: $Path ($Branch)" |
| 41 | + |
| 42 | + if (Test-GitRef "refs/heads/$Branch") { |
| 43 | + & git worktree add $Path $Branch |
| 44 | + } |
| 45 | + elseif (Test-GitRef "refs/remotes/origin/$Branch") { |
| 46 | + & git worktree add -b $Branch $Path "origin/$Branch" |
| 47 | + } |
| 48 | + else { |
| 49 | + & git worktree add -b $Branch $Path HEAD |
| 50 | + } |
| 51 | + |
| 52 | + if ($LASTEXITCODE -ne 0) { |
| 53 | + throw "Failed to create worktree $Path for branch $Branch." |
| 54 | + } |
| 55 | +} |
| 56 | + |
| 57 | +if (-not (Get-Command git -ErrorAction SilentlyContinue)) { |
| 58 | + throw "git was not found on PATH. Install Git or add it to PATH, then rerun this script." |
| 59 | +} |
| 60 | + |
| 61 | +$currentPath = Resolve-CanonicalPath (Get-Location).Path |
| 62 | +$expectedPath = Resolve-CanonicalPath $expectedRepo |
| 63 | + |
| 64 | +if ($currentPath -ne $expectedPath) { |
| 65 | + throw "Run this script from $expectedRepo. Current path: $currentPath" |
| 66 | +} |
| 67 | + |
| 68 | +$gitRootRaw = (& git rev-parse --show-toplevel).Trim() |
| 69 | +if ($LASTEXITCODE -ne 0) { |
| 70 | + throw "Current directory is not inside a Git repository." |
| 71 | +} |
| 72 | + |
| 73 | +$gitRoot = Resolve-CanonicalPath $gitRootRaw |
| 74 | +if ($gitRoot -ne $expectedPath) { |
| 75 | + throw "Expected Git root $expectedRepo, but found $gitRoot." |
| 76 | +} |
| 77 | + |
| 78 | +$worktrees = @( |
| 79 | + @{ Path = "$flowMemoryRoot\flowmemory-contracts"; Branch = "agent/contracts" }, |
| 80 | + @{ Path = "$flowMemoryRoot\flowmemory-indexer"; Branch = "agent/indexer" }, |
| 81 | + @{ Path = "$flowMemoryRoot\flowmemory-hardware"; Branch = "agent/hardware" }, |
| 82 | + @{ Path = "$flowMemoryRoot\flowmemory-dashboard"; Branch = "agent/dashboard" }, |
| 83 | + @{ Path = "$flowMemoryRoot\flowmemory-research"; Branch = "agent/research" }, |
| 84 | + @{ Path = "$flowMemoryRoot\flowmemory-crypto"; Branch = "agent/crypto" }, |
| 85 | + @{ Path = "$flowMemoryRoot\flowmemory-chain"; Branch = "agent/chain" }, |
| 86 | + @{ Path = "$flowMemoryRoot\flowmemory-review"; Branch = "agent/review" } |
| 87 | +) |
| 88 | + |
| 89 | +foreach ($worktree in $worktrees) { |
| 90 | + Add-AgentWorktree -Path $worktree.Path -Branch $worktree.Branch |
| 91 | +} |
| 92 | + |
| 93 | +Write-Host "" |
| 94 | +Write-Host "Exact cd commands:" |
| 95 | +foreach ($worktree in $worktrees) { |
| 96 | + Write-Host "cd $($worktree.Path)" |
| 97 | +} |
| 98 | + |
| 99 | +Write-Host "" |
| 100 | +Write-Host "How to run Codex in each worktree:" |
| 101 | +Write-Host "Open a separate PowerShell window for each agent, then run one cd command followed by codex." |
| 102 | +Write-Host "" |
| 103 | +foreach ($worktree in $worktrees) { |
| 104 | + Write-Host "cd $($worktree.Path)" |
| 105 | + Write-Host "codex" |
| 106 | + Write-Host "" |
| 107 | +} |
0 commit comments