# moyun-ultimate installer (ASCII only: PS 5.1 reads BOM-less UTF-8 as ANSI) # Idempotent. Backs up package.json before editing. Does NOT restart DSH. [CmdletBinding()] param( [string]$Profile = 'desktop', [string]$DshHome = '', [switch]$Uninstall, [switch]$DryRun ) $ErrorActionPreference = 'Stop' $Here = Split-Path -Parent $MyInvocation.MyCommand.Path $PkgName = 'moyun-ultimate' if (-not $DshHome) { if ($env:DSH_HOME) { $DshHome = $env:DSH_HOME } elseif (Test-Path 'G:\DeepSeek_dsh') { $DshHome = 'G:\DeepSeek_dsh' } elseif (Test-Path (Join-Path $env:USERPROFILE '.dsh')) { $DshHome = Join-Path $env:USERPROFILE '.dsh' } else { throw 'DSH_HOME not found. Pass -DshHome .' } } $profileDir = Join-Path $DshHome "profiles\$Profile" $pkgJson = Join-Path $profileDir 'package.json' $plugDir = Join-Path $profileDir "plugins\$PkgName" $runDir = Join-Path $profileDir "node_modules\$PkgName" Write-Output "DSH_HOME : $DshHome" Write-Output "profile : $Profile" Write-Output "package dir: $profileDir" if (-not (Test-Path $pkgJson)) { throw "profile package.json not found: $pkgJson" } function Get-Pkg { Get-Content -LiteralPath $pkgJson -Raw -Encoding UTF8 | ConvertFrom-Json } if ($Uninstall) { Write-Output '--- uninstall ---' foreach ($d in @($plugDir, $runDir)) { if (Test-Path $d) { if ($DryRun) { Write-Output "would remove $d" } else { Remove-Item $d -Recurse -Force; Write-Output "removed $d" } } } $raw = Get-Content -LiteralPath $pkgJson -Raw -Encoding UTF8 $lines = $raw -split "`n" $keep = @() foreach ($l in $lines) { if ($l -match "`"$PkgName`":\s*`"file:") { continue } if ($l -match "^\s*`"$PkgName`",\s*$") { continue } $keep += $l } if ($DryRun) { Write-Output 'would rewrite package.json' } else { Copy-Item $pkgJson "$pkgJson.bak-$PkgName-$(Get-Date -Format 'yyyyMMdd-HHmmss')" -Force [IO.File]::WriteAllText($pkgJson, ($keep -join "`n"), (New-Object Text.UTF8Encoding($false))) $null = Get-Pkg Write-Output 'package.json updated (JSON valid)' } Write-Output 'Restart DSH completely to unload.' exit 0 } Write-Output '--- install ---' if ($DryRun) { Write-Output "would copy $Here -> $plugDir" Write-Output "would copy $Here -> $runDir" Write-Output 'would add dependencies + bundles entry' exit 0 } # 1) source + runtime copy (real dirs: mklink needs elevation) foreach ($d in @($plugDir, $runDir)) { if (Test-Path $d) { Remove-Item $d -Recurse -Force } New-Item -ItemType Directory -Force -Path $d | Out-Null Copy-Item "$Here\*" $d -Recurse -Force } Write-Output "copied to $plugDir" Write-Output "copied to $runDir" # 2) patch package.json $stamp = Get-Date -Format 'yyyyMMdd-HHmmss' Copy-Item $pkgJson "$pkgJson.bak-$PkgName-$stamp" -Force Write-Output "backup: package.json.bak-$PkgName-$stamp" $raw = Get-Content -LiteralPath $pkgJson -Raw -Encoding UTF8 $lines = $raw -split "`n" $out = New-Object System.Collections.Generic.List[string] $depAdded = $false $bundleHandled = $false foreach ($l in $lines) { # inject dependency next to an existing file: dependency, or after "dependencies": { if (-not $depAdded -and $l -match '^\s*"dependencies":\s*\{') { $out.Add($l) $out.Add(" `"$PkgName`": `"file:./plugins/$PkgName`",") $depAdded = $true continue } # replace an existing moyun-banzhuan bundle entry in place (it is superseded) if (-not $bundleHandled -and $l -match '^\s*"moyun-banzhuan",\s*$') { $out.Add(" `"$PkgName`",") $bundleHandled = $true continue } $out.Add($l) } [IO.File]::WriteAllText($pkgJson, ($out -join "`n"), (New-Object Text.UTF8Encoding($false))) $j = Get-Pkg $hasDep = $j.dependencies.PSObject.Properties.Name -contains $PkgName $hasBundle = $j.dsh.profile.bundles -contains $PkgName Write-Output "dependencies has ${PkgName}: $hasDep" Write-Output "bundles has ${PkgName} : $hasBundle" Write-Output "bundles total : $($j.dsh.profile.bundles.Count)" if (-not $hasBundle) { Write-Warning "bundles entry missing. Add `"$PkgName`" to dsh.profile.bundles manually, or add the plugin from the DSH plugin panel." } Write-Output '' Write-Output 'DONE. Now fully quit DSH (including the tray icon) and reopen it.' Write-Output 'Verify: ask the agent to call moyun_ultimate_profile -> expect skills=63, 5 layers on.'