@@ -67,7 +67,75 @@ switch ($Adapter) {
6767 Copy-Item (Join-Path $Src ' opencode.json' ) (Join-Path $TargetDir ' opencode.json' ) - Force
6868 }
6969 ' openclaw' {
70+ # 1. Backward-compat: drop the system-prompt include
7071 Copy-Item (Join-Path $Src ' config.md' ) (Join-Path $TargetDir ' .openclaw-system.md' ) - Force
72+ Write-Host " + .openclaw-system.md (system-prompt include; backward compat)"
73+
74+ # 2. OpenClaw auto-injects AGENTS.md from the workspace root.
75+ # Safely handle an existing AGENTS.md (codex/aider/cline also use it).
76+ $ocAgentsPath = Join-Path $TargetDir ' AGENTS.md'
77+ $ocTemplate = Join-Path $Src ' AGENTS.md'
78+ if (Test-Path $ocAgentsPath - PathType Leaf) {
79+ $ocExisting = Get-Content - Path $ocAgentsPath - Raw - ErrorAction SilentlyContinue
80+ if ($ocExisting -match ' \.agent/' ) {
81+ Write-Host " ~ AGENTS.md already references .agent/ — leaving alone"
82+ } else {
83+ Write-Host " ! AGENTS.md exists but does not reference .agent/; not overwriting."
84+ Write-Host " merge this block into your AGENTS.md to wire the brain:"
85+ Write-Host " ---8<---"
86+ Get-Content - Path $ocTemplate | ForEach-Object { Write-Host " $_ " }
87+ Write-Host " --->8---"
88+ }
89+ } else {
90+ Copy-Item $ocTemplate $ocAgentsPath - Force
91+ Write-Host " + AGENTS.md (auto-injected by OpenClaw from the workspace root)"
92+ }
93+
94+ # 3. Register a project-scoped OpenClaw agent so its workspace == this project.
95+ $ocAbs = (Resolve-Path $TargetDir ).Path
96+ $ocBnRaw = Split-Path - Leaf $ocAbs
97+ # lowercase first (OpenClaw normalizes agent ids to lowercase), then sanitize
98+ $ocBnSafe = ($ocBnRaw.ToLower () -replace ' [^a-z0-9._-]' , ' -' ) -replace ' -+' , ' -'
99+ $ocBnSafe = $ocBnSafe.Trim (' -' )
100+ if ([string ]::IsNullOrEmpty($ocBnSafe )) { $ocBnSafe = ' project' }
101+ # 6-hex-char SHA1 suffix of the absolute path for cross-project uniqueness
102+ $ocSha = [System.Security.Cryptography.SHA1 ]::Create()
103+ $ocBytes = [System.Text.Encoding ]::UTF8.GetBytes($ocAbs )
104+ $ocHashHex = -join (($ocSha.ComputeHash ($ocBytes )) | ForEach-Object { $_.ToString (' x2' ) })
105+ $ocAgentName = " $ocBnSafe -$ ( $ocHashHex.Substring (0 , 6 )) "
106+
107+ $ocBin = Get-Command openclaw - ErrorAction SilentlyContinue
108+ if ($ocBin ) {
109+ Write-Host " → registering OpenClaw agent '$ocAgentName ' (workspace: $ocAbs )"
110+ try {
111+ $ocOut = & openclaw agents add $ocAgentName -- workspace $ocAbs 2>&1
112+ $ocRc = $LASTEXITCODE
113+ $ocOut | ForEach-Object { Write-Host " $_ " }
114+ $ocOutJoined = ($ocOut | Out-String )
115+ if ($ocRc -eq 0 ) {
116+ Write-Host " ✓ registered. run from anywhere: openclaw --agent $ocAgentName "
117+ } elseif ($ocOutJoined -match ' (?i)already exists' ) {
118+ Write-Host " ✓ already registered (idempotent re-run). run: openclaw --agent $ocAgentName "
119+ } else {
120+ Write-Host " ! 'openclaw agents add' failed (details above)."
121+ Write-Host " if your OpenClaw fork does not support 'agents add --workspace',"
122+ Write-Host " fall back to the system-prompt include we wrote:"
123+ Write-Host " openclaw --system-prompt-file `" $ocAbs \.openclaw-system.md`" "
124+ Write-Host " otherwise retry: openclaw agents add `" $ocAgentName `" --workspace `" $ocAbs `" "
125+ }
126+ } catch {
127+ Write-Host " ! 'openclaw agents add' errored: $_ "
128+ Write-Host " fall back to the system-prompt include:"
129+ Write-Host " openclaw --system-prompt-file `" $ocAbs \.openclaw-system.md`" "
130+ Write-Host " or retry: openclaw agents add `" $ocAgentName `" --workspace `" $ocAbs `" "
131+ }
132+ } else {
133+ Write-Host " ! 'openclaw' CLI not found on PATH. after installing OpenClaw, try:"
134+ Write-Host " openclaw agents add `" $ocAgentName `" --workspace `" $ocAbs `" "
135+ Write-Host " openclaw --agent $ocAgentName "
136+ Write-Host " or, on forks without 'agents add', use the system-prompt include:"
137+ Write-Host " openclaw --system-prompt-file `" $ocAbs \.openclaw-system.md`" "
138+ }
71139 }
72140 ' hermes' {
73141 Copy-Item (Join-Path $Src ' AGENTS.md' ) (Join-Path $TargetDir ' AGENTS.md' ) - Force
0 commit comments