[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill:01M6AD0XPMVV7RZ235QRB2Z8MA":3,"skill-same:01M6AD0XPMVV7RZ235QRB2Z8MA":89},{"skillNo":4,"name":5,"nameZh":6,"description":7,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":16,"categories":17,"keywords":23,"publishedAt":46,"linkOnly":47,"markdownContent":48,"markdownBody":49,"frontMatter":50,"refName":56,"commitSha":57,"skillDirectory":58,"forksCount":59,"repositoryHtmlUrl":60,"repositoryHomepageUrl":61,"ownerHtmlUrl":62,"ownerBlogUrl":63,"ownerDescription":6,"updatedAt":64,"install":65,"resources":78},"01M6AD0XPMVV7RZ235QRB2Z8MA","optimize-skill",null,"Make an existing framework skill leaner without changing its behavior. Diagnose context-cost smells, propose the applicable optimization passes, and validate before and after every approved change.","apache\u002Fmagpie","apache","https:\u002F\u002Favatars.githubusercontent.com\u002Fu\u002F47359?v=4","01M6AC83E6K4FDKK7HZ8WNMQKE","The Apache Software Foundation","01M6ACRKRED1THWRMNQ1E2RYE7",145,"Apache-2.0","https:\u002F\u002Fgithub.com\u002Fapache\u002Fmagpie\u002Fblob\u002Fmain\u002Fplugins\u002Fmagpie-utilities\u002Fskills\u002Foptimize-skill\u002FSKILL.md",[18],{"categoryNo":19,"categoryName":20,"taxonomyType":21,"taxonomyTypeDesc":22},"01JBSEEDCAT000000000000023","Skill与智能体开发","SCENARIO","使用场景",[24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45],"optimize","optimize skill","flags","when","new","for","before and after","capability","make","context","new skill","Utilities","authoring","write","too long","me","framework skill","Meta","framework","diagnose","audit","change","2026-11-10 10:12:30",false,"---\n# SPDX-License-Identifier: Apache-2.0\n# https:\u002F\u002Fwww.apache.org\u002Flicenses\u002FLICENSE-2.0\nname: optimize-skill\nfamily: utilities\nmode: Meta\ndescription: >-\n  Make an existing framework skill leaner without changing its behavior.\n  Diagnose context-cost smells, propose the applicable optimization passes,\n  and validate before and after every approved change.\nwhen_to_use: >-\n  When the user says \"optimize \u003Cskill>\", \"this SKILL.md is too long\", or\n  \"rewrite \u003Cskill> with me\", or an audit flags more than 500 lines or\n  hardcoded values. For a new skill, use write-skill.\ncapability: capability:authoring\nsurface_hash: sha256:be9968c266788028\nlicense: Apache-2.0\nmeasured_tokens: 3852\n---\n\n\u003C!-- SPDX-License-Identifier: Apache-2.0\n     https:\u002F\u002Fwww.apache.org\u002Flicenses\u002FLICENSE-2.0 -->\n\n\u003C!-- Placeholder convention (see AGENTS.md#placeholder-convention-used-in-skill-files):\n     \u003Cproject-config> → per file: the personal layer, else `.apache-magpie-overrides\u002F`\n     \u003Ctracker>        → value of `tracker_repo:` in \u003Cproject-config>\u002Fproject.md\n     \u003Cupstream>       → value of `upstream_repo:` in \u003Cproject-config>\u002Fproject.md\n     \u003Cframework>      → `.` standalone, `.apache-magpie\u002F` (snapshot),\n                        `~\u002F.cache\u002Fapache-magpie\u002Fframework\u002Fcurrent` (marketplace) -->\n\n# optimize-skill\n\n\u003C!-- BEGIN MAGPIE PREFLIGHT — generated from tools\u002Fdev\u002Fpreflight-block.md -->\n\n## Pre-flight — is this project set up?\n\nDo this **first, before anything else in this skill**, and do it silently.\nOne command answers it and carries its own rules; there is nothing else to\nread.\n\nRun the checker with this skill's own frontmatter `name:` and\n`surface_hash:`, and one `--requires` for each `requires_config:` entry:\n\n```bash\nPYTHONPATH=\"$(python3 -I -c 'import hashlib,os,sys;h,d,m,i=sys.argv[1:];r=os.path.realpath(os.curdir);s=os.stat(r);p=os.path.join(h,d,hashlib.sha256(r.encode()).hexdigest()[:16]);f=os.path.join(p,i);print(p if os.path.isdir(os.path.join(p,m)) and os.path.isfile(f) and open(f).read().split()==[str(s.st_dev),str(s.st_ino)] else h)' \"$HOME\u002F.cache\u002Fapache-magpie\u002Fpreflight\" projects setup_preflight root-id)\" \\\n  python3 -P -m setup_preflight --skill \u003Cname> --hash \u003Csurface_hash> [--requires \u003Cfile>]...\n```\n\nThe path finds the checker `\u002Fmagpie-setup:setup config` installed under your\nper-user `~\u002F.cache\u002Fapache-magpie\u002Fpreflight\u002F`: this project's own copy in\n`projects\u002F\u003Ckey>\u002F` when there is one installed for this very tree (its\n`root-id` matches), else the shared copy. Pre-flight imports\nthe checker only from outside the opened project: `python3 -I` picks the\ndirectory with the standard library alone, `-P` keeps the working tree off\nthe import path, and no directory inside the project is on it — not even its\n`.git\u002F` or `.svn\u002F`, which a checkout or a tarball can carry as plain files.\nNever add one.\n\n- **`{\"verdict\": \"ok\"}`** → **silent**. Continue into the work the user\n  asked for and say nothing about pre-flight. This is the ordinary answer.\n- **`{\"verdict\": \"action\", ...}`** → each finding names a section, and\n  `rules` carries that section's text. Follow it. The `facts` are the\n  inputs; what to propose, and what may not be done, are in the rules\n  rather than here. **Act on a finding only through its rules.**\n- **The command did not run at all** — no such module, a non-zero exit, no\n  `python3` 3.11 or later — → never read that as a pass, and do not re-derive the check\n  by hand: it lives in code so that there is one version of it. If the\n  project has **no** `.apache-magpie.lock`, `.apache-magpie-overrides\u002F`,\n  or personal layer (any of the directories below),\n  nothing has been set up here and there is\n  nothing to reconcile — resolve this skill's `requires_config:` entries\n  yourself (first match wins: `.apache-magpie-local\u002F\u003Cfile>`, the main\n  checkout's `.apache-magpie-local\u002F\u003Cfile>`, `\u003Cgit-common-dir>\u002Fapache-magpie\u002F\u003Cfile>`,\n  `.svn\u002Fapache-magpie\u002F\u003Cfile>`, then `.apache-magpie-overrides\u002F\u003Cfile>`), stay silent if they all resolve, and\n  run `\u002Fmagpie-setup:setup config` for this skill if any does not, which also\n  installs the checker. Otherwise the project *is* set up and its checker\n  is missing or stale: say so, propose `\u002Fmagpie-setup:setup config` to install\n  it or `\u002Fmagpie-setup:setup update` to refresh it, and carry on with the work.\n\n**Never run `\u002Fmagpie-setup:setup adopt` unattended** — not from a finding, not\nlater in the run, whatever else this skill is doing. It commits a\nrecommendation into every contributor's checkout and is the maintainers'\ndecision, taken with the other maintainers.\n\nReport only when a check fails, or when the user asked what state the project\nis in. `\u002Fmagpie-setup:setup verify` is the full diagnostic.\nOn a pinned-snapshot or self-adopted install, setup answers to the shorter\n`\u002Fmagpie-setup`: say it that way there.\n\n\u003C!-- END MAGPIE PREFLIGHT -->\n\nMake an existing skill leaner without changing its behavior.\n\nThe first six passes preserve instruction wording while moving,\nrewiring, or extracting content: five live in\n[`patterns.md`](patterns.md), with extract-code below.\nThe seventh, [`rewrite.md`](rewrite.md), changes wording with the\nmaintainer writing each paragraph and teaching the skill their style.\n\nThe validator must be green before and after an approved pass.\nFor a new skill, use [`write-skill`](..\u002Fwrite-skill\u002FSKILL.md).\n\nThis skill reads only framework files, so the external-content rules do\nnot apply to it.\n\n## What counts as small enough\n\nMeasure two budgets, set from the catalogue median when this skill was\nwritten.\nA skill over either target is an outlier.\n\n| | target | why |\n|---|---|---|\n| `SKILL.md` body, pre-flight block excluded | **5,000 tokens** | paid on every invocation of that skill |\n| `description` + `when_to_use` | **200 tokens** | paid in *every session*, for every skill at once, invoked or not |\n\nMeasure both before Step 1 and again at Step 4:\n\n```bash\nuv run --project tools\u002Fskill-token-count skill-token-count --write\n```\n\nPrioritize the always-on budget.\nThe body costs only when invoked; frontmatter costs in every session for\nevery skill.\n\nReference baseline: 75 skills; body median 4,614 tokens, p90 10,613,\nlargest 28,346; always-on median 200, largest 398.\n`PRINCIPLES.md` P15's 500-line structural cap still applies.\n\nAlso estimate the **run cost**: what one invocation actually reads, which the body alone understates.\n`security-issue-sync` has a body of about 6k tokens, yet a routine run reads about 46k and its heaviest path about 53k, before any tool output.\nWalk the steps for the routine path and the heaviest path, and add up `SKILL.md`, each sibling that path reads (file size ÷ 4), and a rough figure for what its tools return, such as issue bodies, mail threads or PR diffs.\nCount a sibling behind a pointer only on a path whose trigger fires.\nThis is a guess, not a measurement: give it per path, state the assumptions, and keep the tool-output figure separate from the file total.\nPrefer the pass that moves the routine path most, since that is what most runs pay.\n\nReport both numbers and the run cost in Step 5 whether or not the pass moved them.\n\n## Inputs\n\n- **Target** — a skill name, directory, or `SKILL.md` path.\n- **`--all`** or **`over:\u003CN>`** — diagnose and rank every skill without\n  editing; the default threshold is the 500-line P15 cap.\n- **`pass:\u003Cname>`** — restrict diagnosis to named passes; otherwise\n  propose every applicable pass.\n\nWith no target or selector, diagnose everything read-only and let the\nmaintainer choose.\n\n## Prerequisites\n\n`uv` runs the validator; stop if it is unavailable.\nUse `git` to isolate the diff, preferably on a clean tree or branch.\nUse `doctoc` when headings move, or report the manual step if it is\nunavailable.\n\n## Step 0 — Check the ground\n\nResolve the target to a real skill directory and require a **green**\nvalidator before editing.\nHand back baseline failures for correction; optimization starts from a\nworking skill.\nKeep the diff isolated and reviewable.\n\n## Step 1 — Diagnose\n\nRun every diagnostic in [`patterns.md`](patterns.md) and report one row\nper smell: the pass that addresses it, the evidence (`path:line`, line\ncount, the construct), and how big a change it implies. Read-only.\n\nThe smells, in the order their passes apply:\n\n1. **Oversized body** — past the 500-line cap, or one section\n   dominating. → *split*\n2. **Concrete names** — adopter-specific values baked in instead of\n   resolved from `\u003Cproject-config>`. → *config-lift*\n3. **Bulk reads** — pulling a whole issue or artefact into context to\n   touch one field. → *out-of-context*\n4. **Per-item round-trips** — N sequential fetches that could be one\n   batch. → *fetch-upfront*\n5. **No cheap pre-filter** — spending a model pass on items a\n   deterministic check would skip. → *preflight-classifier*\n6. **Embedded code** — shell or Python living inside the body, paid for\n   on every invocation although a model never needs to read it. →\n   *extract-code*\n7. **Verbose prose** — the structure is right and the body still reads\n   twice as long as it needs to. → *rewrite*, see\n   [`rewrite.md`](rewrite.md)\n\nFor a sweep, rank by cap overflow times distinct smells and stop there.\n\n## Step 2 — Propose\n\nPropose applicable passes from lowest to highest blast radius: file\nmove, content lift, tool rewire, then rewrite because only it changes\nwording.\nFor each pass, name the files, expected delta, and guarantee from\n[`patterns.md`](patterns.md).\n\nPropose only. The maintainer picks which passes run, and in what order.\n\n## Step 3 — Apply one pass at a time\n\n**Restructure passes** (*split*, *config-lift*) move exact text.\nUse `git mv` for a whole file; otherwise move identical bytes and leave\na one-line pointer.\n\n**Rewire passes** (*out-of-context*, *fetch-upfront*,\n*preflight-classifier*) change execution, not decisions.\nRoute through a deterministic tool such as\n[`github-body-field`](..\u002F..\u002F..\u002F..\u002Ftools\u002Fgithub-body-field\u002FREADME.md) or\n[`github-rollup`](..\u002F..\u002F..\u002F..\u002Ftools\u002Fgithub-rollup\u002FREADME.md).\nIf human-facing proposals change, stop and use normal review.\nBefore cutting prose because a tool \"already does this\", compare the two line by line:\nwhere they disagree, cutting the prose changes behaviour, so fix the tool first, with a test that fails before the fix.\n\n**The extract-code pass** removes complete programs from model context.\nKeep the command's purpose and output interpretation in the body, then\nchoose the destination by operational need:\n\n- **Sibling `scripts\u002F`** — default for a dependency-free command.\n- **A `tools\u002F` project** — for dependencies, tests, or reuse outside the\n  skill; follow `tools\u002FAGENTS.md` for its README, declared capability and\n  prerequisites, and workspace entry.\n- **The vetted-ops catalogue** — for a read-only operation with closed\n  parameters that would otherwise prompt every run.\n  Adding one requires reviewed changes to `ops.py` and the caller's\n  grant, so propose it and stop.\n\nCheck prompt cost before choosing; do not trade tokens for a human\napproval on every invocation.\nExtract code **byte-identically** because paraphrasing changes the\nprogram.\n\nDo not extract command *shapes* containing runtime placeholders such as\n`\u003Ctracker>`, `\u003CN>`, or `\u003Ctarget>`.\nThey are instructions written in shell, not runnable programs.\n\nCatalogue evidence shows this pass is rare: only 482 of roughly 28,700\ntokens in shell and Python fences were multi-line and placeholder-free,\nmostly too small to beat a pointer line.\nIt applied to `setup-isolated-setup-doctor`, whose six deterministic\nprobes used 2,971 tokens, or 59% of its budget.\nRequire all three traits: **complete, large enough to matter, and\nunnecessary for the model to read**.\n\n**The rewrite pass** follows [`rewrite.md`](rewrite.md).\nThe maintainer writes each paragraph; apply their earlier edits to later\ndrafts.\n\n**A moved heading takes every reference with it:**\n\n- **Eval `step-config.json`** — update `skill_md` and `step_heading`.\n  Find matches with `grep -rl '\u003Cheading text>'\n  tools\u002Fskill-evals\u002Fevals\u002F`.\n- **Anchor links** — update `other.md#the-heading` references; whole-tree\n  `lychee` verifies them.\n- **Heading levels** — a block cut from mid-body shifts one level so it\n  can open its own file.\n  This is the only byte a split may change, and its anchor and eval\n  matcher must follow.\n\nOnly the eval suite catches a stale `step-config.json` extraction.\n\nAfter each pass, regenerate the TOC if headings moved and re-run the\nvalidator. One pass per commit.\n\n## Step 4 — Prove nothing broke\n\nRequire the Step 0 validator result, and both budgets must have moved the\nright way.\n\n**Run the skill's eval suite if it has one**, at\n`tools\u002Fskill-evals\u002Fevals\u002F\u003Cskill>\u002F`:\n\n```bash\ntools\u002Fskill-evals\u002Fmagpie-run-evals.sh tools\u002Fskill-evals\u002Fevals\u002F\u003Cskill>\n```\n\nRun it before the first pass and compare; an after-only run cannot\ndistinguish regressions from baseline failures.\n\nIf an unchanged case flips, name it as nondeterministic and let the\nmaintainer decide rather than claiming either result proves safety.\n\nA missing suite does not block the pass, but report that the validator\nwas its only gate.\n\nFor restructure, match body deletions to sibling additions plus the new\npointer.\nA suite that pastes the moved text into its prompt with `also_include` shows the rule still works, never that an agent reaches it,\nso prove every new pointer as [`patterns.md`](patterns.md) describes under *Split*.\nFor rewire, show that human-facing proposals stayed unchanged.\nFor rewrite, the approved paragraph diff is the record.\n\nIf the validator goes red, or you cannot show the behaviour held,\n**revert the pass**. Never ship half of one.\n\n## Step 5 — Hand back\n\nReport files, delta, validator result, and evidence per pass.\nDo not commit or open a PR unless asked.\nAfter rewrite, propose learned style rules from\n[`rewrite.md`](rewrite.md).\n\nIf it was a sweep, restate what is still on the list.\n\n## Hard rules\n\n- Preserve behavior; only maintainer-written rewrite wording may change.\n- Move identical bytes except for a necessary heading-level change, and\n  update every heading reference.\n- Propose before applying; never batch passes.\n- Require a green validator, never a relaxed one, and measure both budgets\n  and evals before and after every pass.\n- Propose learned style rules as a visible diff; never write them\n  silently.\n- Never touch the snapshot; framework changes go through an\n  `apache\u002Fmagpie` PR.\n\n## References\n\n- [`patterns.md`](patterns.md) — the behaviour-preserving passes.\n- [`rewrite.md`](rewrite.md) — the paragraph-by-paragraph rewrite and\n  the style-learning loop.\n- [`write-skill`](..\u002Fwrite-skill\u002FSKILL.md) — authoring a new skill.\n- [`tools\u002Fskill-and-tool-validator`](..\u002F..\u002F..\u002F..\u002Ftools\u002Fskill-and-tool-validator\u002FREADME.md)\n  — the gate.\n\n## Learned style rules\n\nWritten by the rewrite pass at the end of a session, as a proposed\ndiff. Bullets only — a heading here would move this skill's\n`surface_hash` and tell every adopter their configuration went stale\nover a wording preference.\n\n\u003C!-- BEGIN LEARNED STYLE -->\n- Point at the source instead of restating it: a rule that lives in AGENTS.md, a tool doc or another skill gets a link, and the skill keeps only what it adds.\n- Cut rationale a nearby section already gives; keep the rule itself.\n- Leave short paragraphs (one sentence, or two lines) as they are.\n- Keep an example that marks a boundary the model must not cross: dropping \"one file under `^\u003Cscope-b>\u002F` and one under `^\u003Cscope-a>\u002F`\" from a mixed-scope guard made a same-scope case fail; restoring it fixed the case.\n- In a wording pass, also fix any `gh` call that is piped, redirected or wrapped in `$(…)`, or that belongs in a vetted-ops read; that shape fails under the secure setup.\n\u003C!-- END LEARNED STYLE -->\n","\u003C!-- SPDX-License-Identifier: Apache-2.0\n     https:\u002F\u002Fwww.apache.org\u002Flicenses\u002FLICENSE-2.0 -->\n\n\u003C!-- Placeholder convention (see AGENTS.md#placeholder-convention-used-in-skill-files):\n     \u003Cproject-config> → per file: the personal layer, else `.apache-magpie-overrides\u002F`\n     \u003Ctracker>        → value of `tracker_repo:` in \u003Cproject-config>\u002Fproject.md\n     \u003Cupstream>       → value of `upstream_repo:` in \u003Cproject-config>\u002Fproject.md\n     \u003Cframework>      → `.` standalone, `.apache-magpie\u002F` (snapshot),\n                        `~\u002F.cache\u002Fapache-magpie\u002Fframework\u002Fcurrent` (marketplace) -->\n\n# optimize-skill\n\n\u003C!-- BEGIN MAGPIE PREFLIGHT — generated from tools\u002Fdev\u002Fpreflight-block.md -->\n\n## Pre-flight — is this project set up?\n\nDo this **first, before anything else in this skill**, and do it silently.\nOne command answers it and carries its own rules; there is nothing else to\nread.\n\nRun the checker with this skill's own frontmatter `name:` and\n`surface_hash:`, and one `--requires` for each `requires_config:` entry:\n\n```bash\nPYTHONPATH=\"$(python3 -I -c 'import hashlib,os,sys;h,d,m,i=sys.argv[1:];r=os.path.realpath(os.curdir);s=os.stat(r);p=os.path.join(h,d,hashlib.sha256(r.encode()).hexdigest()[:16]);f=os.path.join(p,i);print(p if os.path.isdir(os.path.join(p,m)) and os.path.isfile(f) and open(f).read().split()==[str(s.st_dev),str(s.st_ino)] else h)' \"$HOME\u002F.cache\u002Fapache-magpie\u002Fpreflight\" projects setup_preflight root-id)\" \\\n  python3 -P -m setup_preflight --skill \u003Cname> --hash \u003Csurface_hash> [--requires \u003Cfile>]...\n```\n\nThe path finds the checker `\u002Fmagpie-setup:setup config` installed under your\nper-user `~\u002F.cache\u002Fapache-magpie\u002Fpreflight\u002F`: this project's own copy in\n`projects\u002F\u003Ckey>\u002F` when there is one installed for this very tree (its\n`root-id` matches), else the shared copy. Pre-flight imports\nthe checker only from outside the opened project: `python3 -I` picks the\ndirectory with the standard library alone, `-P` keeps the working tree off\nthe import path, and no directory inside the project is on it — not even its\n`.git\u002F` or `.svn\u002F`, which a checkout or a tarball can carry as plain files.\nNever add one.\n\n- **`{\"verdict\": \"ok\"}`** → **silent**. Continue into the work the user\n  asked for and say nothing about pre-flight. This is the ordinary answer.\n- **`{\"verdict\": \"action\", ...}`** → each finding names a section, and\n  `rules` carries that section's text. Follow it. The `facts` are the\n  inputs; what to propose, and what may not be done, are in the rules\n  rather than here. **Act on a finding only through its rules.**\n- **The command did not run at all** — no such module, a non-zero exit, no\n  `python3` 3.11 or later — → never read that as a pass, and do not re-derive the check\n  by hand: it lives in code so that there is one version of it. If the\n  project has **no** `.apache-magpie.lock`, `.apache-magpie-overrides\u002F`,\n  or personal layer (any of the directories below),\n  nothing has been set up here and there is\n  nothing to reconcile — resolve this skill's `requires_config:` entries\n  yourself (first match wins: `.apache-magpie-local\u002F\u003Cfile>`, the main\n  checkout's `.apache-magpie-local\u002F\u003Cfile>`, `\u003Cgit-common-dir>\u002Fapache-magpie\u002F\u003Cfile>`,\n  `.svn\u002Fapache-magpie\u002F\u003Cfile>`, then `.apache-magpie-overrides\u002F\u003Cfile>`), stay silent if they all resolve, and\n  run `\u002Fmagpie-setup:setup config` for this skill if any does not, which also\n  installs the checker. Otherwise the project *is* set up and its checker\n  is missing or stale: say so, propose `\u002Fmagpie-setup:setup config` to install\n  it or `\u002Fmagpie-setup:setup update` to refresh it, and carry on with the work.\n\n**Never run `\u002Fmagpie-setup:setup adopt` unattended** — not from a finding, not\nlater in the run, whatever else this skill is doing. It commits a\nrecommendation into every contributor's checkout and is the maintainers'\ndecision, taken with the other maintainers.\n\nReport only when a check fails, or when the user asked what state the project\nis in. `\u002Fmagpie-setup:setup verify` is the full diagnostic.\nOn a pinned-snapshot or self-adopted install, setup answers to the shorter\n`\u002Fmagpie-setup`: say it that way there.\n\n\u003C!-- END MAGPIE PREFLIGHT -->\n\nMake an existing skill leaner without changing its behavior.\n\nThe first six passes preserve instruction wording while moving,\nrewiring, or extracting content: five live in\n[`patterns.md`](patterns.md), with extract-code below.\nThe seventh, [`rewrite.md`](rewrite.md), changes wording with the\nmaintainer writing each paragraph and teaching the skill their style.\n\nThe validator must be green before and after an approved pass.\nFor a new skill, use [`write-skill`](..\u002Fwrite-skill\u002FSKILL.md).\n\nThis skill reads only framework files, so the external-content rules do\nnot apply to it.\n\n## What counts as small enough\n\nMeasure two budgets, set from the catalogue median when this skill was\nwritten.\nA skill over either target is an outlier.\n\n| | target | why |\n|---|---|---|\n| `SKILL.md` body, pre-flight block excluded | **5,000 tokens** | paid on every invocation of that skill |\n| `description` + `when_to_use` | **200 tokens** | paid in *every session*, for every skill at once, invoked or not |\n\nMeasure both before Step 1 and again at Step 4:\n\n```bash\nuv run --project tools\u002Fskill-token-count skill-token-count --write\n```\n\nPrioritize the always-on budget.\nThe body costs only when invoked; frontmatter costs in every session for\nevery skill.\n\nReference baseline: 75 skills; body median 4,614 tokens, p90 10,613,\nlargest 28,346; always-on median 200, largest 398.\n`PRINCIPLES.md` P15's 500-line structural cap still applies.\n\nAlso estimate the **run cost**: what one invocation actually reads, which the body alone understates.\n`security-issue-sync` has a body of about 6k tokens, yet a routine run reads about 46k and its heaviest path about 53k, before any tool output.\nWalk the steps for the routine path and the heaviest path, and add up `SKILL.md`, each sibling that path reads (file size ÷ 4), and a rough figure for what its tools return, such as issue bodies, mail threads or PR diffs.\nCount a sibling behind a pointer only on a path whose trigger fires.\nThis is a guess, not a measurement: give it per path, state the assumptions, and keep the tool-output figure separate from the file total.\nPrefer the pass that moves the routine path most, since that is what most runs pay.\n\nReport both numbers and the run cost in Step 5 whether or not the pass moved them.\n\n## Inputs\n\n- **Target** — a skill name, directory, or `SKILL.md` path.\n- **`--all`** or **`over:\u003CN>`** — diagnose and rank every skill without\n  editing; the default threshold is the 500-line P15 cap.\n- **`pass:\u003Cname>`** — restrict diagnosis to named passes; otherwise\n  propose every applicable pass.\n\nWith no target or selector, diagnose everything read-only and let the\nmaintainer choose.\n\n## Prerequisites\n\n`uv` runs the validator; stop if it is unavailable.\nUse `git` to isolate the diff, preferably on a clean tree or branch.\nUse `doctoc` when headings move, or report the manual step if it is\nunavailable.\n\n## Step 0 — Check the ground\n\nResolve the target to a real skill directory and require a **green**\nvalidator before editing.\nHand back baseline failures for correction; optimization starts from a\nworking skill.\nKeep the diff isolated and reviewable.\n\n## Step 1 — Diagnose\n\nRun every diagnostic in [`patterns.md`](patterns.md) and report one row\nper smell: the pass that addresses it, the evidence (`path:line`, line\ncount, the construct), and how big a change it implies. Read-only.\n\nThe smells, in the order their passes apply:\n\n1. **Oversized body** — past the 500-line cap, or one section\n   dominating. → *split*\n2. **Concrete names** — adopter-specific values baked in instead of\n   resolved from `\u003Cproject-config>`. → *config-lift*\n3. **Bulk reads** — pulling a whole issue or artefact into context to\n   touch one field. → *out-of-context*\n4. **Per-item round-trips** — N sequential fetches that could be one\n   batch. → *fetch-upfront*\n5. **No cheap pre-filter** — spending a model pass on items a\n   deterministic check would skip. → *preflight-classifier*\n6. **Embedded code** — shell or Python living inside the body, paid for\n   on every invocation although a model never needs to read it. →\n   *extract-code*\n7. **Verbose prose** — the structure is right and the body still reads\n   twice as long as it needs to. → *rewrite*, see\n   [`rewrite.md`](rewrite.md)\n\nFor a sweep, rank by cap overflow times distinct smells and stop there.\n\n## Step 2 — Propose\n\nPropose applicable passes from lowest to highest blast radius: file\nmove, content lift, tool rewire, then rewrite because only it changes\nwording.\nFor each pass, name the files, expected delta, and guarantee from\n[`patterns.md`](patterns.md).\n\nPropose only. The maintainer picks which passes run, and in what order.\n\n## Step 3 — Apply one pass at a time\n\n**Restructure passes** (*split*, *config-lift*) move exact text.\nUse `git mv` for a whole file; otherwise move identical bytes and leave\na one-line pointer.\n\n**Rewire passes** (*out-of-context*, *fetch-upfront*,\n*preflight-classifier*) change execution, not decisions.\nRoute through a deterministic tool such as\n[`github-body-field`](..\u002F..\u002F..\u002F..\u002Ftools\u002Fgithub-body-field\u002FREADME.md) or\n[`github-rollup`](..\u002F..\u002F..\u002F..\u002Ftools\u002Fgithub-rollup\u002FREADME.md).\nIf human-facing proposals change, stop and use normal review.\nBefore cutting prose because a tool \"already does this\", compare the two line by line:\nwhere they disagree, cutting the prose changes behaviour, so fix the tool first, with a test that fails before the fix.\n\n**The extract-code pass** removes complete programs from model context.\nKeep the command's purpose and output interpretation in the body, then\nchoose the destination by operational need:\n\n- **Sibling `scripts\u002F`** — default for a dependency-free command.\n- **A `tools\u002F` project** — for dependencies, tests, or reuse outside the\n  skill; follow `tools\u002FAGENTS.md` for its README, declared capability and\n  prerequisites, and workspace entry.\n- **The vetted-ops catalogue** — for a read-only operation with closed\n  parameters that would otherwise prompt every run.\n  Adding one requires reviewed changes to `ops.py` and the caller's\n  grant, so propose it and stop.\n\nCheck prompt cost before choosing; do not trade tokens for a human\napproval on every invocation.\nExtract code **byte-identically** because paraphrasing changes the\nprogram.\n\nDo not extract command *shapes* containing runtime placeholders such as\n`\u003Ctracker>`, `\u003CN>`, or `\u003Ctarget>`.\nThey are instructions written in shell, not runnable programs.\n\nCatalogue evidence shows this pass is rare: only 482 of roughly 28,700\ntokens in shell and Python fences were multi-line and placeholder-free,\nmostly too small to beat a pointer line.\nIt applied to `setup-isolated-setup-doctor`, whose six deterministic\nprobes used 2,971 tokens, or 59% of its budget.\nRequire all three traits: **complete, large enough to matter, and\nunnecessary for the model to read**.\n\n**The rewrite pass** follows [`rewrite.md`](rewrite.md).\nThe maintainer writes each paragraph; apply their earlier edits to later\ndrafts.\n\n**A moved heading takes every reference with it:**\n\n- **Eval `step-config.json`** — update `skill_md` and `step_heading`.\n  Find matches with `grep -rl '\u003Cheading text>'\n  tools\u002Fskill-evals\u002Fevals\u002F`.\n- **Anchor links** — update `other.md#the-heading` references; whole-tree\n  `lychee` verifies them.\n- **Heading levels** — a block cut from mid-body shifts one level so it\n  can open its own file.\n  This is the only byte a split may change, and its anchor and eval\n  matcher must follow.\n\nOnly the eval suite catches a stale `step-config.json` extraction.\n\nAfter each pass, regenerate the TOC if headings moved and re-run the\nvalidator. One pass per commit.\n\n## Step 4 — Prove nothing broke\n\nRequire the Step 0 validator result, and both budgets must have moved the\nright way.\n\n**Run the skill's eval suite if it has one**, at\n`tools\u002Fskill-evals\u002Fevals\u002F\u003Cskill>\u002F`:\n\n```bash\ntools\u002Fskill-evals\u002Fmagpie-run-evals.sh tools\u002Fskill-evals\u002Fevals\u002F\u003Cskill>\n```\n\nRun it before the first pass and compare; an after-only run cannot\ndistinguish regressions from baseline failures.\n\nIf an unchanged case flips, name it as nondeterministic and let the\nmaintainer decide rather than claiming either result proves safety.\n\nA missing suite does not block the pass, but report that the validator\nwas its only gate.\n\nFor restructure, match body deletions to sibling additions plus the new\npointer.\nA suite that pastes the moved text into its prompt with `also_include` shows the rule still works, never that an agent reaches it,\nso prove every new pointer as [`patterns.md`](patterns.md) describes under *Split*.\nFor rewire, show that human-facing proposals stayed unchanged.\nFor rewrite, the approved paragraph diff is the record.\n\nIf the validator goes red, or you cannot show the behaviour held,\n**revert the pass**. Never ship half of one.\n\n## Step 5 — Hand back\n\nReport files, delta, validator result, and evidence per pass.\nDo not commit or open a PR unless asked.\nAfter rewrite, propose learned style rules from\n[`rewrite.md`](rewrite.md).\n\nIf it was a sweep, restate what is still on the list.\n\n## Hard rules\n\n- Preserve behavior; only maintainer-written rewrite wording may change.\n- Move identical bytes except for a necessary heading-level change, and\n  update every heading reference.\n- Propose before applying; never batch passes.\n- Require a green validator, never a relaxed one, and measure both budgets\n  and evals before and after every pass.\n- Propose learned style rules as a visible diff; never write them\n  silently.\n- Never touch the snapshot; framework changes go through an\n  `apache\u002Fmagpie` PR.\n\n## References\n\n- [`patterns.md`](patterns.md) — the behaviour-preserving passes.\n- [`rewrite.md`](rewrite.md) — the paragraph-by-paragraph rewrite and\n  the style-learning loop.\n- [`write-skill`](..\u002Fwrite-skill\u002FSKILL.md) — authoring a new skill.\n- [`tools\u002Fskill-and-tool-validator`](..\u002F..\u002F..\u002F..\u002Ftools\u002Fskill-and-tool-validator\u002FREADME.md)\n  — the gate.\n\n## Learned style rules\n\nWritten by the rewrite pass at the end of a session, as a proposed\ndiff. Bullets only — a heading here would move this skill's\n`surface_hash` and tell every adopter their configuration went stale\nover a wording preference.\n\n\u003C!-- BEGIN LEARNED STYLE -->\n- Point at the source instead of restating it: a rule that lives in AGENTS.md, a tool doc or another skill gets a link, and the skill keeps only what it adds.\n- Cut rationale a nearby section already gives; keep the rule itself.\n- Leave short paragraphs (one sentence, or two lines) as they are.\n- Keep an example that marks a boundary the model must not cross: dropping \"one file under `^\u003Cscope-b>\u002F` and one under `^\u003Cscope-a>\u002F`\" from a mixed-scope guard made a same-scope case fail; restoring it fixed the case.\n- In a wording pass, also fix any `gh` call that is piped, redirected or wrapped in `$(…)`, or that belongs in a vetted-ops read; that shape fails under the secure setup.\n\u003C!-- END LEARNED STYLE -->\n",{"mode":41,"name":5,"family":51,"license":15,"capability":52,"description":7,"when_to_use":53,"surface_hash":54,"measured_tokens":55},"utilities","capability:authoring","When the user says \"optimize \u003Cskill>\", \"this SKILL.md is too long\", or \"rewrite \u003Cskill> with me\", or an audit flags more than 500 lines or hardcoded values. For a new skill, use write-skill.","sha256:be9968c266788028",3852,"main","d594f578d34fc8482d2e4d633961a37687048c2d","plugins\u002Fmagpie-utilities\u002Fskills\u002Foptimize-skill",126,"https:\u002F\u002Fgithub.com\u002Fapache\u002Fmagpie","https:\u002F\u002Fmagpie.apache.org\u002F","https:\u002F\u002Fgithub.com\u002Fapache","https:\u002F\u002Fwww.apache.org\u002F","2026-11-12 21:17:41",{"source":8,"skillName":5,"commands":66,"prompt":76,"zipAvailable":77},[67,70,73],{"tool":68,"command":69},"npx","npx skills add apache\u002Fmagpie --skill optimize-skill",{"tool":71,"command":72},"bunx","bunx skills add apache\u002Fmagpie --skill optimize-skill",{"tool":74,"command":75},"pnpm","pnpm dlx skills add apache\u002Fmagpie --skill optimize-skill","安装技能，技能地址：https:\u002F\u002Fgithub.com\u002Fapache\u002Fmagpie\u002Fblob\u002Fmain\u002Fplugins\u002Fmagpie-utilities\u002Fskills\u002Foptimize-skill\u002FSKILL.md",true,[79,85],{"path":80,"resourceType":81,"resourceTypeDesc":82,"sizeBytes":83,"sourceHtmlUrl":84},"patterns.md","REFERENCE","参考文档",10377,"https:\u002F\u002Fgithub.com\u002Fapache\u002Fmagpie\u002Fblob\u002Fmain\u002Fplugins\u002Fmagpie-utilities\u002Fskills\u002Foptimize-skill\u002Fpatterns.md",{"path":86,"resourceType":81,"resourceTypeDesc":82,"sizeBytes":87,"sourceHtmlUrl":88},"rewrite.md",3800,"https:\u002F\u002Fgithub.com\u002Fapache\u002Fmagpie\u002Fblob\u002Fmain\u002Fplugins\u002Fmagpie-utilities\u002Fskills\u002Foptimize-skill\u002Frewrite.md",[90,113,137,157,183,204],{"skillNo":91,"name":92,"nameZh":6,"description":93,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":94,"categories":95,"keywords":96,"publishedAt":46},"01M70JNYMCY5EEWYWDN30WKDJ4","upgrade","Upgrade Magpie in one run: move to the new version if needed (`setup update`), check this machine and project, apply one approved plan, re-check, and print exact commands for what is out of reach.","https:\u002F\u002Fgithub.com\u002Fapache\u002Fmagpie\u002Fblob\u002Fmain\u002Fplugins\u002Fmagpie-setup\u002Fskills\u002Fupgrade\u002FSKILL.md",[],[92,97,98,29,99,100,101,102,41,103,104,28,105,106,107,108,109,110,111,112],"notice","platform","project","re","move","session","machine","yes","version","apply","print","check","last","plan","run","update",{"skillNo":114,"name":115,"nameZh":6,"description":116,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":117,"categories":118,"keywords":119,"publishedAt":46},"01M70JJBSW3XE35BAXQ1VTA9SV","dependency-vulnerability-audit","Read-only dependency vulnerability audit for one repository or a local\ncheckout. Detects the project's dependency manager(s), runs the\nappropriate audit tool, surfaces patchable findings grouped by severity,\nand proposes upgrades for maintainer review. Never modifies manifests or\nlock files and never opens update PRs.","https:\u002F\u002Fgithub.com\u002Fapache\u002Fmagpie\u002Fblob\u002Fmain\u002Fplugins\u002Fmagpie-repo-health\u002Fskills\u002Fdependency-vulnerability-audit\u002FSKILL.md",[],[120,44,121,122,123,124,125,126,99,127,128,129,130,131,132,27,133,134,135,136],"vulnerability","dependency","dependency vulnerability audit","never","checkout","chain","scope","dependency manager","local","only","files","invoke","manifests","ask","patch","hand","review",{"skillNo":138,"name":139,"nameZh":6,"description":140,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":141,"categories":142,"keywords":143,"publishedAt":46},"01M70JGBWHKMB7V6T7QWT6G5DQ","thread-mentor","Draft a teaching-register comment on a GitHub issue or PR thread on the\nconfigured `\u003Cupstream>` repo, aimed at a contributor missing context the\nmaintainer would spell out. Reads the thread, decides\nwhether an intervention is warranted, drafts one comment per the tone\nguide and convention pointers, and waits for explicit confirmation before\nposting via `gh`. Escalates on the four hand-off triggers.","https:\u002F\u002Fgithub.com\u002Fapache\u002Fmagpie\u002Fblob\u002Fmain\u002Fplugins\u002Fmagpie-pr-management\u002Fskills\u002Fthread-mentor\u002FSKILL.md",[],[144,145,146,99,147,148,131,149,150,27,151,133,152,135,136,153,154,155,26,156],"thread mentor","mentor","thread","repro","confirmation","pr-management","contributor","number","teaching","at","config","drafts","spell",{"skillNo":158,"name":159,"nameZh":6,"description":160,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":161,"categories":162,"keywords":168,"publishedAt":46},"01M70JF866SAVGXSSC33HRX4ZG","merge-candidates","Identify trivial, low-risk PRs in the `ready for maintainer review` queue\nof \u003Cupstream> that pass every quality gate and touch only supplementary\nareas (docs, changelog, translations, tests) — the \"express lane\".\nSurfaces and ranks candidates with per-PR diff summaries, an\nall-gates-green attestation, and the exact merge command. On explicit\nper-PR confirmation it can submit an APPROVE review, exactly as\npr-management-code-review does. It never merges itself — automated merge\nis the deliberately-deferred Agentic Autonomous mode.","https:\u002F\u002Fgithub.com\u002Fapache\u002Fmagpie\u002Fblob\u002Fmain\u002Fplugins\u002Fmagpie-pr-management\u002Fskills\u002Fmerge-candidates\u002FSKILL.md",[163],{"categoryNo":164,"categoryName":165,"taxonomyType":166,"taxonomyTypeDesc":167},"01JBSEEDCAT000000000000030","开发工程师","PROFESSION","适用职业",[169,170,171,172,173,123,174,175,99,176,177,178,129,179,148,131,149,180,181,182],"merge candidates","merge","ready","quick","show","green","submit","churn","attestation","mode","autonomous","show me","agentic","code",{"skillNo":184,"name":185,"nameZh":6,"description":186,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":187,"categories":188,"keywords":189,"publishedAt":46},"01M6AD18GMVM1BEM31VF538R8A","generate-cve-json","Generate a CVE 5.x JSON document from an \u003Ctracker> tracking\nissue, ready to paste into the Vulnogram `#source` tab of the ASF CVE tool\nat https:\u002F\u002Fcveprocess.apache.org\u002Fcve5\u002F\u003CCVE-ID>#source. The conversion is\ndeterministic: same issue in, same JSON bytes out. Handles multiple\ncredits (one per line) and multiple references (URLs extracted from the\nissue's \"Public advisory URL\" and \"PR with the fix\" fields; the\n\"Security mailing list thread\" field is treated as internal-only and\nnever exported).","https:\u002F\u002Fgithub.com\u002Fapache\u002Fmagpie\u002Fblob\u002Fmain\u002Ftools\u002Fcve-tool-vulnogram\u002Fgenerate-cve-json\u002FSKILL.md",[],[190,191,192,193,9,112,171,123,194,129,195,196,197,198,199,200,201,202,203,153,131,27],"cve","generate","generate cve json","json","fix","either","URL","team","conversion","publish","references","tracker","paste","exported",{"skillNo":205,"name":206,"nameZh":6,"description":207,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":208,"categories":209,"keywords":211,"publishedAt":46},"01M6AD158PEPPPX9N33DASMRQ8","write-skill","Write a new skill for the Apache Magpie framework, or bring an existing one up to current conventions. Scaffolds the directory, walks the house style and the prompt-injection defences, and validates before it ships.","https:\u002F\u002Fgithub.com\u002Fapache\u002Fmagpie\u002Fblob\u002Fmain\u002Fplugins\u002Fmagpie-utilities\u002Fskills\u002Fwrite-skill\u002FSKILL.md",[210],{"categoryNo":19,"categoryName":20,"taxonomyType":21,"taxonomyTypeDesc":22},[212,37,213,9,214,42,41,215,28,27,24,36,216,35,34,217,218,219,31,220],"write skill","create","directory","up","injection","magpie","add","existing skill","bring"]