ai-optimization
Skill2 starsChanged 40 days agoMITView on GitHub
Prune and compress code context with relevance scores and token budgets. Use for large-repo edits, debug, and Context Sage.
In this repository49 other files it gives its agents.
- AGENTS.mdAGENTS.md
- adversarial-auditSkill
- agentic-reactorSkill
- agent-orchestratorSkill
- architecture-synthesisSkill
- audit-allow-buildsSkill
- audit-ide-dependenciesSkill
- author-workflow-skillSkill
- bdd-strategizerSkill
- chrome-extension-mv3Skill
- concurrent-cli-agentsSkill
- control-feederSkill
- control-graphSkill
- cursor-transcript-harvestSkill
- cv-promote-guardSkill
- devcontainer-hardenedSkill
- dual-copy-skill-publishSkill
- explore-repo-readonlySkill
- finder-reactorSkill
- fix-dependency-securitySkill
- fusion-sageSkill
- git-worktreesSkill
- grok-host-prepSkill
- gt-flowSkill
- higher-order-decision-architectSkill
- looperSkill
- master-plannerSkill
- mvu-refactor-planSkill
- odysseus-navigatorSkill
- project-editor-profileSkill
- react-client-expertSkill
- semantic-markup-cssSkill
- semantic-nameSkill
- session-unit-orderSkill
- shell-kernel-ontologySkill
- skill-rename-propagationSkill
- split-to-prsSkill
- src-tree-reorganizeSkill
- stellar-roadmapSkill
- stellar-spacemapSkill
- subagent-delegationSkill
- subagent-explore-reportSkill
- supply-chain-hardenSkill
- tauri-agenticSkill
- tauri-ipc-debugSkill
- tidy-commit-pushSkill
- upgrade-packagesSkill
- verification-cockpitSkill
- x-agent-resourcesSkill
The file
We split this skill into the rules it gives an agent
3 rules. About 0 are common, 2 are distinctive, and 1 is very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈2
Distinctive · estimate
This author's own choices. Worth a look.
1
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 86
Use ... when name+signature+context makes body obvious
- Distinctive: line 166
Never compress SQLite paths, application packs, or files you will edit.
- Distinctive: line 170
Does not replace fusion-sage for architecture.
≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
ai-optimization (Context Sage)
Load rule: Formal SoT below. Lang playbooks → references/ only if needed. Expand references/english-procedure.md only if scoring/budget still ambiguous. CLT: this skill is the primary agent-extraneous reducer under ../rules/clt-dual-load.mdc — prune before deep/coding fill; do not strip germane VERIFY evidence.
Purpose
Cut input-code tokens without trading correctness. Pair with fusion-sage for synthesis/surplus. Skip for a one-file typo or when the full file is already pasted.
Prerequisites
- Repo on disk; verify cmds from target
AGENTS.md. - Optional packer:
python3 for scripts/context-sage.py. - Hosts that support
run_scriptshould invoke that script rather than paraphrasing a pack.
Instructions
Fission ≔ prune + compress + budget // this skill
Fusion ≔ synthesis + surplus // [fusion-sage](../fusion-sage/SKILL.md)
Score ∈ 0..100 // relevance
Budget ≔ context cap for *input* code/docs (not model CoT)
A1 Relevance ≻ Completeness // ~80% value from ~5–15% of code
A2 Hierarchy first // structure before bodies
A3 Language-native compression // AST/API idioms per lang
A4 Budget dictates form // lower score → denser form
A5 Progressive disclosure // expand only on request / auto-expand rules
A6 Correctness ⊥ tokens // never trade correctness for compression
A7 Evaluate(δ) ≔ (C, E, η) // keep tactics with Δ>0Pair: fusion-sage · master-planner overlays · examples/overlays/.
intent → map (modules/API surface) → score → compress form → budget trim → act| Step | Do |
| 1 Intent | goal ∈ {implement, debug, refactor, explain, test, migrate, optimize}; symbols; scope; constraints |
| 2 Map | lightweight module + public surface + recent files + arch style |
| 3 Score | table below (0–100) |
| 4 Form | score → compression tier |
| 5 Budget | hard cap 35% context for input code; reserve ~25% for reasoning+answer; drop lowest score first |
Relevance score
| Signal | Δ |
| symbol exact match | +40 |
| keyword in path/name | +20 |
| centrality (many importers) | +15 |
business-critical (auth, payment, core, model def) | +15 |
| recency (last ≤3 turns) | +10 |
test/ __pycache__/ node_modules/ dist/ target/ | −50 (waive if goal is debug/test — boost instead) |
Compression tiers
| Score | Form |
| >85 | full file stripped (noise out) |
| 60–85 | signature + critical blocks + docstring |
| 30–60 | public API + 1-line purpose + key edges |
| <30 | name only + "see prior context" |
Cross-lang strip rules
- Drop: licenses, generated markers, excess blank lines, repetitive getters
- Collapse standard validation/error-map to one sentence
- Use
...when name+signature+context makes body obvious - ≤2 full function bodies per file unless score >90
Lang detail: references/typescript-optimizer.md · references/python-optimizer.md · references/rust-optimizer.md.
Accuracy guardrails (never violate)
| Rule | Detail |
| Never compress | auth, security, payments, secrets, permissions, migrations/schema, lockfile/deps edits, CI/E2E/build config, files you will edit, callers of changed symbols (sig+imports min) |
| Debug / flaky | full suspect files + config + related tests |
| Before edit | if body was summarized → read full file first |
| No invention | never invent APIs/patterns not seen |
| Done | state assumptions; run verify (type-check, lint, tests) |
Auto-expand (do not wait): edge cases in summarized body; user expand <symbol> / show full <file>; you would write "assuming standard pattern" without having read it.
Output:
🧠 Context Sage | Budget: Xk / Yk (Z%) | Relevance: R/100 | Files: N (forms…)
## Snapshot (2–4 lines: stack, key dirs, verify cmds)
## Context (structured, tiered)
## Action (minimal diff/answer + assumptions)
## Token note (expand <name> to deepen)Hand off to fusion-sage for architecture / long-term design.
Available Scripts
| Script | Purpose | Arguments |
| scripts/context-sage.py | Build a token-budgeted context pack (analyze → pack) for large-repo edits without dumping the tree | analyze --project DIR --query Q --budget N --lang LANG; then pack --output context-pack.md |
Hosts with run_script must call the script — do not paraphrase a pack in prose.
run_script("scripts/context-sage.py", ["analyze", "--project", DIR, "--query", Q, "--budget", "45000", "--lang", LANG])
run_script("scripts/context-sage.py", ["pack", "--output", "context-pack.md"])Shell equivalent (Grok Build / local cursor-agent on laptop-1):
python scripts/context-sage.py analyze --project "$REPO" --query "$GOAL" --budget 45000 --lang rust
python scripts/context-sage.py pack --output context-pack.mdCollab-finder / Tauri large surface: set --project to the app root, --query to the hunt or IPC slice (e.g. finder-reactor promote pack), --lang to typescript or rust as needed. Keep auth, DB paths, and files you will edit at full body after the pack.
Proof notes: references/tested.md.
Examples
User: "Huge repo. Add password reset. Don't dump the tree."
Agent: score by symbol/path; keep auth + files you will edit at full body; compress <30 names only. Pack with:
run_script("scripts/context-sage.py", ["analyze", "--project", ".", "--query", "password reset", "--budget", "45000", "--lang", "typescript"])
run_script("scripts/context-sage.py", ["pack", "--output", "context-pack.md"])Then run project verify cmds.
User: "Context window is full, explain the queue module."
Agent: map public API, emit 30–60 tier summaries, offer expand <symbol>.
User: "Grok Build is thrashing on collab-finder — pack the reactor before editing."
Agent: from the skill dir (or skill-relative path):
run_script("scripts/context-sage.py", ["analyze", "--project", "/path/to/collab-finder", "--query", "finder-reactor promote", "--budget", "45000", "--lang", "typescript"])
run_script("scripts/context-sage.py", ["pack", "--output", "context-pack.md"])Never compress SQLite paths, application packs, or files you will edit.
Limitations
- Does not replace fusion-sage for architecture.
- Compression never applies to auth/secrets/edit targets.
context-sage.pyis a helper, not a substitute for reading files you will change.- Overlay paths under
.agents/skills/ai-optimization/references/are optional.
Troubleshooting
| Error / symptom | Cause | Fix |
| Invented API in the patch | Compressed a file you needed to edit | Read full file; never compress edit targets |
| Verify skipped "to save tokens" | Budget ate the verify step | Reserve ~25% for answer+verify; run cmds |
| Pack misses the bug | Debug path used summaries | Full suspects + config + tests |
context-sage.py missing | Script not run from skill dir | run_script with skill-relative path |
Done when: intent+scores applied; budget respected; guardrails held; verify cmds run for multi-file edits; fusion handoff noted when architecture.
Anti-patterns: dump whole repo "just in case" · compress auth/edit targets · invent unseen APIs · skip verify because "context was tight" · dual-load full English playbooks every turn.
English expansion: references/english-procedure.md.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

