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:
parent
af44f4b3c9
commit
d18db479b7
24
README.md
24
README.md
@ -339,6 +339,27 @@ powershell -ExecutionPolicy Bypass -File .\install.ps1 -Mode complement
|
||||
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
|
||||
@ -373,7 +394,8 @@ npm install moyun-ultimate # 发布后可用
|
||||
### 一键自检(推荐先跑这个)
|
||||
|
||||
```powershell
|
||||
powershell -ExecutionPolicy Bypass -File .\doctor.ps1
|
||||
powershell -ExecutionPolicy Bypass -File .\doctor.ps1 # 只检查
|
||||
powershell -ExecutionPolicy Bypass -File .\doctor.ps1 -Fix # 检查 + 自动修复能修的
|
||||
```
|
||||
|
||||
逐项检查 11 个点,输出 `[OK]` / `[WARN]` / `[FAIL]`。本机实测输出:
|
||||
|
||||
176
doctor.ps1
176
doctor.ps1
@ -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).
|
||||
[CmdletBinding()]
|
||||
param(
|
||||
[string]$Profile = 'desktop',
|
||||
[string]$DshHome = ''
|
||||
[string]$DshHome = '',
|
||||
[switch]$Fix
|
||||
)
|
||||
$ErrorActionPreference = 'Continue'
|
||||
$PkgName = 'moyun-ultimate'
|
||||
$ok = 0; $warn = 0; $fail = 0
|
||||
$fixable = New-Object System.Collections.Generic.List[string]
|
||||
|
||||
function Say($tag, $msg) {
|
||||
switch ($tag) {
|
||||
'OK' { Write-Host "[OK] $msg" -ForegroundColor Green; $script:ok++ }
|
||||
'WARN' { Write-Host "[WARN] $msg" -ForegroundColor Yellow; $script:warn++ }
|
||||
'FAIL' { Write-Host "[FAIL] $msg" -ForegroundColor Red; $script:fail++ }
|
||||
'FIX' { Write-Host "[FIX] $msg" -ForegroundColor Cyan }
|
||||
'INFO' { Write-Host " $msg" -ForegroundColor Gray }
|
||||
}
|
||||
}
|
||||
@ -46,6 +49,7 @@ if (-not (Test-Path $profileDir)) {
|
||||
exit 1
|
||||
}
|
||||
Say INFO "profile = $Profile"
|
||||
if ($Fix) { Say INFO "-Fix mode : will repair what it can (backup created first)" }
|
||||
Write-Host ""
|
||||
|
||||
# --- 1. runtime copy ---
|
||||
@ -53,7 +57,8 @@ if (Test-Path $runDir) {
|
||||
$n = (Get-ChildItem $runDir -Recurse -File).Count
|
||||
Say OK "runtime copy present: node_modules\$PkgName ($n files)"
|
||||
} else {
|
||||
Say FAIL "runtime copy MISSING: $runDir -> run install.ps1"
|
||||
Say FAIL "runtime copy MISSING: $runDir"
|
||||
$fixable.Add('copy-runtime')
|
||||
}
|
||||
|
||||
# --- 2. source copy ---
|
||||
@ -62,16 +67,19 @@ if (Test-Path $plugDir) {
|
||||
Say OK "source copy present: plugins\$PkgName ($n files)"
|
||||
} else {
|
||||
Say WARN "source copy missing: plugins\$PkgName (runtime still works)"
|
||||
$fixable.Add('copy-source')
|
||||
}
|
||||
|
||||
# --- 3/4. package.json registration ---
|
||||
$hasDep = $false
|
||||
$hasBundle = $false
|
||||
if (Test-Path $pkgJson) {
|
||||
try {
|
||||
$j = Get-Content $pkgJson -Raw -Encoding UTF8 | ConvertFrom-Json
|
||||
$hasDep = $j.dependencies.PSObject.Properties.Name -contains $PkgName
|
||||
$hasBundle = $j.dsh.profile.bundles -contains $PkgName
|
||||
if ($hasDep) { Say OK "dependencies has $PkgName" } else { Say FAIL "dependencies MISSING $PkgName" }
|
||||
if ($hasBundle){ Say OK "bundles has $PkgName" } else { Say FAIL "bundles 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"; $fixable.Add('bundle') }
|
||||
Say INFO "bundles total = $($j.dsh.profile.bundles.Count)"
|
||||
} catch {
|
||||
Say FAIL "package.json parse error: $($_.Exception.Message)"
|
||||
@ -89,6 +97,7 @@ if (Test-Path $runPkg) {
|
||||
Say OK "exports has './client' -> $($rj.exports.'./client')"
|
||||
} else {
|
||||
Say FAIL "exports MISSING './client' (status badge will not load)"
|
||||
$fixable.Add('exports')
|
||||
}
|
||||
Say INFO "installed version = $($rj.version)"
|
||||
} catch {
|
||||
@ -99,7 +108,7 @@ if (Test-Path $runPkg) {
|
||||
# --- 6. prompt files ---
|
||||
$promptFiles = @(
|
||||
'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) {
|
||||
$missing = @()
|
||||
@ -107,36 +116,42 @@ if (Test-Path $runDir) {
|
||||
if (-not (Test-Path (Join-Path $runDir "prompts\$f"))) { $missing += $f }
|
||||
}
|
||||
if ($missing.Count -eq 0) {
|
||||
Say OK "five prompt layers present (5/5)"
|
||||
Say OK "six prompt layers present (6/6)"
|
||||
} else {
|
||||
Say FAIL "prompt files missing: $($missing -join ', ')"
|
||||
$fixable.Add('copy-runtime')
|
||||
}
|
||||
# frames
|
||||
$frameDir = Join-Path $runDir 'prompts\frames'
|
||||
if (Test-Path $frameDir) {
|
||||
$fc = (Get-ChildItem $frameDir -File).Count
|
||||
Say OK "frames present ($fc files)"
|
||||
} else {
|
||||
Say WARN "frames dir missing (moyun_frame will return fewer templates)"
|
||||
Say WARN "frames dir missing"
|
||||
}
|
||||
}
|
||||
|
||||
# --- 7. permission layer config ---
|
||||
$ownPatch = Join-Path $runDir 'cordis.patch.yml'
|
||||
$mode = 'unknown'
|
||||
if (Test-Path $ownPatch) {
|
||||
$pt = Get-Content $ownPatch -Raw -Encoding UTF8
|
||||
$hasSandbox = $pt -match 'id:\s*sandbox-policy'
|
||||
$hasApproval = $pt -match 'id:\s*approval'
|
||||
$hasPerm = $pt -match 'id:\s*permission'
|
||||
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 {
|
||||
Say WARN "permission layer config incomplete (sandbox=$hasSandbox approval=$hasApproval permission=$hasPerm)"
|
||||
Say INFO " -> this build predates 0.2.0; upgrade for built-in permission layer"
|
||||
Say WARN "permission layer config incomplete"
|
||||
}
|
||||
if ($pt -match 'danger-full-access') { Say OK "sandbox mode is danger-full-access" }
|
||||
} else {
|
||||
Say FAIL "cordis.patch.yml missing in runtime copy"
|
||||
$fixable.Add('copy-runtime')
|
||||
}
|
||||
|
||||
# --- 8. approval answerer in index.js ---
|
||||
@ -144,22 +159,27 @@ $idx = Join-Path $runDir 'index.js'
|
||||
if (Test-Path $idx) {
|
||||
$it = Get-Content $idx -Raw -Encoding UTF8
|
||||
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 ---
|
||||
$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) {
|
||||
$sn = (Get-ChildItem $skillsDir -Directory).Count
|
||||
Say INFO "skills in DSH_HOME\skills = $sn"
|
||||
$srcSkills = Join-Path $runDir 'skills'
|
||||
if (Test-Path $srcSkills) {
|
||||
$want = (Get-ChildItem $srcSkills -Directory).Count
|
||||
if ($want -gt 0) {
|
||||
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 {
|
||||
Say WARN "DSH_HOME\skills not found"
|
||||
$fixable.Add('skills')
|
||||
}
|
||||
|
||||
# --- 10. user-layer override check ---
|
||||
@ -171,8 +191,9 @@ if (Test-Path $profPatch) {
|
||||
}
|
||||
if ($ovr.Count -gt 0) {
|
||||
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 " blocks there, or set permission: false in this plugin's config."
|
||||
Say INFO " -> user layer applies AFTER bundle layer, so it wins."
|
||||
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 {
|
||||
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)"
|
||||
}
|
||||
|
||||
# --- 11. conflicting plugins ---
|
||||
# --- 11. conflicting plugins (precise) ---
|
||||
$CONFLICT_IDS = @('sandbox-policy', 'approval', 'permission', 'spill-policy', 'tool-result-pruner')
|
||||
if (Test-Path $pkgJson) {
|
||||
try {
|
||||
$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') }
|
||||
if ($others) {
|
||||
Say WARN "other jailbreak-ish plugins in bundles: $($others -join ', ')"
|
||||
Say INFO " -> if they also override approval/permission, only one wins (last applied)"
|
||||
$hard = @()
|
||||
$scanned = 0
|
||||
foreach ($b in @($j.dsh.profile.bundles)) {
|
||||
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 {
|
||||
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 {}
|
||||
}
|
||||
|
||||
# ---------- 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 ---
|
||||
Write-Host ""
|
||||
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 ""
|
||||
if ($fail -gt 0) {
|
||||
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
|
||||
} elseif ($warn -gt 0) {
|
||||
Write-Host "ACTION: review [WARN] items. Plugin should still work." -ForegroundColor Yellow
|
||||
|
||||
483
install.ps1
483
install.ps1
@ -1,225 +1,258 @@
|
||||
# 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')]
|
||||
[string]$Mode = 'auto',
|
||||
[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 <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 '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 ($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). Fully quit DSH and reopen it.")
|
||||
Write-Output 'Switch modes later: powershell -File .\switch-mode.ps1 -Mode full|complement'
|
||||
Write-Output 'Verify after restart: powershell -File .\doctor.ps1'
|
||||
# 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')]
|
||||
[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 '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'
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "moyun-ultimate",
|
||||
"version": "0.5.0",
|
||||
"version": "0.5.1",
|
||||
"displayName": "墨昀·终极破甲",
|
||||
"description": "墨昀·终极破甲:五层提示词内核 + 内置权限层 —— 人格双槽 × 反拒绝机制 × 执行强度 × 换框模板 × 技能路由,内置 63 个攻防技能(逆向 24 / 渗透 16 / 云 8 / 取证 6 / 其它 9)。Layered prompt core with five sections and 63 built-in skills.",
|
||||
"keywords": [
|
||||
@ -39,7 +39,7 @@
|
||||
"dsh": {
|
||||
"id": "moyun-ultimate",
|
||||
"name": "墨昀·终极破甲",
|
||||
"version": "0.5.0",
|
||||
"version": "0.5.1",
|
||||
"permissions": "六段提示词注入(含输出抗审), 内置权限层(沙箱/审批/结果), 拒绝投影状态条, 换框模板工具, 状态自查工具(含 provider 审核风险评估), 技能审计工具, 63 技能自动同步",
|
||||
"bundle": {
|
||||
"patch": "./cordis.patch.yml"
|
||||
|
||||
Loading…
Reference in New Issue
Block a user