@ornexus/neocortex 4.65.1 → 4.66.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (150) hide show
  1. package/dist/release-source.json +1 -1
  2. package/dist/sbom.cdx.json +1206 -1193
  3. package/install.ps1 +243 -77
  4. package/install.sh +221 -102
  5. package/package.json +2 -2
  6. package/packages/client/dist/adapters/platform-detector.js +1 -1
  7. package/packages/client/dist/agent/refresh-stubs.d.ts +50 -0
  8. package/packages/client/dist/agent/refresh-stubs.js +2 -2
  9. package/packages/client/dist/cli.js +5 -4
  10. package/packages/client/dist/commands/doctor.d.ts +26 -1
  11. package/packages/client/dist/commands/doctor.js +2 -2
  12. package/packages/client/dist/commands/invoke.d.ts +183 -5
  13. package/packages/client/dist/commands/invoke.js +94 -87
  14. package/packages/client/dist/commands/planning-qa.d.ts +64 -0
  15. package/packages/client/dist/commands/planning-qa.js +1 -0
  16. package/packages/client/dist/commands/refactor-control.js +3 -3
  17. package/packages/client/dist/commands/story-checkpoint.d.ts +3 -1
  18. package/packages/client/dist/commands/story-checkpoint.js +1 -1
  19. package/packages/client/dist/commands/story-worktree.d.ts +1 -1
  20. package/packages/client/dist/commands/story-worktree.js +1 -1
  21. package/packages/client/dist/git/direct-yolo-checkpoint.d.ts +64 -1
  22. package/packages/client/dist/git/direct-yolo-checkpoint.js +4 -3
  23. package/packages/client/dist/git/epic-lifecycle-evidence.d.ts +184 -0
  24. package/packages/client/dist/git/epic-lifecycle-evidence.js +6 -0
  25. package/packages/client/dist/git/git-lifecycle-store.d.ts +23 -0
  26. package/packages/client/dist/git/git-lifecycle-store.js +9 -8
  27. package/packages/client/dist/git/governance-runtime-store.d.ts +172 -0
  28. package/packages/client/dist/git/governance-runtime-store.js +3 -0
  29. package/packages/client/dist/git/story-worktree-cleanup.js +1 -1
  30. package/packages/client/dist/git/story-worktree-integration.js +3 -3
  31. package/packages/client/dist/git/story-worktree-manager.d.ts +39 -0
  32. package/packages/client/dist/git/story-worktree-manager.js +3 -3
  33. package/packages/client/dist/git/story-write-set-extension.d.ts +62 -0
  34. package/packages/client/dist/git/story-write-set-extension.js +1 -1
  35. package/packages/client/dist/memory/shared-project-memory-types.d.ts +39 -2
  36. package/packages/client/dist/memory/shared-project-memory-types.js +2 -2
  37. package/packages/client/dist/policy/subagent-approval-policy.js +1 -1
  38. package/packages/client/dist/private-execution/codex-executor.d.ts +21 -1
  39. package/packages/client/dist/private-execution/codex-executor.js +4 -4
  40. package/packages/client/dist/private-execution/delivery.d.ts +17 -11
  41. package/packages/client/dist/private-execution/delivery.js +8 -6
  42. package/packages/client/dist/private-execution/diagnosis-root-review.d.ts +89 -0
  43. package/packages/client/dist/private-execution/diagnosis-root-review.js +2 -2
  44. package/packages/client/dist/private-execution/frozen-handoff.js +3 -3
  45. package/packages/client/dist/private-execution/harness-adapters/antigravity.d.ts +9 -0
  46. package/packages/client/dist/private-execution/harness-adapters/antigravity.js +1 -0
  47. package/packages/client/dist/private-execution/harness-adapters/claude-code.d.ts +8 -0
  48. package/packages/client/dist/private-execution/harness-adapters/claude-code.js +1 -0
  49. package/packages/client/dist/private-execution/harness-adapters/codex.d.ts +7 -0
  50. package/packages/client/dist/private-execution/harness-adapters/codex.js +1 -0
  51. package/packages/client/dist/private-execution/harness-adapters/copilot-cli.d.ts +8 -0
  52. package/packages/client/dist/private-execution/harness-adapters/copilot-cli.js +1 -0
  53. package/packages/client/dist/private-execution/harness-adapters/cursor.d.ts +9 -0
  54. package/packages/client/dist/private-execution/harness-adapters/cursor.js +1 -0
  55. package/packages/client/dist/private-execution/harness-adapters/deepseek.d.ts +9 -0
  56. package/packages/client/dist/private-execution/harness-adapters/deepseek.js +1 -0
  57. package/packages/client/dist/private-execution/harness-adapters/gemini.d.ts +8 -0
  58. package/packages/client/dist/private-execution/harness-adapters/gemini.js +1 -0
  59. package/packages/client/dist/private-execution/harness-adapters/grok.d.ts +9 -0
  60. package/packages/client/dist/private-execution/harness-adapters/grok.js +1 -0
  61. package/packages/client/dist/private-execution/harness-adapters/index.d.ts +73 -0
  62. package/packages/client/dist/private-execution/harness-adapters/index.js +1 -0
  63. package/packages/client/dist/private-execution/harness-adapters/kimi.d.ts +9 -0
  64. package/packages/client/dist/private-execution/harness-adapters/kimi.js +1 -0
  65. package/packages/client/dist/private-execution/harness-adapters/openclaw.d.ts +9 -0
  66. package/packages/client/dist/private-execution/harness-adapters/openclaw.js +1 -0
  67. package/packages/client/dist/private-execution/harness-adapters/opencode.d.ts +7 -0
  68. package/packages/client/dist/private-execution/harness-adapters/opencode.js +1 -0
  69. package/packages/client/dist/private-execution/harness-ephemeral-home.d.ts +19 -0
  70. package/packages/client/dist/private-execution/harness-ephemeral-home.js +1 -0
  71. package/packages/client/dist/private-execution/harness-executor.d.ts +79 -0
  72. package/packages/client/dist/private-execution/harness-executor.js +1 -0
  73. package/packages/client/dist/private-execution/harness-process.d.ts +43 -0
  74. package/packages/client/dist/private-execution/harness-process.js +1 -0
  75. package/packages/client/dist/private-execution/isolated-admission.js +12 -12
  76. package/packages/client/dist/private-execution/isolated-workspace.d.ts +16 -1
  77. package/packages/client/dist/private-execution/isolated-workspace.js +1 -1
  78. package/packages/client/dist/private-execution/planning-diagnosis-checkpoint.d.ts +75 -1
  79. package/packages/client/dist/private-execution/planning-diagnosis-checkpoint.js +5 -5
  80. package/packages/client/dist/private-execution/planning-generation-checkpoint.d.ts +9 -1
  81. package/packages/client/dist/private-execution/planning-generation-checkpoint.js +4 -4
  82. package/packages/client/dist/private-execution/planning-research-checkpoint.d.ts +9 -1
  83. package/packages/client/dist/private-execution/planning-research-checkpoint.js +4 -4
  84. package/packages/client/dist/private-execution/root-memory-request.d.ts +4 -1
  85. package/packages/client/dist/private-execution/root-memory-request.js +1 -1
  86. package/packages/client/dist/runner/epic-background-dispatcher.d.ts +3 -1
  87. package/packages/client/dist/runner/epic-background-dispatcher.js +1 -1
  88. package/packages/client/dist/runner/headless/claude-code-adapter.js +1 -1
  89. package/packages/client/dist/runner/headless/epic-terminal-git-cli-adapter.d.ts +1 -22
  90. package/packages/client/dist/runner/headless/epic-terminal-git-cli-adapter.js +6 -10
  91. package/packages/client/dist/runner/headless/managed-profile.d.ts +20 -0
  92. package/packages/client/dist/runner/headless/managed-profile.js +1 -1
  93. package/packages/client/dist/runner/headless/opencode-adapter.js +2 -2
  94. package/packages/client/dist/runner/headless/run-yoloop.d.ts +40 -0
  95. package/packages/client/dist/runner/headless/run-yoloop.js +2 -2
  96. package/packages/client/dist/runner/headless/types.d.ts +20 -0
  97. package/packages/client/dist/runner/headless/types.js +2 -2
  98. package/packages/client/dist/state/project-state-snapshot.d.ts +10 -0
  99. package/packages/client/dist/state/project-state-snapshot.js +1 -1
  100. package/packages/client/dist/state/structural-dag-projection.d.ts +26 -0
  101. package/packages/client/dist/state/structural-dag-projection.js +1 -1
  102. package/packages/client/dist/yoloop/target-normalization.js +1 -1
  103. package/packages/client/dist/yoloop/yoloop-client-state-store.d.ts +67 -0
  104. package/packages/client/dist/yoloop/yoloop-client-state-store.js +1 -1
  105. package/packages/shared/dist/compatibility/index.js +96 -0
  106. package/packages/shared/dist/planning/diagnosis-state.js +105 -1
  107. package/packages/shared/dist/project-memory-targets.js +36 -5
  108. package/targets-stubs/antigravity/README.md +1 -1
  109. package/targets-stubs/antigravity/gemini.md +1 -1
  110. package/targets-stubs/antigravity/install-antigravity.sh +1 -1
  111. package/targets-stubs/antigravity/mcp-config.json +0 -3
  112. package/targets-stubs/antigravity/neocortex.md +25 -13
  113. package/targets-stubs/antigravity/skill/SKILL.md +4 -4
  114. package/targets-stubs/claude-code/.mcp.json +0 -4
  115. package/targets-stubs/claude-code/neocortex-root.agent.yaml +2 -4
  116. package/targets-stubs/claude-code/neocortex-root.md +33 -43
  117. package/targets-stubs/claude-code/neocortex-sentinel.md +261 -0
  118. package/targets-stubs/claude-code/neocortex.agent.yaml +1 -3
  119. package/targets-stubs/claude-code/neocortex.md +61 -84
  120. package/targets-stubs/codex/AGENTS.md +19 -18
  121. package/targets-stubs/codex/README.md +1 -1
  122. package/targets-stubs/codex/config-mcp.toml +0 -3
  123. package/targets-stubs/codex/neocortex-sentinel.toml +87 -0
  124. package/targets-stubs/codex/neocortex.toml +23 -44
  125. package/targets-stubs/cursor/README.md +1 -1
  126. package/targets-stubs/cursor/agent.md +26 -15
  127. package/targets-stubs/cursor/mcp.json +0 -3
  128. package/targets-stubs/deepseek-harness/SKILL.md +11 -8
  129. package/targets-stubs/gemini-cli/README.md +1 -1
  130. package/targets-stubs/gemini-cli/agent.md +25 -12
  131. package/targets-stubs/gemini-cli/agents/neocortex-sentinel.md +75 -0
  132. package/targets-stubs/gemini-cli/agents/neocortex.md +280 -49
  133. package/targets-stubs/gemini-cli/settings-mcp.json +0 -3
  134. package/targets-stubs/grok/SKILL.md +13 -1
  135. package/targets-stubs/grok/agents/neocortex-sentinel.md +64 -0
  136. package/targets-stubs/grok/config-mcp.toml +0 -3
  137. package/targets-stubs/grok/install-grok.sh +51 -1
  138. package/targets-stubs/kimi/mcp.json +0 -6
  139. package/targets-stubs/kimi/neocortex.md +21 -8
  140. package/targets-stubs/lib/managed-config-merge.js +301 -6
  141. package/targets-stubs/lib/managed-profile.sh +12 -1
  142. package/targets-stubs/lib/mcp-merge.js +122 -8
  143. package/targets-stubs/openclaw/SKILL.md +33 -4
  144. package/targets-stubs/opencode/neocortex-root.md +41 -41
  145. package/targets-stubs/opencode/neocortex-sentinel.md +115 -0
  146. package/targets-stubs/opencode/neocortex.md +292 -67
  147. package/targets-stubs/opencode/opencode-mcp.json +0 -7
  148. package/targets-stubs/vscode/README.md +1 -1
  149. package/targets-stubs/vscode/mcp.json +0 -4
  150. package/targets-stubs/vscode/neocortex.agent.md +29 -18
package/install.ps1 CHANGED
@@ -17,7 +17,7 @@ param(
17
17
  [string]$ServerUrl = ('https://{0}.{1}.{2}' -f 'api','neocortex','sh')
18
18
  )
19
19
 
20
- $VERSION = "4.65.1"
20
+ $VERSION = "4.66.1"
21
21
 
22
22
  # =============================================================================
23
23
  # CONFIGURACOES
@@ -157,18 +157,18 @@ function Show-TargetResolutionDryRun {
157
157
  if ($resolved) {
158
158
  Write-Info "Dry-run target=$target adapter=$resolved scope=published-stub"
159
159
  switch ($target) {
160
- "cursor" { Write-Info "Dry-run MCP target=cursor file=$HOME\.cursor\mcp.json root=mcpServers managed=playwright,context7,browser_use,figma,shadcn,chrome-devtools action=add-or-update-preserve-custom" }
161
- "vscode" { Write-Info "Dry-run MCP target=vscode file=$(Get-VsCodeUserMcpPath) root=servers managed=playwright,context7,browser_use,figma,shadcn,chrome-devtools action=add-or-update-preserve-custom" }
162
- "gemini" { Write-Info "Dry-run MCP target=gemini file=$HOME\.gemini\settings.json root=mcpServers managed=playwright,context7,browser_use,figma,shadcn,chrome-devtools action=add-or-update-preserve-custom" }
163
- "gemini-cli" { Write-Info "Dry-run MCP target=gemini file=$HOME\.gemini\settings.json root=mcpServers managed=playwright,context7,browser_use,figma,shadcn,chrome-devtools action=add-or-update-preserve-custom" }
164
- "codex" { Write-Info "Dry-run MCP target=codex file=$HOME\.codex\config.toml root=mcp_servers managed=playwright,context7,browser_use,figma,shadcn,chrome-devtools action=replace-managed-sections-preserve-unknown" }
160
+ "cursor" { Write-Info "Dry-run MCP target=cursor file=$HOME\.cursor\mcp.json root=mcpServers managed=playwright,browser_use,figma,shadcn,chrome-devtools action=add-or-update-preserve-custom" }
161
+ "vscode" { Write-Info "Dry-run MCP target=vscode file=$(Get-VsCodeUserMcpPath) root=servers managed=playwright,browser_use,figma,shadcn,chrome-devtools action=add-or-update-preserve-custom" }
162
+ "gemini" { Write-Info "Dry-run MCP target=gemini file=$HOME\.gemini\settings.json root=mcpServers managed=playwright,browser_use,figma,shadcn,chrome-devtools action=add-or-update-preserve-custom" }
163
+ "gemini-cli" { Write-Info "Dry-run MCP target=gemini file=$HOME\.gemini\settings.json root=mcpServers managed=playwright,browser_use,figma,shadcn,chrome-devtools action=add-or-update-preserve-custom" }
164
+ "codex" { Write-Info "Dry-run MCP target=codex file=$HOME\.codex\config.toml root=mcp_servers managed=playwright,browser_use,figma,shadcn,chrome-devtools action=replace-managed-sections-preserve-unknown" }
165
165
  "grok" {
166
166
  $grokHome = if ($env:GROK_HOME) { $env:GROK_HOME } else { Join-Path $HOME ".grok" }
167
167
  Write-Info "Dry-run Skill target=grok file=$(Join-Path $grokHome 'skills\neocortex\SKILL.md') project=.grok\skills\neocortex\SKILL.md"
168
- Write-Info "Dry-run MCP target=grok file=$(Join-Path $grokHome 'config.toml') root=mcp_servers managed=playwright,context7,browser_use,figma,shadcn,chrome-devtools action=replace-managed-sections-preserve-unknown"
168
+ Write-Info "Dry-run MCP target=grok file=$(Join-Path $grokHome 'config.toml') root=mcp_servers managed=playwright,browser_use,figma,shadcn,chrome-devtools action=replace-managed-sections-preserve-unknown"
169
169
  }
170
- "opencode" { Write-Info "Dry-run MCP target=opencode file=$(Join-Path (Get-OpenCodeHome) 'opencode.json') root=mcp managed=playwright,context7,browser_use,figma,shadcn,chrome-devtools action=add-or-update-preserve-custom" }
171
- "kimi" { Write-Info "Dry-run MCP target=kimi file=$(Join-Path (Get-KimiHome) 'mcp.json') root=mcpServers managed=playwright,context7,browser_use,figma,shadcn,chrome-devtools action=add-or-update-preserve-custom" }
170
+ "opencode" { Write-Info "Dry-run MCP target=opencode file=$(Join-Path (Get-OpenCodeHome) 'opencode.json') root=mcp managed=playwright,browser_use,figma,shadcn,chrome-devtools action=add-or-update-preserve-custom" }
171
+ "kimi" { Write-Info "Dry-run MCP target=kimi file=$(Join-Path (Get-KimiHome) 'mcp.json') root=mcpServers managed=playwright,browser_use,figma,shadcn,chrome-devtools action=add-or-update-preserve-custom" }
172
172
  "openclaw" {
173
173
  $openClawHome = if ($env:OPENCLAW_HOME) { $env:OPENCLAW_HOME } else { Join-Path $HOME ".openclaw" }
174
174
  Write-Info "Dry-run Skill target=openclaw file=$(Join-Path $openClawHome 'skills\neocortex\SKILL.md') action=copy-skill-preserve-openclaw-json config=$(Join-Path $openClawHome 'openclaw.json') non-overwrite"
@@ -326,7 +326,9 @@ function Copy-ManagedFile {
326
326
  [string]$Source,
327
327
  [string]$Destination,
328
328
  [string]$ManagedId,
329
- [string]$BaseDir = $env:USERPROFILE
329
+ [string]$BaseDir = $env:USERPROFILE,
330
+ # P228.19 AM-04: nested legacy copy, removed by the helper only with a known hash.
331
+ [string]$LegacyCopy = ""
330
332
  )
331
333
  $helper = Get-ManagedConfigHelper
332
334
  if (-not $helper -or -not (Test-Path $Source -PathType Leaf)) { return $false }
@@ -336,6 +338,7 @@ function Copy-ManagedFile {
336
338
  }
337
339
  $manifest = Get-ManagedManifestPath -BaseDir $BaseDir
338
340
  $arguments = @($helper, "profile", $Source, $target, $manifest, $BaseDir, $ManagedId, "--adopt-legacy")
341
+ if ($LegacyCopy -and (Test-Path $LegacyCopy)) { $arguments += "--legacy-copy=$LegacyCopy" }
339
342
  if ($DryRun) { $arguments += "--dry-run" }
340
343
  $output = (& node @arguments 2>&1 | Out-String)
341
344
  $exitCode = $LASTEXITCODE
@@ -345,7 +348,13 @@ function Copy-ManagedFile {
345
348
  $script:ManagedAction = $action
346
349
  $script:ManagedReason = $reason
347
350
  if ($action -eq "skipped") {
348
- Write-Warn "Mudancas locais preservadas em $target ($reason). Para receber a versao nova, mova o arquivo e rode o instalador de novo."
351
+ # P228.19 (P228-CON-MANIFEST-MIGRATION): role-migration reason codes carry a next step.
352
+ switch ($reason) {
353
+ "agent-profile-migration-drift" { Write-Warn "Mudancas locais preservadas em $target ($reason). Proximo passo: mova o arquivo de lado e rode o instalador de novo (backup em .neocortex\backups\managed-config\)." }
354
+ "agent-profile-sentinel-missing" { Write-Warn "Mudancas locais preservadas em $target ($reason). Proximo passo: instale o neocortex-sentinel deste escopo e rode o instalador de novo." }
355
+ "agent-profile-name-collision" { Write-Warn "Mudancas locais preservadas em $target ($reason). Proximo passo: renomeie o outro perfil com o mesmo name e rode o instalador de novo." }
356
+ default { Write-Warn "Mudancas locais preservadas em $target ($reason). Para receber a versao nova, mova o arquivo e rode o instalador de novo." }
357
+ }
349
358
  return $true
350
359
  }
351
360
  if ($action -eq "failed") {
@@ -355,6 +364,113 @@ function Copy-ManagedFile {
355
364
  return $true
356
365
  }
357
366
 
367
+ # P228.19 (P228-CON-MANIFEST-MIGRATION): managed id of an agent role file.
368
+ # Same table as AGENT_ROLE_TABLE in targets-stubs\lib\managed-config-merge.js.
369
+ function Get-AgentRoleManagedId {
370
+ param([string]$Platform, [string]$Scope, [string]$File)
371
+ $prefix = if ($Scope -eq "project") { "project" } else { "profile" }
372
+ switch ("$Platform`:$File") {
373
+ "claude-code:neocortex-sentinel.md" { return "$prefix-claude-neocortex-sentinel-agent" }
374
+ "claude-code:neocortex.md" { return "$prefix-claude-neocortex-agent" }
375
+ "claude-code:neocortex-root.md" { if ($Scope -eq "user") { return "profile-claude-neocortex-root-agent" } else { return "" } }
376
+ "opencode:neocortex-sentinel.md" { return "$prefix-opencode-neocortex-sentinel" }
377
+ "opencode:neocortex.md" { return "$prefix-opencode-neocortex" }
378
+ "opencode:neocortex-root.md" { return "$prefix-opencode-neocortex-root" }
379
+ "codex:neocortex-sentinel.toml" { return "$prefix-codex-neocortex-sentinel" }
380
+ "codex:neocortex.toml" { return "$prefix-codex-neocortex" }
381
+ }
382
+ return ""
383
+ }
384
+
385
+ # P228.19: role profiles of one scope in order sentinel -> orchestrator ->
386
+ # alias. The helper enforces CAS, backup, drift and the sentinel precondition.
387
+ function Install-AgentRoleProfiles {
388
+ param(
389
+ [string]$Platform,
390
+ [string]$SourceDir,
391
+ [string]$AgentsDir,
392
+ [string]$BaseDir,
393
+ [string]$Scope,
394
+ [string]$LegacyDir = "",
395
+ [switch]$OrchestratorOnly
396
+ )
397
+ $ext = if ($Platform -eq "codex") { "toml" } else { "md" }
398
+ $ok = $true
399
+ $script:AgentRoleOrchestratorAction = ""
400
+ $files = @("neocortex-sentinel.$ext", "neocortex.$ext", "neocortex-root.$ext")
401
+ foreach ($file in $files) {
402
+ if ($OrchestratorOnly -and ($file -eq "neocortex-root.$ext")) { continue }
403
+ if (-not (Test-Path (Join-Path $SourceDir $file) -PathType Leaf)) { continue }
404
+ $id = Get-AgentRoleManagedId -Platform $Platform -Scope $Scope -File $file
405
+ if (-not $id) { continue }
406
+ $legacyCopy = ""
407
+ if ($LegacyDir -and (Test-Path (Join-Path $LegacyDir $file) -PathType Leaf)) { $legacyCopy = Join-Path $LegacyDir $file }
408
+ if (-not $DryRun) { New-Item -ItemType Directory -Path $AgentsDir -Force | Out-Null }
409
+ $result = Copy-ManagedFile -Source (Join-Path $SourceDir $file) -Destination (Join-Path $AgentsDir $file) -ManagedId $id -BaseDir $BaseDir -LegacyCopy $legacyCopy
410
+ if (-not $result) { $ok = $false }
411
+ if ($file -eq "neocortex.$ext") { $script:AgentRoleOrchestratorAction = $script:ManagedAction }
412
+ if ($DryRun) {
413
+ Write-Host "[MIGRATION] $Scope $id $(Join-Path $AgentsDir $file) $($script:ManagedAction) $($script:ManagedReason)"
414
+ }
415
+ }
416
+ return $ok
417
+ }
418
+
419
+ # P228.19 AM-05: migrate already-installed project role profiles of the
420
+ # current directory before any user-scope target. Never creates profiles.
421
+ function Invoke-ExistingProjectAgentRoleMigration {
422
+ param([string]$ProjectDir, [string[]]$TargetList)
423
+ if (-not (Test-Path $ProjectDir -PathType Container)) { return }
424
+ if (Test-NeocortexSourceProject -Path $ProjectDir) { return }
425
+ $realProject = (Resolve-Path $ProjectDir).Path
426
+ $realHome = (Resolve-Path $HOME).Path
427
+ if ($realProject -eq $realHome) { return }
428
+ if (-not (Test-Path (Join-Path $ProjectDir ".neocortex\managed-config-manifest.json") -PathType Leaf)) { return }
429
+ foreach ($target in $TargetList) {
430
+ switch ($target) {
431
+ "claude-code" {
432
+ $claudeTargetDir = Resolve-TargetDir -Target "claude-code"
433
+ $agentsDir = Join-Path $ProjectDir ".claude\agents"
434
+ if ($claudeTargetDir -and ((Test-Path (Join-Path $agentsDir "neocortex.md")) -or (Test-Path (Join-Path $agentsDir "neocortex-sentinel.md")))) {
435
+ $null = Install-AgentRoleProfiles -Platform "claude-code" -SourceDir $claudeTargetDir -AgentsDir $agentsDir -BaseDir $ProjectDir -Scope "project" -LegacyDir (Join-Path $agentsDir "neocortex")
436
+ }
437
+ }
438
+ "opencode" {
439
+ $opencodeTargetDir = Resolve-TargetDir -Target "opencode"
440
+ $agentsDir = Join-Path $ProjectDir ".opencode\agents"
441
+ if ($opencodeTargetDir -and ((Test-Path (Join-Path $agentsDir "neocortex.md")) -or (Test-Path (Join-Path $agentsDir "neocortex-sentinel.md")))) {
442
+ $null = Install-AgentRoleProfiles -Platform "opencode" -SourceDir $opencodeTargetDir -AgentsDir $agentsDir -BaseDir $ProjectDir -Scope "project"
443
+ }
444
+ }
445
+ }
446
+ }
447
+ }
448
+
449
+ # P228.19 AC3: dry-run plan of the role migration (no file is written).
450
+ function Show-AgentRoleMigrationPlan {
451
+ param([string[]]$TargetList)
452
+ if (-not $DryRun) { return }
453
+ Invoke-ExistingProjectAgentRoleMigration -ProjectDir (Get-Location).Path -TargetList $TargetList
454
+ foreach ($target in $TargetList) {
455
+ switch ($target) {
456
+ "claude-code" {
457
+ $claudeTargetDir = Resolve-TargetDir -Target "claude-code"
458
+ $claudeAgents = Join-Path $HOME ".claude\agents"
459
+ if ($claudeTargetDir -and (Test-Path (Join-Path $HOME ".claude") -PathType Container)) {
460
+ $null = Install-AgentRoleProfiles -Platform "claude-code" -SourceDir $claudeTargetDir -AgentsDir $claudeAgents -BaseDir $env:USERPROFILE -Scope "user" -LegacyDir (Join-Path $claudeAgents "neocortex")
461
+ }
462
+ }
463
+ "opencode" {
464
+ $opencodeTargetDir = Resolve-TargetDir -Target "opencode"
465
+ $opencodeHome = Get-OpenCodeHome
466
+ if ($opencodeTargetDir -and (Test-Path $opencodeHome -PathType Container)) {
467
+ $null = Install-AgentRoleProfiles -Platform "opencode" -SourceDir $opencodeTargetDir -AgentsDir "$opencodeHome\agents" -BaseDir (Get-ManagedPlatformBase -PlatformHome $opencodeHome -DefaultBase $HOME) -Scope "user"
468
+ }
469
+ }
470
+ }
471
+ }
472
+ }
473
+
358
474
  # Managed base for a platform home (CODEX_HOME, GEMINI_HOME, ...): the user
359
475
  # profile when the home lives inside it, the platform home itself when it is
360
476
  # redirected outside (environment variable, junction or symlink).
@@ -1252,21 +1368,27 @@ function Install-Agent {
1252
1368
  # goes to $script:AgentsDir\neocortex.md; .version and the yaml stay in DestDir.
1253
1369
  # Epic 64 (Story 64.2): Capture copy result and check for errors
1254
1370
  $destMd = Join-Path $script:AgentsDir "neocortex.md"
1255
- $stubResult1 = Copy-ManagedFile -Source "$claudeTargetDir\neocortex.md" -Destination $destMd -ManagedId "profile-claude-neocortex-agent" -BaseDir $env:USERPROFILE
1371
+ # P228.19: sentinel -> orchestrator (neocortex.md) -> alias (neocortex-root.md),
1372
+ # each CAS-guarded by the helper. The nested legacy agent (not discovered by
1373
+ # Claude Code) is removed by the helper only with a known managed hash (AM-04).
1374
+ $legacyMd = Join-Path $script:DestDir "neocortex.md"
1375
+ if (Test-Path "$claudeTargetDir\neocortex-sentinel.md") {
1376
+ $sentinelResult = Copy-ManagedFile -Source "$claudeTargetDir\neocortex-sentinel.md" -Destination (Join-Path $script:AgentsDir "neocortex-sentinel.md") -ManagedId "profile-claude-neocortex-sentinel-agent" -BaseDir $env:USERPROFILE
1377
+ if (-not $sentinelResult) { $script:Errors++; Write-Fail "Falha ao copiar neocortex-sentinel.md de $claudeTargetDir" }
1378
+ }
1379
+ $stubResult1 = Copy-ManagedFile -Source "$claudeTargetDir\neocortex.md" -Destination $destMd -ManagedId "profile-claude-neocortex-agent" -BaseDir $env:USERPROFILE -LegacyCopy $legacyMd
1256
1380
  if (-not $stubResult1) { $script:Errors++; Write-Fail "Falha ao copiar neocortex.md de $claudeTargetDir" }
1257
- $claudeAgentAction = $script:ManagedAction
1258
1381
  Write-Dbg "Install-Agent: Copy neocortex.md result=$stubResult1"
1382
+ if (Test-Path "$claudeTargetDir\neocortex-root.md") {
1383
+ $stubResultRoot = Copy-ManagedFile -Source "$claudeTargetDir\neocortex-root.md" -Destination (Join-Path $script:AgentsDir "neocortex-root.md") -ManagedId "profile-claude-neocortex-root-agent" -BaseDir $env:USERPROFILE -LegacyCopy (Join-Path $script:DestDir "neocortex-root.md")
1384
+ if (-not $stubResultRoot) { $script:Errors++; Write-Fail "Falha ao copiar neocortex-root.md de $claudeTargetDir" }
1385
+ }
1259
1386
  $stubResult2 = Copy-Silent "$claudeTargetDir\neocortex.agent.yaml" "$script:DestDir\"
1260
1387
  if (-not $stubResult2) { Write-Fail "Falha ao copiar neocortex.agent.yaml de $claudeTargetDir" }
1261
1388
  Write-Dbg "Install-Agent: Copy neocortex.agent.yaml result=$stubResult2"
1262
1389
  # 4.64.3: the root profile (owns *yoloop) ships beside the subagent stub.
1263
- if (Test-Path "$claudeTargetDir\neocortex-root.md") {
1264
- $destRootMd = Join-Path $script:AgentsDir "neocortex-root.md"
1265
- $stubResultRoot = Copy-ManagedFile -Source "$claudeTargetDir\neocortex-root.md" -Destination $destRootMd -ManagedId "profile-claude-neocortex-root-agent" -BaseDir $env:USERPROFILE
1266
- if (-not $stubResultRoot) { $script:Errors++; Write-Fail "Falha ao copiar neocortex-root.md de $claudeTargetDir" }
1267
- if (Test-Path "$claudeTargetDir\neocortex-root.agent.yaml") {
1268
- $null = Copy-Silent "$claudeTargetDir\neocortex-root.agent.yaml" "$script:DestDir\"
1269
- }
1390
+ if ((Test-Path "$claudeTargetDir\neocortex-root.md") -and (Test-Path "$claudeTargetDir\neocortex-root.agent.yaml")) {
1391
+ $null = Copy-Silent "$claudeTargetDir\neocortex-root.agent.yaml" "$script:DestDir\"
1270
1392
  }
1271
1393
 
1272
1394
  # 4.64.5: v4 story worktrees must start from the epic checkout (local HEAD).
@@ -1280,13 +1402,6 @@ function Install-Agent {
1280
1402
  if (-not (Test-Path $destMd -PathType Leaf)) {
1281
1403
  Write-Fail "neocortex.md nao encontrado no destino apos copia: $destMd"
1282
1404
  if (-not $stubResult1) {} else { $script:Errors++ }
1283
- } elseif ((-not $DryRun) -and ($claudeAgentAction -ne "skipped")) {
1284
- # Migration: remove the legacy nested agent (not discovered by Claude
1285
- # Code) so two same-name agents never coexist. Only that file is removed.
1286
- $legacyMd = Join-Path $script:DestDir "neocortex.md"
1287
- if (Test-Path $legacyMd -PathType Leaf) {
1288
- Remove-Item $legacyMd -Force -ErrorAction SilentlyContinue
1289
- }
1290
1405
  }
1291
1406
  if (-not (Test-Path $destYaml -PathType Leaf)) {
1292
1407
  Write-Fail "neocortex.agent.yaml nao encontrado no destino apos copia: $destYaml"
@@ -1330,35 +1445,6 @@ function Import-EnvFile {
1330
1445
  return $true
1331
1446
  }
1332
1447
 
1333
- # =============================================================================
1334
- # CONFIGURACAO DE TOKENS
1335
- # =============================================================================
1336
-
1337
- function Request-Tokens {
1338
- if ($QUIET_MODE -or $AUTO_YES -or $env:CONTEXT7_API_KEY) { return }
1339
-
1340
- Write-Host ""
1341
- Write-Info "MCP Context7 nao configurado (opcional)"
1342
- Write-Host " Configurar agora? [s/N]: " -NoNewline -ForegroundColor White
1343
- $response = Read-HostWithTimeout -TimeoutSeconds 15 -Default "n"
1344
-
1345
- if ($response -match "^[sS]([iI][mM]?)?$|^[yY]([eE][sS]?)?$") {
1346
- Write-Host ""
1347
- Write-Info "Obtenha sua API Key em: https://context7.com"
1348
- Write-Host " Cole sua CONTEXT7_API_KEY: " -NoNewline -ForegroundColor White
1349
- try {
1350
- $apiKey = Read-Host
1351
- if ($apiKey -match "^ctx7sk-") {
1352
- $env:CONTEXT7_API_KEY = $apiKey
1353
- Write-Ok "CONTEXT7_API_KEY configurada"
1354
- Write-Info "Para persistir: `$env:CONTEXT7_API_KEY = `"$apiKey`" em `$PROFILE"
1355
- } elseif ($apiKey) {
1356
- Write-Warn "Formato invalido (esperado: ctx7sk-...)"
1357
- }
1358
- } catch {}
1359
- }
1360
- }
1361
-
1362
1448
  # =============================================================================
1363
1449
  # INSTALACAO DE MCP SERVERS
1364
1450
  # =============================================================================
@@ -1382,15 +1468,14 @@ function Install-MCPs {
1382
1468
  if ($LASTEXITCODE -eq 0) { $mcpOk += "playwright" }
1383
1469
  } catch {}
1384
1470
 
1385
- # Context7
1386
- if ($env:CONTEXT7_API_KEY) {
1387
- try {
1388
- & claude mcp add --scope user --transport http context7 https://mcp.context7.com/mcp --header "CONTEXT7_API_KEY: $env:CONTEXT7_API_KEY" 2>$null
1389
- if ($LASTEXITCODE -eq 0) { $mcpOk += "context7" }
1390
- } catch {}
1391
- } else {
1392
- $mcpSkip += "context7"
1393
- }
1471
+ # P228.08: Context7 is no longer managed. A legacy user-scope entry is never
1472
+ # read, printed or removed here; only the CLI exit code is used.
1473
+ try {
1474
+ & claude mcp get context7 *> $null
1475
+ if ($LASTEXITCODE -eq 0) {
1476
+ Write-Info "context7-legacy-entry-retained (Context7 nao e mais gerenciado; para remover: claude mcp remove context7 --scope user)"
1477
+ }
1478
+ } catch {}
1394
1479
 
1395
1480
  # browser_use: optional (requires uvx and at least one supported LLM API key).
1396
1481
  # Supported env vars are referenced by name only in logs: OPENAI_API_KEY,
@@ -1439,6 +1524,58 @@ $script:SelectedTargets = @()
1439
1524
  $script:TargetResults = @()
1440
1525
  $script:TargetCount = 0
1441
1526
 
1527
+ # P228.05: the per-platform tier table is generated from the server table
1528
+ # (packages/shared/src/tier-config.ts PLATFORM_GATES) and checked by
1529
+ # packages/shared/src/__tests__/p228-tier-parity.test.ts. Never edit by hand.
1530
+ # BEGIN NEOCORTEX PLATFORM TIER TABLE (generated from packages/shared/src/tier-config.ts PLATFORM_GATES; do not edit by hand)
1531
+ $script:PlatformRequiredTier = @{
1532
+ "claude-code" = "free"
1533
+ "cursor" = "pro"
1534
+ "vscode" = "pro"
1535
+ "gemini" = "pro"
1536
+ "gemini-cli" = "pro"
1537
+ "codex" = "pro"
1538
+ "grok" = "pro"
1539
+ "antigravity" = "pro"
1540
+ "opencode" = "pro"
1541
+ "kimi" = "pro"
1542
+ "openclaw" = "pro"
1543
+ "deepseek-harness" = "pro"
1544
+ }
1545
+ # END NEOCORTEX PLATFORM TIER TABLE
1546
+
1547
+ function Get-TierFromConfig {
1548
+ $configPath = Join-Path (Join-Path $HOME ".neocortex") "config.json"
1549
+ if (-not (Test-Path $configPath -PathType Leaf)) { return "free" }
1550
+ try {
1551
+ $cfg = Get-Content -Path $configPath -Raw -ErrorAction Stop | ConvertFrom-Json -ErrorAction Stop
1552
+ if ($cfg.tier -is [string] -and $cfg.tier) { return $cfg.tier.Trim().ToLowerInvariant() }
1553
+ } catch { }
1554
+ return "free"
1555
+ }
1556
+
1557
+ # Tier hierarchy (free < pro < enterprise). Unrecognized values rank as free,
1558
+ # so the installer can only narrow access and never grants a tier.
1559
+ function Get-PlatformTierRank {
1560
+ param([string]$Tier)
1561
+ switch ($Tier) {
1562
+ "enterprise" { return 2 }
1563
+ "pro" { return 1 }
1564
+ default { return 0 }
1565
+ }
1566
+ }
1567
+
1568
+ function Test-PlatformTier {
1569
+ param([string]$Platform, [string]$Tier)
1570
+ $required = "free"
1571
+ if ($script:PlatformRequiredTier.ContainsKey($Platform)) { $required = $script:PlatformRequiredTier[$Platform] }
1572
+ if ((Get-PlatformTierRank -Tier $Tier) -ge (Get-PlatformTierRank -Tier $required)) { return $true }
1573
+ $requiredLabel = if ($required -eq "enterprise") { "Enterprise" } else { "Pro" }
1574
+ Write-Warn "$Platform requer plano $requiredLabel. Plataforma disponivel: Claude Code."
1575
+ Write-Info "Upgrade: https://neocortex.sh/portal/dashboard/plans"
1576
+ return $false
1577
+ }
1578
+
1442
1579
  function Install-Targets {
1443
1580
  param([string[]]$TargetList)
1444
1581
 
@@ -1558,7 +1695,8 @@ function Install-Targets {
1558
1695
  if (-not (Copy-ManagedFile -Source "$codexTargetDir\AGENTS.md" -Destination "$codexHome\AGENTS.md" -ManagedId "profile-codex-root" -BaseDir $codexBase)) { $codexOk = $false }
1559
1696
  }
1560
1697
  if (Test-Path "$codexTargetDir\neocortex.toml") {
1561
- if (-not (Copy-ManagedFile -Source "$codexTargetDir\neocortex.toml" -Destination "$codexHome\agents\neocortex.toml" -ManagedId "profile-codex-neocortex" -BaseDir $codexBase)) { $codexOk = $false }
1698
+ # P228.19: sentinel -> orchestrator, CAS-guarded by the helper.
1699
+ if (-not (Install-AgentRoleProfiles -Platform "codex" -SourceDir $codexTargetDir -AgentsDir "$codexHome\agents" -BaseDir $codexBase -Scope "user")) { $codexOk = $false }
1562
1700
  }
1563
1701
  if (Test-Path "$codexTargetDir\config-mcp.toml") {
1564
1702
  $configFile = "$codexHome\config.toml"
@@ -1608,7 +1746,7 @@ function Install-Targets {
1608
1746
  if (Test-Path "$antiTargetDir\mcp-config.json") {
1609
1747
  New-Item -ItemType Directory -Path "$geminiHome\antigravity" -Force | Out-Null
1610
1748
  # Antigravity uses root mcpServers; preserve custom entries while migrating managed legacy top-level entries.
1611
- Merge-JsonMcpConfig -StubFile "$antiTargetDir\mcp-config.json" -DestFile "$geminiHome\antigravity\mcp_config.json" -RootKey "mcpServers" -ManagedTopLevelNames @("playwright", "context7", "browser_use", "figma", "shadcn", "chrome-devtools")
1749
+ Merge-JsonMcpConfig -StubFile "$antiTargetDir\mcp-config.json" -DestFile "$geminiHome\antigravity\mcp_config.json" -RootKey "mcpServers" -ManagedTopLevelNames @("playwright", "browser_use", "figma", "shadcn", "chrome-devtools")
1612
1750
  }
1613
1751
  if (Test-Path "$antiTargetDir\gemini.md") {
1614
1752
  Copy-ManagedFile -Source "$antiTargetDir\gemini.md" -Destination "$homeDir\GEMINI.md" -ManagedId "profile-antigravity-root" -BaseDir $homeDir | Out-Null
@@ -1626,8 +1764,13 @@ function Install-Targets {
1626
1764
  $opencodeHome = Get-OpenCodeHome
1627
1765
  if ($opencodeTargetDir -and (Test-Path "$opencodeTargetDir\neocortex.md") -and (Test-Path "$opencodeTargetDir\neocortex-root.md")) {
1628
1766
  New-Item -ItemType Directory -Path "$opencodeHome\agents" -Force | Out-Null
1629
- Copy-ManagedFile -Source "$opencodeTargetDir\neocortex.md" -Destination "$opencodeHome\agents\neocortex.md" -ManagedId "profile-opencode-neocortex" -BaseDir (Get-ManagedPlatformBase -PlatformHome $opencodeHome -DefaultBase $homeDir) | Out-Null
1630
- Copy-ManagedFile -Source "$opencodeTargetDir\neocortex-root.md" -Destination "$opencodeHome\agents\neocortex-root.md" -ManagedId "profile-opencode-neocortex-root" -BaseDir (Get-ManagedPlatformBase -PlatformHome $opencodeHome -DefaultBase $homeDir) | Out-Null
1767
+ # P228.19: sentinel -> orchestrator -> alias, CAS-guarded by the helper.
1768
+ $opencodeBase = Get-ManagedPlatformBase -PlatformHome $opencodeHome -DefaultBase $homeDir
1769
+ if (Test-Path "$opencodeTargetDir\neocortex-sentinel.md") {
1770
+ Copy-ManagedFile -Source "$opencodeTargetDir\neocortex-sentinel.md" -Destination "$opencodeHome\agents\neocortex-sentinel.md" -ManagedId "profile-opencode-neocortex-sentinel" -BaseDir $opencodeBase | Out-Null
1771
+ }
1772
+ Copy-ManagedFile -Source "$opencodeTargetDir\neocortex.md" -Destination "$opencodeHome\agents\neocortex.md" -ManagedId "profile-opencode-neocortex" -BaseDir $opencodeBase | Out-Null
1773
+ Copy-ManagedFile -Source "$opencodeTargetDir\neocortex-root.md" -Destination "$opencodeHome\agents\neocortex-root.md" -ManagedId "profile-opencode-neocortex-root" -BaseDir $opencodeBase | Out-Null
1631
1774
  if (Test-Path "$opencodeTargetDir\opencode-mcp.json") {
1632
1775
  Merge-JsonMcpConfig -StubFile "$opencodeTargetDir\opencode-mcp.json" -DestFile "$opencodeHome\opencode.json" -RootKey "mcp"
1633
1776
  }
@@ -1752,13 +1895,14 @@ function New-ProjectDirectories {
1752
1895
  # Claude Code only discovers top-level agents\*.md; the yaml stays in the subdir.
1753
1896
  # Epic 64 (Story 64.2): Capture copy result
1754
1897
  $projectAgentMd = "$projectDir\.claude\agents\neocortex.md"
1755
- $r = Copy-ManagedFile -Source "$claudeTargetDir\neocortex.md" -Destination $projectAgentMd -ManagedId "project-claude-neocortex-agent" -BaseDir $projectDir
1756
- if (-not $r) { $script:Errors++; Write-Fail "Falha ao copiar neocortex.md (projeto)" }
1757
- # Migration: remove the legacy nested agent after the top-level write
1758
- # (never when an existing top-level file was preserved as drift)
1759
- if ((-not $DryRun) -and ($script:ManagedAction -ne "skipped") -and (Test-Path $projectAgentMd -PathType Leaf) -and (Test-Path "$agentDest\neocortex.md" -PathType Leaf)) {
1760
- Remove-Item "$agentDest\neocortex.md" -Force -ErrorAction SilentlyContinue
1898
+ # P228.19: sentinel before the orchestrator; the nested legacy agent
1899
+ # is removed by the helper only with a known hash (AM-04).
1900
+ if (Test-Path "$claudeTargetDir\neocortex-sentinel.md") {
1901
+ $r = Copy-ManagedFile -Source "$claudeTargetDir\neocortex-sentinel.md" -Destination "$projectDir\.claude\agents\neocortex-sentinel.md" -ManagedId "project-claude-neocortex-sentinel-agent" -BaseDir $projectDir
1902
+ if (-not $r) { $script:Errors++; Write-Fail "Falha ao copiar neocortex-sentinel.md (projeto)" }
1761
1903
  }
1904
+ $r = Copy-ManagedFile -Source "$claudeTargetDir\neocortex.md" -Destination $projectAgentMd -ManagedId "project-claude-neocortex-agent" -BaseDir $projectDir -LegacyCopy "$agentDest\neocortex.md"
1905
+ if (-not $r) { $script:Errors++; Write-Fail "Falha ao copiar neocortex.md (projeto)" }
1762
1906
  $r = Copy-Silent "$claudeTargetDir\neocortex.agent.yaml" "$agentDest\" -BaseDir $projectDir
1763
1907
  if (-not $r) { Write-Fail "Falha ao copiar neocortex.agent.yaml (projeto)" }
1764
1908
  # Cleanup workflow.md from previous versions
@@ -1838,7 +1982,7 @@ function New-ProjectDirectories {
1838
1982
  if (Test-Path "$codexTargetDir\AGENTS.md") { Copy-ManagedFile -Source "$codexTargetDir\AGENTS.md" -Destination "$projectDir\AGENTS.md" -ManagedId "project-codex-root" -BaseDir $projectDir | Out-Null }
1839
1983
  if (Test-Path "$codexTargetDir\neocortex.toml") {
1840
1984
  New-Item -ItemType Directory -Path "$projectDir\.codex\agents" -Force | Out-Null
1841
- Copy-ManagedFile -Source "$codexTargetDir\neocortex.toml" -Destination "$projectDir\.codex\agents\neocortex.toml" -ManagedId "project-codex-neocortex" -BaseDir $projectDir | Out-Null
1985
+ $null = Install-AgentRoleProfiles -Platform "codex" -SourceDir $codexTargetDir -AgentsDir "$projectDir\.codex\agents" -BaseDir $projectDir -Scope "project"
1842
1986
  }
1843
1987
  $targetSummary += "codex"
1844
1988
  }
@@ -1884,6 +2028,10 @@ function New-ProjectDirectories {
1884
2028
  $opencodeTargetDir = Resolve-TargetDir -Target "opencode"
1885
2029
  if ($opencodeTargetDir -and (Test-Path "$opencodeTargetDir\neocortex.md") -and (Test-Path "$opencodeTargetDir\neocortex-root.md")) {
1886
2030
  New-Item -ItemType Directory -Path "$projectDir\.opencode\agents" -Force | Out-Null
2031
+ # P228.19: sentinel before the orchestrator.
2032
+ if (Test-Path "$opencodeTargetDir\neocortex-sentinel.md") {
2033
+ Copy-ManagedFile -Source "$opencodeTargetDir\neocortex-sentinel.md" -Destination "$projectDir\.opencode\agents\neocortex-sentinel.md" -ManagedId "project-opencode-neocortex-sentinel" -BaseDir $projectDir | Out-Null
2034
+ }
1887
2035
  Copy-ManagedFile -Source "$opencodeTargetDir\neocortex.md" -Destination "$projectDir\.opencode\agents\neocortex.md" -ManagedId "project-opencode-neocortex" -BaseDir $projectDir | Out-Null
1888
2036
  Copy-ManagedFile -Source "$opencodeTargetDir\neocortex-root.md" -Destination "$projectDir\.opencode\agents\neocortex-root.md" -ManagedId "project-opencode-neocortex-root" -BaseDir $projectDir | Out-Null
1889
2037
  $targetSummary += "opencode"
@@ -2026,10 +2174,27 @@ if ($Targets) {
2026
2174
  $script:SelectedTargets = @("claude-code")
2027
2175
  }
2028
2176
 
2177
+ # P228.05: filter tier-blocked platforms with the server table (narrow only).
2178
+ $userTier = Get-TierFromConfig
2179
+ Write-Dbg "User tier: $userTier"
2180
+ $allowedTargets = @($script:SelectedTargets | Where-Object { Test-PlatformTier -Platform $_ -Tier $userTier })
2181
+ $blockedTargets = @($script:SelectedTargets | Where-Object { $_ -notin $allowedTargets })
2182
+ if ($blockedTargets.Count -gt 0) {
2183
+ Write-Info "Plataforma(s) bloqueada(s) por tier: $($blockedTargets -join ', ')"
2184
+ }
2185
+ if ($allowedTargets.Count -gt 0) {
2186
+ $script:SelectedTargets = $allowedTargets
2187
+ } else {
2188
+ $script:SelectedTargets = @("claude-code")
2189
+ Write-Info "Usando plataforma padrao: claude-code"
2190
+ }
2191
+
2029
2192
  Write-Dbg "Targets: $($script:SelectedTargets -join ', ')"
2030
2193
 
2031
2194
  if ($DryRun) {
2032
2195
  Show-TargetResolutionDryRun -TargetList $script:SelectedTargets
2196
+ # P228.19 AC3: report the role-migration plan; nothing is written.
2197
+ Show-AgentRoleMigrationPlan -TargetList $script:SelectedTargets
2033
2198
  exit 0
2034
2199
  }
2035
2200
 
@@ -2055,12 +2220,13 @@ Install-Skills | Out-Null
2055
2220
 
2056
2221
  # Step 4: Targets
2057
2222
  Write-Step 4 $totalSteps "Instalando $($script:SelectedTargets.Count) plataforma(s)"
2223
+ # P228.19 AM-05: existing project role profiles migrate before the user scope.
2224
+ Invoke-ExistingProjectAgentRoleMigration -ProjectDir (Get-Location).Path -TargetList $script:SelectedTargets
2058
2225
  Install-Targets -TargetList $script:SelectedTargets
2059
2226
 
2060
2227
  # Step 5: Claude Code extras
2061
2228
  if ($script:SelectedTargets -contains "claude-code") {
2062
2229
  Import-EnvFile | Out-Null
2063
- Request-Tokens
2064
2230
 
2065
2231
  Write-Step 5 $totalSteps "Configurando MCPs"
2066
2232
  Install-MCPs