chore: optimize MCP token usage (43% reduction)#9
Conversation
- Add one-line reference to build-agent.md for MCP optimization patterns - Update TODO.md with task tracking for optimization work - Detailed guidance already exists in tools/build-agent/build-agent.md:264-299
- setup.sh now copies VERSION from repo root to deployed agents - Fixes read-only agents (Plan+) reading wrong version - Also updated ~/.config/opencode/AGENTS.md to specify full path
- Explicit instruction to use Read tool on ~/.aidevops/agents/VERSION - Prevents hallucinated version numbers - Also respond to user's actual message after greeting - Simplified config AGENTS.md, details in main agents file
|
Caution Review failedThe pull request is closed. WalkthroughUpdates docs and scripts for agent generation and deployment: adds MCP token optimization note to AGENTS.md, rewrites generate-opencode-agents.sh to conditionally check Bash and handle version/update messaging, setup.sh now copies a VERSION file to deployed agents, and TODO.md expands the backlog with many new tasks. Changes
Sequence DiagramsequenceDiagram
autonumber
actor User
participant Agent as Agent Process
participant Bash as Bash Runtime
participant Updater as aidevops-update-check.sh
participant VersionFile as ~/.aidevops/agents/VERSION
User->>Agent: Start conversation / send message
Agent->>Bash: Is Bash available?
alt Bash available
Bash->>Updater: Execute update check
Updater-->>Agent: Output (e.g. UPDATE_AVAILABLE|x)
else Bash unavailable
Agent->>VersionFile: Read VERSION
VersionFile-->>Agent: Current Version
end
Agent->>Agent: Compose greeting with version info
alt UPDATE_AVAILABLE
Agent->>User: Notify update available + prompt to run aidevops update
else No update
Agent->>User: Greet with current version and await commands
end
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
📜 Recent review detailsConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro 📒 Files selected for processing (2)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Summary of ChangesHello @marcusquinn, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request focuses on enhancing the efficiency and reliability of the agent system. The primary goal was to optimize token usage, leading to a substantial 43% reduction in the initial context size. Concurrently, it addresses and rectifies several bugs related to agent version checking and their initial interaction behavior, ensuring a more predictable and functional experience. Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
🔍 Code Quality Report�[0;35m[MONITOR]�[0m Code Review Monitoring Report �[0;34m[INFO]�[0m Latest Quality Status: �[0;34m[INFO]�[0m Recent monitoring activity: 📈 Current Quality Metrics
Generated on: Wed Jan 7 20:54:51 UTC 2026 Generated by AI DevOps Framework Code Review Monitoring |
There was a problem hiding this comment.
Code Review
This pull request delivers a significant 43% reduction in MCP token usage by simplifying agent instructions, which is a great optimization. The bug fixes for read-only agents and the greeting behavior are also valuable improvements. My review includes two suggestions for increased robustness: adding error handling for the VERSION file copy operation in setup.sh, and making the agent's greeting format more explicit in generate-opencode-agents.sh to ensure consistent behavior across different language models. Overall, these are excellent changes that improve both efficiency and correctness.
| **On conversation start**: | ||
| 1. If Bash tool available: Run `bash ~/.aidevops/agents/scripts/aidevops-update-check.sh` | ||
| 2. If Bash unavailable: Use Read tool on `~/.aidevops/agents/VERSION` to get version | ||
| 3. Greet with: "Hi!\n\nWe're running https://aidevops.sh v{version}.\n\nWhat would you like to work on?" |
There was a problem hiding this comment.
Using \n for newlines within the heredoc relies on the language model to interpret the escape sequence correctly. While this works with the current model, it could be brittle if a different model is used in the future. For maximum robustness and to guarantee the intended formatting, it's safer to use explicit newlines, similar to the previous version of this instruction.
| 3. Greet with: "Hi!\n\nWe're running https://aidevops.sh v{version}.\n\nWhat would you like to work on?" | |
| 3. Greet with this format (including line breaks): | |
| "Hi! | |
| We're running https://aidevops.sh v{version}. | |
| What would you like to work on?" |
setup.sh
Outdated
|
|
||
| # Copy VERSION file from repo root to deployed agents | ||
| if [[ -f "$script_dir/VERSION" ]]; then | ||
| cp "$script_dir/VERSION" "$target_dir/VERSION" |
There was a problem hiding this comment.
It's good practice to handle potential errors from file operations. The cp command could fail if, for example, there are permission issues with the target directory. Adding a check on the exit code of cp would make the script more robust.
| cp "$script_dir/VERSION" "$target_dir/VERSION" | |
| cp "$script_dir/VERSION" "$target_dir/VERSION" || print_warning "Failed to copy VERSION file to $target_dir" |
🤖 Augment PR SummarySummary: This PR reduces initial MCP context size (~35K → ~20K tokens, ~43%) and fixes Plan+/read-only agent startup behavior around version detection and greetings. Changes:
Technical Notes: Agent deployment copies content from 🤖 Was this summary useful? React with 👍 or 👎 |
There was a problem hiding this comment.
Actionable comments posted: 3
🤖 Fix all issues with AI agents
In @.agent/scripts/generate-opencode-agents.sh:
- Around line 44-54: Update the agent documentation string that currently says
to look for the literal `UPDATE_AVAILABLE|current|latest` and instead instruct
agents to match the pattern produced by aidevops-update-check.sh: detect lines
starting with `UPDATE_AVAILABLE|` followed by two semantic version strings
(e.g., `UPDATE_AVAILABLE|2.41.1|2.41.2`) and then prompt the user to run
`aidevops update`; modify the generated text in the block that describes the
update check (the paragraph referencing `UPDATE_AVAILABLE|current|latest`) to
the new wording so parsing agents will search for the
`UPDATE_AVAILABLE|<current_version>|<latest_version>` pattern rather than the
literal words "current" and "latest".
In @setup.sh:
- Around line 962-965: The VERSION copy currently ignores failures; update the
block that checks [[ -f "$script_dir/VERSION" ]] to attempt cp
"$script_dir/VERSION" "$target_dir/VERSION" and branch on its exit status: on
success call print_info with a clear "Copied VERSION file to deployed agents"
message, on failure call print_warning (or print_error if preferred) with
"Failed to copy VERSION file (Plan+ may not read version correctly)"; reference
the existing variables script_dir and target_dir and the logging helpers
print_info/print_warning so behavior matches other checks in the script.
- Around line 962-965: Replace all indirect exit-code checks like "if [[ $? -eq
0 ]]" with direct command tests (e.g., "if mycmd; then" or "if ! mycmd; then")
throughout the script; separate variable declaration and assignment where
currently combined (the assignments around the blocks flagged at lines
~1159/1160/1207/1245) so you don't mask return values; replace quoted tilde
usages with "$HOME" (the occurrence at ~725); consolidate multiple redirects
into a grouped redirect using "{ cmd1; cmd2; } >> file" for the block near ~730;
ensure PATH export uses quoted variable expansion (e.g., export
PATH="$NEW_PATH:$PATH") for the change near ~693; verify and correct the
AGENTS_DIR assignment (possible misspelling around ~1503); add the "-x" flag
when invoking shellcheck for external scripts (around ~1185); then run
ShellCheck and fix any remaining complaints until zero violations remain.
🧹 Nitpick comments (1)
TODO.md (1)
88-95: Excellent pattern for documenting task context: inline Notes for tool research & gotchas.The Notes sections for t039, t040, t041, t042 provide crucial implementation details (tool stars, rate limits, workarounds, cost estimates). This is a smart way to capture research without burying it in separate files. Example: t039 references Camoufox (4.6k stars) with specific features (WebRTC spoofing, DataDome bypass) and notes the proxy integration requirement—exactly what a developer needs to estimate scope.
If this pattern becomes standard, consider documenting it in
workflows/plans.mdortemplates/tasks-template.mdso future contributors know to include similar context for research-heavy tasks.
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (4)
.agent/AGENTS.md.agent/scripts/generate-opencode-agents.shTODO.mdsetup.sh
🧰 Additional context used
📓 Path-based instructions (4)
**/setup.sh
📄 CodeRabbit inference engine (AGENTS.md)
Deploy agents locally using ./setup.sh script
Files:
setup.sh
**/*.sh
📄 CodeRabbit inference engine (AGENTS.md)
**/*.sh: Use local var="$1" pattern for shell variable assignments
Use explicit returns in shell scripts
Run ShellCheck on all scripts with zero violations required
Files:
setup.sh
**/*.md
📄 CodeRabbit inference engine (AGENTS.md)
Use placeholders in examples and note secure storage location in documentation
Files:
TODO.md
.agent/scripts/*.sh
⚙️ CodeRabbit configuration file
.agent/scripts/*.sh: Automation scripts - focus on:
- Reliability and robustness
- Clear logging and feedback
- Proper exit codes
- Error recovery mechanisms
Files:
.agent/scripts/generate-opencode-agents.sh
🧠 Learnings (13)
📓 Common learnings
Learnt from: CR
Repo: marcusquinn/aidevops PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-11-29T04:34:27.158Z
Learning: All instructions, documentation, and operational guidance should be maintained in AGENTS.md as the single source of truth
Learnt from: CR
Repo: marcusquinn/aidevops PR: 0
File: GEMINI.md:0-0
Timestamp: 2025-11-29T04:34:30.742Z
Learning: Maintain all instructions, documentation, and operational guidance in AGENTS.md as the single source of truth
Learnt from: CR
Repo: marcusquinn/aidevops PR: 0
File: AGENTS.md:0-0
Timestamp: 2026-01-06T15:57:56.007Z
Learning: Applies to **/setup.sh : Deploy agents locally using ./setup.sh script
Learnt from: CR
Repo: marcusquinn/aidevops PR: 0
File: AGENT.md:0-0
Timestamp: 2025-11-29T04:34:42.033Z
Learning: Maintain all AI assistant instructions, documentation, and operational guidance in AGENTS.md as the single source of truth
Learnt from: CR
Repo: marcusquinn/aidevops PR: 0
File: AGENTS.md:0-0
Timestamp: 2026-01-06T15:57:56.008Z
Learning: Applies to **/AGENTS.md : Limit root AGENTS.md to ~50-100 max instructions with universal applicability to >80% of tasks
Learnt from: CR
Repo: marcusquinn/aidevops PR: 0
File: templates/home/AGENTS.md:0-0
Timestamp: 2025-12-22T01:24:53.937Z
Learning: Follow all security protocols and working directory specifications defined in ~/Git/aidevops/AGENTS.md
Learnt from: CR
Repo: marcusquinn/aidevops PR: 0
File: AGENT.md:0-0
Timestamp: 2025-11-29T04:34:42.033Z
Learning: Reference AGENTS.md (authoritative) instead of AGENT.md for AI assistant guidance
Learnt from: CR
Repo: marcusquinn/aidevops PR: 0
File: AGENTS.md:0-0
Timestamp: 2026-01-06T15:57:56.007Z
Learning: Applies to **/.agent/scripts/version-manager.sh : Use .agent/scripts/version-manager.sh release [major|minor|patch] for releases
📚 Learning: 2026-01-06T15:57:56.007Z
Learnt from: CR
Repo: marcusquinn/aidevops PR: 0
File: AGENTS.md:0-0
Timestamp: 2026-01-06T15:57:56.007Z
Learning: Applies to **/setup.sh : Deploy agents locally using ./setup.sh script
Applied to files:
setup.sh
📚 Learning: 2026-01-06T15:57:56.007Z
Learnt from: CR
Repo: marcusquinn/aidevops PR: 0
File: AGENTS.md:0-0
Timestamp: 2026-01-06T15:57:56.007Z
Learning: Applies to **/.agent/scripts/version-manager.sh : Use .agent/scripts/version-manager.sh release [major|minor|patch] for releases
Applied to files:
setup.sh
📚 Learning: 2025-12-22T01:24:53.937Z
Learnt from: CR
Repo: marcusquinn/aidevops PR: 0
File: templates/home/AGENTS.md:0-0
Timestamp: 2025-12-22T01:24:53.937Z
Learning: Follow all security protocols and working directory specifications defined in ~/Git/aidevops/AGENTS.md
Applied to files:
setup.shTODO.md.agent/scripts/generate-opencode-agents.sh.agent/AGENTS.md
📚 Learning: 2026-01-06T15:57:56.007Z
Learnt from: CR
Repo: marcusquinn/aidevops PR: 0
File: AGENTS.md:0-0
Timestamp: 2026-01-06T15:57:56.007Z
Learning: Applies to **/.agent/scripts/linters-local.sh : Run quality checks before committing using .agent/scripts/linters-local.sh
Applied to files:
setup.sh.agent/scripts/generate-opencode-agents.sh
📚 Learning: 2025-11-29T04:34:30.742Z
Learnt from: CR
Repo: marcusquinn/aidevops PR: 0
File: GEMINI.md:0-0
Timestamp: 2025-11-29T04:34:30.742Z
Learning: Maintain all instructions, documentation, and operational guidance in AGENTS.md as the single source of truth
Applied to files:
.agent/scripts/generate-opencode-agents.sh.agent/AGENTS.md
📚 Learning: 2025-11-29T04:34:42.033Z
Learnt from: CR
Repo: marcusquinn/aidevops PR: 0
File: AGENT.md:0-0
Timestamp: 2025-11-29T04:34:42.033Z
Learning: Reference AGENTS.md (authoritative) instead of AGENT.md for AI assistant guidance
Applied to files:
.agent/scripts/generate-opencode-agents.sh.agent/AGENTS.md
📚 Learning: 2025-11-29T04:34:27.158Z
Learnt from: CR
Repo: marcusquinn/aidevops PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-11-29T04:34:27.158Z
Learning: All instructions, documentation, and operational guidance should be maintained in AGENTS.md as the single source of truth
Applied to files:
.agent/scripts/generate-opencode-agents.sh.agent/AGENTS.md
📚 Learning: 2025-11-29T04:34:42.033Z
Learnt from: CR
Repo: marcusquinn/aidevops PR: 0
File: AGENT.md:0-0
Timestamp: 2025-11-29T04:34:42.033Z
Learning: Maintain all AI assistant instructions, documentation, and operational guidance in AGENTS.md as the single source of truth
Applied to files:
.agent/scripts/generate-opencode-agents.sh.agent/AGENTS.md
📚 Learning: 2026-01-06T15:57:56.008Z
Learnt from: CR
Repo: marcusquinn/aidevops PR: 0
File: AGENTS.md:0-0
Timestamp: 2026-01-06T15:57:56.008Z
Learning: Applies to **/AGENTS.md : Limit root AGENTS.md to ~50-100 max instructions with universal applicability to >80% of tasks
Applied to files:
.agent/scripts/generate-opencode-agents.sh.agent/AGENTS.md
📚 Learning: 2025-11-29T04:34:30.742Z
Learnt from: CR
Repo: marcusquinn/aidevops PR: 0
File: GEMINI.md:0-0
Timestamp: 2025-11-29T04:34:30.742Z
Learning: Reference AGENTS.md for authoritative AI assistant guidance instead of GEMINI.md
Applied to files:
.agent/scripts/generate-opencode-agents.sh
📚 Learning: 2026-01-06T15:57:56.008Z
Learnt from: CR
Repo: marcusquinn/aidevops PR: 0
File: AGENTS.md:0-0
Timestamp: 2026-01-06T15:57:56.008Z
Learning: Applies to **/AGENTS.md : Use progressive disclosure in AGENTS.md with pointers to subagents rather than inline content
Applied to files:
.agent/scripts/generate-opencode-agents.sh.agent/AGENTS.md
📚 Learning: 2025-12-22T01:24:53.937Z
Learnt from: CR
Repo: marcusquinn/aidevops PR: 0
File: templates/home/AGENTS.md:0-0
Timestamp: 2025-12-22T01:24:53.937Z
Learning: Reference the authoritative repository at ~/Git/aidevops/ for all detailed AI assistant instructions and configurations
Applied to files:
.agent/scripts/generate-opencode-agents.sh
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
- GitHub Check: Codacy Static Code Analysis
🔇 Additional comments (2)
.agent/AGENTS.md (1)
384-384: ✅ Excellent MCP optimization documentation.Clear, actionable guidance on disabling heavy MCPs globally and enabling per-agent. The reference to
tools/build-agent/build-agent.mdprovides the implementation pattern users need. This aligns perfectly with the 43% token reduction achieved in this PR and enables others to replicate the pattern.TODO.md (1)
71-133: ✅ Well-structured backlog expansion with clear task documentation.All 20 new entries (t023–t042) follow the documented format correctly. Task IDs are sequential and stable, time estimates are present with breakdowns, and references link to relevant resources (posts, tools, GitHub issues). The inline Notes sections for complex tasks (t039–t042, lines 88–95) provide valuable implementation context without cluttering the main task line.
TOON metadata block is correctly updated with matching task counts. The summary line reflects the new totals: 44 tasks, 35 pending.
- Add error handling for VERSION file copy in setup.sh - Fix UPDATE_AVAILABLE pattern description (use actual version format) - Add warning if VERSION file not found
|
🔍 Code Quality Report�[0;35m[MONITOR]�[0m Code Review Monitoring Report �[0;34m[INFO]�[0m Latest Quality Status: �[0;34m[INFO]�[0m Recent monitoring activity: 📈 Current Quality Metrics
Generated on: Wed Jan 7 21:24:47 UTC 2026 Generated by AI DevOps Framework Code Review Monitoring |



Summary
Changes
MCP Token Optimization
Bug Fixes
~/.aidevops/agents/Testing
Tested Plan+ agent - correctly reads VERSION file and responds to user message.
Summary by CodeRabbit
Documentation
Changes
Chores
✏️ Tip: You can customize this high-level summary in your review settings.