moyun-ultimate/switch-mode.ps1
moyun af44f4b3c9 feat: 0.5.0 - auto-detect conflicts at install time, yield the permission layer
Instead of removing other people's plugins (which breaks their environment and
cannot be rolled back), this detects and yields.

1. install.ps1 scans every installed bundle before copying, reads the config ids
   each one actually rewrites, and intersects with ours:
     scanned plugins : 19
     hard conflicts  : none
       ~ dsh-purge  shares: system-prompt  (safe)

2. Three modes. auto (default) picks complement when a hard conflict exists,
   full otherwise.

     full        permission layer owned by this plugin
     complement  permission layer yields, prompt layers + 63 skills still apply
     auto        decided by the scan

3. switch-mode.ps1 flips between them at any time; the full patch is kept as
   cordis.patch.yml.full so switching back is one command.

New file cordis.patch.complement.yml drops the five permission-related config
overrides entirely, so coexistence is structural rather than hopeful.

Deliberately NOT doing: uninstalling other plugins. Reasons are in the README.
2026-11-17 14:55:29 +08:00

85 lines
3.2 KiB
PowerShell

# moyun-ultimate mode switcher (ASCII only - PS 5.1 reads BOM-less UTF-8 as ANSI)
#
# Two modes:
# full - this plugin owns the permission layer (sandbox / approval / preset)
# complement - this plugin keeps prompt layers + skills only; the permission
# layer yields to whichever plugin already handles it
#
# Switching rewrites the installed cordis.patch.yml and asks you to restart DSH.
[CmdletBinding()]
param(
[Parameter(Mandatory = $true)]
[ValidateSet('full', 'complement')]
[string]$Mode,
[string]$Profile = 'desktop',
[string]$DshHome = '',
[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"
$plugDir = Join-Path $profileDir "plugins\$PkgName"
$runDir = Join-Path $profileDir "node_modules\$PkgName"
$compSrc = Join-Path $Here 'cordis.patch.complement.yml'
$fullSrc = Join-Path $Here 'cordis.patch.yml'
if (-not (Test-Path $compSrc)) { throw "missing $compSrc (upgrade to 0.5.0+)" }
if (-not (Test-Path $fullSrc)) { throw "missing $fullSrc" }
Write-Output "switching to: $Mode"
Write-Output "DSH_HOME : $DshHome"
Write-Output "profile : $Profile"
Write-Output ''
$targets = @($plugDir, $runDir) | Where-Object { Test-Path $_ }
if ($targets.Count -eq 0) { throw "plugin not installed under $profileDir (run install.ps1 first)" }
foreach ($d in $targets) {
$target = Join-Path $d 'cordis.patch.yml'
$fullKeep = Join-Path $d 'cordis.patch.yml.full'
if ($Mode -eq 'complement') {
if ($DryRun) {
Write-Output "would write COMPLEMENT patch into $d"
} else {
# keep a full copy first so switching back is always possible
if ((Test-Path $target) -and -not (Test-Path $fullKeep)) {
Copy-Item $target $fullKeep -Force
Write-Output " kept full copy: $fullKeep"
}
Copy-Item $compSrc $target -Force
Write-Output " COMPLEMENT written: $d"
}
} else {
if ($DryRun) {
Write-Output "would write FULL patch into $d"
} else {
if (Test-Path $fullKeep) {
Copy-Item $fullKeep $target -Force
Write-Output " restored from full copy: $d"
} else {
Copy-Item $fullSrc $target -Force
Write-Output " FULL written: $d"
}
}
}
}
Write-Output ''
if ($Mode -eq 'complement') {
Write-Output 'COMPLEMENT: prompt layers + 63 skills stay; permission layer yields.'
Write-Output 'Other plugins keep ownership of sandbox / approval / permission.'
} else {
Write-Output 'FULL: this plugin owns the permission layer.'
Write-Output 'If another plugin also rewrites approval/permission, keep only one contender.'
}
Write-Output ''
Write-Output 'Fully quit DSH (including tray) and reopen it, then run doctor.ps1.'