@ornexus/neocortex 4.66.50 → 4.66.52

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 (41) hide show
  1. package/dist/release-source.json +1 -1
  2. package/dist/sbom.cdx.json +1190 -1190
  3. package/install.js +8 -8
  4. package/install.ps1 +188 -162
  5. package/install.sh +1 -1
  6. package/package.json +2 -2
  7. package/packages/client/dist/commands/activate.js +6 -7
  8. package/packages/client/dist/commands/invoke.js +82 -82
  9. package/packages/client/dist/config/secure-config.d.ts +4 -0
  10. package/packages/client/dist/config/secure-config.js +6 -6
  11. package/packages/client/dist/migrations/project-identity.d.ts +3 -0
  12. package/packages/client/dist/migrations/project-identity.js +7 -7
  13. package/packages/client/dist/private-execution/isolated-admission.js +11 -11
  14. package/packages/client/dist/private-execution/isolated-workspace.js +1 -1
  15. package/packages/client/dist/private-execution/planning-diagnosis-checkpoint.js +5 -5
  16. package/packages/client/dist/private-execution/planning-memory-checkpoint.js +3 -3
  17. package/packages/client/dist/runner/headless/run-yoloop.d.ts +2 -0
  18. package/packages/client/dist/runner/headless/run-yoloop.js +4 -4
  19. package/packages/shared/dist/invocation/semantic-gate-remediation.d.ts +45 -0
  20. package/packages/shared/dist/invocation/semantic-gate-remediation.js +51 -0
  21. package/targets-stubs/antigravity/gemini.md +1 -1
  22. package/targets-stubs/antigravity/neocortex.md +1 -1
  23. package/targets-stubs/antigravity/skill/SKILL.md +1 -1
  24. package/targets-stubs/claude-code/neocortex-root.agent.yaml +1 -1
  25. package/targets-stubs/claude-code/neocortex-root.md +2 -2
  26. package/targets-stubs/claude-code/neocortex-sentinel.md +1 -1
  27. package/targets-stubs/claude-code/neocortex.agent.yaml +1 -1
  28. package/targets-stubs/claude-code/neocortex.md +2 -2
  29. package/targets-stubs/codex/AGENTS.md +1 -1
  30. package/targets-stubs/codex/neocortex.toml +1 -1
  31. package/targets-stubs/cursor/agent.md +2 -2
  32. package/targets-stubs/deepseek-harness/SKILL.md +1 -1
  33. package/targets-stubs/gemini-cli/agent.md +2 -2
  34. package/targets-stubs/gemini-cli/agents/neocortex.md +2 -2
  35. package/targets-stubs/grok/SKILL.md +1 -1
  36. package/targets-stubs/kimi/neocortex.md +1 -1
  37. package/targets-stubs/lib/managed-config-merge.js +12 -4
  38. package/targets-stubs/openclaw/SKILL.md +1 -1
  39. package/targets-stubs/opencode/neocortex-root.md +2 -2
  40. package/targets-stubs/opencode/neocortex.md +2 -2
  41. package/targets-stubs/vscode/neocortex.agent.md +2 -2
package/install.ps1 CHANGED
@@ -19,7 +19,7 @@ param(
19
19
  [string]$ServerUrl = ('https://{0}.{1}.{2}' -f 'api','neocortex','sh')
20
20
  )
21
21
 
22
- $VERSION = "4.66.50"
22
+ $VERSION = "4.66.52"
23
23
 
24
24
  # =============================================================================
25
25
  # CONFIGURACOES
@@ -63,7 +63,7 @@ if ($Help) {
63
63
  Write-Host " Uso: npx @ornexus/neocortex [opcoes]"
64
64
  Write-Host ""
65
65
  Write-Host " Opcoes:" -ForegroundColor DarkGray
66
- Write-Host " -Yes Modo automatico (Claude Code only)" -ForegroundColor Cyan
66
+ Write-Host " -Yes Modo automatico. Use -Targets para selecionar plataformas." -ForegroundColor Cyan
67
67
  Write-Host " -Targets <lista> Plataformas separadas por virgula" -ForegroundColor Cyan
68
68
  Write-Host " -CreateProject Instalar estrutura no projeto (opt-in)" -ForegroundColor Cyan
69
69
  Write-Host " -SkipProject Instalacao somente global (padrao)" -ForegroundColor Cyan
@@ -310,25 +310,34 @@ function Get-ManagedManifestPath {
310
310
  }
311
311
 
312
312
  function Invoke-ManagedPolicy {
313
- param([string]$BaseDir = $env:USERPROFILE)
313
+ param([string]$BaseDir = $env:USERPROFILE, [switch]$CheckOnly)
314
314
  $helper = Get-ManagedConfigHelper
315
- if (-not $helper) { return $false }
315
+ if (-not $helper) {
316
+ Write-Warn "managed-helper-unavailable. Reinstale o pacote npm e confira node.exe."
317
+ return $false
318
+ }
316
319
  $configFile = Join-Path $BaseDir ".neocortex\config.json"
317
320
  $manifest = Get-ManagedManifestPath -BaseDir $BaseDir
318
321
  $arguments = @($helper, "policy", $configFile, $manifest, $BaseDir)
319
- if ($DryRun) { $arguments += "--dry-run" }
320
- & node @arguments 2>$null | Out-Null
321
- return ($LASTEXITCODE -eq 0)
322
- }
323
-
324
- function Test-ManagedPolicy {
325
- param([string]$BaseDir = $env:USERPROFILE)
326
- $helper = Get-ManagedConfigHelper
327
- if (-not $helper) { return $false }
328
- $configFile = Join-Path $BaseDir ".neocortex\config.json"
329
- $manifest = Get-ManagedManifestPath -BaseDir $BaseDir
330
- & node $helper policy $configFile $manifest $BaseDir --dry-run 2>$null | Out-Null
331
- return ($LASTEXITCODE -eq 0)
322
+ if ($DryRun -or $CheckOnly) { $arguments += "--dry-run" }
323
+ $output = @(& node @arguments 2>&1)
324
+ if ($LASTEXITCODE -eq 0) { return $true }
325
+ $reason = "managed-operation-failed"
326
+ foreach ($line in $output) {
327
+ try {
328
+ $report = $line.ToString() | ConvertFrom-Json -ErrorAction Stop
329
+ if ($report.action -eq "failed" -and $report.reasonCode -match '^managed-[a-z0-9-]{1,75}$') {
330
+ $reason = $report.reasonCode
331
+ break
332
+ }
333
+ } catch { }
334
+ }
335
+ if ($reason -eq "managed-config-access-denied") {
336
+ Write-Warn "$reason. Confira o acesso ao perfil usando a conta que o criou e feche programas que usam config.json."
337
+ } else {
338
+ Write-Warn "$reason. Confira a configuracao do perfil e a politica de aprovacao. Arquivos existentes preservados."
339
+ }
340
+ return $false
332
341
  }
333
342
 
334
343
  function Copy-ManagedFile {
@@ -351,7 +360,7 @@ function Copy-ManagedFile {
351
360
  # P231.05 AC4: same tier transform as install.sh, applied by the helper before planning.
352
361
  # Like install.sh: only an explicit config tier is forwarded (no implicit "free").
353
362
  $tierValue = ""
354
- $tierConfig = Join-Path (Join-Path $HOME ".neocortex") "config.json"
363
+ $tierConfig = Join-Path (Join-Path $env:USERPROFILE ".neocortex") "config.json"
355
364
  if (Test-Path $tierConfig -PathType Leaf) {
356
365
  try { $tierCfg = Get-Content -Path $tierConfig -Raw -ErrorAction Stop | ConvertFrom-Json -ErrorAction Stop; if ($tierCfg.tier -is [string]) { $tierValue = $tierCfg.tier } } catch { }
357
366
  }
@@ -550,18 +559,18 @@ function Test-NeocortexUserHome {
550
559
  function Set-FileAcl {
551
560
  param([string]$Path)
552
561
  try {
553
- $username = $env:USERNAME
554
- if (-not $username) { return }
555
- & icacls $Path /inheritance:r /grant:r "${username}:(F)" 2>$null | Out-Null
562
+ $sid = [System.Security.Principal.WindowsIdentity]::GetCurrent().User.Value
563
+ if (-not $sid) { return }
564
+ & "$env:SystemRoot\System32\icacls.exe" $Path /inheritance:r /grant:r "*${sid}:(F)" 2>$null | Out-Null
556
565
  } catch { }
557
566
  }
558
567
 
559
568
  function Set-DirAcl {
560
569
  param([string]$Path)
561
570
  try {
562
- $username = $env:USERNAME
563
- if (-not $username) { return }
564
- & icacls $Path /inheritance:r /grant:r "${username}:(OI)(CI)(F)" 2>$null | Out-Null
571
+ $sid = [System.Security.Principal.WindowsIdentity]::GetCurrent().User.Value
572
+ if (-not $sid) { return }
573
+ & "$env:SystemRoot\System32\icacls.exe" $Path /inheritance:r /grant:r "*${sid}:(OI)(CI)(F)" 2>$null | Out-Null
565
574
  } catch { }
566
575
  }
567
576
 
@@ -596,18 +605,18 @@ function Merge-JsonMcpConfig {
596
605
  function Get-VsCodeUserMcpPath {
597
606
  if ($env:VSCODE_MCP_FILE) { return $env:VSCODE_MCP_FILE }
598
607
  if ($env:APPDATA) { return (Join-Path $env:APPDATA "Code\User\mcp.json") }
599
- return (Join-Path $HOME ".vscode\mcp.json")
608
+ return (Join-Path $env:USERPROFILE ".vscode\mcp.json")
600
609
  }
601
610
 
602
611
  function Get-OpenCodeHome {
603
612
  if ($env:OPENCODE_HOME) { return $env:OPENCODE_HOME }
604
613
  if ($env:XDG_CONFIG_HOME) { return (Join-Path $env:XDG_CONFIG_HOME "opencode") }
605
- return (Join-Path $HOME ".config\opencode")
614
+ return (Join-Path $env:USERPROFILE ".config\opencode")
606
615
  }
607
616
 
608
617
  function Get-KimiHome {
609
618
  if ($env:KIMI_HOME) { return $env:KIMI_HOME }
610
- return (Join-Path $HOME ".kimi")
619
+ return (Join-Path $env:USERPROFILE ".kimi")
611
620
  }
612
621
 
613
622
  function Merge-CodexMcpToml {
@@ -908,59 +917,69 @@ function Invoke-AutoCleanupLegacy {
908
917
  }
909
918
  }
910
919
 
911
- # --- Categoria 2: Claude Code (~\.claude\) ---
912
- # IP proprietaria de versoes anteriores
913
- Remove-LegacyItem "$neocortexDir\core" "IP legada"
914
- Remove-LegacyItem $skillsDir "skills legadas"
915
- Remove-LegacyItem "$neocortexDir\workflow.md" "workflow removido no Tier 3"
916
- Remove-LegacyItem "$neocortexDir\package.json" "arquivo desnecessario"
917
- Remove-LegacyItem "$neocortexDir\README.md" "arquivo desnecessario"
920
+ if ($script:SelectedTargets -contains "claude-code") {
921
+ # --- Categoria 2: Claude Code (~\.claude\) ---
922
+ # IP proprietaria de versoes anteriores
923
+ Remove-LegacyItem "$neocortexDir\core" "IP legada"
924
+ Remove-LegacyItem $skillsDir "skills legadas"
925
+ Remove-LegacyItem "$neocortexDir\workflow.md" "workflow removido no Tier 3"
926
+ Remove-LegacyItem "$neocortexDir\package.json" "arquivo desnecessario"
927
+ Remove-LegacyItem "$neocortexDir\README.md" "arquivo desnecessario"
918
928
 
919
- # Step folders legados
920
- foreach ($folder in @("steps-c", "steps-e", "steps-p", "steps-r", "steps-u")) {
921
- Remove-LegacyItem "$neocortexDir\$folder" "steps legados"
922
- }
929
+ # Step folders legados
930
+ foreach ($folder in @("steps-c", "steps-e", "steps-p", "steps-r", "steps-u")) {
931
+ Remove-LegacyItem "$neocortexDir\$folder" "steps legados"
932
+ }
923
933
 
924
- # Artefatos de instalacoes anteriores
925
- Remove-LegacyItem "$claudeDir\agents\.git" "repo git antigo"
926
- Remove-LegacyItem "$claudeDir\.claude" "diretorio aninhado (erro BMAD)"
927
- Remove-LegacyItem "$claudeDir\agents-ldtn" "diretorio legado"
928
- Remove-LegacyItem "$claudeDir\.superclaude-metadata.json" "metadata SuperClaude"
934
+ # Artefatos de instalacoes anteriores
935
+ Remove-LegacyItem "$claudeDir\agents\.git" "repo git antigo"
936
+ Remove-LegacyItem "$claudeDir\.claude" "diretorio aninhado (erro BMAD)"
937
+ Remove-LegacyItem "$claudeDir\agents-ldtn" "diretorio legado"
938
+ Remove-LegacyItem "$claudeDir\.superclaude-metadata.json" "metadata SuperClaude"
929
939
 
930
- # Backups SuperClaude antigos
931
- if (Test-Path "$claudeDir\backups" -PathType Container) {
932
- Get-ChildItem -Path "$claudeDir\backups" -Filter "superclaude_backup_*.tar.gz" -File -ErrorAction SilentlyContinue | ForEach-Object {
933
- Remove-LegacyItem $_.FullName "backup SuperClaude antigo"
940
+ # Backups SuperClaude antigos
941
+ if (Test-Path "$claudeDir\backups" -PathType Container) {
942
+ Get-ChildItem -Path "$claudeDir\backups" -Filter "superclaude_backup_*.tar.gz" -File -ErrorAction SilentlyContinue | ForEach-Object {
943
+ Remove-LegacyItem $_.FullName "backup SuperClaude antigo"
944
+ }
934
945
  }
935
946
  }
936
947
 
937
- # --- Categoria 3: Cursor ---
938
- Remove-LegacyItem "$env:USERPROFILE\.cursor\neocortex" "configs Cursor legadas"
939
- # .cursorrules com referencias neocortex (verificar antes de remover)
940
- $cursorrules = "$env:USERPROFILE\.cursorrules"
941
- if (Test-Path $cursorrules -PathType Leaf) {
942
- $content = Get-Content $cursorrules -Raw -ErrorAction SilentlyContinue
943
- if ($content -match "(?i)neocortex|ornexus|synapse") {
944
- Remove-LegacyItem $cursorrules "cursorrules com refs legadas"
948
+ if ($script:SelectedTargets -contains "cursor") {
949
+ # --- Categoria 3: Cursor ---
950
+ Remove-LegacyItem "$env:USERPROFILE\.cursor\neocortex" "configs Cursor legadas"
951
+ # .cursorrules com referencias neocortex (verificar antes de remover)
952
+ $cursorrules = "$env:USERPROFILE\.cursorrules"
953
+ if (Test-Path $cursorrules -PathType Leaf) {
954
+ $content = Get-Content $cursorrules -Raw -ErrorAction SilentlyContinue
955
+ if ($content -match "(?i)neocortex|ornexus|synapse") {
956
+ Remove-LegacyItem $cursorrules "cursorrules com refs legadas"
957
+ }
945
958
  }
946
959
  }
947
960
 
948
- # --- Categoria 4: VS Code ---
949
- Remove-LegacyItem "$env:USERPROFILE\.vscode\neocortex" "configs VS Code legadas"
950
- # .instructions.md com referencias neocortex antigo
951
- $instructionsMd = "$env:USERPROFILE\.instructions.md"
952
- if (Test-Path $instructionsMd -PathType Leaf) {
953
- $content = Get-Content $instructionsMd -Raw -ErrorAction SilentlyContinue
954
- if ($content -match "(?i)neocortex|ornexus|synapse") {
955
- Remove-LegacyItem $instructionsMd "instructions.md com refs legadas"
961
+ if ($script:SelectedTargets -contains "vscode") {
962
+ # --- Categoria 4: VS Code ---
963
+ Remove-LegacyItem "$env:USERPROFILE\.vscode\neocortex" "configs VS Code legadas"
964
+ # .instructions.md com referencias neocortex antigo
965
+ $instructionsMd = "$env:USERPROFILE\.instructions.md"
966
+ if (Test-Path $instructionsMd -PathType Leaf) {
967
+ $content = Get-Content $instructionsMd -Raw -ErrorAction SilentlyContinue
968
+ if ($content -match "(?i)neocortex|ornexus|synapse") {
969
+ Remove-LegacyItem $instructionsMd "instructions.md com refs legadas"
970
+ }
956
971
  }
957
972
  }
958
973
 
959
- # --- Categoria 5: Gemini CLI ---
960
- Remove-LegacyItem "$env:USERPROFILE\.gemini\neocortex" "configs Gemini legadas"
974
+ if ($script:SelectedTargets -contains "gemini") {
975
+ # --- Categoria 5: Gemini CLI ---
976
+ Remove-LegacyItem "$env:USERPROFILE\.gemini\neocortex" "configs Gemini legadas"
977
+ }
961
978
 
962
- # --- Categoria 6: Codex ---
963
- Remove-LegacyItem "$env:USERPROFILE\.codex\neocortex" "configs Codex legadas"
979
+ if ($script:SelectedTargets -contains "codex") {
980
+ # --- Categoria 6: Codex ---
981
+ Remove-LegacyItem "$env:USERPROFILE\.codex\neocortex" "configs Codex legadas"
982
+ }
964
983
 
965
984
  # --- Categoria 7: Antigravity ---
966
985
  # Configs legadas de Antigravity sao gerenciadas pelo adapter, sem path fixo global
@@ -1042,15 +1061,11 @@ function Verify-Installation {
1042
1061
  $warns = 0
1043
1062
  $report = @()
1044
1063
 
1045
- if ($script:SelectedTargets -notcontains "claude-code") {
1046
- return $true
1047
- }
1048
-
1049
1064
  # --- Layer 1: File existence + minimum size ---
1050
- $criticalFiles = @(
1065
+ $criticalFiles = if ($script:SelectedTargets -contains "claude-code") { @(
1051
1066
  @{ Name = "neocortex.md"; MinBytes = 512; Label = "Agent principal (stub)" },
1052
1067
  @{ Name = "neocortex.agent.yaml"; MinBytes = 128; Label = "Agent config YAML (stub)" }
1053
- )
1068
+ ) } else { @() }
1054
1069
 
1055
1070
  foreach ($entry in $criticalFiles) {
1056
1071
  # Agent markdown lives at top-level agents\ (Claude Code discovery);
@@ -1097,13 +1112,14 @@ function Verify-Installation {
1097
1112
  if (Test-Path $configFile -PathType Leaf) {
1098
1113
  $report += @{ Status = "OK"; Detail = "~\.neocortex\config.json (thin client configured)" }
1099
1114
  } else {
1100
- $report += @{ Status = "WARN"; Detail = "~\.neocortex\config.json (nao encontrado)" }
1101
- $warns++
1115
+ $report += @{ Status = "FAIL"; Detail = "~\.neocortex\config.json (nao encontrado)" }
1116
+ $fails++
1102
1117
  }
1103
1118
 
1104
1119
  # Verify NO IP directories exist
1105
1120
  $ipFound = $false
1106
- foreach ($dir in @("core", "steps-c", "steps-e", "steps-p", "steps-r", "steps-u")) {
1121
+ $legacyDirs = if ($script:SelectedTargets -contains "claude-code") { @("core", "steps-c", "steps-e", "steps-p", "steps-r", "steps-u") } else { @() }
1122
+ foreach ($dir in $legacyDirs) {
1107
1123
  if (Test-Path (Join-Path $script:DestDir $dir) -PathType Container) {
1108
1124
  $report += @{ Status = "WARN"; Detail = "$dir/ ainda existe (deveria ter sido removido)" }
1109
1125
  $warns++
@@ -1115,16 +1131,18 @@ function Verify-Installation {
1115
1131
  }
1116
1132
 
1117
1133
  # --- Layer 4: Tool availability (Story 66.4 AC1/AC2) ---
1118
- $claudeCmd = Get-Command claude -ErrorAction SilentlyContinue
1119
- if (-not $claudeCmd) {
1120
- $claudeCmd = Get-Command claude.exe -ErrorAction SilentlyContinue
1121
- }
1122
- if (-not $claudeCmd) {
1123
- $report += @{ Status = "WARN"; Detail = "Claude Code CLI nao encontrado no PATH" }
1124
- $warns++
1125
- Write-Info "Instale Claude Code: https://claude.ai/download"
1126
- } else {
1127
- $report += @{ Status = "OK"; Detail = "Claude Code CLI encontrado" }
1134
+ if ($script:SelectedTargets -contains "claude-code") {
1135
+ $claudeCmd = Get-Command claude -ErrorAction SilentlyContinue
1136
+ if (-not $claudeCmd) {
1137
+ $claudeCmd = Get-Command claude.exe -ErrorAction SilentlyContinue
1138
+ }
1139
+ if (-not $claudeCmd) {
1140
+ $report += @{ Status = "WARN"; Detail = "Claude Code CLI nao encontrado no PATH" }
1141
+ $warns++
1142
+ Write-Info "Instale Claude Code: https://claude.ai/download"
1143
+ } else {
1144
+ $report += @{ Status = "OK"; Detail = "Claude Code CLI encontrado" }
1145
+ }
1128
1146
  }
1129
1147
 
1130
1148
  $ncCmd = Get-Command neocortex-client -ErrorAction SilentlyContinue
@@ -1182,22 +1200,28 @@ function Set-ThinClientConfig {
1182
1200
  $configDir = "$env:USERPROFILE\.neocortex"
1183
1201
  $configFile = "$configDir\config.json"
1184
1202
 
1185
- New-Item -ItemType Directory -Path $configDir -Force -ErrorAction SilentlyContinue | Out-Null
1186
- New-Item -ItemType Directory -Path "$configDir\cache" -Force -ErrorAction SilentlyContinue | Out-Null
1187
-
1188
- # Story 66.1 AC5: Apply ACLs on ~/.neocortex/ and cache/
1189
- Set-DirAcl $configDir
1190
- Set-DirAcl "$configDir\cache"
1203
+ foreach ($privateDir in @($configDir, "$configDir\cache")) {
1204
+ if (-not (Test-Path -LiteralPath $privateDir -PathType Container)) {
1205
+ try {
1206
+ New-Item -ItemType Directory -Path $privateDir -ErrorAction Stop | Out-Null
1207
+ Set-DirAcl $privateDir
1208
+ } catch {
1209
+ Write-Warn "AUTH_PROFILE_CONFIG_WRITE_DENIED. Confira o acesso ao perfil com a conta que o criou."
1210
+ return $false
1211
+ }
1212
+ }
1213
+ }
1191
1214
 
1192
1215
  if (Test-Path $configFile) {
1193
- if (-not (Test-ManagedPolicy -BaseDir $env:USERPROFILE)) {
1194
- Invoke-ManagedPolicy -BaseDir $env:USERPROFILE | Out-Null
1195
- Write-Warn "Config ou approval policy invalida; backup criado e original preservado"
1196
- return $false
1197
- }
1216
+ if (-not (Invoke-ManagedPolicy -BaseDir $env:USERPROFILE -CheckOnly)) { return $false }
1198
1217
  try {
1199
1218
  $existingConfig = Get-Content $configFile -Raw -ErrorAction Stop | ConvertFrom-Json -ErrorAction Stop
1200
- if ($existingConfig.mode -eq "active" -or $existingConfig.mode -eq "local" -or $existingConfig.mode -eq "remote") {
1219
+ if (-not $existingConfig.PSObject.Properties["mode"]) {
1220
+ $mode = if ($existingConfig.encryptedLicenseKey -or $existingConfig.licenseKey) { "remote" } else { "pending-activation" }
1221
+ $existingConfig | Add-Member -NotePropertyName mode -NotePropertyValue $mode
1222
+ Write-Utf8NoBomAtomic -Path $configFile -Content ($existingConfig | ConvertTo-Json -Depth 100)
1223
+ }
1224
+ if ($existingConfig.mode -in @("active", "local", "remote", "pending-activation")) {
1201
1225
  # --- Config schema migration (Epic 62 - GAP 4) ---
1202
1226
  if (-not $existingConfig.configVersion) {
1203
1227
  Write-Dbg "Migrando schema do config.json (adicionando configVersion)"
@@ -1211,7 +1235,7 @@ function Set-ThinClientConfig {
1211
1235
  if ($existingConfig.tier -eq 3 -and $existingConfig.mode -eq "pending-activation") {
1212
1236
  $existingConfig.PSObject.Properties.Remove("tier")
1213
1237
  }
1214
- Write-Utf8NoBomAtomic -Path $configFile -Content ($existingConfig | ConvertTo-Json -Depth 5)
1238
+ Write-Utf8NoBomAtomic -Path $configFile -Content ($existingConfig | ConvertTo-Json -Depth 100)
1215
1239
  Write-Dbg "Config migrada para configVersion 1"
1216
1240
  } catch {
1217
1241
  Write-Dbg "Falha na migracao do config: $_"
@@ -1226,8 +1250,7 @@ function Set-ThinClientConfig {
1226
1250
  Write-Dbg "Fixing stale localhost serverUrl to configured remote endpoint"
1227
1251
  try {
1228
1252
  $existingConfig.serverUrl = $NEOCORTEX_SERVER_URL
1229
- Write-Utf8NoBomAtomic -Path $configFile -Content ($existingConfig | ConvertTo-Json -Depth 5)
1230
- Set-FileAcl $configFile
1253
+ Write-Utf8NoBomAtomic -Path $configFile -Content ($existingConfig | ConvertTo-Json -Depth 100)
1231
1254
  Write-Dbg "serverUrl updated to configured remote endpoint"
1232
1255
  } catch {
1233
1256
  Write-Dbg "Failed to update serverUrl: $_"
@@ -1241,8 +1264,7 @@ function Set-ThinClientConfig {
1241
1264
  Write-Dbg "Fixing legacy serverUrl to configured remote endpoint"
1242
1265
  try {
1243
1266
  $existingConfig.serverUrl = $NEOCORTEX_SERVER_URL
1244
- Write-Utf8NoBomAtomic -Path $configFile -Content ($existingConfig | ConvertTo-Json -Depth 5)
1245
- Set-FileAcl $configFile
1267
+ Write-Utf8NoBomAtomic -Path $configFile -Content ($existingConfig | ConvertTo-Json -Depth 100)
1246
1268
  Write-Dbg "serverUrl updated from legacy host to configured remote endpoint"
1247
1269
  } catch {
1248
1270
  Write-Dbg "Failed to update serverUrl: $_"
@@ -1250,15 +1272,15 @@ function Set-ThinClientConfig {
1250
1272
  }
1251
1273
 
1252
1274
  if (-not (Invoke-ManagedPolicy -BaseDir $env:USERPROFILE)) {
1253
- Write-Warn "Approval policy invalida ou ownership ambiguo; config preservada"
1254
1275
  return $false
1255
1276
  }
1256
1277
  Write-Dbg "Config existente preservada (mode=$($existingConfig.mode))"
1257
1278
  return $true
1258
1279
  }
1280
+ Write-Warn "AUTH_PROFILE_CONFIG_INVALID. O modo do perfil existente nao foi reconhecido. Config preservada."
1281
+ return $false
1259
1282
  } catch {
1260
- Invoke-ManagedPolicy -BaseDir $env:USERPROFILE | Out-Null
1261
- Write-Warn "Config invalida; backup criado e original preservado"
1283
+ Write-Warn "AUTH_PROFILE_CONFIG_INVALID. Config preservada."
1262
1284
  return $false
1263
1285
  }
1264
1286
  }
@@ -1281,7 +1303,12 @@ function Set-ThinClientConfig {
1281
1303
  }
1282
1304
  }
1283
1305
 
1284
- Write-Utf8NoBomAtomic -Path $configFile -Content ($config | ConvertTo-Json -Depth 5)
1306
+ try {
1307
+ Write-Utf8NoBomAtomic -Path $configFile -Content ($config | ConvertTo-Json -Depth 5)
1308
+ } catch {
1309
+ Write-Warn "AUTH_PROFILE_CONFIG_WRITE_DENIED. Confira o acesso ao perfil com a conta que o criou."
1310
+ return $false
1311
+ }
1285
1312
  # Story 66.1 AC4: Apply ACL on config.json
1286
1313
  Set-FileAcl $configFile
1287
1314
  if (-not (Invoke-ManagedPolicy -BaseDir $env:USERPROFILE)) { return $false }
@@ -1297,32 +1324,18 @@ function Set-ThinClientConfig {
1297
1324
  # =============================================================================
1298
1325
 
1299
1326
  function Install-Core {
1300
- $script:ClaudeDir = "$env:USERPROFILE\.claude"
1301
- $script:AgentsDir = "$script:ClaudeDir\agents"
1302
- $script:DestDir = "$script:AgentsDir\neocortex"
1303
-
1304
- Write-Dbg "DEST=$script:DestDir"
1305
-
1306
- # Create directories with verification (Epic 65)
1307
- if (-not (Test-Path $script:ClaudeDir)) {
1308
- try { New-Item -ItemType Directory -Path $script:ClaudeDir -Force -ErrorAction Stop | Out-Null }
1309
- catch { Write-Fail "Falha ao criar $script:ClaudeDir`: $_"; return $false }
1310
- }
1311
- try { New-Item -ItemType Directory -Path $script:AgentsDir -Force -ErrorAction Stop | Out-Null }
1312
- catch { Write-Fail "Falha ao criar $script:AgentsDir`: $_"; return $false }
1313
-
1314
- # P201.08: keep the destination and update only managed files additively.
1315
- try { New-Item -ItemType Directory -Path $script:DestDir -Force -ErrorAction Stop | Out-Null }
1316
- catch { Write-Fail "Falha ao criar $script:DestDir`: $_"; return $false }
1317
-
1318
- # Verify directory was actually created (Epic 65: anti-silent-failure)
1319
- if (-not (Test-Path $script:DestDir -PathType Container)) {
1320
- Write-Fail "Diretorio $script:DestDir nao existe apos criacao"
1321
- return $false
1322
- }
1323
-
1324
1327
  # Thin-client invariant: configure the remote client and never copy core/**.
1325
1328
  if (-not (Set-ThinClientConfig)) { return $false }
1329
+ $profileVersionPath = "$env:USERPROFILE\.neocortex\.version"
1330
+ $versionPaths = @($profileVersionPath)
1331
+ if ($script:SelectedTargets -contains "claude-code") {
1332
+ $script:ClaudeDir = "$env:USERPROFILE\.claude"
1333
+ $script:AgentsDir = "$script:ClaudeDir\agents"
1334
+ $script:DestDir = "$script:AgentsDir\neocortex"
1335
+ try { New-Item -ItemType Directory -Path $script:DestDir -Force -ErrorAction Stop | Out-Null }
1336
+ catch { Write-Fail "Falha ao preparar o diretorio de agentes do Claude Code."; return $false }
1337
+ $versionPaths += "$script:DestDir\.version"
1338
+ }
1326
1339
 
1327
1340
  # --- Version-aware cache purge on upgrade (Epic 62 - GAP 2+3) ---
1328
1341
  $pkgJsonPath = Join-Path $script:SourceDir "package.json"
@@ -1335,7 +1348,6 @@ function Install-Core {
1335
1348
  if ($pkgVersion) {
1336
1349
  $oldVersion = $null
1337
1350
  # Read existing .version from either location
1338
- $versionPaths = @("$script:DestDir\.version", "$env:USERPROFILE\.neocortex\.version")
1339
1351
  foreach ($vp in $versionPaths) {
1340
1352
  if (Test-Path $vp -PathType Leaf) {
1341
1353
  $oldVersion = (Get-Content $vp -Raw -ErrorAction SilentlyContinue).Trim()
@@ -1365,8 +1377,10 @@ function Install-Core {
1365
1377
  }
1366
1378
  }
1367
1379
 
1368
- # Write version file
1369
- Write-Utf8NoBom -Path "$script:DestDir\.version" -Content $pkgVersion
1380
+ foreach ($versionPath in $versionPaths) {
1381
+ try { Write-Utf8NoBomAtomic -Path $versionPath -Content $pkgVersion }
1382
+ catch { Write-Fail "Falha ao gravar marcador de versao no perfil."; return $false }
1383
+ }
1370
1384
  }
1371
1385
 
1372
1386
  Write-Ok "Remote mode configured (thin client ready)"
@@ -1591,13 +1605,16 @@ $script:PlatformRequiredTier = @{
1591
1605
  # END NEOCORTEX PLATFORM TIER TABLE
1592
1606
 
1593
1607
  function Get-TierFromConfig {
1594
- $configPath = Join-Path (Join-Path $HOME ".neocortex") "config.json"
1595
- if (-not (Test-Path $configPath -PathType Leaf)) { return "free" }
1608
+ $configPath = Join-Path (Join-Path $env:USERPROFILE ".neocortex") "config.json"
1609
+ if (-not (Test-Path $configPath -PathType Leaf)) { return "unverified" }
1596
1610
  try {
1597
1611
  $cfg = Get-Content -Path $configPath -Raw -ErrorAction Stop | ConvertFrom-Json -ErrorAction Stop
1598
- if ($cfg.tier -is [string] -and $cfg.tier) { return $cfg.tier.Trim().ToLowerInvariant() }
1612
+ if ($cfg.tier -is [string]) {
1613
+ $tier = $cfg.tier.Trim().ToLowerInvariant()
1614
+ if ($tier -in @("free", "pro", "enterprise")) { return $tier }
1615
+ }
1599
1616
  } catch { }
1600
- return "free"
1617
+ return "unverified"
1601
1618
  }
1602
1619
 
1603
1620
  # Tier hierarchy (free < pro < enterprise). Unrecognized values rank as free,
@@ -1617,8 +1634,12 @@ function Test-PlatformTier {
1617
1634
  if ($script:PlatformRequiredTier.ContainsKey($Platform)) { $required = $script:PlatformRequiredTier[$Platform] }
1618
1635
  if ((Get-PlatformTierRank -Tier $Tier) -ge (Get-PlatformTierRank -Tier $required)) { return $true }
1619
1636
  $requiredLabel = if ($required -eq "enterprise") { "Enterprise" } else { "Pro" }
1620
- Write-Warn "$Platform requer plano $requiredLabel. Plataforma disponivel: Claude Code."
1621
- Write-Info "Upgrade: https://neocortex.sh/portal/dashboard/plans"
1637
+ if ($Tier -eq "unverified") {
1638
+ Write-Warn "$Platform requer plano $requiredLabel. Ative a credencial neste perfil e repita a mesma selecao."
1639
+ } else {
1640
+ Write-Warn "$Platform requer plano $requiredLabel. Plano ativo: $Tier."
1641
+ Write-Info "Planos: https://neocortex.sh/portal/dashboard/plans"
1642
+ }
1622
1643
  return $false
1623
1644
  }
1624
1645
 
@@ -1826,7 +1847,11 @@ function Install-Targets {
1826
1847
  if ($opencodeTargetDir -and (Test-Path "$opencodeTargetDir\neocortex.md")) {
1827
1848
  New-Item -ItemType Directory -Path "$opencodeHome\agents" -Force | Out-Null
1828
1849
  $opencodeBase = Get-ManagedPlatformBase -PlatformHome $opencodeHome -DefaultBase $homeDir
1829
- $null = Install-AgentRoleProfiles -Platform "opencode" -SourceDir $opencodeTargetDir -AgentsDir "$opencodeHome\agents" -BaseDir $opencodeBase -Scope "user"
1850
+ if (-not (Install-AgentRoleProfiles -Platform "opencode" -SourceDir $opencodeTargetDir -AgentsDir "$opencodeHome\agents" -BaseDir $opencodeBase -Scope "user")) {
1851
+ $script:TargetResults += "$target`:FAIL"
1852
+ Write-Fail "opencode. A instalacao do perfil falhou."
1853
+ continue
1854
+ }
1830
1855
  if (Test-Path "$opencodeTargetDir\opencode-mcp.json") {
1831
1856
  Merge-JsonMcpConfig -StubFile "$opencodeTargetDir\opencode-mcp.json" -DestFile "$opencodeHome\opencode.json" -RootKey "mcp"
1832
1857
  }
@@ -2176,15 +2201,16 @@ function Show-Result {
2176
2201
  Write-Host " Status: Ready to activate" -ForegroundColor DarkGray
2177
2202
  Write-Host ""
2178
2203
  Write-Host " Activate your license:" -ForegroundColor DarkGray
2179
- Write-Host " neocortex activate YOUR-LICENSE-KEY" -ForegroundColor Cyan
2204
+ Write-Host " neocortex.cmd activate YOUR-LICENSE-KEY" -ForegroundColor Cyan
2180
2205
  Write-Host ""
2181
2206
  Write-Host " Get your key at: https://neocortex.sh/portal/login" -ForegroundColor DarkGray
2182
2207
  Write-Host ""
2183
2208
  Write-Host " After activation:" -ForegroundColor DarkGray
2184
- Write-Host " @neocortex *menu" -ForegroundColor Cyan
2185
- Write-Host ""
2186
- Write-Host " Proximo passo:" -ForegroundColor DarkGray
2187
- Write-Host " @neocortex *menu" -ForegroundColor Cyan
2209
+ if ($script:SelectedTargets.Count -eq 0) {
2210
+ Write-Host " neocortex.cmd --targets=<plataformas>" -ForegroundColor Cyan
2211
+ } else {
2212
+ Write-Host " @neocortex *menu" -ForegroundColor Cyan
2213
+ }
2188
2214
  Write-Host ""
2189
2215
  return $true
2190
2216
  } else {
@@ -2224,12 +2250,12 @@ if ($Targets) {
2224
2250
  Write-Host " Validas: $($script:ValidTargets -join ', ')"
2225
2251
  exit 1
2226
2252
  }
2227
- } elseif ($Yes) {
2228
- $script:SelectedTargets = @("claude-code")
2229
2253
  } else {
2230
- $script:SelectedTargets = @("claude-code")
2254
+ $script:SelectedTargets = @()
2231
2255
  }
2232
2256
 
2257
+ if (-not (Invoke-ManagedPolicy -BaseDir $env:USERPROFILE -CheckOnly)) { exit 1 }
2258
+
2233
2259
  # P228.05: filter tier-blocked platforms with the server table (narrow only).
2234
2260
  $userTier = Get-TierFromConfig
2235
2261
  Write-Dbg "User tier: $userTier"
@@ -2238,12 +2264,11 @@ $blockedTargets = @($script:SelectedTargets | Where-Object { $_ -notin $allowedT
2238
2264
  if ($blockedTargets.Count -gt 0) {
2239
2265
  Write-Info "Plataforma(s) bloqueada(s) por tier: $($blockedTargets -join ', ')"
2240
2266
  }
2241
- if ($allowedTargets.Count -gt 0) {
2242
- $script:SelectedTargets = $allowedTargets
2243
- } else {
2244
- $script:SelectedTargets = @("claude-code")
2245
- Write-Info "Usando plataforma padrao: claude-code"
2267
+ if ($script:SelectedTargets.Count -gt 0 -and $allowedTargets.Count -eq 0) {
2268
+ Write-Fail "installer-target-entitlement-blocked. Nenhuma plataforma solicitada pode ser instalada com o plano atual."
2269
+ exit 3
2246
2270
  }
2271
+ $script:SelectedTargets = $allowedTargets
2247
2272
 
2248
2273
  Write-Dbg "Targets: $($script:SelectedTargets -join ', ')"
2249
2274
 
@@ -2257,19 +2282,19 @@ if ($DryRun) {
2257
2282
  $totalSteps = 4
2258
2283
  if ($script:SelectedTargets -contains "claude-code") { $totalSteps = 5 }
2259
2284
 
2260
- # Step 1: Limpeza automatica de versoes anteriores
2261
- Write-Step 1 $totalSteps "Limpeza de versoes anteriores"
2262
- Invoke-AutoCleanupLegacy
2263
-
2264
- # Step 2: Core
2265
- Write-Step 2 $totalSteps "Instalando core"
2285
+ # Step 1: Verify and prepare the selected user profile before cleanup.
2286
+ Write-Step 1 $totalSteps "Preparando perfil do Neocortex"
2266
2287
  $coreSuccess = Install-Core
2267
2288
 
2268
2289
  if (-not $coreSuccess) {
2269
- Write-Fail "Falha na instalacao do core"
2290
+ Write-Fail "O perfil do Neocortex nao pode ser preparado."
2270
2291
  exit 1
2271
2292
  }
2272
2293
 
2294
+ # Step 2: Legacy cleanup
2295
+ Write-Step 2 $totalSteps "Limpeza de versoes anteriores"
2296
+ Invoke-AutoCleanupLegacy
2297
+
2273
2298
  # Step 3: Skills
2274
2299
  Write-Step 3 $totalSteps "Instalando skills"
2275
2300
  Install-Skills | Out-Null
@@ -2290,7 +2315,7 @@ if ($script:SelectedTargets -contains "claude-code") {
2290
2315
  Install-MCPs
2291
2316
  }
2292
2317
 
2293
- $installSuccess = ($script:TargetResults | Where-Object { $_ -match ":FAIL$" }).Count -eq 0
2318
+ $installSuccess = ($script:TargetResults | Where-Object { $_ -match ":(FAIL|SKIP)$" }).Count -eq 0
2294
2319
  $verifySuccess = Verify-Installation
2295
2320
  $installSuccess = $installSuccess -and $verifySuccess
2296
2321
 
@@ -2305,6 +2330,7 @@ if (Show-Result $installSuccess) {
2305
2330
  New-ProjectDirectories
2306
2331
  Write-Host " Desenvolvido por OrNexus Team" -ForegroundColor DarkGray
2307
2332
  Write-Host ""
2333
+ if ($blockedTargets.Count -gt 0) { exit 3 }
2308
2334
  exit 0
2309
2335
  } else {
2310
2336
  exit 1
package/install.sh CHANGED
@@ -4,7 +4,7 @@
4
4
  # Development Orchestrator
5
5
 
6
6
  # Versao do instalador
7
- VERSION="4.66.50"
7
+ VERSION="4.66.52"
8
8
 
9
9
  # Flags
10
10
  MIGRATION_DETECTED=false
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@ornexus/neocortex",
3
- "version": "4.66.50",
4
- "description": "Neocortex v4.66.50",
3
+ "version": "4.66.52",
4
+ "description": "Neocortex v4.66.52",
5
5
  "keywords": [
6
6
  "claude",
7
7
  "claude-code",