# scripts/tier2/setup_tier2_clone_directives.ps1 <# .SYNOPSIS Directive-based alternative to setup_tier2_clone.ps1. .DESCRIPTION Same bootstrap as setup_tier2_clone.ps1, but promotes the directive-based agent prompt (tier2-autonomous.warm.md) into the clone's .opencode/agents/tier2-autonomous.md slot. The agent then warms via a single manual-slop_aggregate_directives MCP call against conductor/directives/presets/current_baseline.md instead of ingesting the bulk-markdown prompt verbatim. The original tier2-autonomous.md is left untouched in the main repo (per the warm_md_duplicates_not_in_place directive: originals are the rollback target; .warm.md is the experimental layer). This script is the promotion step: it copies .warm.md into the clone's active agent slot. Idempotent: re-running updates templates and re-fetches, but does not destroy existing feature branches in the clone. .PARAMETER WhatIf Show what would happen without making changes. .PARAMETER MainRepoPath Path to the main repo. Default: C:\projects\manual_slop .PARAMETER Tier2ClonePath Path to the Tier 2 clone. Default: C:\projects\manual_slop_tier2 .PARAMETER PresetPath Directive preset the agent should warm with. Default: conductor/directives/presets/current_baseline.md #> [CmdletBinding(SupportsShouldProcess = $true)] param( [string]$MainRepoPath = "C:\projects\manual_slop", [string]$Tier2ClonePath = "C:\projects\manual_slop_tier2", [string]$PresetPath = "conductor/directives/presets/tier2_autonomous.md" ) $ErrorActionPreference = "Stop" # Resolve to absolute paths $MainRepoPath = (Resolve-Path $MainRepoPath).Path if ($PSCmdlet.ShouldProcess("Bootstrap Tier 2 clone (directive variant) at $Tier2ClonePath")) { Write-Host "[tier2-bootstrap-directives] starting bootstrap" Write-Host "[tier2-bootstrap-directives] main repo: $MainRepoPath" Write-Host "[tier2-bootstrap-directives] tier2 clone: $Tier2ClonePath" Write-Host "[tier2-bootstrap-directives] agent prompt: tier2-autonomous.warm.md (directive-based)" Write-Host "[tier2-bootstrap-directives] preset: $PresetPath" # 1. Clone the main repo (if not already present) if (-not (Test-Path $Tier2ClonePath)) { Write-Host "[tier2-bootstrap-directives] cloning $MainRepoPath -> $Tier2ClonePath" git clone $MainRepoPath $Tier2ClonePath if ($LASTEXITCODE -ne 0) { throw "git clone failed" } } else { Write-Host "[tier2-bootstrap-directives] clone already exists, skipping clone" } # 2. Set origin to the main repo's local path (if not already) Push-Location $Tier2ClonePath try { $currentOrigin = git remote get-url origin 2>$null if ($currentOrigin -ne $MainRepoPath) { Write-Host "[tier2-bootstrap-directives] setting origin to $MainRepoPath" git remote set-url origin $MainRepoPath } else { Write-Host "[tier2-bootstrap-directives] origin already set correctly" } # 3. Copy templates — PROMOTE the .warm.md variant into the active slot. # The original tier2-autonomous.md stays untouched in the main repo # (rollback target per warm_md_duplicates_not_in_place directive). # The clone's .opencode/agents/tier2-autonomous.md becomes the directive # variant. The clone also gets a copy of the preset + the directives tree # so manual-slop_aggregate_directives can resolve them from the clone's # own filesystem at session time. Write-Host "[tier2-bootstrap-directives] copying templates (promoting .warm.md -> active slot)" New-Item -ItemType Directory -Force -Path "$Tier2ClonePath\.opencode\agents" | Out-Null New-Item -ItemType Directory -Force -Path "$Tier2ClonePath\.opencode\commands" | Out-Null Copy-Item -Force "$MainRepoPath\conductor\tier2\agents\tier2-autonomous.warm.md" "$Tier2ClonePath\.opencode\agents\tier2-autonomous.md" Copy-Item -Force "$MainRepoPath\conductor\tier2\commands\tier-2-auto-execute.md" "$Tier2ClonePath\.opencode\commands\tier-2-auto-execute.md" # 3a. Verify the preset path exists in the clone. The clone inherits the # main repo's conductor/directives/ tree via git clone, so the preset # and all v1.md files should already be present. If the user passed a # custom -PresetPath that doesn't resolve, fail loudly here rather than # letting the agent hit a missing-file error mid-session. $resolvedPreset = if ([System.IO.Path]::IsPathRooted($PresetPath)) { $PresetPath } else { Join-Path $Tier2ClonePath $PresetPath } if (-not (Test-Path $resolvedPreset)) { throw "Preset not found at $resolvedPreset. The clone should inherit conductor/directives/ from the main repo via git clone. Check that the path is correct and the clone is complete." } Write-Host "[tier2-bootstrap-directives] preset resolved at $resolvedPreset" # Merge opencode.json.fragment into the clone's opencode.json. # Same logic as setup_tier2_clone.ps1 — the case-variant duplicate # keys (*C:/tmp* vs *c:/tmp* etc.) require -AsHashtable. $cloneConfig = "$Tier2ClonePath\opencode.json" $fragment = Get-Content "$MainRepoPath\conductor\tier2\opencode.json.fragment" -Raw | ConvertFrom-Json -AsHashtable if (Test-Path $cloneConfig) { $existing = Get-Content $cloneConfig -Raw | ConvertFrom-Json -AsHashtable if (-not $existing.ContainsKey('agent')) { $existing['agent'] = @{} } $existing['agent']['tier2-autonomous'] = $fragment['agent']['tier2-autonomous'] $existing['permission'] = $fragment['permission'] $existing['default_agent'] = 'tier2-autonomous' $existing['model'] = $fragment['model'] $existing | ConvertTo-Json -Depth 10 | Set-Content $cloneConfig } else { Copy-Item -Force "$MainRepoPath\conductor\tier2\opencode.json.fragment" $cloneConfig $existing = $fragment } # Override the MCP server's command + PYTHONPATH to point at the # Tier 2 clone's files (same rationale as setup_tier2_clone.ps1). if ($existing.ContainsKey('mcp') -and $existing['mcp'].ContainsKey('manual-slop')) { $existing['mcp']['manual-slop']['command'] = @( "$env:USERPROFILE\scoop\apps\uv\current\uv.exe", "run", "python", "$Tier2ClonePath\scripts\mcp_server.py" ) $existing['mcp']['manual-slop']['environment']['PYTHONPATH'] = "$Tier2ClonePath\src" $existing | ConvertTo-Json -Depth 10 | Set-Content $cloneConfig } $cloneMcpPaths = "$Tier2ClonePath\mcp_paths.toml" @" [allowed_paths] extra_dirs = [] "@ | Set-Content -Path $cloneMcpPaths -NoNewline Write-Host "[tier2-bootstrap-directives] MCP server pointed at clone; mcp_paths.toml reset to empty extra_dirs" # 4. Install git hooks Write-Host "[tier2-bootstrap-directives] installing git hooks" Copy-Item -Force "$MainRepoPath\conductor\tier2\githooks\pre-commit" "$Tier2ClonePath\.git\hooks\pre-commit" Copy-Item -Force "$MainRepoPath\conductor\tier2\githooks\pre-push" "$Tier2ClonePath\.git\hooks\pre-push" Copy-Item -Force "$MainRepoPath\conductor\tier2\githooks\post-checkout" "$Tier2ClonePath\.git\hooks\post-checkout" Write-Host "[tier2-bootstrap-directives] git hooks installed (pre-commit auto-unstages sandbox-only files)" # 5. Create desktop shortcut — labeled "Tier 2 (Directives)" so the # user can distinguish it from the bulk-markdown sibling shortcut. Write-Host "[tier2-bootstrap-directives] creating desktop shortcut" $shell = New-Object -ComObject WScript.Shell $shortcut = $shell.CreateShortcut("$env:USERPROFILE\Desktop\Tier 2 (Directives).lnk") $shortcut.TargetPath = "pwsh.exe" $shortcut.Arguments = "-File `"$MainRepoPath\scripts\tier2\run_tier2_sandboxed.ps1`"" $shortcut.WorkingDirectory = $Tier2ClonePath $shortcut.Description = "Open OpenCode in the Tier 2 sandboxed clone (directive-based agent prompt)" $shortcut.Save() } finally { Pop-Location } Write-Host "[tier2-bootstrap-directives] done" Write-Host "[tier2-bootstrap-directives] next steps:" Write-Host "[tier2-bootstrap-directives] 1. Double-click 'Tier 2 (Directives)' on your desktop" Write-Host "[tier2-bootstrap-directives] 2. Type: /tier-2-auto-execute " Write-Host "[tier2-bootstrap-directives] 3. The agent will call manual-slop_aggregate_directives on $PresetPath as its warm-up" }