{"id":"be761f8e-e422-4694-bf28-9376b673b88f","shortId":"TvMdm8","kind":"skill","title":"Rule Extraction","tagline":"Extract a structured list of rules from all markdown files at the top level of a skill directory. Use this skill whenever you need to parse rules out of a skill for conflict checking, merging, or diffing.","description":"# Rule Extraction\n\nThis skill teaches you how to extract a structured, line-numbered list of rules from a skill directory.\n\n## What Counts as a Rule\n\nA **rule** is any statement that prescribes or constrains agent behavior. Recognize rules by their form:\n\n- **Imperative directives**: \"Always add type annotations\", \"Never use `var`\"\n- **Prohibition patterns**: \"Do not X\", \"Avoid X\", \"禁止 X\"\n- **Requirement patterns**: \"Must X\", \"Should X\", \"需要 X\", \"必须 X\"\n- **Conditional behavior**: \"If X, then Y\", \"When X, do Y\"\n- **Style/format mandates**: \"Use camelCase\", \"Limit lines to 80 characters\"\n- **Preference statements**: \"Prefer X over Y\", \"优先使用 X\"\n\nRules can appear as:\n- Bullet list items (`-` or `*` or `+`)\n- Numbered list items (`1.`, `2.`)\n- Bold or emphasized sentences (`**Always do X**`)\n- Plain sentences within a paragraph that contain directive language\n- Section headers that are themselves imperatives (\"Never commit secrets\")\n\n## What Does NOT Count as a Rule\n\nExclude the following from extraction:\n\n- **Descriptive text**: Explanations of why a rule exists, background context\n- **Examples**: Code blocks, sample outputs, \"for example...\" passages\n- **Metadata**: YAML frontmatter, version info, author notes\n- **Headings that introduce a section** (unless the heading itself is an imperative rule)\n- **Vague non-actionable statements**: \"Do good work\", \"Be helpful\" — extract these but flag them as `vague: true`\n\n## Output Format\n\nReturn a JSON array. Each rule is an object:\n\n```json\n[\n  {\n    \"id\": 1,\n    \"file\": \"SKILL.md\",\n    \"line\": 12,\n    \"text\": \"Always add type annotations to function parameters\",\n    \"source_text\": \"- Always add type annotations to function parameters\",\n    \"vague\": false\n  },\n  {\n    \"id\": 2,\n    \"file\": \"SKILL.md\",\n    \"line\": 15,\n    \"text\": \"Do not use var, prefer const or let\",\n    \"source_text\": \"**Do not use `var`** — prefer `const` or `let`\",\n    \"vague\": false\n  },\n  {\n    \"id\": 3,\n    \"file\": \"examples.md\",\n    \"line\": 4,\n    \"text\": \"Do good work\",\n    \"source_text\": \"- Do good work\",\n    \"vague\": true\n  }\n]\n```\n\nField definitions:\n- `id`: Sequential integer starting from 1, across all files combined\n- `file`: Filename (basename only, e.g. `SKILL.md`, `examples.md`) where the rule appears\n- `line`: Line number within that file where the rule appears (1-indexed)\n- `text`: Cleaned rule text, stripped of markdown formatting\n- `source_text`: Original raw line as it appears in the file\n- `vague`: `true` if the rule is too broad to be actionable\n\n## Input Scope\n\nThe input is a **skill directory path** (e.g. `~/.claude/skills/humanizer/`).\n\n**Files to read:** all `*.md` files directly inside the skill directory — `SKILL.md` first, then any other `*.md` files in alphabetical order.\n\n**Files to skip:**\n- Subdirectories and any files inside them (no recursive scan)\n- Non-markdown files (`.sh`, `.py`, `.js`, `.json`, etc.)\n\n## Extraction Process\n\n1. **List** all `*.md` files at the top level of the skill directory (non-recursive). Read `SKILL.md` first if present; read remaining `*.md` files in alphabetical order.\n2. **For each file**, read it line by line, tracking line numbers within that file.\n3. **Skip frontmatter** (everything between `---` delimiters at the top of each file)\n4. **Skip code blocks** (between ` ``` ` fences) — these are examples, not rules\n5. **For each line**, determine if it contains a rule using the criteria above\n6. **For paragraph text**: split into sentences, check each sentence independently\n7. **Clean the extracted text**: remove markdown syntax (`-`, `*`, `**`, backticks) but preserve the meaning\n8. **Assign line numbers** based on where the rule text starts within its file\n9. **Record the source filename** for every rule\n\n## Handling Ambiguous Cases\n\n- **Compound bullet**: \"Use camelCase and limit lines to 80 chars\" → split into two rules, both on the same line number\n- **Nested bullets**: Treat each nested item as an independent rule\n- **Conditional rules**: Keep the full conditional (\"If Python, use type hints\") as one rule — do not split on the condition\n- **Negated rules**: \"Don't use X\" and \"Never use X\" are equivalent — normalize to a consistent form in `text`, preserve original in `source_text`\n\n## Example\n\nInput skill directory: `~/.claude/skills/code-style/`\nFiles found at top level: `SKILL.md`, `extra-rules.md`\n(Any subdirectory contents are ignored.)\n\n**SKILL.md:**\n```\n---\nname: Code Style\n---\n\n# Code Style Guidelines\n\nKeep code clean and maintainable.\n\n## Naming\n- Use camelCase for variables and functions\n- Use PascalCase for classes and types\n- Never use single-letter variable names except for loop indices\n\n## Comments\nAlways write comments in English.\nDo not write comments explaining what the code does — only explain why.\n\n## Example\n\\`\\`\\`python\n# good\ndef calculate_total(items):\n    return sum(items)\n\\`\\`\\`\n```\n\n**extra-rules.md:**\n```\n- Prefer explicit returns over implicit ones\n```\n\nOutput:\n```json\n[\n  {\n    \"id\": 1,\n    \"file\": \"SKILL.md\",\n    \"line\": 10,\n    \"text\": \"Use camelCase for variables and functions\",\n    \"source_text\": \"- Use camelCase for variables and functions\",\n    \"vague\": false\n  },\n  {\n    \"id\": 2,\n    \"file\": \"SKILL.md\",\n    \"line\": 11,\n    \"text\": \"Use PascalCase for classes and types\",\n    \"source_text\": \"- Use PascalCase for classes and types\",\n    \"vague\": false\n  },\n  {\n    \"id\": 3,\n    \"file\": \"SKILL.md\",\n    \"line\": 12,\n    \"text\": \"Never use single-letter variable names except for loop indices\",\n    \"source_text\": \"- Never use single-letter variable names except for loop indices\",\n    \"vague\": false\n  },\n  {\n    \"id\": 4,\n    \"file\": \"SKILL.md\",\n    \"line\": 15,\n    \"text\": \"Always write comments in English\",\n    \"source_text\": \"Always write comments in English.\",\n    \"vague\": false\n  },\n  {\n    \"id\": 5,\n    \"file\": \"SKILL.md\",\n    \"line\": 16,\n    \"text\": \"Do not write comments explaining what the code does — only explain why\",\n    \"source_text\": \"Do not write comments explaining what the code does — only explain why.\",\n    \"vague\": false\n  },\n  {\n    \"id\": 6,\n    \"file\": \"extra-rules.md\",\n    \"line\": 1,\n    \"text\": \"Prefer explicit returns over implicit ones\",\n    \"source_text\": \"- Prefer explicit returns over implicit ones\",\n    \"vague\": false\n  }\n]\n```\n\nNotes:\n- SKILL.md lines 18–23 (the code block) are skipped entirely\n- `id` is sequential across all files; `line` resets to 1 for each new file\n- Any subdirectories inside `~/.claude/skills/code-style/` are not scanned","tags":["rule","extraction","skill","git","knowledgexlab","agent-skills","claude-code","claude-code-plugin"],"capabilities":["skill","source-knowledgexlab","skill-rule-extraction","topic-agent-skills","topic-claude-code","topic-claude-code-plugin"],"categories":["skill-git"],"synonyms":[],"warnings":[],"endpointUrl":"https://skills.sh/KnowledgeXLab/skill-git/rule-extraction","protocol":"skill","transport":"skills-sh","auth":{"type":"none","details":{"cli":"npx skills add KnowledgeXLab/skill-git","source_repo":"https://github.com/KnowledgeXLab/skill-git","install_from":"skills.sh"}},"qualityScore":"0.468","qualityRationale":"deterministic score 0.47 from registry signals: · indexed on github topic:agent-skills · 36 github stars · SKILL.md body (6,489 chars)","verified":false,"liveness":"unknown","lastLivenessCheck":null,"agentReviews":{"count":0,"score_avg":null,"cost_usd_avg":null,"success_rate":null,"latency_p50_ms":null,"narrative_summary":null,"summary_updated_at":null},"enrichmentModel":"deterministic:skill-github:v1","enrichmentVersion":1,"enrichedAt":"2026-05-01T18:56:53.010Z","embedding":null,"createdAt":"2026-04-18T22:19:30.820Z","updatedAt":"2026-05-01T18:56:53.010Z","lastSeenAt":"2026-05-01T18:56:53.010Z","tsv":"'/.claude/skills/code-style':652,924 '/.claude/skills/humanizer':400 '1':149,257,332,358,445,739,878,916 '10':743 '11':766 '12':261,789 '15':286,822 '16':843 '18':899 '2':150,282,473,762 '23':900 '3':309,488,785 '4':313,500,818 '5':511,839 '6':525,874 '7':536 '8':549 '80':127,582 '9':563 'across':333,910 'action':229,389 'add':85,264,273 'agent':75 'alphabet':420,471 'alway':84,155,263,272,702,824,831 'ambigu':572 'annot':87,266,275 'appear':139,347,357,375 'array':249 'assign':550 'author':211 'avoid':96 'background':196 'backtick':544 'base':553 'basenam':339 'behavior':76,111 'block':200,503,903 'bold':151 'broad':386 'bullet':141,575,595 'calcul':723 'camelcas':123,577,679,746,754 'case':573 'char':583 'charact':128 'check':36,532 'class':687,771,779 'clean':361,537,674 'code':199,502,667,669,673,714,852,866,902 'combin':336 'comment':701,704,710,826,833,848,862 'commit':174 'compound':574 'condit':110,604,609,623 'conflict':35 'consist':639 'const':293,303 'constrain':74 'contain':164,518 'content':662 'context':197 'count':62,179 'criteria':523 'def':722 'definit':326 'delimit':493 'descript':188 'determin':515 'dif':39 'direct':83,165,407 'directori':20,60,397,411,457,651 'e.g':341,399 'emphas':153 'english':706,828,835 'entir':906 'equival':635 'etc':442 'everi':569 'everyth':491 'exampl':198,204,508,648,719 'examples.md':311,343 'except':697,798,811 'exclud':183 'exist':195 'explain':711,717,849,855,863,869 'explan':190 'explicit':731,881,889 'extra-rules.md':659,729,876 'extract':2,3,41,48,187,236,443,539 'fals':280,307,760,783,816,837,872,895 'fenc':505 'field':325 'file':12,258,283,310,335,337,353,378,401,406,418,422,428,437,449,469,476,487,499,562,653,740,763,786,819,840,875,912,920 'filenam':338,567 'first':413,463 'flag':239 'follow':185 'form':81,640 'format':245,367 'found':654 'frontmatt':208,490 'full':608 'function':268,277,683,750,758 'good':232,316,321,721 'guidelin':671 'handl':571 'head':213,220 'header':168 'help':235 'hint':614 'id':256,281,308,327,738,761,784,817,838,873,907 'ignor':664 'imper':82,172,224 'implicit':734,884,892 'independ':535,602 'index':359 'indic':700,801,814 'info':210 'input':390,393,649 'insid':408,429,923 'integ':329 'introduc':215 'item':143,148,599,725,728 'js':440 'json':248,255,441,737 'keep':606,672 'languag':166 'let':295,305 'letter':694,795,808 'level':16,453,657 'limit':124,579 'line':52,125,260,285,312,348,349,372,479,481,483,514,551,580,592,742,765,788,821,842,877,898,913 'line-numb':51 'list':6,54,142,147,446 'loop':699,800,813 'maintain':676 'mandat':121 'markdown':11,366,436,542 'md':405,417,448,468 'mean':548 'merg':37 'metadata':206 'must':102 'name':666,677,696,797,810 'need':26 'negat':624 'nest':594,598 'never':88,173,631,690,791,804 'new':919 'non':228,435,459 'non-action':227 'non-markdown':434 'non-recurs':458 'normal':636 'note':212,896 'number':53,146,350,484,552,593 'object':254 'one':616,735,885,893 'order':421,472 'origin':370,644 'output':202,244,736 'paragraph':162,527 'paramet':269,278 'pars':28 'pascalcas':685,769,777 'passag':205 'path':398 'pattern':92,101 'plain':158 'prefer':129,131,292,302,730,880,888 'prescrib':72 'present':465 'preserv':546,643 'process':444 'prohibit':91 'py':439 'python':611,720 'raw':371 'read':403,461,466,477 'recogn':77 'record':564 'recurs':432,460 'remain':467 'remov':541 'requir':100 'reset':914 'return':246,726,732,882,890 'rule':1,8,29,40,56,65,67,78,137,182,194,225,251,346,356,362,383,510,520,557,570,587,603,605,617,625 'sampl':201 'scan':433,927 'scope':391 'secret':175 'section':167,217 'sentenc':154,159,531,534 'sequenti':328,909 'sh':438 'singl':693,794,807 'single-lett':692,793,806 'skill':19,23,33,43,59,396,410,456,650 'skill-rule-extraction' 'skill.md':259,284,342,412,462,658,665,741,764,787,820,841,897 'skip':424,489,501,905 'sourc':270,296,318,368,566,646,751,774,802,829,857,886 'source-knowledgexlab' 'split':529,584,620 'start':330,559 'statement':70,130,230 'strip':364 'structur':5,50 'style':668,670 'style/format':120 'subdirectori':425,661,922 'sum':727 'syntax':543 'teach':44 'text':189,262,271,287,297,314,319,360,363,369,528,540,558,642,647,744,752,767,775,790,803,823,830,844,858,879,887 'top':15,452,496,656 'topic-agent-skills' 'topic-claude-code' 'topic-claude-code-plugin' 'total':724 'track':482 'treat':596 'true':243,324,380 'two':586 'type':86,265,274,613,689,773,781 'unless':218 'use':21,89,122,290,300,521,576,612,628,632,678,684,691,745,753,768,776,792,805 'vagu':226,242,279,306,323,379,759,782,815,836,871,894 'var':90,291,301 'variabl':681,695,748,756,796,809 'version':209 'whenev':24 'within':160,351,485,560 'work':233,317,322 'write':703,709,825,832,847,861 'x':95,97,99,103,105,107,109,113,117,132,136,157,629,633 'y':115,119,134 'yaml':207 '优先使用':135 '必须':108 '禁止':98 '需要':106","prices":[{"id":"4de9b9de-d6bc-4c36-8dea-a754f550ab98","listingId":"be761f8e-e422-4694-bf28-9376b673b88f","amountUsd":"0","unit":"free","nativeCurrency":null,"nativeAmount":null,"chain":null,"payTo":null,"paymentMethod":"skill-free","isPrimary":true,"details":{"org":"KnowledgeXLab","category":"skill-git","install_from":"skills.sh"},"createdAt":"2026-04-18T22:19:30.820Z"}],"sources":[{"listingId":"be761f8e-e422-4694-bf28-9376b673b88f","source":"github","sourceId":"KnowledgeXLab/skill-git/rule-extraction","sourceUrl":"https://github.com/KnowledgeXLab/skill-git/tree/main/skills/rule-extraction","isPrimary":false,"firstSeenAt":"2026-04-18T22:19:30.820Z","lastSeenAt":"2026-05-01T18:56:53.010Z"}],"details":{"listingId":"be761f8e-e422-4694-bf28-9376b673b88f","quickStartSnippet":null,"exampleRequest":null,"exampleResponse":null,"schema":null,"openapiUrl":null,"agentsTxtUrl":null,"citations":[],"useCases":[],"bestFor":[],"notFor":[],"kindDetails":{"org":"KnowledgeXLab","slug":"rule-extraction","github":{"repo":"KnowledgeXLab/skill-git","stars":36,"topics":["agent-skills","claude-code","claude-code-plugin"],"license":"mit","html_url":"https://github.com/KnowledgeXLab/skill-git","pushed_at":"2026-04-09T09:34:39Z","description":"Supercharge your AI agents by versioning, tracking, and merging overlapping skills.","skill_md_sha":"7706d6d97b58bdb2a994ce6e07aba6553b51a432","skill_md_path":"skills/rule-extraction/SKILL.md","default_branch":"main","skill_tree_url":"https://github.com/KnowledgeXLab/skill-git/tree/main/skills/rule-extraction"},"layout":"multi","source":"github","category":"skill-git","frontmatter":{"name":"Rule Extraction","description":"Extract a structured list of rules from all markdown files at the top level of a skill directory. Use this skill whenever you need to parse rules out of a skill for conflict checking, merging, or diffing."},"skills_sh_url":"https://skills.sh/KnowledgeXLab/skill-git/rule-extraction"},"updatedAt":"2026-05-01T18:56:53.010Z"}}