From 98006f395a6277256bd8b41bb6835c3a6b4db8ab Mon Sep 17 00:00:00 2001 From: jon Date: Wed, 22 Jul 2026 11:41:03 -0500 Subject: [PATCH] Sync from upstream: ncp.ps1 works under PowerShell on Linux Co-Authored-By: Claude Opus 4.8 --- bin/restore-linux.sh | 14 ++++++++++++++ management/ncp.ps1 | 41 +++++++++++++++++++++++++++-------------- 2 files changed, 41 insertions(+), 14 deletions(-) diff --git a/bin/restore-linux.sh b/bin/restore-linux.sh index d56fec7..504e768 100644 --- a/bin/restore-linux.sh +++ b/bin/restore-linux.sh @@ -73,6 +73,20 @@ EOF echo "Registered promethean in ~/.bashrc." fi + # Same ncp inside PowerShell, if pwsh is installed here. bash functions are + # invisible to pwsh, so without this `ncp` is "not recognized" there even + # though it works in bash. install-windows.ps1 does this on the Windows side; + # this profile lives outside the repo, so a restore has to re-add it. + if command -v pwsh >/dev/null; then + ps_profile="$HOME/.config/powershell/profile.ps1" + if ! grep -q "NexusOS ncp" "$ps_profile" 2>/dev/null; then + mkdir -p "$(dirname "$ps_profile")" + printf '\n# NexusOS ncp\nfunction ncp { & "%s/management/ncp.ps1" @args }\n' \ + "$NEXUS_ROOT" >> "$ps_profile" + echo "Registered ncp in $ps_profile." + fi + fi + # The AMD box runs CPU-only (Vega 20, 4GB VRAM thrashes). An NVIDIA box should not. if command -v nvidia-smi >/dev/null && command -v sqlite3 >/dev/null && \ [ "$(sqlite3 "$NEXUS_ROOT/synapse/memory/memory.db" \ diff --git a/management/ncp.ps1 b/management/ncp.ps1 index 1a67d7b..378f0b6 100644 --- a/management/ncp.ps1 +++ b/management/ncp.ps1 @@ -1,10 +1,11 @@ -# ncp - Windows entry point. The CLI itself is management\ncp.py, the same file -# the Linux box runs; this only picks an interpreter and forwards the arguments. +# ncp - PowerShell entry point. The CLI itself is management/ncp.py, the same +# file the Linux shell wrapper runs; this only picks an interpreter and forwards +# the arguments. # -# Register it once per machine by adding this to your PowerShell profile -# (notepad $PROFILE): +# Windows: install-windows.ps1 registers this automatically. To do it by hand, +# or to get ncp inside PowerShell on Linux, add to $PROFILE.CurrentUserAllHosts: # -# function ncp { & "$HOME\nexus-core\management\ncp.ps1" @args } +# function ncp { & "/management/ncp.ps1" @args } # # ASCII only, no exceptions: PowerShell 5.1 decodes BOM-less files as ANSI, so a # single Unicode dash eats a quote and the script dies at parse time. A test in @@ -12,17 +13,29 @@ $Root = Split-Path -Parent (Split-Path -Parent $MyInvocation.MyCommand.Path) -# Prefer the venv interpreter (ncp.py needs psutil for service management), but -# fall back to system Python so backup/restore still work before the venv is -# built - those delegate to the stdlib-only bin\sync.py. -$Py = Join-Path $Root "Promethean\Scripts\python.exe" -if (-not (Test-Path $Py)) { - $Py = (Get-Command python -ErrorAction SilentlyContinue).Source +# Forward slashes and per-platform venv layout: backslash is a literal character +# on Linux, not a separator, so "Promethean\Scripts\python.exe" would resolve to +# a single nonsense filename under pwsh on Linux. Windows accepts "/" happily. +# $env:OS is the 5.1-safe check; the automatic $IsWindows only exists on PS 6+. +$OnWindows = ($env:OS -eq "Windows_NT") +if ($OnWindows) { + $Py = Join-Path $Root "Promethean/Scripts/python.exe" +} else { + $Py = Join-Path $Root "Promethean/bin/python3" } -if (-not $Py) { - Write-Error "No Python found. Run install-windows.ps1 first." + +# Fall back to a system Python so backup/restore still work before the venv is +# built - those delegate to the stdlib-only bin/sync.py. +if (-not (Test-Path $Py)) { + foreach ($candidate in @("python3", "python")) { + $found = Get-Command $candidate -ErrorAction SilentlyContinue + if ($found) { $Py = $found.Source; break } + } +} +if (-not (Test-Path $Py)) { + Write-Error "No Python found. Run install.sh (Linux) or install-windows.ps1 first." exit 1 } -& $Py (Join-Path $Root "management\ncp.py") @args +& $Py (Join-Path $Root "management/ncp.py") @args exit $LASTEXITCODE