---
name: gist-publish
description: Publish a local file (typically HTML) as a public GitHub gist and return a gistpreview URL the user can share. Use when the user asks to publish, share, or create a viewable public link for a file — phrases like "опубликуй этот файл", "publish this", "share this html", "сделай ссылку на этот файл", "создай gist".
---

# gist-publish

Publish a file as a public GitHub gist via the `gh` CLI, then return both the raw gist URL and a `gistpreview.github.io` URL that renders HTML directly.

## Prerequisites

The `gh` CLI must be installed and authenticated. If not:

```
brew install gh
gh auth login
```

If `gh` is missing or `gh auth status` fails, stop and tell the user to run those two commands first. Don't try to work around it.

## Steps

1. Confirm the file path the user wants to publish. If ambiguous, ask.
2. Verify the file exists and check its size with `ls -la <path>`. Warn if >5 MB (gist hard limit is ~1 MB per file for the web preview to work reliably; gist itself accepts up to ~10 MB but rendering may fail).
3. Decide the gist filename:
   - HTML files → use `index.html` so `gistpreview.github.io` renders them as HTML.
   - Other files → use the original basename.
4. Create the gist:
   ```
   gh gist create --public --filename <gist-filename> "<source-path>"
   ```
   `gh` prints the gist URL to stdout (form: `https://gist.github.com/<user>/<hash>`).
5. Extract `<hash>` (the last path segment).
6. Reply with two links:
   - **Gist:** the original `https://gist.github.com/...` URL
   - **Preview:** `https://gistpreview.github.io/?<hash>`

   For non-HTML files, the gist URL alone is enough — preview won't render them meaningfully.

## Notes

- The gist is **public** by default. If the user wants private/secret, use `gh gist create` without `--public` (default is secret) and warn that gistpreview won't work for secret gists — they'd need to share the raw URL directly.
- Edits to the gist (`gh gist edit <id> <file>`) propagate automatically — the preview URL keeps working.
- If the user wants the file's actual filename preserved in the gist (not renamed to `index.html`), ask before renaming.
