|
| 1 | +--- |
| 2 | +name: github-to-markdown |
| 3 | +description: Converts a GitHub repository, directory, or file into a single markdown document using 2md. Use when asked to convert a repo to markdown, flatten GitHub code into one file, dump a repo for an LLM, bundle source for a prompt, snapshot GitHub code, or use 2md. |
| 4 | +license: MIT |
| 5 | +compatibility: Requires internet access and either curl or Bun/Node.js for the optional CLI path |
| 6 | +metadata: |
| 7 | + author: github.com/o-az |
| 8 | + version: "1.0.0" |
| 9 | +--- |
| 10 | + |
| 11 | +# github-to-markdown |
| 12 | + |
| 13 | +Use [2md](https://github.com/o-az/2md) to turn a GitHub repository, subdirectory, or single file into one markdown document. |
| 14 | + |
| 15 | +## When to auto-trigger |
| 16 | + |
| 17 | +- The user wants a GitHub repo converted into one markdown file. |
| 18 | +- The user wants to feed a repo, folder, or file into an LLM or prompt as a single document. |
| 19 | +- The user asks to flatten, concatenate, dump, bundle, snapshot, or export GitHub code into markdown. |
| 20 | +- The user wants a specific GitHub repo, directory, file, or filtered subset bundled into markdown. |
| 21 | +- The user wants to include or exclude files while generating the markdown bundle. |
| 22 | +- The user asks to use 2md or wants a rerunnable 2md command. |
| 23 | +- Do not use this skill for local non-GitHub directories unless the user explicitly wants GitHub-hosted input. |
| 24 | +- Do not use this skill for generic web scraping or for converting markdown into some other format. |
| 25 | + |
| 26 | +## Requirements |
| 27 | + |
| 28 | +- Network access to `https://2md.sauce.wiki` |
| 29 | +- Either: |
| 30 | + - `curl`, or |
| 31 | + - Bun with `bunx`, or |
| 32 | + - Node.js with `npx --yes` as a fallback when `bunx` is unavailable |
| 33 | + |
| 34 | +## Inputs |
| 35 | + |
| 36 | +Accepted source forms: |
| 37 | + |
| 38 | +- Full GitHub repo URL: `https://github.com/owner/repo` |
| 39 | +- Repo shorthand: `owner/repo` |
| 40 | +- Directory URL: `https://github.com/owner/repo/tree/<ref>/path/to/dir` |
| 41 | +- File URL: `https://github.com/owner/repo/blob/<ref>/README.md` |
| 42 | +- Path shorthand accepted by the CLI: |
| 43 | + - `owner/repo/path/to/dir` |
| 44 | + - `owner/repo/README.md` |
| 45 | + |
| 46 | +Optional query params: |
| 47 | + |
| 48 | +- `include=.ts` |
| 49 | +- `include=.tsx` |
| 50 | +- `exclude=.test.ts` |
| 51 | +- `exclude=dist/` |
| 52 | +- `submodules=true` |
| 53 | + |
| 54 | +Supported filter pattern styles: |
| 55 | + |
| 56 | +- suffix match like `.test.ts` |
| 57 | +- directory match like `src/` |
| 58 | +- glob match like `*.test.*` |
| 59 | +- contains match like `test` |
| 60 | + |
| 61 | +## Instructions |
| 62 | + |
| 63 | +### 1. Normalize the target |
| 64 | + |
| 65 | +First classify the request as one of these target types: |
| 66 | + |
| 67 | +- repo |
| 68 | +- directory |
| 69 | +- file |
| 70 | +- filtered subset of a repo |
| 71 | + |
| 72 | +If the user gives repo shorthand or owner/repo/path shorthand, convert it into one of these 2md target path forms: |
| 73 | + |
| 74 | +- repo: `github.com/owner/repo` |
| 75 | +- directory: `github.com/owner/repo/tree/<ref>/path/to/dir` |
| 76 | +- file: `github.com/owner/repo/blob/<ref>/path/to/file` |
| 77 | + |
| 78 | +Rules: |
| 79 | + |
| 80 | +- Preserve the branch or ref from the user input whenever it is present. |
| 81 | +- Do not invent `main` unless you have verified that it is the intended ref. |
| 82 | +- Do not widen scope. If the user asked for a file or directory, do not silently bundle the whole repo. |
| 83 | +- Treat “specific set of files” as a filtered repo or filtered directory request using `include` and `exclude` params. |
| 84 | +- If the user gives a local path like `./src` or `/tmp/project`, this skill is usually not the right tool. |
| 85 | + |
| 86 | +### 2. Prefer the hosted HTTP endpoint |
| 87 | + |
| 88 | +For direct retrieval, use the 2md endpoint: |
| 89 | + |
| 90 | +```bash |
| 91 | +curl --silent --show-error --fail-with-body --location "https://2md.sauce.wiki/github.com/owner/repo" |
| 92 | +``` |
| 93 | + |
| 94 | +Directory example: |
| 95 | + |
| 96 | +```bash |
| 97 | +curl --silent --show-error --fail-with-body --location "https://2md.sauce.wiki/github.com/owner/repo/tree/<ref>/src" |
| 98 | +``` |
| 99 | + |
| 100 | +File example: |
| 101 | + |
| 102 | +```bash |
| 103 | +curl --silent --show-error --fail-with-body --location "https://2md.sauce.wiki/github.com/owner/repo/blob/<ref>/README.md" |
| 104 | +``` |
| 105 | + |
| 106 | +With filters: |
| 107 | + |
| 108 | +```bash |
| 109 | +curl --silent --show-error --fail-with-body --location "https://2md.sauce.wiki/github.com/owner/repo?include=.ts&exclude=.test.ts" |
| 110 | +``` |
| 111 | + |
| 112 | +With submodules: |
| 113 | + |
| 114 | +```bash |
| 115 | +curl --silent --show-error --fail-with-body --location "https://2md.sauce.wiki/github.com/owner/repo?submodules=true" |
| 116 | +``` |
| 117 | + |
| 118 | +When the user wants a saved artifact, write the response to a local file: |
| 119 | + |
| 120 | +```bash |
| 121 | +curl --silent --show-error --fail-with-body --location "https://2md.sauce.wiki/github.com/owner/repo" -o repo.md |
| 122 | +``` |
| 123 | + |
| 124 | +If 2md returns an HTTP error, surface the status and response body instead of guessing. Prefer `--fail-with-body` so HTTP failures do not get treated as successful markdown output. Common failures include private repos, nonexistent repos, bad paths, rate limits, timeouts, and other upstream fetch failures. |
| 125 | + |
| 126 | +### 3. Use the CLI when it is a better fit |
| 127 | + |
| 128 | +Use the CLI when the user explicitly wants a command they can rerun locally. |
| 129 | + |
| 130 | +Prefer `bunx` first. If `bunx` is unavailable, fall back to `npx --yes`. |
| 131 | + |
| 132 | +Preferred examples: |
| 133 | + |
| 134 | +```bash |
| 135 | +bunx github:o-az/2md o-az/2md > repo.md |
| 136 | +bunx github:o-az/2md o-az/sandbox/src > src.md |
| 137 | +bunx github:o-az/2md https://github.com/honojs/hono/blob/main/README.md > README.bundle.md |
| 138 | +``` |
| 139 | + |
| 140 | +Fallback examples: |
| 141 | + |
| 142 | +```bash |
| 143 | +npx --yes github:o-az/2md o-az/2md > repo.md |
| 144 | +npx --yes github:o-az/2md o-az/sandbox/src > src.md |
| 145 | +npx --yes github:o-az/2md https://github.com/honojs/hono/blob/main/README.md > README.bundle.md |
| 146 | +``` |
| 147 | + |
| 148 | +The CLI also accepts full GitHub URLs. |
| 149 | + |
| 150 | +### 4. Choose filters carefully |
| 151 | + |
| 152 | +When the user wants a smaller bundle for LLM context, prefer targeted `include` and `exclude` params. |
| 153 | + |
| 154 | +Use filters to narrow scope, not to broaden it. |
| 155 | + |
| 156 | +Examples: |
| 157 | + |
| 158 | +- TypeScript only: |
| 159 | + |
| 160 | + ```text |
| 161 | + ?include=.ts&include=.tsx |
| 162 | + ``` |
| 163 | + |
| 164 | +- Exclude tests: |
| 165 | + |
| 166 | + ```text |
| 167 | + ?exclude=.test.ts&exclude=.spec.ts |
| 168 | + ``` |
| 169 | + |
| 170 | +- Include source, exclude tests: |
| 171 | + |
| 172 | + ```text |
| 173 | + ?include=src&exclude=*.test.ts |
| 174 | + ``` |
| 175 | + |
| 176 | +- Filter a specific directory instead of the whole repo: |
| 177 | + |
| 178 | + ```text |
| 179 | + https://2md.sauce.wiki/github.com/owner/repo/tree/<ref>/src?include=.ts&exclude=.test.ts |
| 180 | + ``` |
| 181 | + |
| 182 | +If the requested bundle could become very large, warn the user and suggest `include` and `exclude` filters before returning a huge inline response. |
| 183 | + |
| 184 | +### 5. Return the right thing |
| 185 | + |
| 186 | +- If the user asked you to do the conversion and save an artifact, execute it and report the exact output file path. |
| 187 | +- If the user asked for a rerunnable workflow, return the exact 2md URL, CLI command, or both. |
| 188 | +- If the user asked for the markdown content itself, return the generated markdown or the specific excerpt they asked for. |
| 189 | +- If the generated markdown is too large to return comfortably inline, say so and offer to save it to a file or narrow it with filters. |
| 190 | + |
| 191 | +## Agent checklist |
| 192 | + |
| 193 | +1. Classify the target as repo, directory, file, or filtered subset. |
| 194 | +2. Preserve the branch or ref from the input. |
| 195 | +3. Prefer the hosted endpoint unless the user asked for a rerunnable CLI command. |
| 196 | +4. Do not widen scope. |
| 197 | +5. Use filters only to narrow scope. |
| 198 | +6. Report the exact output file path when saving locally. |
| 199 | +7. On failure, report the HTTP status and response body instead of fabricating output. |
| 200 | + |
| 201 | +## Quick reference |
| 202 | + |
| 203 | +Show a whole repo as markdown: |
| 204 | + |
| 205 | +```bash |
| 206 | +curl --silent --show-error --fail-with-body --location "https://2md.sauce.wiki/github.com/o-az/2md" |
| 207 | +``` |
| 208 | + |
| 209 | +Show a subdirectory as markdown: |
| 210 | + |
| 211 | +```bash |
| 212 | +curl --silent --show-error --fail-with-body --location "https://2md.sauce.wiki/github.com/o-az/2md/tree/main/scripts" |
| 213 | +``` |
| 214 | + |
| 215 | +Show a single file as markdown: |
| 216 | + |
| 217 | +```bash |
| 218 | +curl --silent --show-error --fail-with-body --location "https://2md.sauce.wiki/github.com/o-az/2md/blob/main/bunfig.toml" |
| 219 | +``` |
| 220 | + |
| 221 | +Show a smaller LLM-focused bundle: |
| 222 | + |
| 223 | +```bash |
| 224 | +curl --silent --show-error --fail-with-body --location "https://2md.sauce.wiki/github.com/o-az/2md?include=.tsx&include=.mjs" |
| 225 | +``` |
| 226 | + |
| 227 | +Save a whole repo locally: |
| 228 | + |
| 229 | +```bash |
| 230 | +curl --silent --show-error --fail-with-body --location "https://2md.sauce.wiki/github.com/o-az/2md" -o o-az-2md.md |
| 231 | +``` |
| 232 | + |
| 233 | +Save a subdirectory locally: |
| 234 | + |
| 235 | +```bash |
| 236 | +curl --silent --show-error --fail-with-body --location "https://2md.sauce.wiki/github.com/o-az/2md/tree/main/scripts" -o o-az-2md-scripts.md |
| 237 | +``` |
| 238 | + |
| 239 | +Save a single file locally: |
| 240 | + |
| 241 | +```bash |
| 242 | +curl --silent --show-error --fail-with-body --location "https://2md.sauce.wiki/github.com/o-az/2md/blob/main/bunfig.toml" -o o-az-2md-bunfig-toml.md |
| 243 | +``` |
0 commit comments