Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions .antigravity-plugin/scripts/uninstall-monk-agent.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ $AgentDataDir = Join-Path $MonkHome "agent"
$PidFile = Join-Path $AgentDataDir "launcher\run\monk-agent.pid"
$Target = Join-Path $InstallDir "monk-agent.exe"
$Checksum = Join-Path $InstallDir "monk-agent.sha256"
$AntigravityMcpConfig = if ($env:MONK_ANTIGRAVITY_CONFIG) { $env:MONK_ANTIGRAVITY_CONFIG } else {
Join-Path $HOME ".gemini\config\mcp_config.json"
}

if (-not $Yes) {
$suffix = if ($Runtime) { " and Monk runtime" } else { "" }
Expand Down Expand Up @@ -135,10 +138,53 @@ fi
wsl.exe -d $distro --user root -- sh -lc $script
}

function Remove-AntigravityMcpRegistration {
if (-not (Test-Path -LiteralPath $AntigravityMcpConfig -PathType Leaf)) {
return
}

try {
$Config = Get-Content -LiteralPath $AntigravityMcpConfig -Raw | ConvertFrom-Json
} catch {
Write-Warning "Leaving malformed Antigravity MCP config unchanged: $AntigravityMcpConfig"
return
}

if ($null -eq $Config) {
return
}
$ServersProperty = $Config.PSObject.Properties["mcpServers"]
if ($null -eq $ServersProperty -or $null -eq $ServersProperty.Value) {
return
}
$MonkProperty = $ServersProperty.Value.PSObject.Properties["monk"]
if ($null -eq $MonkProperty) {
return
}

$ServersProperty.Value.PSObject.Properties.Remove("monk")
if (@($ServersProperty.Value.PSObject.Properties).Count -eq 0) {
$Config.PSObject.Properties.Remove("mcpServers")
}

$Directory = Split-Path -Parent $AntigravityMcpConfig
$TempPath = Join-Path $Directory (".monk-mcp-config-{0}.tmp" -f [guid]::NewGuid())
try {
$Json = $Config | ConvertTo-Json -Depth 100
[IO.File]::WriteAllText($TempPath, $Json + [Environment]::NewLine, [Text.UTF8Encoding]::new($false))
Move-Item -LiteralPath $TempPath -Destination $AntigravityMcpConfig -Force
Write-Host "Removed Monk MCP registration from $AntigravityMcpConfig"
} catch {
Remove-Item -LiteralPath $TempPath -Force -ErrorAction SilentlyContinue
Write-Warning "Could not update Antigravity MCP config: $AntigravityMcpConfig"
}
}

Stop-ManagedAgent
Remove-AgentFiles
if ($Runtime) {
Remove-MonkRuntime
}
Remove-AntigravityMcpRegistration

Write-Host "monk-agent uninstall complete."
68 changes: 68 additions & 0 deletions .antigravity-plugin/scripts/uninstall-monk-agent.sh
Original file line number Diff line number Diff line change
Expand Up @@ -156,10 +156,78 @@ remove_runtime() {
esac
}

remove_antigravity_mcp_registration() {
mcp_cfg="${MONK_ANTIGRAVITY_CONFIG:-"$home_dir/.gemini/config/mcp_config.json"}"
[ -f "$mcp_cfg" ] || return 0

tmp="$(mktemp "${TMPDIR:-/tmp}/monk-mcp-config.XXXXXX")"
if command -v jq >/dev/null 2>&1; then
if ! jq empty "$mcp_cfg" >/dev/null 2>&1; then
rm -f "$tmp"
echo "Warning: leaving malformed Antigravity MCP config unchanged: $mcp_cfg" >&2
return 0
fi
if ! jq -e '.mcpServers | type == "object" and has("monk")' "$mcp_cfg" >/dev/null 2>&1; then
rm -f "$tmp"
return 0
fi
if ! jq 'del(.mcpServers.monk) | if .mcpServers == {} then del(.mcpServers) else . end' "$mcp_cfg" >"$tmp"; then
rm -f "$tmp"
echo "Warning: could not update Antigravity MCP config: $mcp_cfg" >&2
return 0
fi
elif command -v python3 >/dev/null 2>&1; then
status=0
python3 - "$mcp_cfg" >"$tmp" <<'PY' || status=$?
import json
import sys

path = sys.argv[1]
try:
with open(path, encoding="utf-8-sig") as source:
config = json.load(source)
except (OSError, ValueError):
sys.exit(2)

servers = config.get("mcpServers") if isinstance(config, dict) else None
if not isinstance(servers, dict) or "monk" not in servers:
sys.exit(3)

del servers["monk"]
if not servers:
del config["mcpServers"]
json.dump(config, sys.stdout, indent=2)
sys.stdout.write("\n")
PY
case "$status" in
0) ;;
3) rm -f "$tmp"; return 0 ;;
*)
rm -f "$tmp"
echo "Warning: leaving malformed Antigravity MCP config unchanged: $mcp_cfg" >&2
return 0
;;
esac
else
rm -f "$tmp"
echo "Warning: could not inspect $mcp_cfg; remove mcpServers.monk manually (jq or python3 required)." >&2
return 0
fi

if mv "$tmp" "$mcp_cfg"; then
echo "Removed Monk MCP registration from $mcp_cfg" >&2
else
rm -f "$tmp"
echo "Warning: could not update Antigravity MCP config: $mcp_cfg" >&2
fi
}

stop_agent
remove_agent_files
if [ "$remove_runtime" = "1" ]; then
remove_runtime
fi

remove_antigravity_mcp_registration

echo "monk-agent uninstall complete."
8 changes: 8 additions & 0 deletions .github/workflows/install-e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ jobs:
- name: Checkout
uses: actions/checkout@v6

- name: Test POSIX Antigravity MCP cleanup
shell: bash
run: ./tests/uninstall-antigravity-mcp.sh

- name: Install monk-agent
shell: bash
env:
Expand Down Expand Up @@ -66,6 +70,10 @@ jobs:
shell: pwsh
run: .\tests\block-monk-windows.ps1

- name: Test Windows Antigravity MCP cleanup
shell: pwsh
run: .\tests\uninstall-antigravity-mcp-windows.ps1

- name: Install monk-agent
shell: pwsh
env:
Expand Down
46 changes: 46 additions & 0 deletions plugins/monk/scripts/uninstall-monk-agent.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ $AgentDataDir = Join-Path $MonkHome "agent"
$PidFile = Join-Path $AgentDataDir "launcher\run\monk-agent.pid"
$Target = Join-Path $InstallDir "monk-agent.exe"
$Checksum = Join-Path $InstallDir "monk-agent.sha256"
$AntigravityMcpConfig = if ($env:MONK_ANTIGRAVITY_CONFIG) { $env:MONK_ANTIGRAVITY_CONFIG } else {
Join-Path $HOME ".gemini\config\mcp_config.json"
}

if (-not $Yes) {
$suffix = if ($Runtime) { " and Monk runtime" } else { "" }
Expand Down Expand Up @@ -135,10 +138,53 @@ fi
wsl.exe -d $distro --user root -- sh -lc $script
}

function Remove-AntigravityMcpRegistration {
if (-not (Test-Path -LiteralPath $AntigravityMcpConfig -PathType Leaf)) {
return
}

try {
$Config = Get-Content -LiteralPath $AntigravityMcpConfig -Raw | ConvertFrom-Json
} catch {
Write-Warning "Leaving malformed Antigravity MCP config unchanged: $AntigravityMcpConfig"
return
}

if ($null -eq $Config) {
return
}
$ServersProperty = $Config.PSObject.Properties["mcpServers"]
if ($null -eq $ServersProperty -or $null -eq $ServersProperty.Value) {
return
}
$MonkProperty = $ServersProperty.Value.PSObject.Properties["monk"]
if ($null -eq $MonkProperty) {
return
}

$ServersProperty.Value.PSObject.Properties.Remove("monk")
if (@($ServersProperty.Value.PSObject.Properties).Count -eq 0) {
$Config.PSObject.Properties.Remove("mcpServers")
}

$Directory = Split-Path -Parent $AntigravityMcpConfig
$TempPath = Join-Path $Directory (".monk-mcp-config-{0}.tmp" -f [guid]::NewGuid())
try {
$Json = $Config | ConvertTo-Json -Depth 100
[IO.File]::WriteAllText($TempPath, $Json + [Environment]::NewLine, [Text.UTF8Encoding]::new($false))
Move-Item -LiteralPath $TempPath -Destination $AntigravityMcpConfig -Force
Write-Host "Removed Monk MCP registration from $AntigravityMcpConfig"
} catch {
Remove-Item -LiteralPath $TempPath -Force -ErrorAction SilentlyContinue
Write-Warning "Could not update Antigravity MCP config: $AntigravityMcpConfig"
}
}

Stop-ManagedAgent
Remove-AgentFiles
if ($Runtime) {
Remove-MonkRuntime
}
Remove-AntigravityMcpRegistration

Write-Host "monk-agent uninstall complete."
68 changes: 68 additions & 0 deletions plugins/monk/scripts/uninstall-monk-agent.sh
Original file line number Diff line number Diff line change
Expand Up @@ -156,10 +156,78 @@ remove_runtime() {
esac
}

remove_antigravity_mcp_registration() {
mcp_cfg="${MONK_ANTIGRAVITY_CONFIG:-"$home_dir/.gemini/config/mcp_config.json"}"
[ -f "$mcp_cfg" ] || return 0

tmp="$(mktemp "${TMPDIR:-/tmp}/monk-mcp-config.XXXXXX")"
if command -v jq >/dev/null 2>&1; then
if ! jq empty "$mcp_cfg" >/dev/null 2>&1; then
rm -f "$tmp"
echo "Warning: leaving malformed Antigravity MCP config unchanged: $mcp_cfg" >&2
return 0
fi
if ! jq -e '.mcpServers | type == "object" and has("monk")' "$mcp_cfg" >/dev/null 2>&1; then
rm -f "$tmp"
return 0
fi
if ! jq 'del(.mcpServers.monk) | if .mcpServers == {} then del(.mcpServers) else . end' "$mcp_cfg" >"$tmp"; then
rm -f "$tmp"
echo "Warning: could not update Antigravity MCP config: $mcp_cfg" >&2
return 0
fi
elif command -v python3 >/dev/null 2>&1; then
status=0
python3 - "$mcp_cfg" >"$tmp" <<'PY' || status=$?
import json
import sys

path = sys.argv[1]
try:
with open(path, encoding="utf-8-sig") as source:
config = json.load(source)
except (OSError, ValueError):
sys.exit(2)

servers = config.get("mcpServers") if isinstance(config, dict) else None
if not isinstance(servers, dict) or "monk" not in servers:
sys.exit(3)

del servers["monk"]
if not servers:
del config["mcpServers"]
json.dump(config, sys.stdout, indent=2)
sys.stdout.write("\n")
PY
case "$status" in
0) ;;
3) rm -f "$tmp"; return 0 ;;
*)
rm -f "$tmp"
echo "Warning: leaving malformed Antigravity MCP config unchanged: $mcp_cfg" >&2
return 0
;;
esac
else
rm -f "$tmp"
echo "Warning: could not inspect $mcp_cfg; remove mcpServers.monk manually (jq or python3 required)." >&2
return 0
fi

if mv "$tmp" "$mcp_cfg"; then
echo "Removed Monk MCP registration from $mcp_cfg" >&2
else
rm -f "$tmp"
echo "Warning: could not update Antigravity MCP config: $mcp_cfg" >&2
fi
}

stop_agent
remove_agent_files
if [ "$remove_runtime" = "1" ]; then
remove_runtime
fi

remove_antigravity_mcp_registration

echo "monk-agent uninstall complete."
46 changes: 46 additions & 0 deletions scripts/uninstall-monk-agent.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ $AgentDataDir = Join-Path $MonkHome "agent"
$PidFile = Join-Path $AgentDataDir "launcher\run\monk-agent.pid"
$Target = Join-Path $InstallDir "monk-agent.exe"
$Checksum = Join-Path $InstallDir "monk-agent.sha256"
$AntigravityMcpConfig = if ($env:MONK_ANTIGRAVITY_CONFIG) { $env:MONK_ANTIGRAVITY_CONFIG } else {
Join-Path $HOME ".gemini\config\mcp_config.json"
}

if (-not $Yes) {
$suffix = if ($Runtime) { " and Monk runtime" } else { "" }
Expand Down Expand Up @@ -135,10 +138,53 @@ fi
wsl.exe -d $distro --user root -- sh -lc $script
}

function Remove-AntigravityMcpRegistration {
if (-not (Test-Path -LiteralPath $AntigravityMcpConfig -PathType Leaf)) {
return
}

try {
$Config = Get-Content -LiteralPath $AntigravityMcpConfig -Raw | ConvertFrom-Json
} catch {
Write-Warning "Leaving malformed Antigravity MCP config unchanged: $AntigravityMcpConfig"
return
}

if ($null -eq $Config) {
return
}
$ServersProperty = $Config.PSObject.Properties["mcpServers"]
if ($null -eq $ServersProperty -or $null -eq $ServersProperty.Value) {
return
}
$MonkProperty = $ServersProperty.Value.PSObject.Properties["monk"]
if ($null -eq $MonkProperty) {
return
}

$ServersProperty.Value.PSObject.Properties.Remove("monk")
if (@($ServersProperty.Value.PSObject.Properties).Count -eq 0) {
$Config.PSObject.Properties.Remove("mcpServers")
}

$Directory = Split-Path -Parent $AntigravityMcpConfig
$TempPath = Join-Path $Directory (".monk-mcp-config-{0}.tmp" -f [guid]::NewGuid())
try {
$Json = $Config | ConvertTo-Json -Depth 100
[IO.File]::WriteAllText($TempPath, $Json + [Environment]::NewLine, [Text.UTF8Encoding]::new($false))
Move-Item -LiteralPath $TempPath -Destination $AntigravityMcpConfig -Force
Write-Host "Removed Monk MCP registration from $AntigravityMcpConfig"
} catch {
Remove-Item -LiteralPath $TempPath -Force -ErrorAction SilentlyContinue
Write-Warning "Could not update Antigravity MCP config: $AntigravityMcpConfig"
}
}

Stop-ManagedAgent
Remove-AgentFiles
if ($Runtime) {
Remove-MonkRuntime
}
Remove-AntigravityMcpRegistration

Write-Host "monk-agent uninstall complete."
Loading