agentleFS
p10ns11yp10ns11y/skills/ai-optimization/SKILL.md

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.

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
  1. Very specific:

    Use ... when name+signature+context makes body obvious

    line 86
  2. Distinctive:

    Never compress SQLite paths, application packs, or files you will edit.

    line 166
  3. Distinctive:

    Does not replace fusion-sage for architecture.

    line 170

≈ “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.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

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: python 3 for scripts/context-sage.py.
  • Hosts that support run_script should 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 Δ>0

Pair: fusion-sage · master-planner overlays · examples/overlays/.

intent → map (modules/API surface) → score → compress form → budget trim → act
StepDo
1 Intentgoal ∈ {implement, debug, refactor, explain, test, migrate, optimize}; symbols; scope; constraints
2 Maplightweight module + public surface + recent files + arch style
3 Scoretable below (0–100)
4 Formscore → compression tier
5 Budgethard 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

ScoreForm
>85full file stripped (noise out)
60–85signature + critical blocks + docstring
30–60public API + 1-line purpose + key edges
<30name 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)

RuleDetail
Never compressauth, 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 / flakyfull suspect files + config + related tests
Before editif body was summarized → read full file first
No inventionnever invent APIs/patterns not seen
Donestate 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

ScriptPurposeArguments
scripts/context-sage.pyBuild a token-budgeted context pack (analyze → pack) for large-repo edits without dumping the treeanalyze --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.md

Collab-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.py is a helper, not a substitute for reading files you will change.
  • Overlay paths under .agents/skills/ai-optimization/references/ are optional.

Troubleshooting

Error / symptomCauseFix
Invented API in the patchCompressed a file you needed to editRead full file; never compress edit targets
Verify skipped "to save tokens"Budget ate the verify stepReserve ~25% for answer+verify; run cmds
Pack misses the bugDebug path used summariesFull suspects + config + tests
context-sage.py missingScript not run from skill dirrun_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.

Download now (ZIP)

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
What did you use it for? e.g. Reviewing pull requests in a Rails app

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.