Image Reference
Insert references to a specific image into a document so the media file lives
beside the document and is cited with a stable local relative link. This is the
AI-equivalent of the nvim Markdown <Leader>mi "paste media" keybinding: same
assets-directory layout, same filename and collision rules.
Goals
- Put every referenced image in a per-document assets directory next to the doc.
- Reuse the exact nvim naming convention (
<basename>.assets/, basename kept,
-1/-2 on collision) so the layout is consistent with the user's editor.
- When a source name is missing or meaningless (chat attachment,
pasted-image.png,
Screen Shot 2024-01-01 at 3.42.12 PM.png, IMG_9527.heic, a temp path with
random characters), derive a clean, descriptive name from the image content /
subject, not its filename.
- Insert the correct Markdown image reference at the requested location.
The nvim convention (mirror these rules exactly)
For a document at docs/implementation.md:
- Assets directory: name it
implementation.assets/ and place it in the same
folder as the document. (docs/implementation.md → docs/implementation.assets/).
General rule: take the document filename without extension and append .assets.
- Filename: keep the source file's basename when it is already clean and
meaningful (a lowercase slug like
mobile-arch.png stays mobile-arch.png;
MyDiagram.v2.png stays as-is if it reads fine).
- Extension: preserve the original extension (case-insensitive). Normalize the
saved filename so spaces/punctuation/weird characters are not carried over when
you pick a content-based name.
- Collision: if the target name already exists in the assets dir but holds
different bytes, rename to
<stem>-1, <stem>-2, ... until free
(e.g. mobile-arch.png → mobile-arch-1.png). If the existing file is
byte-identical, reuse it — never create a duplicate.
- Link: reference the image with a path relative to the document:
.
The alt text should describe the image subject, not the filename.
Example result for docs/implementation.md, source My Mobile Arch!!.PNG:
docs/
└── implementation.md
└── implementation.assets/
└── my-mobile-arch.png
And in the document:

Naming the file (the most important judgment call)
This is where you do the real work. Rules, in priority order:
- If the user gave an explicit, clean name for the image, use it verbatim
(slugified).
- If the source basename is already clean and descriptive (e.g.
mobile-arch.png,
auth-flow.jpg, redis-cache.svg) — keep it. Do not rename an existing
meaningful name.
- Otherwise (chat attachment, generic
image.png, pasted-image-<random>.png,
Screen Shot ..., IMG_xxxx, a /tmp/... temp path, or any name not
descriptive) — derive a name from the image's content/subject:
- Look at what the image actually depicts: an architecture diagram, a login form,
a chart, a table, a photo, a logo.
- Summarize it in 2–4 English words, lowercase, joined by a single hyphen
(
-), ASCII letters and digits only.
- Examples:
mobile-arch.png, redis-cache-flow.svg, auth-login-form.png,
q1-revenue-chart.jpg, unified-search-ui.png, ci-pipeline-diagram.png.
- If you genuinely cannot tell what the image is (no vision available), fall back
to a generic but stable name like
image-<n>.png and tell the user, then offer
to rename it once they describe it.
Never use consecutive hyphens, leading/trailing hyphens, spaces, or non-ASCII
characters in the final filename.
Workflow
Follow these steps in order.
1. Resolve the target document
- The user may name a file (
implementation.md) or point at the doc they are editing.
- If none is given and you are already editing a document, use that document.
- The document must have a real filesystem path. If the document is new/unsaved
or the path is unknown, save it first (or ask for the path) so the assets dir can
live next to it. Never create the
.assets/ folder in an arbitrary location.
2. Resolve the source image
The source is one of:
- A path the user typed (absolute, relative,
~, or a file:// URL). Normalize
it and confirm the file exists and is an image.
- An image dropped / pasted into the chat. Locate the actual bytes:
- If the tool exposed a path for the attachment, read from that path.
- If only in-context pixels are available (no writable file), save the image to the
unified cache directory first
(
<user-cache>/mythril-skills-cache/image-reference/<random>/), then copy it into
the assets dir from there. Never invent a path that does not exist.
3. Copy into the assets directory
Compute everything deterministically — you can and should use the bundled helper
script so the rules are exact:
python3 scripts/image_assets.py assets-dir docs/implementation.md
python3 scripts/image_assets.py slug-filter "My Mobile Arch!!.PNG"
python3 scripts/image_assets.py unique docs/implementation.assets "my-mobile-arch.png" /path/to/source.png
python3 scripts/image_assets.py rel-link docs/implementation.md my-mobile-arch.png
python3 scripts/image_assets.py md-link implementation.assets/my-mobile-arch.png "Mobile app architecture"
Steps (mirror the nvim logic exactly):
assets_dir = assets-dir <md_path> and mkdir -p it.
- Decide the desired filename (see "Naming the file").
dst = unique <assets_dir> <desired> <src> — this reuses byte-identical files
and adds -1/-2 on conflicts.
- If
dst already exists and holds identical bytes, skip the copy. Otherwise copy
the source bytes to dst.
rel = rel-link <md_path> <dst.name>.
- Insert
md-link <rel> <alt> at the requested spot (start of a new line, or right
after the sentence/paragraph the user wants the image to accompany). Use a
descriptive, image-content-based alt text. For GIFs that animate meaningfully,
you may keep the  form; no special syntax is required.
The helper is deterministic, but deciding the content-based name is yours — pick
it from what the image shows before you sanitize it.
4. Report
Tell the user concisely:
- the absolute path of the copied asset,
- the exact Markdown reference you inserted,
- the relative path used, and
- if you renamed the file (generic/messy → content-based), say so and note they can
rename it later — the link updates automatically since you reuse the same stem.
Rules & edge cases
- Never duplicate. If the identical bytes already exist in the assets dir, reuse
the existing file and reference it.
- Never touch the source. Copy, never move or delete the original unless the user
explicitly asks.
- Not just Markdown. The
<stem>.assets/ rule generalizes to other text docs; but
Markdown is the primary target and the link syntax below is Markdown. For non-Markdown
docs, produce whatever relative-reference syntax that format uses and note it.
- Only copy real images. If the path is not an existing image file (or you cannot
obtain bytes), stop and ask rather than guessing.
- Don't fabricate byte-identity: read actual bytes, never assume.
- If the user is referencing images in an existing doc that already has an
established assets directory with a different name, prefer the document's existing
convention over creating a new one.
1---2name: image-reference3description: Reference a specific image in a document, copying the source into an assets directory next to the document (named after the doc, e.g. `guide.assets/`) and inserting the correct Markdown image link — mirroring the nvim markdown paste-image workflow. Trigger whenever the user asks to insert, embed, paste, add, or reference an image/file in a document — e.g. one dropped into the chat, pasted, or given as a path. Example phrases: "把这个图加进文档", "把截图 放进 README", "put this image in the doc", "insert screenshot.png", "embed the diagram in implementation.md", "引用这张图", "在这篇文章里加一张架构图". Use it whenever a user wants an image to live alongside a specific document and be cited with a local relative link. When the source has no name or a messy auto-generated name, derive a clean content-based slug filename (lowercase ASCII letters/digits + hyphens, e.g. `mobile-arch.png`).4license: Apache-2.05---67# Image Reference89Insert references to a specific image into a document so the media file lives10*beside* the document and is cited with a stable local relative link. This is the11AI-equivalent of the nvim Markdown `<Leader>mi` "paste media" keybinding: same12assets-directory layout, same filename and collision rules.1314## Goals1516- Put every referenced image in a per-document assets directory next to the doc.17- Reuse the exact nvim naming convention (`<basename>.assets/`, basename kept,18 `-1`/`-2` on collision) so the layout is consistent with the user's editor.19- When a source name is missing or meaningless (chat attachment, `pasted-image.png`,20 `Screen Shot 2024-01-01 at 3.42.12 PM.png`, `IMG_9527.heic`, a temp path with21 random characters), derive a clean, descriptive name from the image **content /22 subject**, not its filename.23- Insert the correct Markdown image reference at the requested location.2425## The nvim convention (mirror these rules exactly)2627For a document at `docs/implementation.md`:28291. **Assets directory**: name it `implementation.assets/` and place it in the same30 folder as the document. (`docs/implementation.md` → `docs/implementation.assets/`).31 General rule: take the document filename *without extension* and append `.assets`.322. **Filename**: keep the source file's basename when it is already clean and33 meaningful (a lowercase slug like `mobile-arch.png` stays `mobile-arch.png`;34 `MyDiagram.v2.png` stays as-is if it reads fine).353. **Extension**: preserve the original extension (case-insensitive). Normalize the36 saved filename so spaces/punctuation/weird characters are not carried over when37 you pick a content-based name.384. **Collision**: if the target name already exists in the assets dir but holds39 *different* bytes, rename to `<stem>-1`, `<stem>-2`, ... until free40 (e.g. `mobile-arch.png` → `mobile-arch-1.png`). If the existing file is41 **byte-identical**, reuse it — never create a duplicate.425. **Link**: reference the image with a path relative to the document:43 ``.44 The alt text should describe the image subject, not the filename.4546Example result for `docs/implementation.md`, source `My Mobile Arch!!.PNG`:4748```text49docs/50└── implementation.md51└── implementation.assets/52 └── my-mobile-arch.png53```5455And in the document:5657```markdown5859```6061## Naming the file (the most important judgment call)6263This is where you do the real work. Rules, in priority order:64651. If the user gave an explicit, clean name for the image, use it verbatim66 (slugified).672. If the source basename is already clean and descriptive (e.g. `mobile-arch.png`,68 `auth-flow.jpg`, `redis-cache.svg`) — **keep it**. Do not rename an existing69 meaningful name.703. Otherwise (chat attachment, generic `image.png`, `pasted-image-<random>.png`,71 `Screen Shot ...`, `IMG_xxxx`, a `/tmp/...` temp path, or any name not72 descriptive) — **derive a name from the image's content/subject**:73 - Look at what the image actually depicts: an architecture diagram, a login form,74 a chart, a table, a photo, a logo.75 - Summarize it in 2–4 English words, lowercase, joined by a single hyphen76 (`-`), ASCII letters and digits only.77 - Examples: `mobile-arch.png`, `redis-cache-flow.svg`, `auth-login-form.png`,78 `q1-revenue-chart.jpg`, `unified-search-ui.png`, `ci-pipeline-diagram.png`.79 - If you genuinely cannot tell what the image is (no vision available), fall back80 to a generic but stable name like `image-<n>.png` and tell the user, then offer81 to rename it once they describe it.8283Never use consecutive hyphens, leading/trailing hyphens, spaces, or non-ASCII84characters in the final filename.8586## Workflow8788Follow these steps in order.8990### 1. Resolve the target document9192- The user may name a file (`implementation.md`) or point at the doc they are editing.93- If none is given and you are already editing a document, use that document.94- **The document must have a real filesystem path.** If the document is new/unsaved95 or the path is unknown, save it first (or ask for the path) so the assets dir can96 live next to it. Never create the `.assets/` folder in an arbitrary location.9798### 2. Resolve the source image99100The source is one of:101102- **A path the user typed** (absolute, relative, `~`, or a `file://` URL). Normalize103 it and confirm the file exists and is an image.104- **An image dropped / pasted into the chat.** Locate the actual bytes:105 - If the tool exposed a path for the attachment, read from that path.106 - If only in-context pixels are available (no writable file), save the image to the107 unified cache directory first108 (`<user-cache>/mythril-skills-cache/image-reference/<random>/`), then copy it into109 the assets dir from there. Never invent a path that does not exist.110111### 3. Copy into the assets directory112113Compute everything deterministically — you can and should use the bundled helper114script so the rules are exact:115116```bash117python3 scripts/image_assets.py assets-dir docs/implementation.md118python3 scripts/image_assets.py slug-filter "My Mobile Arch!!.PNG"119python3 scripts/image_assets.py unique docs/implementation.assets "my-mobile-arch.png" /path/to/source.png120python3 scripts/image_assets.py rel-link docs/implementation.md my-mobile-arch.png121python3 scripts/image_assets.py md-link implementation.assets/my-mobile-arch.png "Mobile app architecture"122```123124Steps (mirror the nvim logic exactly):1251261. `assets_dir = assets-dir <md_path>` and `mkdir -p` it.1272. Decide the desired filename (see "Naming the file").1283. `dst = unique <assets_dir> <desired> <src>` — this reuses byte-identical files129 and adds `-1`/`-2` on conflicts.1304. If `dst` already exists and holds identical bytes, skip the copy. Otherwise copy131 the source bytes to `dst`.1325. `rel = rel-link <md_path> <dst.name>`.1336. Insert `md-link <rel> <alt>` at the requested spot (start of a new line, or right134 after the sentence/paragraph the user wants the image to accompany). Use a135 descriptive, image-content-based alt text. For GIFs that animate meaningfully,136 you may keep the `` form; no special syntax is required.137138The helper is deterministic, but **deciding the content-based name is yours** — pick139it from what the image shows before you sanitize it.140141### 4. Report142143Tell the user concisely:144145- the absolute path of the copied asset,146- the exact Markdown reference you inserted,147- the relative path used, and148- if you renamed the file (generic/messy → content-based), say so and note they can149 rename it later — the link updates automatically since you reuse the same stem.150151## Rules & edge cases152153- **Never duplicate.** If the identical bytes already exist in the assets dir, reuse154 the existing file and reference it.155- **Never touch the source.** Copy, never move or delete the original unless the user156 explicitly asks.157- **Not just Markdown.** The `<stem>.assets/` rule generalizes to other text docs; but158 Markdown is the primary target and the link syntax below is Markdown. For non-Markdown159 docs, produce whatever relative-reference syntax that format uses and note it.160- **Only copy real images.** If the path is not an existing image file (or you cannot161 obtain bytes), stop and ask rather than guessing.162- **Don't fabricate** byte-identity: read actual bytes, never assume.163- If the user is referencing images in an existing doc that already has an164 established assets directory with a different name, prefer the document's existing165 convention over creating a new one.