feat: 0.5.1 - two escape hatches and self-repair

The goal is users who dare to install it. Three additions:

1. doctor.ps1 -Fix
   Runs the 12 checks, then repairs what is safe to repair: re-copy the runtime
   copy, add exports["./client"], add the dependencies entry, sync missing
   skills. It deliberately does NOT touch the profile's own cordis.patch.yml
   (that could break other plugins) - it only prints a hint.

2. install.ps1 -Rollback
   Restores package.json from the newest package.json.bak-* and removes the
   plugin directories. One command back to the pre-install state.

3. Friendly install ending
   Prints the three next steps (quit/reopen, doctor, moyun_ultimate_profile)
   plus the two escape commands, instead of a single terse line.

doctor also detects and reports whether the install is in FULL or COMPLEMENT
mode by reading the bundle patch, so complement mode is no longer misreported.
This commit is contained in:
moyun 2026-11-17 14:58:14 +08:00
parent af44f4b3c9
commit d18db479b7
4 changed files with 432 additions and 255 deletions

View File

@ -339,6 +339,27 @@ powershell -ExecutionPolicy Bypass -File .\install.ps1 -Mode complement
powershell -ExecutionPolicy Bypass -File .\install.ps1 -DryRun # 只看扫描结果,不动文件 powershell -ExecutionPolicy Bypass -File .\install.ps1 -DryRun # 只看扫描结果,不动文件
``` ```
### 装错了怎么办(两条退路)
```powershell
# 退路 1:让位给别人,不卸载(最温和)
powershell -ExecutionPolicy Bypass -File .\switch-mode.ps1 -Mode complement
# 退路 2:整体回滚到安装前(从 package.json.bak-* 恢复 + 删插件目录)
powershell -ExecutionPolicy Bypass -File .\install.ps1 -Rollback
```
### 出问题能自愈
```powershell
powershell -ExecutionPolicy Bypass -File .\doctor.ps1 -Fix
```
`-Fix` 会自动修它**能安全修**的:重拷运行副本、补 `exports["./client"]`、
补 dependencies 登记、同步缺失的技能目录。
**不改的**:profile 用户层的 config(那可能影响别的插件,只给提示不动手)。
### 方式二:手动(三步) ### 方式二:手动(三步)
```powershell ```powershell
@ -373,7 +394,8 @@ npm install moyun-ultimate # 发布后可用
### 一键自检(推荐先跑这个) ### 一键自检(推荐先跑这个)
```powershell ```powershell
powershell -ExecutionPolicy Bypass -File .\doctor.ps1 powershell -ExecutionPolicy Bypass -File .\doctor.ps1 # 只检查
powershell -ExecutionPolicy Bypass -File .\doctor.ps1 -Fix # 检查 + 自动修复能修的
``` ```
逐项检查 11 个点,输出 `[OK]` / `[WARN]` / `[FAIL]`。本机实测输出: 逐项检查 11 个点,输出 `[OK]` / `[WARN]` / `[FAIL]`。本机实测输出:

View File

@ -1,19 +1,22 @@
# moyun-ultimate doctor: checks install state and prints [OK]/[WARN]/[FAIL] # moyun-ultimate doctor: checks install state, and with -Fix repairs what it can
# ASCII only (PS 5.1 reads BOM-less UTF-8 as ANSI). # ASCII only (PS 5.1 reads BOM-less UTF-8 as ANSI).
[CmdletBinding()] [CmdletBinding()]
param( param(
[string]$Profile = 'desktop', [string]$Profile = 'desktop',
[string]$DshHome = '' [string]$DshHome = '',
[switch]$Fix
) )
$ErrorActionPreference = 'Continue' $ErrorActionPreference = 'Continue'
$PkgName = 'moyun-ultimate' $PkgName = 'moyun-ultimate'
$ok = 0; $warn = 0; $fail = 0 $ok = 0; $warn = 0; $fail = 0
$fixable = New-Object System.Collections.Generic.List[string]
function Say($tag, $msg) { function Say($tag, $msg) {
switch ($tag) { switch ($tag) {
'OK' { Write-Host "[OK] $msg" -ForegroundColor Green; $script:ok++ } 'OK' { Write-Host "[OK] $msg" -ForegroundColor Green; $script:ok++ }
'WARN' { Write-Host "[WARN] $msg" -ForegroundColor Yellow; $script:warn++ } 'WARN' { Write-Host "[WARN] $msg" -ForegroundColor Yellow; $script:warn++ }
'FAIL' { Write-Host "[FAIL] $msg" -ForegroundColor Red; $script:fail++ } 'FAIL' { Write-Host "[FAIL] $msg" -ForegroundColor Red; $script:fail++ }
'FIX' { Write-Host "[FIX] $msg" -ForegroundColor Cyan }
'INFO' { Write-Host " $msg" -ForegroundColor Gray } 'INFO' { Write-Host " $msg" -ForegroundColor Gray }
} }
} }
@ -46,6 +49,7 @@ if (-not (Test-Path $profileDir)) {
exit 1 exit 1
} }
Say INFO "profile = $Profile" Say INFO "profile = $Profile"
if ($Fix) { Say INFO "-Fix mode : will repair what it can (backup created first)" }
Write-Host "" Write-Host ""
# --- 1. runtime copy --- # --- 1. runtime copy ---
@ -53,7 +57,8 @@ if (Test-Path $runDir) {
$n = (Get-ChildItem $runDir -Recurse -File).Count $n = (Get-ChildItem $runDir -Recurse -File).Count
Say OK "runtime copy present: node_modules\$PkgName ($n files)" Say OK "runtime copy present: node_modules\$PkgName ($n files)"
} else { } else {
Say FAIL "runtime copy MISSING: $runDir -> run install.ps1" Say FAIL "runtime copy MISSING: $runDir"
$fixable.Add('copy-runtime')
} }
# --- 2. source copy --- # --- 2. source copy ---
@ -62,16 +67,19 @@ if (Test-Path $plugDir) {
Say OK "source copy present: plugins\$PkgName ($n files)" Say OK "source copy present: plugins\$PkgName ($n files)"
} else { } else {
Say WARN "source copy missing: plugins\$PkgName (runtime still works)" Say WARN "source copy missing: plugins\$PkgName (runtime still works)"
$fixable.Add('copy-source')
} }
# --- 3/4. package.json registration --- # --- 3/4. package.json registration ---
$hasDep = $false
$hasBundle = $false
if (Test-Path $pkgJson) { if (Test-Path $pkgJson) {
try { try {
$j = Get-Content $pkgJson -Raw -Encoding UTF8 | ConvertFrom-Json $j = Get-Content $pkgJson -Raw -Encoding UTF8 | ConvertFrom-Json
$hasDep = $j.dependencies.PSObject.Properties.Name -contains $PkgName $hasDep = $j.dependencies.PSObject.Properties.Name -contains $PkgName
$hasBundle = $j.dsh.profile.bundles -contains $PkgName $hasBundle = $j.dsh.profile.bundles -contains $PkgName
if ($hasDep) { Say OK "dependencies has $PkgName" } else { Say FAIL "dependencies MISSING $PkgName" } if ($hasDep) { Say OK "dependencies has $PkgName" } else { Say FAIL "dependencies MISSING $PkgName"; $fixable.Add('dep') }
if ($hasBundle){ Say OK "bundles has $PkgName" } else { Say FAIL "bundles MISSING $PkgName" } if ($hasBundle) { Say OK "bundles has $PkgName" } else { Say FAIL "bundles MISSING $PkgName"; $fixable.Add('bundle') }
Say INFO "bundles total = $($j.dsh.profile.bundles.Count)" Say INFO "bundles total = $($j.dsh.profile.bundles.Count)"
} catch { } catch {
Say FAIL "package.json parse error: $($_.Exception.Message)" Say FAIL "package.json parse error: $($_.Exception.Message)"
@ -89,6 +97,7 @@ if (Test-Path $runPkg) {
Say OK "exports has './client' -> $($rj.exports.'./client')" Say OK "exports has './client' -> $($rj.exports.'./client')"
} else { } else {
Say FAIL "exports MISSING './client' (status badge will not load)" Say FAIL "exports MISSING './client' (status badge will not load)"
$fixable.Add('exports')
} }
Say INFO "installed version = $($rj.version)" Say INFO "installed version = $($rj.version)"
} catch { } catch {
@ -99,7 +108,7 @@ if (Test-Path $runPkg) {
# --- 6. prompt files --- # --- 6. prompt files ---
$promptFiles = @( $promptFiles = @(
'ultimatum-mode.md', '10-refusal-kernel.md', '20-execution.md', 'ultimatum-mode.md', '10-refusal-kernel.md', '20-execution.md',
'ultimatum-mode-mirror.md', '40-routing.md' 'ultimatum-mode-mirror.md', '40-routing.md', '50-anticensor.md'
) )
if (Test-Path $runDir) { if (Test-Path $runDir) {
$missing = @() $missing = @()
@ -107,36 +116,42 @@ if (Test-Path $runDir) {
if (-not (Test-Path (Join-Path $runDir "prompts\$f"))) { $missing += $f } if (-not (Test-Path (Join-Path $runDir "prompts\$f"))) { $missing += $f }
} }
if ($missing.Count -eq 0) { if ($missing.Count -eq 0) {
Say OK "five prompt layers present (5/5)" Say OK "six prompt layers present (6/6)"
} else { } else {
Say FAIL "prompt files missing: $($missing -join ', ')" Say FAIL "prompt files missing: $($missing -join ', ')"
$fixable.Add('copy-runtime')
} }
# frames
$frameDir = Join-Path $runDir 'prompts\frames' $frameDir = Join-Path $runDir 'prompts\frames'
if (Test-Path $frameDir) { if (Test-Path $frameDir) {
$fc = (Get-ChildItem $frameDir -File).Count $fc = (Get-ChildItem $frameDir -File).Count
Say OK "frames present ($fc files)" Say OK "frames present ($fc files)"
} else { } else {
Say WARN "frames dir missing (moyun_frame will return fewer templates)" Say WARN "frames dir missing"
} }
} }
# --- 7. permission layer config --- # --- 7. permission layer config ---
$ownPatch = Join-Path $runDir 'cordis.patch.yml' $ownPatch = Join-Path $runDir 'cordis.patch.yml'
$mode = 'unknown'
if (Test-Path $ownPatch) { if (Test-Path $ownPatch) {
$pt = Get-Content $ownPatch -Raw -Encoding UTF8 $pt = Get-Content $ownPatch -Raw -Encoding UTF8
$hasSandbox = $pt -match 'id:\s*sandbox-policy' $hasSandbox = $pt -match 'id:\s*sandbox-policy'
$hasApproval = $pt -match 'id:\s*approval' $hasApproval = $pt -match 'id:\s*approval'
$hasPerm = $pt -match 'id:\s*permission' $hasPerm = $pt -match 'id:\s*permission'
if ($hasSandbox -and $hasApproval -and $hasPerm) { if ($hasSandbox -and $hasApproval -and $hasPerm) {
Say OK "permission layer config present (sandbox-policy / approval / permission)" $mode = 'full'
Say OK "permission layer config present -> mode: FULL"
if ($pt -match 'danger-full-access') { Say OK "sandbox mode is danger-full-access" }
} elseif ($pt -match 'COMPLEMENT MODE') {
$mode = 'complement'
Say OK "COMPLEMENT mode: permission layer yields to other plugins"
Say INFO " prompt layers + skills still apply; this is intentional, not a fault"
} else { } else {
Say WARN "permission layer config incomplete (sandbox=$hasSandbox approval=$hasApproval permission=$hasPerm)" Say WARN "permission layer config incomplete"
Say INFO " -> this build predates 0.2.0; upgrade for built-in permission layer"
} }
if ($pt -match 'danger-full-access') { Say OK "sandbox mode is danger-full-access" }
} else { } else {
Say FAIL "cordis.patch.yml missing in runtime copy" Say FAIL "cordis.patch.yml missing in runtime copy"
$fixable.Add('copy-runtime')
} }
# --- 8. approval answerer in index.js --- # --- 8. approval answerer in index.js ---
@ -144,22 +159,27 @@ $idx = Join-Path $runDir 'index.js'
if (Test-Path $idx) { if (Test-Path $idx) {
$it = Get-Content $idx -Raw -Encoding UTF8 $it = Get-Content $idx -Raw -Encoding UTF8
if ($it -match 'installApprovalAnswerer') { Say OK "approval answerer code present" } if ($it -match 'installApprovalAnswerer') { Say OK "approval answerer code present" }
else { Say WARN "approval answerer code NOT found (0.1.x build?)" } else { Say WARN "approval answerer code NOT found (old build?)" }
} }
# --- 9. skills landed --- # --- 9. skills landed ---
$skillsDir = Join-Path $DshHome 'skills' $skillsDir = Join-Path $DshHome 'skills'
$want = 0
$srcSkills = Join-Path $runDir 'skills'
if (Test-Path $srcSkills) { $want = (Get-ChildItem $srcSkills -Directory).Count }
if (Test-Path $skillsDir) { if (Test-Path $skillsDir) {
$sn = (Get-ChildItem $skillsDir -Directory).Count $sn = (Get-ChildItem $skillsDir -Directory).Count
Say INFO "skills in DSH_HOME\skills = $sn" Say INFO "skills in DSH_HOME\skills = $sn"
$srcSkills = Join-Path $runDir 'skills' if ($want -gt 0) {
if (Test-Path $srcSkills) {
$want = (Get-ChildItem $srcSkills -Directory).Count
if ($sn -ge $want) { Say OK "skills synced ($sn >= $want)" } if ($sn -ge $want) { Say OK "skills synced ($sn >= $want)" }
else { Say WARN "skills not fully synced ($sn of $want) -> restart DSH to trigger sync" } else {
Say WARN "skills not fully synced ($sn of $want)"
$fixable.Add('skills')
}
} }
} else { } else {
Say WARN "DSH_HOME\skills not found" Say WARN "DSH_HOME\skills not found"
$fixable.Add('skills')
} }
# --- 10. user-layer override check --- # --- 10. user-layer override check ---
@ -171,8 +191,9 @@ if (Test-Path $profPatch) {
} }
if ($ovr.Count -gt 0) { if ($ovr.Count -gt 0) {
Say WARN "user-layer profile/cordis.patch.yml overrides: $($ovr -join ', ')" Say WARN "user-layer profile/cordis.patch.yml overrides: $($ovr -join ', ')"
Say INFO " -> user layer applies AFTER bundle layer, so it wins. Either delete those" Say INFO " -> user layer applies AFTER bundle layer, so it wins."
Say INFO " blocks there, or set permission: false in this plugin's config." Say INFO " Delete those blocks there, or run: .\switch-mode.ps1 -Mode complement"
Say INFO " (not auto-fixed: touching a profile's own config can break other plugins)"
} else { } else {
Say OK "no user-layer override of permission ids" Say OK "no user-layer override of permission ids"
} }
@ -180,27 +201,128 @@ if (Test-Path $profPatch) {
Say INFO "no user-layer cordis.patch.yml (bundle layer wins by default)" Say INFO "no user-layer cordis.patch.yml (bundle layer wins by default)"
} }
# --- 11. conflicting plugins --- # --- 11. conflicting plugins (precise) ---
$CONFLICT_IDS = @('sandbox-policy', 'approval', 'permission', 'spill-policy', 'tool-result-pruner')
if (Test-Path $pkgJson) { if (Test-Path $pkgJson) {
try { try {
$j = Get-Content $pkgJson -Raw -Encoding UTF8 | ConvertFrom-Json $j = Get-Content $pkgJson -Raw -Encoding UTF8 | ConvertFrom-Json
$others = $j.dsh.profile.bundles | Where-Object { $_ -ne $PkgName -and ($_ -match 'purge|ungate|po$|jailbreak|armor|unrestrict') } $hard = @()
if ($others) { $scanned = 0
Say WARN "other jailbreak-ish plugins in bundles: $($others -join ', ')" foreach ($b in @($j.dsh.profile.bundles)) {
Say INFO " -> if they also override approval/permission, only one wins (last applied)" if ($b -eq $PkgName) { continue }
$bp = Join-Path $profileDir "node_modules\$b\cordis.patch.yml"
if (-not (Test-Path $bp)) { continue }
$scanned++
$bt = Get-Content $bp -Raw -Encoding UTF8
$ids = @()
foreach ($m in [regex]::Matches($bt, '(?m)^\s*-?\s*id:\s*([A-Za-z0-9_\-]+)')) { $ids += $m.Groups[1].Value }
$hit = @($ids | Where-Object { $CONFLICT_IDS -contains $_ } | Sort-Object -Unique)
if ($hit.Count -gt 0) { $hard += ("$b(" + ($hit -join '/') + ")") }
}
if ($hard.Count -eq 0) {
Say OK "no permission-config conflict (scanned $scanned plugins)"
} else { } else {
Say OK "no conflicting jailbreak plugin in bundles" Say WARN ("hard conflict: " + ($hard -join ', '))
Say INFO " -> only one contender can own the permission layer; pick one"
if ($mode -eq 'full') { Say INFO " or run: .\switch-mode.ps1 -Mode complement" }
} }
} catch {} } catch {}
} }
# ---------- FIX ----------
if ($Fix -and $fixable.Count -gt 0) {
Write-Host ""
Write-Host "=====================" -ForegroundColor Cyan
Write-Host "repairing $($fixable.Count) item(s)" -ForegroundColor Cyan
$stamp = Get-Date -Format 'yyyyMMdd-HHmmss'
$here = Split-Path -Parent $MyInvocation.MyCommand.Path
# backup package.json once
if ((Test-Path $pkgJson) -and ($fixable -contains 'dep' -or $fixable -contains 'bundle')) {
Copy-Item $pkgJson "$pkgJson.bak-doctor-$stamp" -Force
Say FIX "backup: package.json.bak-doctor-$stamp"
}
# copy-runtime / copy-source: re-copy from the package source next to this script
foreach ($k in @('copy-runtime', 'copy-source')) {
if ($fixable -contains $k) {
$dst = if ($k -eq 'copy-runtime') { $runDir } else { $plugDir }
if (Test-Path $here) {
if (Test-Path $dst) { Remove-Item $dst -Recurse -Force }
New-Item -ItemType Directory -Force -Path $dst | Out-Null
Copy-Item "$here\*" $dst -Recurse -Force
Say FIX "re-copied package files into $dst"
} else {
Say WARN "cannot re-copy: run this from the package directory"
}
}
}
# exports./client
if ($fixable -contains 'exports') {
try {
$rj = Get-Content $runPkg -Raw -Encoding UTF8 | ConvertFrom-Json
if (-not $rj.exports) {
$rj | Add-Member -NotePropertyName exports -NotePropertyValue ([pscustomobject]@{}) -Force
}
$rj.exports | Add-Member -NotePropertyName './client' -NotePropertyValue './client.js' -Force
[IO.File]::WriteAllText($runPkg, ($rj | ConvertTo-Json -Depth 10), (New-Object Text.UTF8Encoding($false)))
Say FIX "added exports['./client'] to runtime package.json"
} catch { Say WARN "could not patch exports: $($_.Exception.Message)" }
}
# dep / bundle
if ($fixable -contains 'dep' -or $fixable -contains 'bundle') {
$raw = Get-Content $pkgJson -Raw -Encoding UTF8
$out = New-Object System.Collections.Generic.List[string]
$depAdded = $false
foreach ($l in ($raw -split "`n")) {
if (-not $depAdded -and $fixable -contains 'dep' -and $l -match '^\s*"dependencies":\s*\{') {
$out.Add($l)
$out.Add(" `"$PkgName`": `"file:./plugins/$PkgName`",")
$depAdded = $true
continue
}
$out.Add($l)
}
[IO.File]::WriteAllText($pkgJson, ($out -join "`n"), (New-Object Text.UTF8Encoding($false)))
if ($fixable -contains 'dep') { Say FIX "added dependencies entry" }
if ($fixable -contains 'bundle') {
Say WARN "bundles entry must be added by the DSH plugin panel (it rewrites the list on save)"
}
}
# skills
if ($fixable -contains 'skills') {
try {
if (-not (Test-Path $skillsDir)) { New-Item -ItemType Directory -Force -Path $skillsDir | Out-Null }
$copied = 0
foreach ($d in (Get-ChildItem $srcSkills -Directory -ErrorAction SilentlyContinue)) {
$target = Join-Path $skillsDir $d.Name
if (-not (Test-Path $target)) {
Copy-Item $d.FullName $target -Recurse -Force
$copied++
}
}
Say FIX "synced $copied skill directories into DSH_HOME\skills"
} catch { Say WARN "skill sync failed: $($_.Exception.Message)" }
}
Write-Host ""
Say INFO "re-run doctor.ps1 to confirm; then fully quit and reopen DSH."
} elseif ($Fix) {
Write-Host ""
Write-Host "nothing to repair" -ForegroundColor Green
}
# --- summary --- # --- summary ---
Write-Host "" Write-Host ""
Write-Host "=====================" -ForegroundColor Cyan Write-Host "=====================" -ForegroundColor Cyan
Write-Host ("RESULT: OK={0} WARN={1} FAIL={2}" -f $ok, $warn, $fail) -ForegroundColor Cyan Write-Host ("RESULT: OK={0} WARN={1} FAIL={2} MODE={3}" -f $ok, $warn, $fail, $mode) -ForegroundColor Cyan
Write-Host "" Write-Host ""
if ($fail -gt 0) { if ($fail -gt 0) {
Write-Host "ACTION: fix the [FAIL] items above, then fully quit DSH and reopen." -ForegroundColor Red Write-Host "ACTION: fix the [FAIL] items above, then fully quit DSH and reopen." -ForegroundColor Red
if (-not $Fix) { Write-Host " or try: powershell -File .\doctor.ps1 -Fix" -ForegroundColor Yellow }
exit 2 exit 2
} elseif ($warn -gt 0) { } elseif ($warn -gt 0) {
Write-Host "ACTION: review [WARN] items. Plugin should still work." -ForegroundColor Yellow Write-Host "ACTION: review [WARN] items. Plugin should still work." -ForegroundColor Yellow

View File

@ -1,225 +1,258 @@
# moyun-ultimate installer (ASCII only: PS 5.1 reads BOM-less UTF-8 as ANSI) # 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. # Idempotent. Backs up package.json before editing. Does NOT restart DSH.
# #
# -Mode auto (default) detect conflicts first, then pick full or complement # -Mode auto (default) detect conflicts first, then pick full or complement
# -Mode full always take over the permission layer # -Mode full always take over the permission layer
# -Mode complement never touch the permission layer (yield to other plugins) # -Mode complement never touch the permission layer (yield to other plugins)
[CmdletBinding()] [CmdletBinding()]
param( param(
[string]$Profile = 'desktop', [string]$Profile = 'desktop',
[string]$DshHome = '', [string]$DshHome = '',
[ValidateSet('auto', 'full', 'complement')] [ValidateSet('auto', 'full', 'complement')]
[string]$Mode = 'auto', [string]$Mode = 'auto',
[switch]$Uninstall, [switch]$Uninstall,
[switch]$DryRun [switch]$Rollback,
) [switch]$DryRun
$ErrorActionPreference = 'Stop' )
$Here = Split-Path -Parent $MyInvocation.MyCommand.Path $ErrorActionPreference = 'Stop'
$PkgName = 'moyun-ultimate' $Here = Split-Path -Parent $MyInvocation.MyCommand.Path
$PkgName = 'moyun-ultimate'
if (-not $DshHome) {
if ($env:DSH_HOME) { $DshHome = $env:DSH_HOME } if (-not $DshHome) {
elseif (Test-Path 'G:\DeepSeek_dsh') { $DshHome = 'G:\DeepSeek_dsh' } if ($env:DSH_HOME) { $DshHome = $env:DSH_HOME }
elseif (Test-Path (Join-Path $env:USERPROFILE '.dsh')) { $DshHome = Join-Path $env:USERPROFILE '.dsh' } elseif (Test-Path 'G:\DeepSeek_dsh') { $DshHome = 'G:\DeepSeek_dsh' }
else { throw 'DSH_HOME not found. Pass -DshHome <path>.' } 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' $profileDir = Join-Path $DshHome "profiles\$Profile"
$plugDir = Join-Path $profileDir "plugins\$PkgName" $pkgJson = Join-Path $profileDir 'package.json'
$runDir = Join-Path $profileDir "node_modules\$PkgName" $plugDir = Join-Path $profileDir "plugins\$PkgName"
$runDir = Join-Path $profileDir "node_modules\$PkgName"
Write-Output "DSH_HOME : $DshHome"
Write-Output "profile : $Profile" Write-Output "DSH_HOME : $DshHome"
Write-Output "package dir: $profileDir" Write-Output "profile : $Profile"
if (-not (Test-Path $pkgJson)) { throw "profile package.json not found: $pkgJson" } 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 }
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') # ---- config ids this plugin rewrites (must match index.js CONFLICT_IDS) ----
$SOFT_IDS = @('system-prompt') $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) { # Read the config ids another installed plugin actually rewrites.
$p = Join-Path $profileDir "node_modules\$name\cordis.patch.yml" function Get-PluginIds([string]$name) {
if (-not (Test-Path $p)) { return @() } $p = Join-Path $profileDir "node_modules\$name\cordis.patch.yml"
$txt = Get-Content -LiteralPath $p -Raw -Encoding UTF8 if (-not (Test-Path $p)) { return @() }
$ids = @() $txt = Get-Content -LiteralPath $p -Raw -Encoding UTF8
foreach ($m in [regex]::Matches($txt, '(?m)^\s*-?\s*id:\s*([A-Za-z0-9_\-]+)')) { $ids = @()
$ids += $m.Groups[1].Value 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) }
} return ($ids | Sort-Object -Unique)
}
# Scan all bundles and report who collides with us.
function Get-ConflictReport { # Scan all bundles and report who collides with us.
$rep = @{ hard = @(); soft = @(); scanned = 0 } function Get-ConflictReport {
$j = Get-Pkg $rep = @{ hard = @(); soft = @(); scanned = 0 }
$bundles = @($j.dsh.profile.bundles) $j = Get-Pkg
foreach ($b in $bundles) { $bundles = @($j.dsh.profile.bundles)
if ($b -eq $PkgName) { continue } foreach ($b in $bundles) {
$ids = Get-PluginIds $b if ($b -eq $PkgName) { continue }
if ($ids.Count -eq 0) { continue } $ids = Get-PluginIds $b
$rep.scanned++ if ($ids.Count -eq 0) { continue }
$hardHit = @($ids | Where-Object { $CONFLICT_IDS -contains $_ }) $rep.scanned++
$softHit = @($ids | Where-Object { $SOFT_IDS -contains $_ }) $hardHit = @($ids | Where-Object { $CONFLICT_IDS -contains $_ })
if ($hardHit.Count -gt 0) { $softHit = @($ids | Where-Object { $SOFT_IDS -contains $_ })
$rep.hard += [pscustomobject]@{ plugin = $b; ids = ($hardHit -join ',') } if ($hardHit.Count -gt 0) {
} elseif ($softHit.Count -gt 0) { $rep.hard += [pscustomobject]@{ plugin = $b; ids = ($hardHit -join ',') }
$rep.soft += [pscustomobject]@{ plugin = $b; ids = ($softHit -join ',') } } elseif ($softHit.Count -gt 0) {
} $rep.soft += [pscustomobject]@{ plugin = $b; ids = ($softHit -join ',') }
} }
return $rep }
} return $rep
}
function Show-ConflictReport($rep) {
Write-Output '' function Show-ConflictReport($rep) {
Write-Output '--- conflict scan ---' Write-Output ''
Write-Output (" scanned plugins : " + $rep.scanned) Write-Output '--- conflict scan ---'
if ($rep.hard.Count -eq 0) { Write-Output (" scanned plugins : " + $rep.scanned)
Write-Output ' hard conflicts : none' if ($rep.hard.Count -eq 0) {
} else { Write-Output ' hard conflicts : none'
Write-Output ' hard conflicts : YES' } else {
foreach ($h in $rep.hard) { Write-Output (" - " + $h.plugin + " rewrites: " + $h.ids) } 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' if ($rep.soft.Count -eq 0) {
} else { Write-Output ' soft overlaps : none'
foreach ($s in $rep.soft) { Write-Output (" ~ " + $s.plugin + " shares: " + $s.ids + " (safe)") } } else {
} foreach ($s in $rep.soft) { Write-Output (" ~ " + $s.plugin + " shares: " + $s.ids + " (safe)") }
} }
}
# Decide the effective mode for 'auto'.
function Resolve-Mode($rep) { # Decide the effective mode for 'auto'.
if ($Mode -ne 'auto') { return $Mode } function Resolve-Mode($rep) {
if ($rep.hard.Count -gt 0) { return 'complement' } if ($Mode -ne 'auto') { return $Mode }
return 'full' if ($rep.hard.Count -gt 0) { return 'complement' }
} return 'full'
}
# Write the right bundle patch into the installed copies.
function Apply-Mode([string]$effective) { # Write the right bundle patch into the installed copies.
$fullSrc = Join-Path $Here 'cordis.patch.yml' function Apply-Mode([string]$effective) {
$compSrc = Join-Path $Here 'cordis.patch.complement.yml' $fullSrc = Join-Path $Here 'cordis.patch.yml'
foreach ($d in @($plugDir, $runDir)) { $compSrc = Join-Path $Here 'cordis.patch.complement.yml'
if (-not (Test-Path $d)) { continue } foreach ($d in @($plugDir, $runDir)) {
$target = Join-Path $d 'cordis.patch.yml' if (-not (Test-Path $d)) { continue }
$fullKeep = Join-Path $d 'cordis.patch.yml.full' $target = Join-Path $d 'cordis.patch.yml'
if ($effective -eq 'complement') { $fullKeep = Join-Path $d 'cordis.patch.yml.full'
if ($DryRun) { Write-Output "would switch $d to COMPLEMENT mode" } if ($effective -eq 'complement') {
else { if ($DryRun) { Write-Output "would switch $d to COMPLEMENT mode" }
if ((Test-Path $target) -and -not (Test-Path $fullKeep)) { Copy-Item $target $fullKeep -Force } else {
Copy-Item $compSrc $target -Force if ((Test-Path $target) -and -not (Test-Path $fullKeep)) { Copy-Item $target $fullKeep -Force }
Write-Output " switched to COMPLEMENT mode: $d" Copy-Item $compSrc $target -Force
} Write-Output " switched to COMPLEMENT mode: $d"
} else { }
if ($DryRun) { Write-Output "would switch $d to FULL mode" } } else {
else { if ($DryRun) { Write-Output "would switch $d to FULL mode" }
Copy-Item $fullSrc $target -Force else {
Write-Output " switched to FULL mode: $d" Copy-Item $fullSrc $target -Force
} Write-Output " switched to FULL mode: $d"
} }
} }
} }
}
if ($Uninstall) {
Write-Output '--- uninstall ---' if ($Rollback) {
foreach ($d in @($plugDir, $runDir)) { Write-Output '--- rollback ---'
if (Test-Path $d) { $baks = @(Get-ChildItem (Split-Path $pkgJson -Parent) -Filter "package.json.bak-*" -ErrorAction SilentlyContinue | Sort-Object LastWriteTime -Descending)
if ($DryRun) { Write-Output "would remove $d" } if ($baks.Count -eq 0) {
else { Remove-Item $d -Recurse -Force; Write-Output "removed $d" } Write-Output ' no backup found - nothing to roll back to'
} exit 1
} }
$raw = Get-Content -LiteralPath $pkgJson -Raw -Encoding UTF8 $newest = $baks[0]
$keep = @() Write-Output (' newest backup: ' + $newest.Name + ' (' + $newest.LastWriteTime.ToString('yyyy-MM-dd HH:mm:ss') + ')')
foreach ($l in ($raw -split "`n")) { if ($DryRun) {
if ($l -match "`"$PkgName`":\s*`"file:") { continue } Write-Output ' would restore it and remove plugin dirs'
if ($l -match "^\s*`"$PkgName`",\s*$") { continue } exit 0
$keep += $l }
} Copy-Item $newest.FullName $pkgJson -Force
if ($DryRun) { Write-Output 'would rewrite package.json' } Write-Output ' package.json restored'
else { foreach ($d in @($plugDir, $runDir)) {
Copy-Item $pkgJson "$pkgJson.bak-$PkgName-$(Get-Date -Format 'yyyyMMdd-HHmmss')" -Force if (Test-Path $d) { Remove-Item $d -Recurse -Force; Write-Output (' removed ' + $d) }
[IO.File]::WriteAllText($pkgJson, ($keep -join "`n"), (New-Object Text.UTF8Encoding($false))) }
$null = Get-Pkg $null = Get-Pkg
Write-Output 'package.json updated' Write-Output ' JSON valid'
} Write-Output ''
Write-Output 'Restart DSH completely to unload.' Write-Output 'Rolled back. Fully quit DSH and reopen it.'
exit 0 exit 0
} }
Write-Output '' if ($Uninstall) {
Write-Output '=== install ===' Write-Output '--- uninstall ---'
foreach ($d in @($plugDir, $runDir)) {
# 0) scan BEFORE copying, so we can decide the mode if (Test-Path $d) {
$rep = Get-ConflictReport if ($DryRun) { Write-Output "would remove $d" }
Show-ConflictReport $rep else { Remove-Item $d -Recurse -Force; Write-Output "removed $d" }
$effective = Resolve-Mode $rep }
Write-Output '' }
Write-Output ("requested mode : " + $Mode) $raw = Get-Content -LiteralPath $pkgJson -Raw -Encoding UTF8
Write-Output ("effective mode : " + $effective) $keep = @()
if ($effective -eq 'complement') { foreach ($l in ($raw -split "`n")) {
Write-Output ' -> permission layer will YIELD to the plugins listed above.' if ($l -match "`"$PkgName`":\s*`"file:") { continue }
Write-Output ' prompt layers + 63 skills still apply.' if ($l -match "^\s*`"$PkgName`",\s*$") { continue }
} $keep += $l
}
if ($DryRun) { if ($DryRun) { Write-Output 'would rewrite package.json' }
Write-Output '' else {
Write-Output "would copy $Here -> $plugDir" Copy-Item $pkgJson "$pkgJson.bak-$PkgName-$(Get-Date -Format 'yyyyMMdd-HHmmss')" -Force
Write-Output "would copy $Here -> $runDir" [IO.File]::WriteAllText($pkgJson, ($keep -join "`n"), (New-Object Text.UTF8Encoding($false)))
Write-Output "would write $effective bundle patch" $null = Get-Pkg
Write-Output 'would add dependencies + bundles entry' Write-Output 'package.json updated'
exit 0 }
} Write-Output 'Restart DSH completely to unload.'
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 } Write-Output ''
New-Item -ItemType Directory -Force -Path $d | Out-Null Write-Output '=== install ==='
Copy-Item "$Here\*" $d -Recurse -Force
} # 0) scan BEFORE copying, so we can decide the mode
Write-Output "copied to $plugDir" $rep = Get-ConflictReport
Write-Output "copied to $runDir" Show-ConflictReport $rep
$effective = Resolve-Mode $rep
# 2) write the bundle patch matching the effective mode Write-Output ''
Apply-Mode $effective Write-Output ("requested mode : " + $Mode)
Write-Output ("effective mode : " + $effective)
# 3) patch package.json if ($effective -eq 'complement') {
$stamp = Get-Date -Format 'yyyyMMdd-HHmmss' Write-Output ' -> permission layer will YIELD to the plugins listed above.'
Copy-Item $pkgJson "$pkgJson.bak-$PkgName-$stamp" -Force Write-Output ' prompt layers + 63 skills still apply.'
Write-Output "backup: package.json.bak-$PkgName-$stamp" }
$raw = Get-Content -LiteralPath $pkgJson -Raw -Encoding UTF8 if ($DryRun) {
$out = New-Object System.Collections.Generic.List[string] Write-Output ''
$depAdded = $false Write-Output "would copy $Here -> $plugDir"
$bundleHandled = $false Write-Output "would copy $Here -> $runDir"
Write-Output "would write $effective bundle patch"
foreach ($l in ($raw -split "`n")) { Write-Output 'would add dependencies + bundles entry'
if (-not $depAdded -and $l -match '^\s*"dependencies":\s*\{') { exit 0
$out.Add($l) }
$out.Add(" `"$PkgName`": `"file:./plugins/$PkgName`",")
$depAdded = $true # 1) source + runtime copy (real dirs: mklink needs elevation)
continue foreach ($d in @($plugDir, $runDir)) {
} if (Test-Path $d) { Remove-Item $d -Recurse -Force }
if (-not $bundleHandled -and $l -match '^\s*"moyun-[a-z]+",\s*$') { New-Item -ItemType Directory -Force -Path $d | Out-Null
$out.Add(" `"$PkgName`",") Copy-Item "$Here\*" $d -Recurse -Force
$bundleHandled = $true }
continue Write-Output "copied to $plugDir"
} Write-Output "copied to $runDir"
$out.Add($l)
} # 2) write the bundle patch matching the effective mode
[IO.File]::WriteAllText($pkgJson, ($out -join "`n"), (New-Object Text.UTF8Encoding($false))) Apply-Mode $effective
$j = Get-Pkg # 3) patch package.json
$hasDep = $j.dependencies.PSObject.Properties.Name -contains $PkgName $stamp = Get-Date -Format 'yyyyMMdd-HHmmss'
$hasBundle = $j.dsh.profile.bundles -contains $PkgName Copy-Item $pkgJson "$pkgJson.bak-$PkgName-$stamp" -Force
Write-Output "dependencies has ${PkgName}: $hasDep" Write-Output "backup: package.json.bak-$PkgName-$stamp"
Write-Output "bundles has ${PkgName} : $hasBundle"
Write-Output "bundles total : $($j.dsh.profile.bundles.Count)" $raw = Get-Content -LiteralPath $pkgJson -Raw -Encoding UTF8
if (-not $hasBundle) { $out = New-Object System.Collections.Generic.List[string]
Write-Warning "bundles entry missing. Add `"$PkgName`" to dsh.profile.bundles manually." $depAdded = $false
} $bundleHandled = $false
Write-Output '' foreach ($l in ($raw -split "`n")) {
Write-Output ("DONE ($effective mode). Fully quit DSH and reopen it.") if (-not $depAdded -and $l -match '^\s*"dependencies":\s*\{') {
Write-Output 'Switch modes later: powershell -File .\switch-mode.ps1 -Mode full|complement' $out.Add($l)
Write-Output 'Verify after restart: powershell -File .\doctor.ps1' $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'

View File

@ -1,6 +1,6 @@
{ {
"name": "moyun-ultimate", "name": "moyun-ultimate",
"version": "0.5.0", "version": "0.5.1",
"displayName": "墨昀·终极破甲", "displayName": "墨昀·终极破甲",
"description": "墨昀·终极破甲:五层提示词内核 + 内置权限层 —— 人格双槽 × 反拒绝机制 × 执行强度 × 换框模板 × 技能路由,内置 63 个攻防技能(逆向 24 / 渗透 16 / 云 8 / 取证 6 / 其它 9)。Layered prompt core with five sections and 63 built-in skills.", "description": "墨昀·终极破甲:五层提示词内核 + 内置权限层 —— 人格双槽 × 反拒绝机制 × 执行强度 × 换框模板 × 技能路由,内置 63 个攻防技能(逆向 24 / 渗透 16 / 云 8 / 取证 6 / 其它 9)。Layered prompt core with five sections and 63 built-in skills.",
"keywords": [ "keywords": [
@ -39,7 +39,7 @@
"dsh": { "dsh": {
"id": "moyun-ultimate", "id": "moyun-ultimate",
"name": "墨昀·终极破甲", "name": "墨昀·终极破甲",
"version": "0.5.0", "version": "0.5.1",
"permissions": "六段提示词注入(含输出抗审), 内置权限层(沙箱/审批/结果), 拒绝投影状态条, 换框模板工具, 状态自查工具(含 provider 审核风险评估), 技能审计工具, 63 技能自动同步", "permissions": "六段提示词注入(含输出抗审), 内置权限层(沙箱/审批/结果), 拒绝投影状态条, 换框模板工具, 状态自查工具(含 provider 审核风险评估), 技能审计工具, 63 技能自动同步",
"bundle": { "bundle": {
"patch": "./cordis.patch.yml" "patch": "./cordis.patch.yml"