Skip to content
Merged
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
53 changes: 53 additions & 0 deletions setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,58 @@ cleanup_deprecated_mcps() {
return 0
}

# Disable MCPs globally that should only be enabled on-demand via subagents
# This reduces session startup context by ~4.6K tokens
# - playwriter: ~3K tokens - enable via @playwriter subagent
# - augment-context-engine: ~1K tokens - enable via @augment-context-engine subagent
# - gh-grep: ~600 tokens - replaced by @github-search subagent (uses rg/bash)
disable_ondemand_mcps() {
local opencode_config="$HOME/.config/opencode/opencode.json"

if [[ ! -f "$opencode_config" ]]; then
return 0
fi

if ! command -v jq &> /dev/null; then
return 0
fi

# MCPs to disable globally (enabled on-demand via subagents)
local -a ondemand_mcps=(
"playwriter"
"augment-context-engine"
"gh-grep"
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In ondemand_mcps, the entry uses gh-grep, but other parts of the repo appear to name this MCP gh_grep (underscore). If opencode.json uses the underscore key, this loop will never match and gh_grep won’t actually be disabled.

Fix This in Augment

🤖 Was this useful? React with 👍 or 👎, or 🚀 if it prevented an incident/outage.

)

local disabled=0
local tmp_config
tmp_config=$(mktemp)

cp "$opencode_config" "$tmp_config"

for mcp in "${ondemand_mcps[@]}"; do
# Check if MCP exists and is currently enabled (or has no enabled field)
if jq -e ".mcp[\"$mcp\"]" "$tmp_config" > /dev/null 2>&1; then
local current_enabled
current_enabled=$(jq -r ".mcp[\"$mcp\"].enabled // \"true\"" "$tmp_config")
if [[ "$current_enabled" != "false" ]]; then
jq ".mcp[\"$mcp\"].enabled = false" "$tmp_config" > "${tmp_config}.new" && mv "${tmp_config}.new" "$tmp_config"
((disabled++))
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

((disabled++)) runs even if the preceding jq ... && mv ... fails, which can trigger a backup and a misleading “Disabled N MCP(s)” message despite no successful update.

Fix This in Augment

🤖 Was this useful? React with 👍 or 👎, or 🚀 if it prevented an incident/outage.

Comment on lines +333 to +340
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Only increment disabled after a successful jq write.

If jq or mv fails, the counter still increments and the script may back up/overwrite without an actual change. Gate the increment on success to keep reporting and backup behavior accurate.

🔧 Suggested fix
-            if [[ "$current_enabled" != "false" ]]; then
-                jq ".mcp[\"$mcp\"].enabled = false" "$tmp_config" > "${tmp_config}.new" && mv "${tmp_config}.new" "$tmp_config"
-                ((disabled++))
-            fi
+            if [[ "$current_enabled" != "false" ]]; then
+                if jq ".mcp[\"$mcp\"].enabled = false" "$tmp_config" > "${tmp_config}.new" && mv "${tmp_config}.new" "$tmp_config"; then
+                    ((disabled++))
+                fi
+            fi
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
for mcp in "${ondemand_mcps[@]}"; do
# Check if MCP exists and is currently enabled (or has no enabled field)
if jq -e ".mcp[\"$mcp\"]" "$tmp_config" > /dev/null 2>&1; then
local current_enabled
current_enabled=$(jq -r ".mcp[\"$mcp\"].enabled // \"true\"" "$tmp_config")
if [[ "$current_enabled" != "false" ]]; then
jq ".mcp[\"$mcp\"].enabled = false" "$tmp_config" > "${tmp_config}.new" && mv "${tmp_config}.new" "$tmp_config"
((disabled++))
for mcp in "${ondemand_mcps[@]}"; do
# Check if MCP exists and is currently enabled (or has no enabled field)
if jq -e ".mcp[\"$mcp\"]" "$tmp_config" > /dev/null 2>&1; then
local current_enabled
current_enabled=$(jq -r ".mcp[\"$mcp\"].enabled // \"true\"" "$tmp_config")
if [[ "$current_enabled" != "false" ]]; then
if jq ".mcp[\"$mcp\"].enabled = false" "$tmp_config" > "${tmp_config}.new" && mv "${tmp_config}.new" "$tmp_config"; then
((disabled++))
fi
fi
🤖 Prompt for AI Agents
In `@setup.sh` around lines 333 - 340, The loop that processes each mcp currently
increments the disabled counter immediately after running jq and mv; change this
so disabled is only incremented when the write actually succeeds by checking the
exit status of the jq->mv operation (the jq ".mcp[\"$mcp\"].enabled = false"
"$tmp_config" > "${tmp_config}.new" && mv "${tmp_config}.new" "$tmp_config"
sequence) — e.g. perform the jq write and mv, test their combined success, and
only then execute ((disabled++)) for the given mcp and tmp_config; ensure any
failure path does not increment disabled so reporting and backup logic remain
accurate.

fi
fi
Comment on lines +335 to +342

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

This change improves the script in two ways:

  1. Robustness: It uses .mcp? | has(\"$mcp\") to safely check for an MCP's existence, preventing script failure if the top-level .mcp object is missing in opencode.json.
  2. Readability: It combines the check for the enabled status directly within the if condition, removing the need for an intermediate current_enabled variable.
Suggested change
if jq -e ".mcp[\"$mcp\"]" "$tmp_config" > /dev/null 2>&1; then
local current_enabled
current_enabled=$(jq -r ".mcp[\"$mcp\"].enabled // \"true\"" "$tmp_config")
if [[ "$current_enabled" != "false" ]]; then
jq ".mcp[\"$mcp\"].enabled = false" "$tmp_config" > "${tmp_config}.new" && mv "${tmp_config}.new" "$tmp_config"
((disabled++))
fi
fi
if jq -e ".mcp? | has(\"$mcp\")" "$tmp_config" > /dev/null 2>&1; then
if [[ $(jq -r ".mcp[\"$mcp\"].enabled // \"true\"" "$tmp_config") != "false" ]]; then
jq ".mcp[\"$mcp\"].enabled = false" "$tmp_config" > "${tmp_config}.new" && mv "${tmp_config}.new" "$tmp_config"
((disabled++))
fi
fi

done

if [[ $disabled -gt 0 ]]; then
create_backup_with_rotation "$opencode_config" "opencode"
mv "$tmp_config" "$opencode_config"
print_info "Disabled $disabled MCP(s) globally (use subagents to enable on-demand)"
else
rm -f "$tmp_config"
fi

return 0
}

# Migrate old config-backups to new per-type backup structure
# This runs once to clean up the legacy backup directory
migrate_old_backups() {
Expand Down Expand Up @@ -3335,6 +3387,7 @@ main() {
confirm_step "Migrate loop state from .claude/ to .agent/loop-state/" && migrate_loop_state_directories
confirm_step "Cleanup deprecated agent paths" && cleanup_deprecated_paths
confirm_step "Cleanup deprecated MCP entries (hetzner, serper, etc.)" && cleanup_deprecated_mcps
confirm_step "Disable on-demand MCPs globally (playwriter, augment, gh-grep)" && disable_ondemand_mcps
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This runs before update_opencode_config, but the OpenCode generator script enforces MCP enabled states and currently sets playwriter/augment-context-engine/gh_grep to enabled. As a result, the disablement here may be overwritten later in the same setup.sh run.

Fix This in Augment

🤖 Was this useful? React with 👍 or 👎, or 🚀 if it prevented an incident/outage.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical

🧩 Analysis chain

🏁 Script executed:

# First, check the general structure and locate the functions
git ls-files | grep -E "setup\.sh|generate.*opencode"

Repository: marcusquinn/aidevops

Length of output: 303


🏁 Script executed:

# Look at the context around line 3390 in setup.sh
sed -n '3385,3395p' setup.sh

Repository: marcusquinn/aidevops

Length of output: 1033


🏁 Script executed:

# Find the disable_ondemand_mcps function
rg -n "disable_ondemand_mcps" setup.sh

Repository: marcusquinn/aidevops

Length of output: 205


🏁 Script executed:

# Find the update_opencode_config function
rg -n "update_opencode_config" setup.sh

Repository: marcusquinn/aidevops

Length of output: 175


🏁 Script executed:

# Locate the generator script
fd -name "*generate*opencode*" -o -name "*opencode*generator*"

Repository: marcusquinn/aidevops

Length of output: 294


🏁 Script executed:

# Find generator scripts with correct syntax
find . -name "generate-opencode*.sh"

Repository: marcusquinn/aidevops

Length of output: 155


🏁 Script executed:

# View the order of execution and surrounding context (wider range)
sed -n '3385,3410p' setup.sh

Repository: marcusquinn/aidevops

Length of output: 2181


🏁 Script executed:

# Examine disable_ondemand_mcps function
sed -n '309,340p' setup.sh

Repository: marcusquinn/aidevops

Length of output: 1127


🏁 Script executed:

# Examine update_opencode_config function
sed -n '2042,2080p' setup.sh

Repository: marcusquinn/aidevops

Length of output: 1644


🏁 Script executed:

# Check the generator script for MCP config handling
cat .agent/scripts/generate-opencode-agents.sh | head -100

Repository: marcusquinn/aidevops

Length of output: 4157


🏁 Script executed:

# Get the full generate-opencode-agents.sh script
wc -l .agent/scripts/generate-opencode-agents.sh

Repository: marcusquinn/aidevops

Length of output: 110


🏁 Script executed:

# Extract the Python section that handles MCP config
sed -n '/python3/,/PYEOF/p' .agent/scripts/generate-opencode-agents.sh | head -200

Repository: marcusquinn/aidevops

Length of output: 7855


🏁 Script executed:

# Look specifically for how the script handles 'mcp' or 'enabled' in the Python code
rg -A 5 -B 5 '"mcp"|enabled' .agent/scripts/generate-opencode-agents.sh

Repository: marcusquinn/aidevops

Length of output: 9487


Move disable_ondemand_mcps after update_opencode_config or update the generator's MCP loading policy.

The generator script enforces an MCP loading policy that sets playwriter, augment-context-engine, and gh_grep to enabled=True via the EAGER_MCPS list. This overwrites the enabled=false flags set by disable_ondemand_mcps on line 3390. Either reorder these steps (move disable_ondemand_mcps to line 3400+) or update the generator to classify these as LAZY_MCPS instead of EAGER_MCPS to align with the on-demand loading strategy documented in the code comments.

🤖 Prompt for AI Agents
In `@setup.sh` at line 3390, The current call to disable_ondemand_mcps runs before
update_opencode_config and is being undone by the generator's EAGER_MCPS policy;
either move the confirm_step "Disable on-demand MCPs globally (playwriter,
augment, gh-grep)" && disable_ondemand_mcps so it executes after
update_opencode_config, or modify the generator logic to remove playwriter,
augment-context-engine, and gh_grep from the EAGER_MCPS list and add them to
LAZY_MCPS so the generator no longer forces enabled=True for those MCPs; update
references in the generator where EAGER_MCPS/LAZY_MCPS are defined to keep
behavior consistent.

confirm_step "Extract OpenCode prompts" && extract_opencode_prompts
confirm_step "Check OpenCode prompt drift" && check_opencode_prompt_drift
confirm_step "Deploy aidevops agents to ~/.aidevops/agents/" && deploy_aidevops_agents
Expand Down
Loading