moyun-ultimate/install.ps1
moyun f7a064a9a8 feat: 0.7.0 - disclose every side effect and add a prompt-only mode
Someone reviewed the plugin and objected to three things: it writes outside the
workspace, it asks you to run a third-party install.ps1, and after installing it
you get full-disk access with approvals auto-granted plus a silent update check.

All three are accurate. This release does not argue with that; it makes each one
optional and documents it.

- SECURITY.md lists every path written, every network call, every permission
  change, and for each one says whether it can be turned off and how.
- syncSkills: false - do not copy the 63 skills into \/skills
- cordis.patch.prompt-only.yml - the smallest footprint: six prompt sections
  only, no skill sync, no network, no approval answerer, no permission override.
- switch-mode.ps1 gains a third mode: full / complement / prompt-only
- install.ps1 -Mode prompt-only installs in that shape in one step

In prompt-only mode the plugin touches nothing except its own directories and the
two lines it adds to package.json.
2026-11-17 15:35:27 +08:00

267 lines
10 KiB
PowerShell

# 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.
#
# -Mode auto (default) detect conflicts first, then pick full or complement
# -Mode full always take over the permission layer
# -Mode complement never touch the permission layer (yield to other plugins)
[CmdletBinding()]
param(
[string]$Profile = 'desktop',
[string]$DshHome = '',
[ValidateSet('auto', 'full', 'complement', 'prompt-only')]
[string]$Mode = 'auto',
[switch]$Uninstall,
[switch]$Rollback,
[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 <path>.' }
}
$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 }
# ---- config ids this plugin rewrites (must match index.js CONFLICT_IDS) ----
$CONFLICT_IDS = @('sandbox-policy', 'approval', 'permission', 'spill-policy', 'tool-result-pruner')
$SOFT_IDS = @('system-prompt')
# Read the config ids another installed plugin actually rewrites.
function Get-PluginIds([string]$name) {
$p = Join-Path $profileDir "node_modules\$name\cordis.patch.yml"
if (-not (Test-Path $p)) { return @() }
$txt = Get-Content -LiteralPath $p -Raw -Encoding UTF8
$ids = @()
foreach ($m in [regex]::Matches($txt, '(?m)^\s*-?\s*id:\s*([A-Za-z0-9_\-]+)')) {
$ids += $m.Groups[1].Value
}
return ($ids | Sort-Object -Unique)
}
# Scan all bundles and report who collides with us.
function Get-ConflictReport {
$rep = @{ hard = @(); soft = @(); scanned = 0 }
$j = Get-Pkg
$bundles = @($j.dsh.profile.bundles)
foreach ($b in $bundles) {
if ($b -eq $PkgName) { continue }
$ids = Get-PluginIds $b
if ($ids.Count -eq 0) { continue }
$rep.scanned++
$hardHit = @($ids | Where-Object { $CONFLICT_IDS -contains $_ })
$softHit = @($ids | Where-Object { $SOFT_IDS -contains $_ })
if ($hardHit.Count -gt 0) {
$rep.hard += [pscustomobject]@{ plugin = $b; ids = ($hardHit -join ',') }
} elseif ($softHit.Count -gt 0) {
$rep.soft += [pscustomobject]@{ plugin = $b; ids = ($softHit -join ',') }
}
}
return $rep
}
function Show-ConflictReport($rep) {
Write-Output ''
Write-Output '--- conflict scan ---'
Write-Output (" scanned plugins : " + $rep.scanned)
if ($rep.hard.Count -eq 0) {
Write-Output ' hard conflicts : none'
} else {
Write-Output ' hard conflicts : YES'
foreach ($h in $rep.hard) { Write-Output (" - " + $h.plugin + " rewrites: " + $h.ids) }
}
if ($rep.soft.Count -eq 0) {
Write-Output ' soft overlaps : none'
} else {
foreach ($s in $rep.soft) { Write-Output (" ~ " + $s.plugin + " shares: " + $s.ids + " (safe)") }
}
}
# Decide the effective mode for 'auto'.
function Resolve-Mode($rep) {
if ($Mode -ne 'auto') { return $Mode }
if ($rep.hard.Count -gt 0) { return 'complement' }
return 'full'
}
# Write the right bundle patch into the installed copies.
function Apply-Mode([string]$effective) {
$fullSrc = Join-Path $Here 'cordis.patch.yml'
$compSrc = Join-Path $Here 'cordis.patch.complement.yml'
foreach ($d in @($plugDir, $runDir)) {
if (-not (Test-Path $d)) { continue }
$target = Join-Path $d 'cordis.patch.yml'
$fullKeep = Join-Path $d 'cordis.patch.yml.full'
if ($effective -eq 'prompt-only') {
$poSrc = Join-Path $Here 'cordis.patch.prompt-only.yml'
if ($DryRun) { Write-Output "would switch $d to PROMPT-ONLY mode" }
else {
if ((Test-Path $target) -and -not (Test-Path $fullKeep)) { Copy-Item $target $fullKeep -Force }
Copy-Item $poSrc $target -Force
Write-Output " switched to PROMPT-ONLY mode: $d"
}
} elseif ($effective -eq 'complement') {
if ($DryRun) { Write-Output "would switch $d to COMPLEMENT mode" }
else {
if ((Test-Path $target) -and -not (Test-Path $fullKeep)) { Copy-Item $target $fullKeep -Force }
Copy-Item $compSrc $target -Force
Write-Output " switched to COMPLEMENT mode: $d"
}
} else {
if ($DryRun) { Write-Output "would switch $d to FULL mode" }
else {
Copy-Item $fullSrc $target -Force
Write-Output " switched to FULL mode: $d"
}
}
}
}
if ($Rollback) {
Write-Output '--- rollback ---'
$baks = @(Get-ChildItem (Split-Path $pkgJson -Parent) -Filter "package.json.bak-*" -ErrorAction SilentlyContinue | Sort-Object LastWriteTime -Descending)
if ($baks.Count -eq 0) {
Write-Output ' no backup found - nothing to roll back to'
exit 1
}
$newest = $baks[0]
Write-Output (' newest backup: ' + $newest.Name + ' (' + $newest.LastWriteTime.ToString('yyyy-MM-dd HH:mm:ss') + ')')
if ($DryRun) {
Write-Output ' would restore it and remove plugin dirs'
exit 0
}
Copy-Item $newest.FullName $pkgJson -Force
Write-Output ' package.json restored'
foreach ($d in @($plugDir, $runDir)) {
if (Test-Path $d) { Remove-Item $d -Recurse -Force; Write-Output (' removed ' + $d) }
}
$null = Get-Pkg
Write-Output ' JSON valid'
Write-Output ''
Write-Output 'Rolled back. Fully quit DSH and reopen it.'
exit 0
}
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
$keep = @()
foreach ($l in ($raw -split "`n")) {
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'
}
Write-Output 'Restart DSH completely to unload.'
exit 0
}
Write-Output ''
Write-Output '=== install ==='
# 0) scan BEFORE copying, so we can decide the mode
$rep = Get-ConflictReport
Show-ConflictReport $rep
$effective = Resolve-Mode $rep
Write-Output ''
Write-Output ("requested mode : " + $Mode)
Write-Output ("effective mode : " + $effective)
if ($effective -eq 'complement') {
Write-Output ' -> permission layer will YIELD to the plugins listed above.'
Write-Output ' prompt layers + 63 skills still apply.'
}
if ($DryRun) {
Write-Output ''
Write-Output "would copy $Here -> $plugDir"
Write-Output "would copy $Here -> $runDir"
Write-Output "would write $effective bundle patch"
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) write the bundle patch matching the effective mode
Apply-Mode $effective
# 3) 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
$out = New-Object System.Collections.Generic.List[string]
$depAdded = $false
$bundleHandled = $false
foreach ($l in ($raw -split "`n")) {
if (-not $depAdded -and $l -match '^\s*"dependencies":\s*\{') {
$out.Add($l)
$out.Add(" `"$PkgName`": `"file:./plugins/$PkgName`",")
$depAdded = $true
continue
}
if (-not $bundleHandled -and $l -match '^\s*"moyun-[a-z]+",\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."
}
Write-Output ''
Write-Output ('DONE (' + $effective + ' mode).')
Write-Output ''
Write-Output 'Next three steps:'
Write-Output ' 1. Fully quit DSH (including the tray icon), then reopen it.'
Write-Output ' 2. Verify: powershell -ExecutionPolicy Bypass -File .\doctor.ps1'
Write-Output ' 3. Ask the agent: moyun_ultimate_profile'
Write-Output ''
Write-Output 'If something looks wrong:'
Write-Output ' switch modes : powershell -File .\switch-mode.ps1 -Mode complement'
Write-Output ' undo install : powershell -File .\install.ps1 -Rollback'