1414
1515
1616ENHANCE_PROMPT = """You are enhancing a Claude Code skill for an API. Given the LAP spec below,
17- generate the following sections in markdown:
17+ generate ADDITIONAL content to supplement (not replace) the existing skill document.
1818
19- 1. **Question Mapping** (10-15 entries): Natural language questions mapped to API endpoints.
20- Format each as: - "Question?" -> METHOD /path
21- Cover common use cases, edge cases, and multi-step workflows.
19+ Use ### (level 3) headings only -- never ## (level 2). The output will be appended to an existing
20+ document that already has ## sections.
2221
23- 2. **Response Tips** (one line per endpoint category): How to interpret responses.
24- Focus on pagination, error patterns, and nested objects.
22+ Generate these sections:
2523
26- 3. **Anomaly Flags**: What should an agent surface proactively?
27- (e.g., rate limits approaching, deprecated fields, unusual status codes)
24+ ### Workflow Playbooks
25+ 3-5 common multi-step workflows as numbered lists under descriptive ### headings.
26+ Focus on tasks that chain multiple endpoints together.
2827
29- 4. **Playbook** (3-5 common workflows): Step-by-step guides for typical tasks.
30- Format as numbered lists under descriptive headings.
28+ ### Response Interpretation
29+ One line per endpoint category: how to interpret responses.
30+ Focus on pagination patterns, error codes, nested objects, and status fields.
31+
32+ ### Edge Cases and Gotchas
33+ 5-10 practical warnings: rate limits, deprecated fields, required-but-undocumented params,
34+ common mistakes, and order-of-operations requirements.
35+
36+ IMPORTANT: Do NOT generate question-to-endpoint mappings -- the existing skill already has a
37+ comprehensive endpoint catalog. Do NOT repeat endpoint names or paths.
3138
3239Return ONLY the markdown content -- no preamble, no code fences.
3340
@@ -125,11 +132,14 @@ def enhance_skill(spec, skill: SkillOutput, api_key: str = None) -> SkillOutput:
125132 # Fallback: anthropic SDK (deferred import inside _enhance_via_sdk)
126133 enhanced_content = _enhance_via_sdk (prompt , api_key )
127134
128- # Replace mechanical sections in SKILL.md with LLM-enhanced ones
135+ # Append LLM-enhanced content after existing SKILL.md (additive, not destructive)
129136 skill_md = skill .file_map ["SKILL.md" ]
130137
131- # Replace Common Questions section
132- skill_md = _replace_section (skill_md , "Common Questions" , enhanced_content )
138+ # Strip any ## headings from LLM output (force ### only)
139+ enhanced_content = _demote_headings (enhanced_content )
140+
141+ # Append under a new ## section
142+ skill_md = skill_md .rstrip () + "\n \n ## LLM-Enhanced Guidance\n \n " + enhanced_content .strip () + "\n "
133143
134144 # Update file map
135145 new_file_map = dict (skill .file_map )
@@ -146,10 +156,13 @@ def enhance_skill(spec, skill: SkillOutput, api_key: str = None) -> SkillOutput:
146156 )
147157
148158
149- def _replace_section ( md : str , section_name : str , new_content : str ) -> str :
150- """Replace everything from ## {section_name} to the next ## heading ."""
159+ def _demote_headings ( content : str ) -> str :
160+ """Ensure all headings in LLM output are ### or lower (never ##) ."""
151161 import re
152- pattern = rf'(## { re .escape (section_name )} \n).*?(?=\n## |\Z)'
153- replacement = f"## Enhanced Skill Content\n { new_content } \n "
154- result = re .sub (pattern , replacement , md , flags = re .DOTALL )
155- return result
162+ lines = content .split ("\n " )
163+ result = []
164+ for line in lines :
165+ if re .match (r'^## [^#]' , line ):
166+ line = "#" + line # ## -> ###
167+ result .append (line )
168+ return "\n " .join (result )
0 commit comments