chore: optimize AI agent context and implement CI cost controls#5335
Merged
jamesarich merged 2 commits intomainfrom May 2, 2026
Merged
chore: optimize AI agent context and implement CI cost controls#5335jamesarich merged 2 commits intomainfrom
jamesarich merged 2 commits intomainfrom
Conversation
- Modularize `AGENTS.md` by relocating detailed rules to the `.skills/` directory. - Add `scripts/sort-strings.py` and `strings-index.txt` to organize and index string resources. - Introduce CI cost control guidelines and a pre-commit `ai-guardrail.sh` to prevent binary and log leaks. - Expand `.copilotignore`, `.aiexclude`, and `.gitattributes` to reduce context window usage and indexing costs. - Establish `.agent_memory/session_context.md` for persistent task tracking and project state. - Update `SKILL.md` for code reviews with specific Git and PR hygiene requirements.
Contributor
There was a problem hiding this comment.
Pull request overview
This PR introduces repository-level “AI agent token/cost hygiene” improvements by modularizing agent guidance into .skills/, adding guardrails against committing high-cost artifacts, and formalizing a string-resource indexing workflow to reduce large-file churn.
Changes:
- Adds tooling to keep
strings.xmlsorted and to regenerate a searchablestrings-index.txt. - Introduces an AI commit guardrail script and CI cost-control guidance.
- Expands AI indexing ignore/exclude rules and adds
.gitattributessettings intended to reduce review/indexing costs.
Reviewed changes
Copilot reviewed 10 out of 11 changed files in this pull request and generated 9 comments.
Show a summary per file
| File | Description |
|---|---|
| scripts/sort-strings.py | New Python helper to sort string resources and regenerate the strings index. |
| scripts/ai-guardrail.sh | New guardrail script intended for use as a pre-commit check. |
| core/resources/src/commonMain/composeResources/values/strings.xml | Large re-ordering/grouping of strings; content retained but reorganized. |
| AGENTS.md | Condenses “unified guide” and points to .skills/ + session context. |
| .skills/compose-ui/strings-index.txt | New generated index of string keys for quick lookup. |
| .skills/code-review/SKILL.md | Adds Git/PR hygiene rules to the code review playbook. |
| .skills/ci-cost-control/SKILL.md | Adds CI cost-control playbook (run-checking guidance, rerun strategy). |
| .gitattributes | Adds linguist/binary settings intended to reduce PR summary/indexing costs. |
| .copilotignore | Expands Copilot ignore rules for binaries, artifacts, and resource churn. |
| .aiexclude | Mirrors .copilotignore for other AI tools. |
| .agent_memory/session_context.md | Adds a persistent session handover/project-state document. |
Comments suppressed due to low confidence (1)
.copilotignore:55
- The comment says this section ignores translations, but the glob
**/composeResources/**/values*/*.xmlalso matches the basevalues/strings.xml(no locale qualifier). If you only mean localized resources, consider narrowing this tovalues-*/(or update the comment if excluding the base file is intentional).
# ── Resources ────────────────────────────────────────────────────────────────
# Ignore translations (reduces churn and indexing tokens)
**/values-*/strings.xml
**/composeResources/**/values*/*.xml
Comment on lines
+10
to
+13
| print(f"Reading {xml_path}...") | ||
| with open(xml_path, 'r') as f: | ||
| content = f.read() | ||
|
|
Comment on lines
+20
to
+29
| STAGED_FILES=$(git diff --cached --name-only) | ||
| VIOLATIONS=() | ||
|
|
||
| for file in $STAGED_FILES; do | ||
| for pattern in "${FORBIDDEN_PATTERNS[@]}"; do | ||
| if [[ $file =~ $pattern ]]; then | ||
| VIOLATIONS+=("$file (matched $pattern)") | ||
| fi | ||
| done | ||
| done |
| <!-- ADD --> | ||
| <string name="add">Add</string> | ||
| <string name="add_a_note">Add a private note…</string> | ||
| <string name="add_channels_description">The following channels were found in the QR code. Select the once you would like to add to your device. Existing channels will be preserved.</string> |
| - **Memory Persistence:** Update `.agent_memory/session_context.md` at the end of every session or major task. | ||
| - **Bootstrap First:** Run the mandatory bootstrap steps in `.skills/project-overview/SKILL.md` before any build. | ||
| - **Plan Before Execution:** Use `.agent_plans/` (git-ignored) for complex refactors. | ||
| - **Baseline Verification:** Always run: `./gradlew spotlessCheck spotlessApply detekt assembleDebug test allTests` |
|
|
||
| # Resources (Indexing non-English strings is a token sink) | ||
| **/values-*/strings.xml | ||
| **/composeResources/**/values*/*.xml |
| **/src/main/res/**/*.xml linguist-generated=true | ||
| **/composeResources/**/*.xml linguist-generated=true | ||
| **/strings.xml linguist-generated=true | ||
| *.json linguist-generated=true |
|
|
||
| ### 2. Local First | ||
| NEVER use CI as a "remote compiler." | ||
| - You must run `./gradlew spotlessCheck detekt test` locally before pushing. |
Comment on lines
+3
to
+13
| ## Current Project State | ||
| - **Token Mitigation (Phase 1-3):** COMPLETE. | ||
| - **Ignore Rules:** Stricter `.copilotignore` and `.aiexclude` are active. | ||
| - **Instruction Optimization:** `AGENTS.md` is modularized (~3KB base). | ||
| - **Cleanup:** 1.5GB of stale build artifacts and logs purged. | ||
| - **Guardrails:** Pre-commit AI guardrail script installed in `scripts/`. CI Cost Control skill active. | ||
|
|
||
| ## Active Task History | ||
| - **Task:** Mitigate astronomical Copilot token costs. | ||
| - **Outcome:** Significantly reduced context tax by moving detailed rules to `.skills/` and ignoring binary/log artifacts. | ||
| - **Next Steps:** None. Mitigation project finalized. |
| @@ -0,0 +1,41 @@ | |||
| #!/bin/bash | |||
| # Meshtastic AI Guardrail - Prevent binary/log leaks in commits | |||
|
|
|||
Collaborator
Author
|
@copilot apply changes based on the comments in this thread |
- Use explicit encoding='utf-8'/newline='\n' in sort-strings.py - Fix ai-guardrail.sh to use NUL-delimited staged-files loop - Add installation instructions to ai-guardrail.sh - Fix typo in strings.xml: 'once' -> 'ones' - Fix AGENTS.md: spotlessApply before spotlessCheck - Narrow .aiexclude pattern to values-*/ only - Narrow .gitattributes linguist-generated rules - Add allTests to ci-cost-control SKILL.md command - Rewrite session_context.md as dated append-only handover log Agent-Logs-Url: https://github.com/meshtastic/Meshtastic-Android/sessions/1ffb7a86-714e-42eb-b9ab-3b9d49349b20 Co-authored-by: jamesarich <2199651+jamesarich@users.noreply.github.com>
Contributor
Applied all review feedback in commit e3fdac6:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
AGENTS.mdby relocating detailed rules to the.skills/directory.scripts/sort-strings.pyandstrings-index.txtto organize and index string resources.ai-guardrail.shto prevent binary and log leaks..copilotignore,.aiexclude, and.gitattributesto reduce context window usage and indexing costs..agent_memory/session_context.mdfor persistent task tracking and project state.SKILL.mdfor code reviews with specific Git and PR hygiene requirements.