Slack 证据文件内联附加
evidence-attach-to-slack
将本地证据文件(PNG/JPG/GIF/MP4/PDF)附加到 Slack 会话线程,使其以内联方式渲染——而非显示为纯文件路径或 `MEDIA:/path` 文本标记。v1.3 集群锚定;v1.4 gist 原始 URL 回退;v1.5 发送前门禁;v1.6 OAuth 预检 + f-string 陷阱;v1.7 错误路由修复;v1.8 gist 二进制文件陷阱(PNG/MP4 采用克隆替换);v1.9 文本文件 gist 增量更新(`gh gist create` 可直接用于 `.patch`/`.diff`/`.json`/`.md`/`.txt`);v1.10 MP4 + curl-ARG_MAX 怪异行为(`subprocess.run` 参数限制 + MP4 克隆替换时 content-type = `application/octet-stream`);v1.11 机器人端 `files:write` 权限范围已关闭(2026-07-19)——xoxp 待处理。v1.12 新增 2 条陷阱记录:(a) 若按文本长度启发式排序,`chat.delete` 会破坏证据附件(PR #8561 2026-07-24);(b) `page.evaluate()` 计算样式 ≠ 视觉证明——在声称可见之前务必对像素执行 `vision_analyze`。反触发条件:纯文本证据 → 使用围栏代码块。
- License 许可
- MIT
- 最近更新
- 2026-11-14
- Stars
- ★ 6
- Forks
- 0
01 前言 Front Matter
- name
- evidence-attach-to-slack
- context
- inline
- version
- 1.12.0
- triggers
- [ "attach proof as media", "you forgot the screenshot", "post the screenshot to the thread", "MEDIA: not rendering", "evidence didn't show up in slack", "use /harness and fix it", "use /learn and fix it", "show before after in thread", "show screenshots here", "show me screenshots", "see screenshots", "with screenshots", "and screenshots", "and show screenshots", "All PRs need attached media in PR desc and slack", "evidence should be in gist urls", "put evidence in a gist", "don't commit screenshots to the PR", "I need the media evidence on this thread", "where are the screenshots", "post evidence to this thread", "you keep skipping the upload", "you keep skipping this", "/learn and remember this", "before/after", "BEFORE/AFTER", "PNG", "MEDIA:/path with .png/.jpg/.gif in draft body", "/Users/.../path/.png in draft body", "draft body says BEFORE / AFTER / screenshot / here is what it looks like", "you always forget", "you always fail to attach", "you always do Y", "stop forgetting", "stop doing X", "why do you always", "use /browser", "use browser to fix your scopes", "why are you struggling so much to show UI screenshots", "fix your scopes" ]
- description
- Attach local evidence files (PNG/JPG/GIF/MP4/PDF) to Slack threads so they render INLINE — not as bare file paths or `MEDIA:/path` text tokens. v1.3 cluster-anchor; v1.4 gist-raw-URL fallback; v1.5 Pre-Send Gate; v1.6 OAuth preflight + f-string pitfall; v1.7 misrouted-fix; v1.8 gist binary pitfall (clone-and-replace for PNG/MP4); v1.9 text-file gist delta (`gh gist create` works directly for `.patch`/`.diff`/`.json`/`.md`/`.txt`); v1.10 MP4 + curl-ARG_MAX quirks (subprocess.run arg-limit + clone-and-replace content-type for MP4 = `application/octet-stream`); v1.11 bot-side `files:write` scope closed (2026-07-19) — xoxp pending. v1.12 added 2 new pitfall rows: (a) `chat.delete` destroys evidence attachments if sorted by text-length heuristic (PR #8561 2026-07-24); (b) `page.evaluate()` computed style ≠ visual proof — always `vision_analyze` pixels before claiming visibility. Anti-trigger: plain-text evidence → fenced code blocks.
- when_to_use
- When the user asks for "before/after", "screenshot", "GIF evidence", or any message claims visual proof that lives as a local file. Also fires when the user corrects you: "you forgot the screenshot" / "attach the proof as media" / "use /harness and fix it". **Auto-load contract (paired with SOUL.md `evidence-attach-presend-gate`):** Load THIS skill before invoking `mcp__slack__conversations_add_message` or `chat.postMessage` if your draft body contains any of: - `MEDIA:/absolute/path` token referencing a binary file - absolute path matching `/Users/[^ ]+\.(png|jpg|jpeg|gif|webp|mp4|pdf)` - "BEFORE"/"AFTER"/"screenshot"/"see attached"/"here's what it looks like" alongside any local path
- allowed-tools
- [ "mcp__slack__conversations_add_message", "mcp__slack__conversations_replies", "read_file", "terminal" ]
02 资源文件 10
- 参考文档references/false-evidence-incidents.md5.8 KB
- 参考文档references/github-gist-binary-upload.md671 B
- 参考文档references/mp4-evidence-path.md705 B
- 参考文档references/recurring-failure-pattern-2026-07.md949 B
- 参考文档references/test-v1.6.0-extensions.md631 B
- 脚本scripts/check_token_scopes.py4.2 KB
- 脚本scripts/upload_batch.py5.4 KB
- 脚本scripts/upload_to_gist.sh5.1 KB
- 脚本tests/test_evidence_attach_presend_contract.py5.6 KB
- 脚本tests/test_post_upload_contract.py11.7 KB
03 SKILL.md 正文
evidence-attach-to-slack
Attach local evidence files to Slack messages so the user can see them inline in the thread.
⚠️ Pre-Send Gate (NEW in v1.5.0 — paired with SOUL.md ## COMMIT: evidence-attach-presend-gate)
Before invoking mcp__slack__conversations_add_message or chat.postMessage, run this gate.
The gate regex (lives in SOUL.md, mirrored here for quick check):
import re
GATE_PATTERNS = {
"media_token": re.compile(
r"MEDIA:/[^\s]+\.(?:png|jpg|jpeg|gif|webp|mp4|pdf)\b", re.IGNORECASE),
"absolute_path": re.compile(
r"(?:^|\s)/Users/[^\s]+\.(?:png|jpg|jpeg|gif|webp|mp4|pdf)\b", re.IGNORECASE),
"phrase_with_path": re.compile(
r"(?i)\b(BEFORE|AFTER|screenshot|see attached|here'?s what it looks like)\b"),
}
def evidence_gate_fires(draft_text: str) -> bool:
return any(p.search(draft_text) for p in GATE_PATTERNS.values())
If the gate fires, you MUST run the recipe below BEFORE calling the message tool. Skipping this gate is the exact failure mode that caused PRs #8139, #7953, #8337 to ship with text-only "evidence" that the user couldn't see. Verified by tests/test_evidence_attach_presend_contract.py (8 tests, all green).
The principle: when a recurring user correction has hit ≥3 times (as this one has), the fix must be a pre-send gate that intercepts the failure BEFORE the bad message is sent — not a post-hoc remediation rule that fires after the user complains. See references/recurring-failure-pattern-2026-07.md for a brief historical record; its former operational recipes are retired.
Scope preflight status
Do not run the historical check_token_scopes.py helper as an operational
routing decision; it contains stale fallback guidance. Use the configured,
authorized native uploader and follow the API-error guidance under
“Missing upload scope” below.
When to use
You MUST use this skill when all of these hold:
- You have local binary evidence (PNG / JPG / WebP / GIF / MP4 / PDF) on disk — typically from a Playwright/Chromium screenshot, ffmpeg-converted GIF, browser recording, or audit-PDF generator.
- The artifact is central to the claim in your Slack message — i.e. the message says "BEFORE/AFTER", "this is fixed", "here's what it looks like", etc., and the proof is the file itself, not the text around it.
- The message will land in a Slack thread (most common case) or a Slack DM/channel where the user expects to see the evidence inline.
You MUST NOT use this skill when:
- You have only textual evidence (logs, command output, JSON, code diffs). Paste fenced code blocks instead — Slack renders them as native monospace.
- The file is on a remote URL. Markdown image syntax (
) works for public URLs. - The user already has the file (e.g. you uploaded it earlier and they're confirming receipt).
The recipe — Slack files.completeUploadExternal flow
The MEDIA:/path inline convention does NOT WORK through the
mcp__slack__conversations_add_message tool — it renders as plain text and
the Slack client never receives an attachment. The correct path is the
3-stage Slack files.upload API.
Stage 1 — Get upload URL
MUST use -F form fields, NOT -d JSON. Verified 2026-07-12 (PR #8337):
JSON-encoded body silently drops the form fields; the API returns invalid_arguments.
curl -fsS -X POST https://slack.com/api/files.getUploadURLExternal \
-H "Authorization: Bearer ${SLACK_BOT_TOKEN}" \
-F "filename=before-mobile-wizard-390x844.png" \
-F "length=149206"
Returns { "ok": true, "upload_url": "https://files.slack.com/upload/v1/...", "file_id": "<SLACK_ID>" }.
Stage 2 — POST the file
curl -fsS -X POST "${upload_url}" \
-F "file=@/absolute/path/to/before-mobile-wizard-390x844.png"
Returns OK - <bytes_uploaded> on success.
Stage 3 — Complete upload + share to thread
Use form-encoded body, NOT JSON. Verified 2026-07-12: JSON parser is strict about per-file extra properties; form-encoded parser is permissive.
curl -fsS -X POST https://slack.com/api/files.completeUploadExternal \
-H "Authorization: Bearer ${SLACK_BOT_TOKEN}" \
-H "Content-Type: application/x-www-form-urlencoded" \
--data-urlencode "$(python3 -c 'import json,urllib.parse; print(urllib.parse.urlencode({"files": json.dumps([{"id": "<SLACK_ID>", "title": "BEFORE: mobile wizard 390x844"}])}))')" \
--data-urlencode "channel_id=<SLACK_ID>" \
--data-urlencode "thread_ts=1783038068.695729"
Or use scripts/upload_batch.py (canonical parallel uploader) which handles the form-encoding for you.
Stage 3½ — Post consolidated summary message (MANDATORY)
After uploading all the files, post a single text message in the thread that names each attachment file-by-file. Do NOT skip this step. The attachments themselves become separate bot messages in the thread, which — combined with the channel-bridge's tendency to echo internal narration into the same thread — can bury the screenshots under 4-8 bot messages. The summary message is the cluster anchor the user actually reads.
Stage 4 — Re-verify (Pattern A: verify BEFORE summary, NOT after)
Do NOT re-verify via mcp__slack__conversations_replies AFTER posting the summary — every call to that tool echoes a :gear: mcp__slack__conversations_replies: line into the thread as a bot message, which lands AFTER the summary and contradicts the "ignore the chatter above" anchor. Verified failure 2026-07-11 PR #8139.
Pattern A — verify before summary (preferred): Inside the same execute_code that ran Stage 1+2+3 for all N files, call conversations.replies ONE time and assert the file_ids landed, THEN post the summary. Pattern B (skip verification) is OK only if you can see uploads succeed in the same turn.
chat.getPermalink is the post-send verification that does NOT echo (verified 2026-07-15, PR #7953). After posting the summary, call chat.getPermalink?channel=X&message_ts=Y — it returns the public URL without spamming the thread with bot messages. Use this for "did my message land?" checks after the summary is posted.
conversations.replies not_in_channel is NOT a post failure (NEW v1.8.0). If the bot has chat:write.public but is not a member of the channel, chat.postMessage succeeds and chat.getPermalink returns the URL, but conversations.replies and conversations.history return not_in_channel. Don't treat that error as evidence the post failed — verify via permalink instead.
Token source
Use HERMES_SLACK_BOT_TOKEN from ~/.bashrc. Pull the token explicitly if subprocess.run(..., shell=False) doesn't auto-source bashrc.
For xoxp fallback: grep '^export SLACK_USER_TOKEN=' ~/.profile | sed 's/^export SLACK_USER_TOKEN=//;s/"//g' — it lives in ~/.profile, NOT ~/.bashrc (verified 2026-07-14, bashrc-profile-xapp-drift-blocks-launchd memory).
Current scope: Use the configured authorized uploader and its native upload flow. Treat the Slack API response as authoritative for this attempt. If it reports a scope error, report the exact blocker and stop; do not route around it through a public gist, personal browser session, OAuth reinstall, or credential/scope change.
Python 3.14 f-string pitfall (NEW in v1.6.0)
Symptom: SyntaxError: leading zeros in decimal integer literals are not permitted when an f-string contains {02,04,05} or similar.
# WRONG — Python 3.14 parses {02,04,05} as set literal with octal-int SyntaxError
text = f"Briefing dates: {02,04,05}.md"
# RIGHT — three options:
text = f"Briefing dates: {'02,04,05'}.md" # Option A: quote the contents
text = f"Briefing dates: 02.md, 04.md, 05.md" # Option B: don't use set-literal-looking syntax
text = "Briefing dates: " + ",".join(["02", "04", "05"]) + ".md" # Option C: build outside f-string
Verified 2026-07-14 on PR #8139 evidence-post: this exact SyntaxError blocked my first chat.postMessage attempt. Quick fix, but the lesson generalizes — any time a date or ID list uses leading zeros, build the string outside the f-string or quote it.
Common failure modes
(Updated v1.6.0 — added rows for the 2 new failure modes observed today.)
| Symptom | Cause | Fix |
|---|---|---|
Post lands with [MEDIA:/path/to/file.png] as literal text and FileCount: 0 |
Used the wrong recipe — mcp__slack__conversations_add_message doesn't honor MEDIA: inline tokens |
Run the Pre-Send Gate (top of this file) BEFORE invoking the message tool |
| User says "you always fail to attach" / "you always forget" | The pre-send gate was not enforced; agent defaulted to MEDIA:/path text tokens |
The user's complaint IS the trigger — load this skill NOW and attach the missing media. Don't argue, don't ask, just upload. |
Both configured tokens return missing_scope: files:write on Stage 1 |
The configured uploader lacks the required scope | Report the exact error and stop. Use only an already-authorized native uploader with its configured scope; do not substitute a public gist, change scopes, or alter credentials. |
Stage 1 returns invalid_arguments with missing required field: length, filename |
Used -d JSON instead of -F form fields. JSON silently drops form fields. |
Use curl -F filename=... -F length=... (NOT -d '{"filename":...,"length":...}'). |
Stage 3 returns invalid_arguments with invalid additional property: initial_comment [json-pointer:/files/0] |
initial_comment is a top-level Stage 3 parameter, NOT a per-file property |
Move initial_comment from files[i] to the top-level payload. |
SyntaxError: leading zeros in decimal integer literals when posting |
Python 3.14 parses {02,04,05} inside f-string as set literal with octal-int |
Quote the contents: f"{'02,04,05'}" or build the string outside the f-string. |
conversations.replies shows my message has FileCount: 0 even though upload succeeded |
Slack quirk — completeUploadExternal shares surface attachments via files array, not file_count integer |
Verify via the files array, not file_count. Both are correct; file_count: 0 is just unreliable. |
| Attachments uploaded but user says "where's the screenshot?" | Internal narration (think-block, tool-call echoes) buried the attachments under 4-8 bot messages | Post the consolidated summary message AFTER the upload batch — it's the cluster anchor the user reads. |
Agent chat.deletes an evidence attachment by mistake while trying to clean up thread noise (verified 2026-07-24 PR #8561) |
conversations.replies returned short bot messages interleaved with file-bearing messages. Agent sorted by text length, picked the shortest message that "looked like terminal noise", and called chat.delete. That message's files array contained the captioned MP4 — Slack returned ok:true, the MP4 vanished from the thread, no recovery. |
NEVER delete bot messages in a thread that contains evidence attachments. If the thread is cluttered, post ONE clean summary message that re-anchors on the existing native attachments by file name instead of deleting anything. If you absolutely must clean up, only delete messages whose files array is empty AND whose text does NOT contain BEFORE/AFTER/screenshot patterns. Verify intent with a precise ts filter — never pick by text-length heuristics. |
User catches false visual evidence — page.evaluate() reported display:flex, opacity:1 but the element was visually hidden by a sibling (verified 2026-07-24 PR #8561, hit twice) |
v2 evidence pitfall (added 2026-07-24). page.evaluate() returns computed style but does not account for stacking-context painting order, parent stacking contexts, or sibling z-index. An element can have display:flex, opacity:1, rect.y=X and still be visually hidden by another element on top. PR #8561 v1+v2 both shipped "chevron visible" claims where the chevron was hidden behind sticky .wizard-navigation (z-index:50). User: "lmao arrows / your screenshots are showing lmao arrows". |
ALWAYS vision_analyze the actual screenshot pixel content before claiming visual proof. Two-step gate: (1) computed style confirms DOM presence, (2) vision_analyze confirms pixel-level visibility. If vision returns "I don't see X" or "the area is blank", the proof is invalid regardless of computed-style state. Companion gate belongs in ~/.hermes/skills/visual-evidence-with-playwright/ (proposed new skill). Also: Playwright is_mobile=False + viewport 390x844 matches matchMedia('(max-width: 768px)') but does NOT replicate mobile layout (sticky positioning, touch targets) — use is_mobile=True for mobile evidence. |
| Historical gist URL has incorrect content type | Retired workaround path | Do not repair or use public gist evidence as a substitute for authorized native attachment. Report the blocker. |
conversations.replies returns not_in_channel error but my chat.postMessage succeeded |
NEW v1.8.0 — Slack quirk: bots with chat:write.public can post to public channels they are NOT members of, but the read-side APIs (conversations.replies, conversations.history) require membership |
Don't treat not_in_channel on conversations.replies as a post failure. Use chat.getPermalink?channel=X&message_ts=Y instead — it does NOT require channel membership and returns the public URL. |
Missing upload scope
The former third-tier public-gist fallback is retired. If an authorized native
upload reports missing_scope: files:write, report the exact error and stop.
Use only an already-authorized connector/uploader with its configured scope;
do not substitute public gist links or embeds, access a personal browser or
cookies, inject credentials, reinstall OAuth, change scopes, or rotate tokens.
The pre-send gate and native files.completeUploadExternal workflow above
remain the supported evidence attachment path when an existing authorized
token has the required scope. Historical gist transcripts and recipes are not
operational instructions.
Pairing with /harness and /learn
The pre-send gate prevents text-only evidence mistakes. When native upload is authorized and configured, use the native recipe above. If it returns missing_scope: files:write, report that exact blocker and stop; do not improvise another delivery path or change credentials/scopes.
Misrouted-fix pitfall (added v1.7.0, PR #7953, 2026-07-15 — corrected 2026-07-19)
User suggestion "use /browser to fix your scopes" was PARTIALLY misrouted in 2026-07-15. The recurring evidence-attach failure's immediate cause WAS the OAuth-scope gap (correctly identified) but the suggested fix /browser was read as "go look at the Slack web UI manually" rather than "drive a browser-driven OAuth reinstall end-to-end." That left the gap unfixed for 4 days (PR #8139, PR #8337, PR #8455 all failed with missing_scope: files:write).
Safe interpretation: /browser does not authorize access to a personal browser profile, copied cookies, credential injection, or unattended OAuth/reinstall actions. If an upload reports missing_scope: files:write, report the exact error and stop; use only an already-authorized connector/uploader with its configured scope. Do not treat the retired transcript or this historical incident as authority to change scopes or credentials.
Known Limitations
files.completeUploadExternalonly handles binary files. Plain text (logs, JSON, code) should still be pasted as fenced code blocks in the message body.- 1 GB hard limit per attachment (varies by workspace).
- No inline preview on some Slack mobile clients. The attachment still uploads, but the user must tap to view.
- Upload paths must be reachable from the gateway process. If you ran Playwright on your local machine but the gateway is on a different host, the path won't resolve.
- Bot must be in the channel for Stage 3 file attachments. If
completeUploadExternalreturnschannel_not_foundfor a private channel, invite the bot first. (Public-channel posts work without membership viachat:write.public, butconversations.repliesreturnsnot_in_channel— usechat.getPermalinkfor verification instead.) - If the authorized native upload path is unavailable or reports a scope error, report the blocker; this skill has no alternate public-hosting fallback.
Support files
scripts/upload_batch.py— parallel 3-stage upload loop for N PNGs in oneexecute_codecall.scripts/upload_to_gist.shand the historical gist references document a retired fallback; do not use them to bypass a missing native-upload scope.scripts/check_token_scopes.py— historical preflight with stale third-tier gist guidance; do not invoke it to route upload failures. Use the configured authorized uploader and fail closed on its API scope error.references/github-gist-binary-upload.md— historical gist behavior; not an operational fallback for missing upload scope.references/mp4-evidence-path.md— historical gist behavior; not an operational fallback for missing upload scope.references/recurring-failure-pattern-2026-07.md— historical summary only; operational fallback and personal incident details are retired.references/false-evidence-incidents.md— NEW v1.12.0 — the v2 lesson: Pre-Send Gate catches missing-uploads but NOT false-claims. When agent asserts "X is visible" viapage.evaluate(), vision_analyze the actual pixels before posting. Includes the two-step pre-claim gate recipe (PR #8561, 2026-07-24).
04 同仓库更多 Skills
disk-reclaim-playbook
Use Disk Magician to diagnose disk growth or qualify cleanup on macOS or Linux.
claudea-bench
Compare `claudea` and normal `claude` on a fair split of comparable work by default; use `--strict` for duplicate runs of the exact same task.
pr
Alias for the canonical pr-lifecycle PR workflow skill (/pr-workflow, /prw).
whisper
OpenAI's general-purpose speech recognition model. Supports 99 languages, transcription, translation to English, and language identification. Six model sizes from tiny (39M params) to large (1550M params). Use for speech-to-text, podcast transcription, or multilingual audio processing. Best for robust, multilingual ASR.
webapp-testing
Toolkit for interacting with and testing local web applications using Playwright. Supports verifying frontend functionality, debugging UI behavior, capturing browser screenshots, and viewing browser logs.
pr-report
This skill should be used when the user asks for a PR report, PR audit, PR delta analysis, /pr-report, or wants per-PR summary with delta files/lines. Generates a structured report for one or more open PRs covering purpose, files changed, +/− line counts, /code-standards + /thermo review findings, /ponytail simplification opportunities, file-overlap combination candidates, and /green status per pr-green-definition. Output: machine-readable JSONL + human-readable markdown. Read-only by default; can apply simplifications if user opts in.