feat: SKILL.md with natural-language trigger and procedure
This commit is contained in:
83
plugins/md-to-pdf/skills/md-to-pdf/SKILL.md
Normal file
83
plugins/md-to-pdf/skills/md-to-pdf/SKILL.md
Normal file
@@ -0,0 +1,83 @@
|
|||||||
|
---
|
||||||
|
name: md-to-pdf
|
||||||
|
description: Use when the user asks to export, regenerate, build, or "make" a PDF from a Markdown file. Triggers on phrases like "exportier mal das PDF", "mach das als PDF", "regenerate the PDF", "PDF neu generieren", "convert this markdown to pdf". Do NOT trigger on requests to read, open, or display an existing PDF.
|
||||||
|
version: 0.1.0
|
||||||
|
---
|
||||||
|
|
||||||
|
# md-to-pdf
|
||||||
|
|
||||||
|
Regenerate a PDF from a Markdown file using the user's preferred styling. The skill walks upward for a project-local `.md-to-pdf.config.js`; if none is found it falls back to the bundled `default.config.js` shipped with this skill.
|
||||||
|
|
||||||
|
## When This Skill Applies
|
||||||
|
|
||||||
|
Trigger when the user wants a Markdown file converted to PDF — typical phrasings: "exportier mal", "mach mir das als PDF", "PDF regenerieren", "regenerate the PDF", "convert to pdf". Do **not** trigger when the user just wants to view, read, or open an existing PDF.
|
||||||
|
|
||||||
|
## Procedure
|
||||||
|
|
||||||
|
### 1. Identify the source `.md`
|
||||||
|
|
||||||
|
Resolve in this order — stop at the first that yields a single unambiguous file:
|
||||||
|
|
||||||
|
1. A `.md` path explicitly named in the user's most recent message.
|
||||||
|
2. The `.md` file the assistant most recently read or wrote in this session.
|
||||||
|
3. The single most-recently-modified `.md` file in the current working directory (`ls -t *.md | head -1` semantics).
|
||||||
|
|
||||||
|
If none of these resolves to one file, **ask** the user which file to convert. Do not guess.
|
||||||
|
|
||||||
|
### 2. Resolve the config
|
||||||
|
|
||||||
|
Walk from the source file's directory upward toward `/`, looking for `.md-to-pdf.config.js`. Use the first match.
|
||||||
|
|
||||||
|
If no project-local config is found, fall back to the bundled default:
|
||||||
|
|
||||||
|
```
|
||||||
|
${CLAUDE_PLUGIN_ROOT}/skills/md-to-pdf/default.config.js
|
||||||
|
```
|
||||||
|
|
||||||
|
`CLAUDE_PLUGIN_ROOT` is provided by Claude Code at runtime and points to this plugin's root directory.
|
||||||
|
|
||||||
|
### 3. Run the converter
|
||||||
|
|
||||||
|
```bash
|
||||||
|
npx --yes md-to-pdf <source.md> --config-file <resolved-config>
|
||||||
|
```
|
||||||
|
|
||||||
|
The PDF is written next to the source (`Loesung.md` → `Loesung.pdf`), overwriting any existing file.
|
||||||
|
|
||||||
|
### 4. Confirm
|
||||||
|
|
||||||
|
Tell the user:
|
||||||
|
|
||||||
|
- The output PDF path and file size (`ls -la` style).
|
||||||
|
- Which config was used: project-local path, or "bundled default".
|
||||||
|
|
||||||
|
## Error Handling
|
||||||
|
|
||||||
|
- **`npx` / Node not on PATH** → tell the user Node.js is required and stop. Don't try to install it.
|
||||||
|
- **`md-to-pdf` fetch or render fails** → relay the npx output verbatim. Don't retry silently.
|
||||||
|
- **Source `.md` ambiguous** → ask, don't guess.
|
||||||
|
- **Config file is syntactically broken** → relay the error from md-to-pdf. Don't try to "fix" the user's config.
|
||||||
|
|
||||||
|
## Examples
|
||||||
|
|
||||||
|
### Project-local config
|
||||||
|
|
||||||
|
User: *"exportier mal das PDF"* (after editing `Uebungen/03/Loesung.md`)
|
||||||
|
|
||||||
|
Skill:
|
||||||
|
|
||||||
|
1. Source: `Uebungen/03/Loesung.md` (most recently edited).
|
||||||
|
2. Walks up; finds `.md-to-pdf.config.js` at the repo root.
|
||||||
|
3. Runs `npx --yes md-to-pdf Uebungen/03/Loesung.md --config-file .md-to-pdf.config.js`.
|
||||||
|
4. Reports: `Uebungen/03/Loesung.pdf (280K) — using project config .md-to-pdf.config.js`.
|
||||||
|
|
||||||
|
### Bundled default
|
||||||
|
|
||||||
|
User: *"convert this markdown to pdf"* (in a fresh directory with one `.md` file and no config).
|
||||||
|
|
||||||
|
Skill:
|
||||||
|
|
||||||
|
1. Source: `notes.md` (only `.md` in CWD).
|
||||||
|
2. Walks up; no `.md-to-pdf.config.js` found.
|
||||||
|
3. Runs `npx --yes md-to-pdf notes.md --config-file ${CLAUDE_PLUGIN_ROOT}/skills/md-to-pdf/default.config.js`.
|
||||||
|
4. Reports: `notes.pdf (62K) — using bundled default`.
|
||||||
Reference in New Issue
Block a user